class HDLRuby::Low::TypeDef

Describes a high-level type definition.

NOTE: type definition are actually type with a name refering to another

type (and equivalent to it).

Extends the TypeDef class with generation of C text.

Extends the TypeDef class with generation of hdr text.

Add the conversion to high.

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

Describes a high-level type definition.

NOTE: type definition are actually type with a name refering to another

type (and equivalent to it).

Replace type by refered type.

Attributes

def[R]

The definition of the type.

Public Class Methods

new(name,type) click to toggle source

Creates a new type definition named name from type.

Calls superclass method HDLRuby::Low::Type::new
# File lib/HDLRuby/hruby_low.rb, line 1500
def initialize(name,type)
    # Initialize with name.
    super(name)
    # Checks the referered type.
    unless type.is_a?(Type) then
        raise AnyError, "Invalid class for a type: #{type.class}"
    end
    # Set the referened type.
    @def = type

    # Sets the delegations
    self.extend Forwardable
    [ :signed?, :unsigned?, :fixed?, :float?, :leaf?, :vector?,
      :width, :range?, :range, :base?, :base, :types?,
      :get_all_types, :get_type, :each, :each_type, 
      :regular?,
      :each_name,
      :equivalent? ].each do |meth|
          if @def.respond_to?(meth)
              self.def_delegator :@def, meth
          end
      end
end

Public Instance Methods

each_deep(&ruby_block)
Alias for: each_type_deep
each_type_deep(&ruby_block) click to toggle source

Iterates over the types deeply if any.

# File lib/HDLRuby/hruby_low.rb, line 1540
def each_type_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_type_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And recurse on the definition.
    @def.each_type_deep(&ruby_block)
end
Also aliased as: each_deep
eql?(obj) click to toggle source

Comparison for hash: structural comparison.

Calls superclass method HDLRuby::Low::Type#eql?
# File lib/HDLRuby/hruby_low.rb, line 1525
def eql?(obj)
    # General type comparison.
    return false unless super(obj)
    # Specific comparison.
    return false unless obj.is_a?(TypeDef)
    return false unless @def.eql?(obj.def)
    return true
end
hash() click to toggle source

Hash function.

Calls superclass method HDLRuby::Low::Type#hash
# File lib/HDLRuby/hruby_low.rb, line 1535
def hash
    return [super,@def].hash
end
set_def!(type) click to toggle source

Sets the type definition to type.

# File lib/HDLRuby/hruby_low_mutable.rb, line 282
def set_def!(type)
    # Checks the referered type.
    unless type.is_a?(Type) then
        raise AnyError, "Invalid class for a type: #{type.class}"
    end
    # Set the referened type.
    @def = type
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 531
def to_c(level = 0)
    # # Simply use the name of the type.
    # return Low2C.type_name(self.name) + "()"
    # Simply return the defined type.
    return self.def.to_c(level)
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 184
def to_hdr(level = 0)
    # Simply generates the redefined type.
    self.def.to_hdr(level)
end
to_high() click to toggle source

Creates a new high type definition.

# File lib/HDLRuby/hruby_low2high.rb, line 70
def to_high
    return HDLRuby::High::Typdef.new(self.name,self.type.to_high)
end
to_verilog() click to toggle source

Converts the type to verilog code.

# File lib/HDLRuby/hruby_verilog.rb, line 1697
def to_verilog
    return self.def.to_verilog
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 629
def to_vhdl(level = 0)
    # # Simply generates the redefined type.
    # return self.def.to_vhdl(level)
    # Simply use the name of the type.
    # Is it a composite type?
    if (self.def.is_a?(TypeStruct) ||
      (self.def.is_a?(TypeVector) && 
            (self.def.base.is_a?(TypeVector) || 
             self.def.base.is_a?(TypeStruct))))
        # Yes, generate a VHDL type definition.
        return Low2VHDL.vhdl_name(self.name)
    else
        # No, generates the defined type.
        return self.def.to_vhdl(level)
    end
end