Class: RubyHDL::High::Swhile

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

Overview

Describes a SW implementation of a while statement.

Instance Method Summary collapse

Constructor Details

#initialize(sequencer, cond, &ruby_block) ⇒ Swhile

Create a new while statement in sequencer +sequencer+ with +cond+ condition and +ruby_block+ for generating the block that is taken while the condition is met.



3125
3126
3127
3128
3129
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3125

def initialize(sequencer,cond, &ruby_block)
  @sequencer = sequencer
  @condition = cond.to_expr
  @yes_blk = Sblock.new(sequencer,&ruby_block)
end

Instance Method Details

#each_statement(&ruby_block) ⇒ Object

Iterate on the statements.



3132
3133
3134
3135
3136
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3132

def each_statement(&ruby_block)
  return to_enum(:each_statement) unless ruby_block
  # Apply ruby_block on the block.
  ruby_block.call(@yes_blk)
end

#each_statement_deep(&ruby_block) ⇒ Object

Iterate deeply on the statements.



3139
3140
3141
3142
3143
3144
3145
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3139

def each_statement_deep(&ruby_block)
  return to_enum(:each_statement_deep) unless ruby_block
  # Recurse on the yes block.
  @yes_blk.each_statement_deep
  # And apply ruby_block on self.
  ruby_block.call(self)
end

#to_cObject

Convert to C code.



3154
3155
3156
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3154

def to_c
    "\nwhile(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n#{@sequencer.clk_up_c}\n}"
end

#to_python(l = "") ⇒ Object

Convert to Python code.



3159
3160
3161
3162
3163
3164
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3159

def to_python(l = "")
  return @sequencer.clk_up_python(l) + 
    "\n#{l}while (#{@condition.to_python}) != 0:\n" +
    "#{@yes_blk.to_python(l + "  ")}\n" +
    @sequencer.clk_up_python(l + "  ")
end

#to_rubyObject

Convert to Ruby code.



3148
3149
3150
3151
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3148

def to_ruby
  return @sequencer.clk_up + 
    "\nwhile((#{@condition.to_ruby}) != 0) do\n#{@yes_blk.to_ruby}\n#{@sequencer.clk_up}\nend"
end

#to_tf(l = "") ⇒ Object

Convert to Tensorflow code.



3167
3168
3169
3170
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3167

def to_tf(l = "")
  return "#{l}tf.while_loop(lambda: tf.constant(0)," + 
    "_: #{@condition.to_tf} == 0, #{@yes_blk.to_tf(l + "  ")})"
end