Class: HDLRuby::High::RefObject
- Inherits:
-
Low::Ref
- Object
- Low::Expression
- Low::Ref
- HDLRuby::High::RefObject
- Includes:
- HRef
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb
Overview
Describes a high-level object reference: no low-level equivalent!
Constant Summary
Constants included from Low::Low2Symbol
Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
The base of the reference.
-
#object ⇒ Object
readonly
The refered object.
Attributes inherited from Low::Expression
Attributes included from Low::Hparent
Instance Method Summary collapse
-
#assign(mode, value) ⇒ Object
Assigns +value+ the the reference.
-
#assign_at(mode, value, index) ⇒ Object
Assigns +value+ at +index+ (integer or range).
-
#clone ⇒ Object
Clones.
-
#constant? ⇒ Boolean
Tell if the expression is constant.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#execute(mode) ⇒ Object
Execute the expression.
-
#init_sim(systemT) ⇒ Object
Initialize the simulation for system +systemT+.
-
#initialize(base, object) ⇒ RefObject
constructor
Creates a new reference from a +base+ reference and named +object+.
-
#method_missing(m, *args, &ruby_block) ⇒ Object
Missing methods are looked for into the refered object.
-
#to_low ⇒ Object
Converts the name reference to a HDLRuby::Low::RefName.
-
#to_rcsim ⇒ Object
Generate the C description of the reference object.
-
#to_rcsim_subs ⇒ Object
Generate the C description of the reference object with sub signals.
-
#to_ref ⇒ Object
Converts to a new reference.
Methods included from HRef
Methods inherited from Low::Ref
#each_node, #each_node_deep, #explicit_types, #hash, #map_nodes!, #path_each, #resolve, #to_c, #to_hdr, #to_vhdl
Methods inherited from Low::Expression
#boolean?, #break_types!, #each_node, #each_node_deep, #each_ref_deep, #explicit_types, #extract_selects_to!, #fix_scope_refnames!, #hash, #immutable?, #leftvalue?, #map_nodes!, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #signal2subs!, #statement, #to_c, #to_c_expr, #to_hdr, #to_high, #to_vhdl, #to_viz_names, #use_name?
Methods included from Low::Low2Symbol
Methods included from Low::Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(base, object) ⇒ RefObject
Creates a new reference from a +base+ reference and named +object+.
3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 |
# File 'lib/HDLRuby/hruby_high.rb', line 3714 def initialize(base,object) # puts "New RefObjet with base=#{base}, object=#{object}" if object.respond_to?(:type) then # Typed object, so typed reference. super(object.type) else # Untyped object, so untyped reference. super(void) end # Check and set the base (it must be convertible to a reference). unless base.respond_to?(:to_ref) raise AnyError, "Invalid base for a RefObject: #{base}" end @base = base # Set the object @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &ruby_block) ⇒ Object
Missing methods are looked for into the refered object.
3795 3796 3797 |
# File 'lib/HDLRuby/hruby_high.rb', line 3795 def method_missing(m, *args, &ruby_block) @object.send(m,*args,&ruby_block) end |
Instance Attribute Details
#base ⇒ Object (readonly)
The base of the reference
3708 3709 3710 |
# File 'lib/HDLRuby/hruby_high.rb', line 3708 def base @base end |
#object ⇒ Object (readonly)
The refered object.
3711 3712 3713 |
# File 'lib/HDLRuby/hruby_high.rb', line 3711 def object @object end |
Instance Method Details
#assign(mode, value) ⇒ Object
Assigns +value+ the the reference.
1404 1405 1406 1407 1408 1409 1410 1411 1412 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 1404 def assign(mode,value) self.object.assign(mode,value) # puts "name=#{self.object.name} value=#{value.to_vstr}" # puts "c_value=#{self.object.c_value.content}" if self.object.c_value # puts "f_value=#{self.object.f_value.content}" if self.object.f_value if !(self.object.c_value.eql?(self.object.f_value)) then @sim.add_sig_active(self.object) end end |
#assign_at(mode, value, index) ⇒ Object
Assigns +value+ at +index+ (integer or range).
1415 1416 1417 1418 1419 1420 1421 1422 1423 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 1415 def assign_at(mode,value,index) # puts "name=#{self.object.name} value=#{value.to_vstr}" self.object.assign_at(mode,value,index) # puts "c_value=#{self.object.c_value.content}" if self.object.c_value # puts "f_value=#{self.object.f_value.content}" if self.object.f_value if !(self.object.c_value.eql?(self.object.f_value)) then @sim.add_sig_active(self.object) end end |
#clone ⇒ Object
Clones.
3733 3734 3735 |
# File 'lib/HDLRuby/hruby_high.rb', line 3733 def clone return RefObject.new(self.base.clone,self.object) end |
#constant? ⇒ Boolean
Tell if the expression is constant.
3738 3739 3740 |
# File 'lib/HDLRuby/hruby_high.rb', line 3738 def constant? return self.base.constant? end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3748 3749 3750 3751 3752 3753 |
# File 'lib/HDLRuby/hruby_high.rb', line 3748 def eql?(obj) return false unless obj.is_a?(RefObject) return false unless @base.eql?(obj.base) return false unless @object.eql?(obj.object) return true end |
#execute(mode) ⇒ Object
Execute the expression.
1399 1400 1401 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 1399 def execute(mode) return self.object.execute(mode) end |
#init_sim(systemT) ⇒ Object
Initialize the simulation for system +systemT+.
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 1357 def init_sim(systemT) # puts "init_sim for RefObject=#{self}" @sim = systemT # Modify the exectute and assign methods if the object has # sub signals (for faster execution). if self.object.each_signal.any? then ## Execute the expression. self.define_singleton_method(:execute) do |mode| # Recurse on the children. iter = self.object.each_signal iter = iter.reverse_each unless self.object.type.direction == :big tmpe = iter.map {|sig| sig.execute(mode) } # Concatenate the result. # return tmpe.reduce(:concat) return Vprocess.concat(*tmpe) end ## Assigns +value+ the the reference. self.define_singleton_method(:assign) do |mode,value| # puts "RefObject #{self} assign with object=#{self.object}" # Flatten the value type. value.type = [value.type.width].to_type pos = 0 width = 0 # Recurse on the children. iter = self.object.each_signal iter = iter.reverse_each unless self.object.type.direction == :big iter.each do |sig| width = sig.type.width sig.assign(mode,value[(pos+width-1).to_expr..pos.to_expr]) # Tell the signal changed. if !(sig.c_value.eql?(sig.f_value)) then @sim.add_sig_active(sig) end # Prepare for the next reference. pos += width end end end end |
#to_low ⇒ Object
Converts the name reference to a HDLRuby::Low::RefName.
3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 |
# File 'lib/HDLRuby/hruby_high.rb', line 3756 def to_low # puts "to_low with base=#{@base} @object=#{@object} @object.parent=#{@object.parent} High.cur_system=#{High.cur_system}" # puts "@object.name=#{@object.name}" # puts "@object.parent.name=#{@object.parent.name}" if @object.parent # Check if a direct access is possible or not. # It is possible if the object parent is the top level, # or if it is a system or the first scope of a system. # (NOTE: previously we ensured that it was only for the # current system, however, this did not support the case # of object within included systems). if @base.is_a?(RefThis) && (@object.parent != High.top_user) && # (@object.parent != High.cur_system) && (!@object.parent.is_a?(SystemT)) && # (@object.parent != High.cur_system.scope) then # && (!(@object.parent.is_a?(Scope) && @object.parent.parent.is_a?(SystemT))) then # ([email protected]?) then # Need to have a hierachical access. if @object.respond_to?(:low_object) && @object.low_object then # There where already a low object, create the ref from it. # puts "absolute ref!" refNameL = @object.low_object.absolute_ref else # No create the indirect reference. refNameL = HDLRuby::Low::RefName.new(self.type.to_low, @object.parent.to_ref.to_low,@object.name) end else # Direct access is enough. refNameL = HDLRuby::Low::RefName.new(self.type.to_low, @base.to_ref.to_low,@object.name) end # # For debugging: set the source high object # refNameL.properties[:low2high] = self.hdr_id # self.properties[:high2low] = refNameL return refNameL end |
#to_rcsim ⇒ Object
Generate the C description of the reference object.
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 1164 def to_rcsim # puts "object=#{self.object.name}(#{self.object})" if self.object.is_a?(SignalI) return self.object.each_signal.any? ? self.to_rcsim_subs : self.object.rcsignalI elsif self.object.is_a?(SignalC) return self.object.each_signal.any? ? self.to_rcsim_subs : self.object.rcsignalC else raise "Invalid object: #{self.object}" end end |
#to_rcsim_subs ⇒ Object
Generate the C description of the reference object with sub signals.
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 1144 def to_rcsim_subs # Create the reference concat C object. # The reference is always big endian, it is the sequence # of element which is reversed if necessary. rcref = RCSim.rcsim_make_refConcat(self.type.to_rcsim,:big) # self.type.direction) # Add the concatenated expressions. */ if self.object.each_signal.any? then iter = self.object.each_signal iter = iter.reverse_each if self.type.direction == :big RCSim.rcsim_add_refConcat_refs(rcref, iter.map do|sig| sig.is_a?(SignalI) ? sig.rcsignalI : sig.rcsignalC end) end return rcref end |