Class: RubyHDL::High::Print
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a hardware print statement.
Instance Method Summary collapse
-
#initialize(sequencer, *args) ⇒ Print
constructor
Create a new hprint statement in sequencer +sequencer+ for displaying +args+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Methods inherited from Statement
#each_statement, #each_statement_deep
Constructor Details
Instance Method Details
#to_c ⇒ Object
Convert to C code.
3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3256 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.
3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3277 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_ruby ⇒ Object
Convert to Ruby code.
3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3239 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 |