Class: RubyHDL::High::Sloop

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

Overview

Describes a SW implementation of a loop statement.

Instance Method Summary collapse

Constructor Details

#initialize(sequencer, &ruby_block) ⇒ Sloop

Create a new infinite loop statement in sequencer +sequencer+ with +ruby_block+ for generating the block that is taken.



3076
3077
3078
3079
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3076

def initialize(sequencer, &ruby_block)
  @sequencer = sequencer
  @blk = Sblock.new(sequencer,&ruby_block)
end

Instance Method Details

#each_statement(&ruby_block) ⇒ Object

Iterate on the statements.



3082
3083
3084
3085
3086
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3082

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

#each_statement_deep(&ruby_block) ⇒ Object

Iterate deeply on the statements.



3089
3090
3091
3092
3093
3094
3095
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3089

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

#to_cObject

Convert to C code.



3103
3104
3105
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3103

def to_c
  return "for(;;){\n#{@blk.to_ruby}\n#{@sequencer.clk_up_c}\n}"
end

#to_python(l = "") ⇒ Object

Convert to Python code.



3108
3109
3110
3111
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3108

def to_python(l = "")
  return "#{l}while True:\n#{@blk.to_python(l + "  ")}\n" +
    @sequencer.clk_up_python(l + "  ")
end

#to_rubyObject

Convert to Ruby code.



3098
3099
3100
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3098

def to_ruby
  return "loop do\n#{@blk.to_ruby}\n#{@sequencer.clk_up}\nend"
end

#to_tf(l = "") ⇒ Object

Convert to TensorFlow code.



3114
3115
3116
3117
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3114

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