Class: HDLRuby::High::Select

Inherits:
Low::Select show all
Includes:
HExpression
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb

Overview

Extends the Select class for hybrid Ruby-C simulation.

Constant Summary

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary

Attributes included from HExpression

#systemT, #type

Attributes inherited from Low::Select

#select

Attributes inherited from Low::Operation

#operator

Attributes inherited from Low::Expression

#type

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HExpression

#[], #as, #coerce, #constant?, #inout, #input, #ljust, #lr, #ls, #match_type, #mux, orig_operator, #orig_operator, #output, #rjust, #rr, #rs, #sext, #to_bit, #to_unsigned, #to_value, #to_value?, #zext

Methods inherited from Low::Select

#add_choice, #boolean?, #boolean_in_assign2select, #casts_without_expression!, #clone, #delete_choice!, #each_choice, #each_deep, #each_node, #each_node_deep, #each_ref_deep, #eql?, #explicit_types, #get_choice, #hash, #immutable?, #initialize, #map_choices!, #map_nodes!, #replace_expressions!, #set_select!, #to_c, #to_hdr, #to_high, #to_verilog, #to_vhdl, #use_name?

Methods inherited from Low::Operation

#eql?, #explicit_types, #hash, #initialize, #set_operator!, #to_c, #to_hdr, #to_vhdl

Methods inherited from Low::Expression

#boolean?, #break_types!, #clone, #each_node, #each_node_deep, #each_ref_deep, #eql?, #explicit_types, #extract_selects_to!, #hash, #immutable?, #initialize, #leftvalue?, #map_nodes!, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #statement, #to_c, #to_c_expr, #to_hdr, #to_high, #to_vhdl, #use_name?

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

This class inherits a constructor from HDLRuby::Low::Select

Instance Method Details

#execute(mode) ⇒ Object

Execute the expression.



1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/HDLRuby/hruby_rsim.rb', line 1016

def execute(mode)
    unless @mask then
        # Need to initialize the execution of the select.
        width = (@choices.size-1).width
        width = 1 if width == 0
        @mask = 2**width - 1
        @choices.concat([@choices[-1]] * (2**width-@choices.size))
    end
    # Recurse on the select.
    tmps = self.select.execute(mode).to_i & @mask
    # puts "select tmps=#{tmps}, @choices.size=#{@choices.size}"
    # Recurse on the selection result.
    return @choices[tmps].execute(mode)
end

#to_exprObject

Converts to a new expression.



3163
3164
3165
3166
3167
3168
# File 'lib/HDLRuby/hruby_high.rb', line 3163

def to_expr
    return Select.new(self.type,"?",self.select.to_expr,
    *self.each_choice.map do |choice|
        choice.to_expr
    end)
end

#to_lowObject

Converts the selection expression to HDLRuby::Low.



3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
# File 'lib/HDLRuby/hruby_high.rb', line 3171

def to_low
    # return HDLRuby::Low::Select.new(self.type.to_low,"?",
    #                                 self.select.to_low,
    # *self.each_choice.map do |choice|
    #     choice.to_low
    # end)
    selectL = HDLRuby::Low::Select.new(self.type.to_low,"?",
                                    self.select.to_low,
    *self.each_choice.map do |choice|
        choice.to_low
    end)
    # # For debugging: set the source high object 
    # selectL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = selectL
    return selectL
end

#to_rcsimObject

Generate the C description of the select operation.



886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/HDLRuby/hruby_rcsim.rb', line 886

def to_rcsim
    # Create the select C object.
    rcexpression = RCSim.rcsim_make_select(self.type.to_rcsim,
                                      self.select.to_rcsim)

    # Add the choice expressions. */
    # self.each_choice do |choice|
    #     rcsim_add_select_choice(rcexpression,choice.to_rcsim)
    # end
    if self.each_choice.any? then
        RCSim.rcsim_add_select_choices(rcexpression,
                                       self.each_choice.map(&:to_rcsim))
    end
    
    return rcexpression
end