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

Extends the RefObject 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 collapse

Attributes inherited from Low::Expression

#type

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HRef

#each, included, #to_event

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!, #hash, #immutable?, #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

#initialize(base, object) ⇒ RefObject

Creates a new reference from a +base+ reference and named +object+.



3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
# File 'lib/HDLRuby/hruby_high.rb', line 3328

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.



3382
3383
3384
# File 'lib/HDLRuby/hruby_high.rb', line 3382

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

Instance Attribute Details

#baseObject (readonly)

The base of the reference



3322
3323
3324
# File 'lib/HDLRuby/hruby_high.rb', line 3322

def base
  @base
end

#objectObject (readonly)

The refered object.



3325
3326
3327
# File 'lib/HDLRuby/hruby_high.rb', line 3325

def object
  @object
end

Instance Method Details

#assign(mode, value) ⇒ Object

Assigns +value+ the the reference.



1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'lib/HDLRuby/hruby_rsim.rb', line 1105

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



1116
1117
1118
1119
1120
1121
1122
1123
1124
# File 'lib/HDLRuby/hruby_rsim.rb', line 1116

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.



3347
3348
3349
# File 'lib/HDLRuby/hruby_high.rb', line 3347

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

#constant?Boolean

Tell if the expression is constant.

Returns:

  • (Boolean)


3352
3353
3354
# File 'lib/HDLRuby/hruby_high.rb', line 3352

def constant?
    return self.base.constant?
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


3362
3363
3364
3365
3366
3367
# File 'lib/HDLRuby/hruby_high.rb', line 3362

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.



1100
1101
1102
# File 'lib/HDLRuby/hruby_rsim.rb', line 1100

def execute(mode)
    return self.object.execute(mode)
end

#init_sim(systemT) ⇒ Object

Initialize the simulation for system +systemT+.



1095
1096
1097
# File 'lib/HDLRuby/hruby_rsim.rb', line 1095

def init_sim(systemT)
    @sim = systemT
end

#to_lowObject

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



3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
# File 'lib/HDLRuby/hruby_high.rb', line 3370

def to_low
    # puts "to_low with base=#{@base} @object=#{@object}"
    # puts "@object.name=#{@object.name}"
    refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
                                     @base.to_ref.to_low,@object.name)
    # # 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.



965
966
967
968
969
970
971
972
973
974
# File 'lib/HDLRuby/hruby_rcsim.rb', line 965

def to_rcsim
    # puts "object=#{self.object.name}(#{self.object})"
    if self.object.is_a?(SignalI)
        return self.object.rcsignalI
    elsif self.object.is_a?(SignalC)
        return self.object.rcsignalC
    else
        raise "Invalid object: #{self.object}"
    end
end

#to_refObject

Converts to a new reference.



3357
3358
3359
# File 'lib/HDLRuby/hruby_high.rb', line 3357

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