Class: HDLRuby::Low::TypeDef

Inherits:
Type
  • Object
show all
Defined in:
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb

Overview

Describes a high-level type definition.

NOTE: type definition are actually type with a name refering to another type (and equivalent to it).

Direct Known Subclasses

High::TypeDef

Constant Summary

Constants included from Low2Symbol

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

Instance Attribute Summary collapse

Attributes inherited from Type

#name

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Type

#boolean?, #break_types!, #set_name!, #to_viz_name

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#absolute_ref, #hierarchy, #no_parent!, #scope

Constructor Details

#initialize(name, type) ⇒ TypeDef

Creates a new type definition named +name+ from +type+.



1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'lib/HDLRuby/hruby_low.rb', line 1647

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

Instance Attribute Details

#defObject (readonly)

The definition of the type.



1642
1643
1644
# File 'lib/HDLRuby/hruby_low.rb', line 1642

def def
  @def
end

Instance Method Details

#baseObject

Gets the base type, by default base type is not defined.



1768
1769
1770
# File 'lib/HDLRuby/hruby_low.rb', line 1768

def base
    return @def.base
end

#base?Boolean

Tells if the type has a base.

Returns:

  • (Boolean)


1763
1764
1765
# File 'lib/HDLRuby/hruby_low.rb', line 1763

def base?
    return @def.base?
end

#directionObject

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



1748
1749
1750
# File 'lib/HDLRuby/hruby_low.rb', line 1748

def direction
    return @def.direction
end

#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep

Iterates over the types deeply if any.



1688
1689
1690
1691
1692
1693
1694
1695
# File 'lib/HDLRuby/hruby_low.rb', line 1688

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

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


1672
1673
1674
1675
1676
1677
1678
1679
1680
# File 'lib/HDLRuby/hruby_low.rb', line 1672

def eql?(obj)
    # # General type comparison.
    # return false unless super(obj)
    # Specific comparison.
    return false unless obj.is_a?(TypeDef)
    return false unless @name.eql?(obj.name)
    return false unless @def.eql?(obj.def)
    return true
end

#equivalent?(type) ⇒ Boolean

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.

Returns:

  • (Boolean)


1796
1797
1798
# File 'lib/HDLRuby/hruby_low.rb', line 1796

def equivalent?(type)
    return @def.equivalent?(type)
end

#fixed?Boolean

Tells if the type is fixed point.

Returns:

  • (Boolean)


1710
1711
1712
# File 'lib/HDLRuby/hruby_low.rb', line 1710

def fixed?
    return @def.fixed?
end

#float?Boolean

Tells if the type is floating point.

Returns:

  • (Boolean)


1715
1716
1717
# File 'lib/HDLRuby/hruby_low.rb', line 1715

def float?
    return @def.float?
end

#hashObject

Hash function.



1683
1684
1685
# File 'lib/HDLRuby/hruby_low.rb', line 1683

def hash
    return [super,@def].hash
end

#hierarchical?Boolean

Tells if the type is hierarchical.

Returns:

  • (Boolean)


1788
1789
1790
# File 'lib/HDLRuby/hruby_low.rb', line 1788

def hierarchical?
    return @def.hierarchical?
end

#leaf?Boolean

Tells if the type is a leaf.

Returns:

  • (Boolean)


1720
1721
1722
# File 'lib/HDLRuby/hruby_low.rb', line 1720

def leaf?
    return @def.leaf?
end

#maxObject

Gets the type max value if any. Default: not defined.



1737
1738
1739
# File 'lib/HDLRuby/hruby_low.rb', line 1737

def max
    return @def.max
end

#minObject

Gets the type min value if any. Default: not defined.



1743
1744
1745
# File 'lib/HDLRuby/hruby_low.rb', line 1743

def min
    return @def.min
end

#rangeObject

Gets the range of the type, by default range is not defined.



1758
1759
1760
# File 'lib/HDLRuby/hruby_low.rb', line 1758

def range
    return @def.range
end

#range?Boolean

Tells if the type has a range.

Returns:

  • (Boolean)


1753
1754
1755
# File 'lib/HDLRuby/hruby_low.rb', line 1753

def range?
    return @def.range?
end

#regular?Boolean

Tells if the type is regular (applies for tuples).

Returns:

  • (Boolean)


1778
1779
1780
# File 'lib/HDLRuby/hruby_low.rb', line 1778

def regular?
    return @def.regular?
end

#set_def!(type) ⇒ Object

Sets the type definition to +type+.



286
287
288
289
290
291
292
293
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 286

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

#signed?Boolean

Tells if the type signed.

Returns:

  • (Boolean)


1700
1701
1702
# File 'lib/HDLRuby/hruby_low.rb', line 1700

def signed?
    return @def.signed?
end

#struct?Boolean

Tells if the type has named sub types.

Returns:

  • (Boolean)


1783
1784
1785
# File 'lib/HDLRuby/hruby_low.rb', line 1783

def struct?
    return @def.struct?
end

#to_c(res, level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)



597
598
599
600
601
602
# File 'lib/HDLRuby/hruby_low2c.rb', line 597

def to_c(res,level = 0)
    # Simply return the defined type.
    # return self.def.to_c(level)
    self.def.to_c(res,level)
    return res
end

#to_hdr(level = 0) ⇒ Object

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



185
186
187
188
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 185

def to_hdr(level = 0)
    # Simply generates the redefined type.
    self.def.to_hdr(level)
end

#to_highObject

Creates a new high type definition.



74
75
76
# File 'lib/HDLRuby/hruby_low2high.rb', line 74

def to_high
    return HDLRuby::High::Typdef.new(self.name,self.type.to_high)
end

#to_vectorObject

Converts to a bit vector.



1801
1802
1803
# File 'lib/HDLRuby/hruby_low.rb', line 1801

def to_vector
    return @def.to_vector
end

#to_verilogObject

Converts the type to verilog code.



1934
1935
1936
# File 'lib/HDLRuby/hruby_verilog.rb', line 1934

def to_verilog
    return self.def.to_verilog
end

#to_vhdl(level = 0) ⇒ Object

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



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 630

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

#types?Boolean

Tells if the type has sub types.

Returns:

  • (Boolean)


1773
1774
1775
# File 'lib/HDLRuby/hruby_low.rb', line 1773

def types?
    return @def.types?
end

#unsigned?Boolean

Tells if the type is unsigned.

Returns:

  • (Boolean)


1705
1706
1707
# File 'lib/HDLRuby/hruby_low.rb', line 1705

def unsigned?
    return @def.unsigned?
end

#vector?Boolean

Tells if the type of of vector kind.

Returns:

  • (Boolean)


1725
1726
1727
# File 'lib/HDLRuby/hruby_low.rb', line 1725

def vector?
    return @def.vector?
end

#widthObject

Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float base have a width of 1.



1731
1732
1733
# File 'lib/HDLRuby/hruby_low.rb', line 1731

def width
    return @def.width
end