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



3814
3815
3816
3817
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3814

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

Instance Method Details

#to_cObject

Convert to C code.



3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3837

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_python(l = "") ⇒ Object

Convert to Python code.



3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3858

def to_python(l = "")
  return "" if @arguments.empty?
  res = "#{l}print("
  @arguments.each do |arg|
    if arg.is_a?(::String) then
      res << "\"#{arg}\""
    else
      res << arg.to_python
    end
    res << ","
  end
  res[-1] = ")"
  res << "\n"
  return res
end

#to_rubyObject

Convert to Ruby code.



3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3820

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
    res << ","
  end
  res[-1] = ")"
  res << "\n"
  return res
end