class HDLRuby::Low::TypeTuple

Describes a tuple data type.

Describes a tuple type.

Extends the TypeTuple class with generation of C text.

Extends the TypeTuple class with generation of hdr text.

Add the conversion to high.

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

Describes a tuple type.

Extends the TypeTuple class with functionality for breaking hierarchical types.

Public Class Methods

new(name,direction,*content) click to toggle source

Creates a new tuple type named name width direction and whose sub types are given by content.

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 1774
def initialize(name,direction,*content)
    # Initialize the type.
    super(name)

    # Set the direction.
    @direction = direction.to_sym
    unless [:little, :big].include?(@direction)
        raise AnyError, "Invalid direction for a type: #{direction}"
    end

    # Check and set the content.
    content.each do |sub|
        unless sub.is_a?(Type) then
            raise AnyError, "Invalid class for a type: #{sub.class}"
        end
    end
    @types = content
end

Public Instance Methods

add_type(type) click to toggle source

Adds a sub type.

# File lib/HDLRuby/hruby_low.rb, line 1829
def add_type(type)
    unless type.is_a?(Type) then
        raise AnyError, 
              "Invalid class for a type: #{type.class} (#{type})"
    end
    @types << type
end
base() click to toggle source

Gets the base type.

NOTE: only valid if the tuple is regular (i.e., all its sub types

are identical)
# File lib/HDLRuby/hruby_low.rb, line 1916
def base
    if regular? then
        # Regular tuple, return the type of its first element.
        return @types[0]
    else
        raise AnyError, "No base type for type #{self}"
    end
end
base?() click to toggle source

Tells if the type has a base.

NOTE: only if the tuple is regular (i.e., all its sub types

are identical)
# File lib/HDLRuby/hruby_low.rb, line 1908
def base?
    return regular?
end
break_types!(types) click to toggle source

Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. types include the resulting types.

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 337
def break_types!(types)
    self.map_types! do |sub|
        if sub.is_a?(TypeVector) || sub.is_a?(TypeTuple) ||
                sub.is_a?(TypeStruct) then
            # Need to break
            # First recurse on the sub.
            nsub = sub.break_types!(types)
            # Maybe such a type already exists.
            ndef = types[sub]
            if ndef then
                # Yes, use it.
                ndef.clone
            else
                # No change it to a type definition
                ndef = TypeDef.new(HDLRuby.uniq_name,nsub)
                # And add it to the types by structure.
                types[nsub] = ndef
                nsub
            end
        end
    end
    return self
end
delete_type!(type) click to toggle source

Deletes a type.

# File lib/HDLRuby/hruby_low_mutable.rb, line 334
def delete_type!(type)
    if @types.include?(type) then
        # The type is present, delete it.
        @types.delete(type)
        # And remove its parent.
        type.parent = nil
    end
    type
end
direction() click to toggle source

Get the direction of the type, little or big endian.

# File lib/HDLRuby/hruby_low.rb, line 1887
def direction
    return @direction
end
each(&ruby_block) click to toggle source

Iterates over the sub name/type pair.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 1840
def each(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each) unless ruby_block
    # A ruby block? Apply it on each input signal instance.
    @types.each(&ruby_block)
end
each_deep(&ruby_block)
Alias for: each_type_deep
each_type(&ruby_block) click to toggle source

Iterates over the sub types.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 1850
def each_type(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_type) unless ruby_block
    # A ruby block? Apply it on each input signal instance.
    @types.each(&ruby_block)
end
each_type_deep(&ruby_block) click to toggle source

Iterates over the types deeply if any.

# File lib/HDLRuby/hruby_low.rb, line 1858
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 sub types.
    @types.each { |type| type.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
# File lib/HDLRuby/hruby_low.rb, line 1795
def eql?(obj)
    # General type comparison.
    return false unless super(obj)
    # Specific comparison.
    idx = 0
    obj.each_type do |type|
        return false unless @types[idx].eql?(type)
        idx += 1
    end
    return false unless idx == @types.size
    return true
end
equivalent?(type) click to toggle source

Tell if type is equivalent to current type.

NOTE: type can be compatible while not being equivalent, please

refer to `hruby_types.rb` for type compatibility.
# File lib/HDLRuby/hruby_low.rb, line 1929
def equivalent?(type)
    return (type.is_a?(TypeTuple) and
            !@types.zip(type.types).index {|t0,t1| !t0.equivalent?(t1) })
end
get_all_types() click to toggle source

Gets an array containing all the syb types.

# File lib/HDLRuby/hruby_low.rb, line 1819
def get_all_types
    return @types.clone
end
get_type(index) click to toggle source

Gets a sub type by index.

# File lib/HDLRuby/hruby_low.rb, line 1824
def get_type(index)
    return @types[index.to_i]
end
hash() click to toggle source

Hash function.

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 1809
def hash
    return [super,@types].hash
end
map_types!(&ruby_block) click to toggle source

Maps on the sub types.

# File lib/HDLRuby/hruby_low_mutable.rb, line 329
def map_types!(&ruby_block)
    @types.map(&ruby_block)
end
range() click to toggle source

Gets the range of the type.

NOTE: only valid if the tuple is regular (i.e., all its sub types

are identical)
# File lib/HDLRuby/hruby_low.rb, line 1895
def range
    if regular? then
        # Regular tuple, return its range as if it was an array.
        return 0..@types.size-1
    else
        raise AnyError, "No range for type #{self}"
    end
end
regular?() click to toggle source

Tell if the tuple is regular, i.e., all its sub types are equivalent.

NOTE: empty tuples are assumed not to be regular.

# File lib/HDLRuby/hruby_low.rb, line 1872
def regular?
    return false if @types.empty?
    t0 = @types[0]
    @types[1..-1].each do |type|
        return false unless t0.equivalent?(type)
    end
    return true
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.

NOTE: type tuples are converted to bit vector of their contents.

# File lib/HDLRuby/hruby_low2c.rb, line 558
def to_c(level = 0)
    # return "get_type_tuple(#{self.each.to_a.join(",") do |type|
    #    type.to_c(level+1)
    # end})"
    return self.to_vector.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 213
def to_hdr(level = 0)
    # The resulting string.
    res = "["
    # Generate each sub type.
    res << self.each_type.map { |type| type.to_hdr(level) }.join(", ")
    # Close the tuple.
    res << "]"
    # Return the result.
    return res
end
to_high() click to toggle source

Creates a new high type tuple.

# File lib/HDLRuby/hruby_low2high.rb, line 109
def to_high
    return HDLRuby::High::TypeTuple.new(self.name,self.direction,
                        *self.each_type.map { |typ| typ.to_high })
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.

NOTE: type tuples are converted to bit vector of their contents.

# File lib/HDLRuby/hruby_low2vhd.rb, line 713
def to_vhdl(level = 0)
    # raise AnyError, "Tuple types are not supported in VHDL, please convert them to Struct types using Low::tuple2struct from HDLRuby/hruby_low_witout_tuple."
    return self.to_vector.to_vhdl(level)
end
types?() click to toggle source

Tells if the type has sub types.

# File lib/HDLRuby/hruby_low.rb, line 1814
def types?
    return true
end
width() click to toggle source

Gets the bitwidth.

# File lib/HDLRuby/hruby_low.rb, line 1882
def width
    return @types.reduce(0) { |sum,type| sum + type.width }
end