class HDLRuby::Low::SignalI

Describes a signal.

Describes a signal.

Extends the SignalI class with generation of C text.

Extends the SignalI class with generation of hdr text.

Add the conversion to high.

Extends the SignalI class with conversion to symbol.

Extends the SignalI class with generation of HDLRuby::High text.

Extends the SignalI class with fixing of types and constants.

Describes a signal.

Extends the SignalI class with functionality for moving the declarations to the upper namespace.

For declaring variables. Enhance SignalI with generation of verilog code.

Attributes

name[R]

The name of the signal

type[R]

The type of the signal

value[R]

The initial value of the signal if any.

Public Class Methods

new(name,type) click to toggle source

Creates a new signal named name typed as type.

Calls superclass method
# File lib/HDLRuby/hruby_db.rb, line 234
def initialize(name,type)
    # Ensures type is from Low::Type
    type = Type.get(type)
    # Initialize the signal structure.
    super(name,type)
end

Public Instance Methods

clone() click to toggle source

Clones (deeply)

# File lib/HDLRuby/hruby_low.rb, line 2471
def clone
    return SignalI.new(self.name,self.type)
end
each_deep(&ruby_block) click to toggle source

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 2441
def each_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # Then apply on the type.
    self.type.each_deep(&ruby_block)
    # Then apply on the value.
    self.value.each_deep(&ruby_block) if self.value
end
eql?(obj) click to toggle source

Comparison for hash: structural comparison.

# File lib/HDLRuby/hruby_low.rb, line 2453
def eql?(obj)
    return false unless obj.is_a?(SignalI)
    return false unless @name.eql?(obj.name)
    return false unless @type.eql?(obj.type)
    return true
end
explicit_types!() click to toggle source

Explicit the types conversions in the signal.

# File lib/HDLRuby/hruby_low_fix_types.rb, line 57
def explicit_types!
    # Is there a value?
    value = self.value
    if value then
        # Yes recurse on it.
        self.set_value!(value.explicit_types(self.type))
    end
    # No, nothing to do.
    return self
end
hash() click to toggle source

Hash function.

# File lib/HDLRuby/hruby_low.rb, line 2461
def hash
    return [@name,@type].hash
end
immutable?() click to toggle source

Tells if the signal is immutable (cannot be written.)

# File lib/HDLRuby/hruby_low.rb, line 2430
def immutable?
    # By default, signals are not immutable.
    false
end
replace_names!(former,nname) click to toggle source

Replaces recursively former name by nname until it is redeclared.

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 399
def replace_names!(former,nname)
    # Recurse on the type.
    self.type.each_type_deep do |type|
        if type.respond_to?(:name) && type.name == former then
            type.set_name!(nname)
        end
    end
end
set_name!(name) click to toggle source

Sets the name.

# File lib/HDLRuby/hruby_low_mutable.rb, line 478
def set_name!(name)
    # Check and set the name.
    @name = name.to_sym
end
set_type!(type) click to toggle source

Sets the type.

# File lib/HDLRuby/hruby_low_mutable.rb, line 484
def set_type!(type)
    # Check and set the type.
    if type.is_a?(Type) then
        @type = type
    else
        raise AnyError, "Invalid class for a type: #{type.class}."
    end
end
set_value!(value) click to toggle source

Sets the value (can also be nil for removing the value).

# File lib/HDLRuby/hruby_low_mutable.rb, line 494
def set_value!(value)
    # Check and set teh value.
    unless value == nil || value.is_a?(Expression) then
        raise AnyError, "Invalid class for a constant: #{value.class}"
    end
    @value = value
    value.parent = self unless value == nil
end
to_c(level = 0) click to toggle source

