Class: RubyHDL::High::Hif
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a hif statement.
Instance Method Summary collapse
-
#to_c ⇒ Object
Convert to C code.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
-
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
Methods inherited from Sif
#each_statement, #each_statement_deep, #initialize, #selse, #selsif
Methods inherited from Statement
#each_statement, #each_statement_deep
Constructor Details
This class inherits a constructor from RubyHDL::High::Sif
Instance Method Details
#to_c ⇒ Object
Convert to C code.
3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3031 def to_c res = "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}" @elsifs.each do |(cond,blk)| res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}" end if @else_blk then res << "\nelse {\n#{@else_blk.to_c}\n}" end return res end |
#to_python(l = "") ⇒ Object
Convert to Python code.
3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3043 def to_python(l = "") res = "#{l}if (#{@condition.to_python}) != 0:\n" + "#{@yes_blk.to_python(l + " ")}\n" @elsifs.each do |(cond,blk)| res << "#{l}elif (#{cond.to_python}) != 0:\n" + "#{blk.to_python(l + " ")}\n" end if @else_blk then res << "#{l}else:\n#{@else_blk.to_python(l + " ")}\n" end return res end |
#to_ruby ⇒ Object
Convert to Ruby code.
3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3019 def to_ruby res = "\nif((#{@condition.to_ruby}) != 0)\n#{@yes_blk.to_ruby}\n" @elsifs.each do |(cond,blk)| res << "elsif((#{cond.to_ruby}) != 0)\n#{blk.to_ruby}\n" end if @else_blk then res << "else\n#{@else_blk.to_ruby}\n" end return res + "end\n" end |
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3057 def to_tf(l = "") res = "\n#{l}tf.cond(#{@condition.to_tf},\n" + "\n#{l} lambda: #{@yes_blk.to_f(l + " ")},\n" @elseif.each do |(cond,blk)| res<<"\n#{l} lambda: tf.cond(#{cond.to_tf}, lambda: #{blk}),\n" end if @else_blk then res << "\n#{l} lambda: #{else_blk.to_tf(l + " ")})\n" else res << "\n#{l} lambda: tf.constant0)\n" end return res end |