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.



2430
2431
2432
2433
2434
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2430

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.



2437
2438
2439
2440
2441
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2437

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.



2444
2445
2446
2447
2448
2449
2450
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2444

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.



2459
2460
2461
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2459

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

#to_rubyObject

Convert to Ruby code.



2453
2454
2455
2456
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2453

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