Generates the C text of the equivalent HDLRuby code. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2c.rb, line 760
def to_c(level = 0)
    # The resulting string.
    res = ""

    # Declare the global variable holding the signal.
    res << "SignalI #{self.to_c_signal(level+1)};\n\n"

    # The header of the signal generation.
    res << " " * level*3
    res << "SignalI #{Low2C.make_name(self)}() {\n"
    res << " " * (level+1)*3
    res << "SignalI signalI = malloc(sizeof(SignalIS));\n"
    res << " " * (level+1)*3
    res << "signalI->kind = SIGNALI;\n";

    # Sets the global variable of the signal.
    res << "\n"
    res << " " * (level+1)*3
    res << "#{self.to_c_signal(level+1)} = signalI;\n"

    # Set the owner if any.
    if self.parent then
        res << " " * (level+1)*3
        res << "signalI->owner = (Object)" + 
               "#{Low2C.obj_name(self.parent)};\n"
    else
        res << "signalI->owner = NULL;\n"
    end

    # Set the name
    res << " " * (level+1)*3
    res << "signalI->name = \"#{self.name}\";\n"
    # Set the type.
    res << " " * (level+1)*3
    res << "signalI->type = #{self.type.to_c(level+2)};\n"
    # Set the current and the next value.
    res << " " * (level+1)*3
    res << "signalI->c_value = make_value(signalI->type,0);\n"
    res << " " * (level+1)*3
    res << "signalI->c_value->signal = signalI;\n"
    res << " " * (level+1)*3
    res << "signalI->f_value = make_value(signalI->type,0);\n"
    res << " " * (level+1)*3
    res << "signalI->f_value->signal = signalI;\n"
    if self.value then
        # There is an initial value.
        res << " " * (level+1)*3
        res << "copy_value(#{self.value.to_c(level+2)}," +
               "signalI->c_value);\n"
    end

    # Initially the signal can be overwritten by anything.
    res << " " * (level+1)*3
    res << "signalI->fading = 1;\n"

    # Initialize the lists of behavior activated on this signal to 0.
    res << " " * (level+1)*3
    res << "signalI->num_any = 0;\n"
    res << " " * (level+1)*3
    res << "signalI->any = NULL;\n"
    res << " " * (level+1)*3
    res << "signalI->num_pos = 0;\n"
    res << " " * (level+1)*3
    res << "signalI->pos = NULL;\n"
    res << " " * (level+1)*3
    res << "signalI->num_neg = 0;\n"
    res << " " * (level+1)*3
    res << "signalI->neg = NULL;\n"

    # Register the signal for global processing.
    res << " " * (level+1)*3
    res << "register_signal(signalI);\n"


    # Generate the return of the signal.
    res << "\n"
    res << " " * (level+1)*3
    res << "return signalI;\n"

    # Close the signal.
    res << " " * level*3
    res << "};\n\n"
    return res
end
to_c_signal(level = 0) click to toggle source

Generates the C text for an access to the signal. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2c.rb, line 747
def to_c_signal(level = 0)
    res = Low2C.obj_name(self)
    # Accumulate the names of each parent until there is no one left.
    obj = self.parent
    while(obj) do
        res << "_" << Low2C.obj_name(obj)
        obj = obj.parent
    end
    return res
end
to_ch() click to toggle source

Generates the content of the h file.

# File lib/HDLRuby/hruby_low2c.rb, line 846
def to_ch
    res = ""
    # puts "to_ch for SignalI: #{self.to_c_signal()}"
    # Declare the global variable holding the signal.
    res << "extern SignalI #{self.to_c_signal()};\n\n"

    # Generate the access to the function making the behavior.
    res << "extern SignalI #{Low2C.make_name(self)}();\n\n"

    return res;
end
to_hdr(level = 0) click to toggle source

Generates the text of the equivalent hdr text. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2hdr.rb, line 304
def to_hdr(level = 0)
    return Low2HDR.hdr_use_name(self.name)
end
to_high() click to toggle source

Creates a new high signal.

# File lib/HDLRuby/hruby_low2high.rb, line 165
def to_high
    # Is there an initial value?
    if (self.value) then
        # Yes, create a new high signal with it.
        return HDLRuby::High::SignalI.new(self.name,self.type.to_high,
                                      self.val.to_high)
    else
        # No, create a new high signal with it.
        return HDLRuby::High::SignalI.new(self.name,self.type.to_high)
    end
end
to_verilog() click to toggle source

Converts the system to Verilog code.

# File lib/HDLRuby/hruby_verilog.rb, line 1677
def to_verilog
    # Convert unusable characters and return them.
    vname = name_to_verilog(self.name)
    self.properties[:verilog_name] = vname
    return "#{vname}"
end
to_vhdl(level = 0) click to toggle source

Generates the text of the equivalent HDLRuby::High code. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2vhd.rb, line 865
def to_vhdl(level = 0)
    # Should never be here.
    raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}"
end
width() click to toggle source

Gets the bit width.

# File lib/HDLRuby/hruby_low.rb, line 2466
def width
    return @type.width
end