Class: RubyHDL::High::Sblock

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

Overview

Describes a SW implementation of a block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SblockTop

#callable, #callable?, #each_signal, #make_inners, #register

Constructor Details

#initialize(sequencer, &ruby_block) ⇒ Sblock

Create a new block for sequencer +sequencer+ and fill it by executing +ruby_block+



2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2580

def initialize(sequencer,&ruby_block)
  super()
  # Sets the sequencer.
  @sequencer = sequencer
  # Initialize the statements.
  @statements = []
  # Push the new sblock on top of the stack.
  RubyHDL::High.push_sblock(self)
  # Fill it.
  self.instance_eval(&ruby_block)
  # Pop the new sblock.
  RubyHDL::High.pop_sblock
end

Instance Attribute Details

#sequencerObject (readonly)

Returns the value of attribute sequencer.



2576
2577
2578
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2576

def sequencer
  @sequencer
end

Instance Method Details

#add(statement) ⇒ Object Also known as: <<

Add a new statement to the block.



2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2595

def add(statement)
  # Add the statement.
  @statements.push(statement)
  # # If the statement is a transmit, schedule the corresponding
  # # signal for final update.
  # if statement.is_a?(Transmit) then
  #   @sequencer.to_update(statement.left)
  # end
  statement
end

#delete(statement) ⇒ Object

Delete a statement.



2608
2609
2610
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2608

def delete(statement)
  @statements.delete(statement)
end

#ruby(&ruby_block) ⇒ Object

Some arbirary Ruby code.



2701
2702
2703
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2701

def ruby(&ruby_block)
  self << RubyHDL::High::Ruby.new(&ruby_block)
end

#sbreakObject

Breaks current iteration.



2638
2639
2640
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2638

def sbreak
  self << RubyHDL::High::Sbreak.new(@sequencer)
end

#scontinueObject

Continues current iteration.



2643
2644
2645
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2643

def scontinue
  self << RubyHDL::High::Scontinue.new(@sequencer)
end

#selse(&ruby_block) ⇒ Object

Create a sequential else statement.



2663
2664
2665
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2663

def selse(&ruby_block)
  self.statements[-1].selse(&ruby_block)
end

#selsif(cond, &ruby_block) ⇒ Object

Create a sequential elsif statement on +cond+.



2658
2659
2660
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2658

def selsif(cond, &ruby_block)
  self.statements[-1].selsif(&ruby_block)
end

#sfor(expr, &ruby_block) ⇒ Object

Create a sequential for statement iterating over the elements of +expr+.



2684
2685
2686
2687
2688
2689
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2684

def sfor(expr,&ruby_block)
  # Ensures there is a ruby block to avoid returning an enumerator
  # (returning an enumerator would be confusing for a for statement).
  ruby_block = proc {} unless ruby_block
  expr.seach.with_index(&ruby_block)
end

#sif(cond, &ruby_block) ⇒ Object

Create a sequential if statement on +cond+.



2653
2654
2655
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2653

def sif(cond, &ruby_block)
  self << RubyHDL::High::Sif.new(@sequencer,cond,&ruby_block)
end

#sloop(&ruby_block) ⇒ Object

Create a sequential infinite loop statement.



2678
2679
2680
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2678

def sloop(&ruby_block)
  self << RubyHDL::High::Sloop.new(@sequencer,&ruby_block)
end

#stepObject

Mark a step.



2628
2629
2630
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2628

def step
  self << RubyHDL::High::Step.new(@sequencer)
end

#steps(num) ⇒ Object

Mark several steps.



2633
2634
2635
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2633

def steps(num)
  num.times { self.step }
end

#sterminateObject

Terminates the sequencer.



2648
2649
2650
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2648

def sterminate
  self << RubyHDL::High::Sterminate.new(@sequencer)
end

#swait(cond) ⇒ Object

Wait a given condition.



2668
2669
2670
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2668

def swait(cond)
  self.swhile(~cond)
end

#swhile(cond, &ruby_block) ⇒ Object

Create a sequential while statement on +cond+.



2673
2674
2675
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2673

def swhile(cond,&ruby_block)
  self << RubyHDL::High::Swhile.new(@sequencer,cond,&ruby_block)
end

#syncObject

Mark a synchronisation. For software only: stop the current sequencer for allowing sharing of variables with other ones.



2696
2697
2698
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2696

def sync
  self << RubyHDL::High::Sync.new
end

#to_rubyObject

Convert to ruby code.



2619
2620
2621
2622
2623
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2619

def to_ruby
  return @statements.map do |stmnt|
    stmnt.to_ruby + "\n"
  end.join
end

#unshift(statement) ⇒ Object

Unshift a new statement.



2613
2614
2615
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2613

def unshift(statement)
  @statements.unshift(statement)
end