module HDLRuby::Low::LowWithoutSelect

Module containing helping methods for converting Select expressions to Case.

Public Class Methods

selects2block(selects) click to toggle source

Generate a block with Cases from a list of Select objects.

# 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