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
#each, included, #objects, #to_event
Methods included from Enumerable
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, #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+.
3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 |
# File 'lib/HDLRuby/hruby_high.rb', line 3479 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.
3551 3552 3553 |
# File 'lib/HDLRuby/hruby_high.rb', line 3551 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
3473 3474 3475 |
# File 'lib/HDLRuby/hruby_high.rb', line 3473 def base @base end |
#object ⇒ Object (readonly)
The refered object.
3476 3477 3478 |
# File 'lib/HDLRuby/hruby_high.rb', line 3476 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.
3498 3499 3500 |
# File 'lib/HDLRuby/hruby_high.rb', line 3498 def clone return RefObject.new(self.base.clone,self.object) end |
#constant? ⇒ Boolean
Tell if the expression is constant.
3503 3504 3505 |
# File 'lib/HDLRuby/hruby_high.rb', line 3503 def constant? return self.base.constant? end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3513 3514 3515 3516 3517 3518 |
# File 'lib/HDLRuby/hruby_high.rb', line 3513 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.
3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 |
# File 'lib/HDLRuby/hruby_high.rb', line 3521 def to_low # puts "to_low with base=#{@base} @object=#{@object}" # puts "@object.name=#{@object.name} @object.parent=#{@object.parent.name}" if @base.is_a?(RefThis) && (@object.parent != High.top_user) && (@object.parent != High.cur_system) && (@object.parent != High.cur_system.scope) && (!@object.parent.name.empty?) 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.
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 1152 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.
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 1132 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 |