Class: HDLRuby::High::SignalC

Inherits:
Low::SignalC show all
Includes:
HRef
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Describes a high-level constant signal.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

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

Instance Attribute Summary

Attributes inherited from Low::SignalI

#name, #type, #value

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HRef

#each, included, #to_event

Methods inherited from Low::SignalC

#immutable?, #to_high

Methods inherited from Low::SignalI

#clone, #each_deep, #eql?, #explicit_types!, #hash, #immutable?, #replace_names!, #set_name!, #set_type!, #set_value!, #to_c, #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, #scope

Constructor Details

#initialize(name, type, value) ⇒ SignalC

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



3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
# File 'lib/HDLRuby/hruby_high.rb', line 3539

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 Method Details

#coerce(obj) ⇒ Object

Coerce by converting signal to an expression.



3578
3579
3580
# File 'lib/HDLRuby/hruby_high.rb', line 3578

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

#to_exprObject

Converts to a new expression.



3573
3574
3575
# File 'lib/HDLRuby/hruby_high.rb', line 3573

def to_expr
    return self.to_ref
end

#to_low(name = self.name) ⇒ Object

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



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

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_refObject

Converts to a new reference.



3568
3569
3570
# File 'lib/HDLRuby/hruby_high.rb', line 3568

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