Class: RubyHDL::High::Print

Inherits:
Statement show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of a hardware print statement.

Instance Method Summary collapse

Methods inherited from Statement

#each_statement, #each_statement_deep

Constructor Details

#initialize(sequencer, *args) ⇒ Print

Create a new hprint statement in sequencer +sequencer+ for displaying +args+.



2986
2987
2988
2989
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2986

def initialize(sequencer,*args)
  @sequencer = sequencer
  @arguments = args
end

Instance Method Details

#to_cObject

Convert to C code.



3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3007

def to_c
  return "" if @arguments.empty?
  # Create the format.
  format = @arguments.each do |arg|
    if arg.is_a?(Expression) then
      arg.type.signed? ? "%lld" : "%llu"
    else
      "%s"
    end
  end.join
  return "printf(\"#{format}\"," +
    @arguments.each do |arg|
      if arg.is_a?(::String) then
        "\"#{arg}\""
      else
        arg.to_c
      end
    end.join(",")
end

#to_rubyObject

Convert to Ruby code.



2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2992

def to_ruby
  return "" if @arguments.empty?
  res = "print("
  @arguments.each do |arg|
      if arg.is_a?(::String) then
        res << "\"#{arg}\""
      else
        res << arg.to_ruby
      end
    end
    res << ")\n"
    return res
end