Class: HDLRuby::High::RefObject

Inherits:
Low::Ref show all
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

Attributes inherited from Low::Expression

#type

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HRef

#each, included, #objects, #to_event

Methods included from Enumerable

#seach

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

#to_sym

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+.



3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
# File 'lib/HDLRuby/hruby_high.rb', line 3551

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.



3632
3633
3634
# File 'lib/HDLRuby/hruby_high.rb', line 3632

def method_missing(m, *args, &ruby_block)
    @object.send(m,*args,&ruby_block)
end

Instance Attribute Details

#baseObject (readonly)

The base of the reference



3545
3546
3547
# File 'lib/HDLRuby/hruby_high.rb', line 3545

def base
  @base
end

#objectObject (readonly)

The refered object.



3548
3549
3550
# File 'lib/HDLRuby/hruby_high.rb', line 3548

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

#cloneObject

Clones.



3570
3571
3572
# File 'lib/HDLRuby/hruby_high.rb', line 3570

def clone
    return RefObject.new(self.base.clone,self.object)
end

#constant?Boolean

Tell if the expression is constant.

Returns:

  • (Boolean)


3575
3576
3577
# File 'lib/HDLRuby/hruby_high.rb', line 3575

def constant?
    return self.base.constant?
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


3585
3586
3587
3588
3589
3590
# File 'lib/HDLRuby/hruby_high.rb', line 3585

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_lowObject

Converts the name reference to a HDLRuby::Low::RefName.



3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
# File 'lib/HDLRuby/hruby_high.rb', line 3593

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
            # (!@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_rcsimObject

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_subsObject

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

#to_refObject

Converts to a new reference.



3580
3581
3582
# File 'lib/HDLRuby/hruby_high.rb', line 3580

def to_ref
    return RefObject.new(@base,@object)
end