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+.



3025
3026
3027
3028
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3025

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

Instance Method Details

#to_cObject

Convert to C code.



3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3046

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

#to_rubyObject

Convert to Ruby code.



3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3031

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