Class: HDLRuby::High::Cast

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

Overview

Extends the Cast 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::Cast

#child

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::Cast

#boolean_in_assign2select, #casts_without_expression!, #clone, #each_deep, #each_node, #each_node_deep, #each_ref_deep, #eql?, #explicit_types, #hash, #immutable?, #initialize, #to_c, #to_hdr, #to_high, #to_verilog, #to_vhdl, #use_name?

Methods included from Low::OneChildMutable

#map_nodes!, #replace_expressions!, #set_child!

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::Cast

Instance Method Details

#execute(mode) ⇒ Object

Executes the expression.



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/HDLRuby/hruby_rsim.rb', line 836

def execute(mode)
    # Recurse on the child.
    # res = tocast.execute(mode)
    # Shall we reverse the content of a concat.
    if self.child.is_a?(Concat) && 
            self.type.direction != self.child.type.direction then
        # Yes, do it.
        res = self.child.execute(mode,:reverse)
    else
        res = self.child.execute(mode)
    end
    # Cast it.
    res = res.cast(self.type,true)
    # Returns the result.
    return res
end

#to_exprObject

Converts to a new expression.



3090
3091
3092
# File 'lib/HDLRuby/hruby_high.rb', line 3090

def to_expr
    return Cast.new(self.type,self.child.to_expr)
end

#to_lowObject

Converts the unary expression to HDLRuby::Low.



3095
3096
3097
3098
3099
3100
3101
3102
# File 'lib/HDLRuby/hruby_high.rb', line 3095

def to_low
    # return HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
    castL =HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
    # # For debugging: set the source high object 
    # castL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = castL
    return castL
end

#to_rcsimObject

Generate the C description of the cast.



786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/HDLRuby/hruby_rcsim.rb', line 786

def to_rcsim
    # puts "Cast to width=#{self.type.width} and child=#{self.child}"
    # Shall we reverse when casting?
    if self.type.direction != self.child.type.direction then
        # Yes, reverse the direction of the child.
        if self.child.type.respond_to?(:direction=) then
            self.child.type.direction = self.type.direction
        end
    end
    # Create the cast C object.
    return RCSim.rcsim_make_cast(self.type.to_rcsim,self.child.to_rcsim)
end