Module: HDLRuby::Low::LowWithoutSelect
- Defined in:
- lib/HDLRuby/hruby_low_without_select.rb
Overview
Module containing helping methods for converting Select expressions to Case.
Class Method Summary collapse
-
.selects2block(selects) ⇒ Object
Generate a block with Cases from a list of Select objects.
Class Method Details
.selects2block(selects) ⇒ Object
Generate a block with Cases from a list of Select objects.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 21 def self.selects2block(selects) blk = Block.new(:seq) selects.each do |select,sig| # puts "for select=#{select.to_high} with sig=#{sig.name}(#{sig.type.name})" # Create the case. cas = Case.new(select.select.clone) # Get the type for the matches. type = select.select.type # Create and add the whens. size = select.each_choice.count select.each_choice.with_index do |choice,i| # Create the transmission statements of the when. left = RefName.new(sig.type,RefThis.new,sig.name) trans = Transmit.new(left,choice.clone) # Put it into a block for the when. tb = Block.new(:par) tb.add_statement(trans) if i < size-1 then # Create and add the when. cas.add_when( When.new(Value.new(type,i), tb) ) else # Last choice, add a default/ cas.default = tb end end # puts "Resulting case: #{cas.to_high}" # Adds the case to the block. blk.add_statement(cas) end return blk end |