Class: HDLRuby::High::SignalC

Inherits:
Low::SignalC show all
Includes:
HRef, SimSignal, WithFullname
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb,
lib/HDLRuby/hruby_high_fullname.rb

Overview

Extends the SignalC class for hybrid Ruby-C simulation.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes included from SimSignal

#c_value, #f_value

Attributes inherited from Low::SignalI

#name, #type, #value

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from WithFullname

#fullname

Methods included from SimSignal

#add_anyedge, #add_negedge, #add_posedge, #assign, #assign_at, #each_anyedge, #each_negedge, #each_posedge, #execute, #fullname, #init_sim

Methods included from HRef

#each, included, #to_event

Methods inherited from Low::SignalC

#immutable?, #to_high

Methods inherited from Low::SignalI

#clone, #each_deep, #explicit_types!, #immutable?, #replace_names!, #set_name!, #set_type!, #set_value!, #to_c, #to_c_alias, #to_c_signal, #to_ch, #to_hdr, #to_high, #to_verilog, #to_vhdl, #width

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

#initialize(name, type, value) ⇒ SignalC

Creates a new constant signal named +name+ typed as +type+ and +value+.



3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
# File 'lib/HDLRuby/hruby_high.rb', line 3891

def initialize(name,type,value)
    # Check the value is a constant.
    value = value.to_expr.match_type(type)
    unless value.constant? then
        raise AnyError,"Non-constant value assignment to constant."
    end
    # Initialize the type structure.
    super(name,type,value)

    unless name.empty? then
        # Named signal, set the hdl-like access to the signal.
        obj = self # For using the right self within the proc
        High.space_reg(name) { obj }
    end

    # Hierarchical type allows access to sub references, so generate
    # the corresponding methods.
    if type.struct? then
        type.each_name do |name|
            self.define_singleton_method(name) do
                RefObject.new(self.to_ref,
                            SignalC.new(name,type.get_type(name),
                                        value[name]))
            end
        end
    end
end

Instance Attribute Details

#rcsignalCObject (readonly)

Returns the value of attribute rcsignalC.



425
426
427
# File 'lib/HDLRuby/hruby_rcsim.rb', line 425

def rcsignalC
  @rcsignalC
end

Instance Method Details

#coerce(obj) ⇒ Object

Coerce by converting signal to an expression.



3930
3931
3932
# File 'lib/HDLRuby/hruby_high.rb', line 3930

def coerce(obj)
    return [obj,self.to_expr]
end

#to_exprObject

Converts to a new expression.



3925
3926
3927
# File 'lib/HDLRuby/hruby_high.rb', line 3925

def to_expr
    return self.to_ref
end

#to_low(name = self.name) ⇒ Object

Converts the system to HDLRuby::Low and set its +name+.



3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
# File 'lib/HDLRuby/hruby_high.rb', line 3935

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

#to_rcsim(rcowner) ⇒ Object

Generate the C description of the signal comming from object whose C description is +rcowner+



429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/HDLRuby/hruby_rcsim.rb', line 429

def to_rcsim(rcowner)
    # Create the signal C object.
    @rcsignalC = RCSim.rcsim_make_signal(self.name.to_s,
                                   self.type.to_rcsim)

    # Set the owner.
    RCSim.rcsim_set_owner(@rcsignalC,rcowner)

    # Set the initial value.
    RCSim.rcsim_set_signal_value(@rcsignalC,self.value.to_rcsim)

    return @rcsignalC
end

#to_refObject

Converts to a new reference.



3920
3921
3922
# File 'lib/HDLRuby/hruby_high.rb', line 3920

def to_ref
    return RefObject.new(this,self)
end