Class: HDLRuby::Low::TypeDef
- 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
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#def ⇒ Object
readonly
The definition of the type.
Attributes inherited from Type
Attributes included from Hparent
Instance Method Summary collapse
-
#base ⇒ Object
Gets the base type, by default base type is not defined.
-
#base? ⇒ Boolean
Tells if the type has a base.
-
#direction ⇒ Object
Get the direction of the type, little or big endian.
-
#each_type_deep(&ruby_block) ⇒ Object
(also: #each_deep)
Iterates over the types deeply if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#equivalent?(type) ⇒ Boolean
Tell if +type+ is equivalent to current type.
-
#fixed? ⇒ Boolean
Tells if the type is fixed point.
-
#float? ⇒ Boolean
Tells if the type is floating point.
-
#hash ⇒ Object
Hash function.
-
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
-
#initialize(name, type) ⇒ TypeDef
constructor
Creates a new type definition named +name+ from +type+.
-
#leaf? ⇒ Boolean
Tells if the type is a leaf.
-
#max ⇒ Object
Gets the type max value if any.
-
#min ⇒ Object
Gets the type min value if any.
-
#range ⇒ Object
Gets the range of the type, by default range is not defined.
-
#range? ⇒ Boolean
Tells if the type has a range.
-
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
-
#set_def!(type) ⇒ Object
Sets the type definition to +type+.
-
#signed? ⇒ Boolean
Tells if the type signed.
-
#struct? ⇒ Boolean
Tells if the type has named sub types.
-
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high type definition.
-
#to_vector ⇒ Object
Converts to a bit vector.
-
#to_verilog ⇒ Object
Converts the type to verilog code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#types? ⇒ Boolean
Tells if the type has sub types.
-
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
-
#vector? ⇒ Boolean
Tells if the type of of vector kind.
-
#width ⇒ Object
Gets the bitwidth of the type, by default 0.
Methods inherited from Type
#boolean?, #break_types!, #set_name!
Methods included from Low2Symbol
Methods included from Hparent
#hierarchy, #no_parent!, #scope
Methods included from Ltype
Constructor Details
#initialize(name, type) ⇒ TypeDef
Creates a new type definition named +name+ from +type+.
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 |
# File 'lib/HDLRuby/hruby_low.rb', line 1584 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
#def ⇒ Object (readonly)
The definition of the type.
1579 1580 1581 |
# File 'lib/HDLRuby/hruby_low.rb', line 1579 def def @def end |
Instance Method Details
#base ⇒ Object
Gets the base type, by default base type is not defined.
1705 1706 1707 |
# File 'lib/HDLRuby/hruby_low.rb', line 1705 def base return @def.base end |
#base? ⇒ Boolean
Tells if the type has a base.
1700 1701 1702 |
# File 'lib/HDLRuby/hruby_low.rb', line 1700 def base? return @def.base? end |
#direction ⇒ Object
Get the direction of the type, little or big endian.
1685 1686 1687 |
# File 'lib/HDLRuby/hruby_low.rb', line 1685 def direction return @def.direction end |
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1625 1626 1627 1628 1629 1630 1631 1632 |
# File 'lib/HDLRuby/hruby_low.rb', line 1625 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.
1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/HDLRuby/hruby_low.rb', line 1609 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.
1733 1734 1735 |
# File 'lib/HDLRuby/hruby_low.rb', line 1733 def equivalent?(type) return @def.equivalent?(type) end |
#fixed? ⇒ Boolean
Tells if the type is fixed point.
1647 1648 1649 |
# File 'lib/HDLRuby/hruby_low.rb', line 1647 def fixed? return @def.fixed? end |
#float? ⇒ Boolean
Tells if the type is floating point.
1652 1653 1654 |
# File 'lib/HDLRuby/hruby_low.rb', line 1652 def float? return @def.float? end |
#hash ⇒ Object
Hash function.
1620 1621 1622 |
# File 'lib/HDLRuby/hruby_low.rb', line 1620 def hash return [super,@def].hash end |
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
1725 1726 1727 |
# File 'lib/HDLRuby/hruby_low.rb', line 1725 def hierarchical? return @def.hierarchical? end |
#leaf? ⇒ Boolean
Tells if the type is a leaf.
1657 1658 1659 |
# File 'lib/HDLRuby/hruby_low.rb', line 1657 def leaf? return @def.leaf? end |
#max ⇒ Object
Gets the type max value if any. Default: not defined.
1674 1675 1676 |
# File 'lib/HDLRuby/hruby_low.rb', line 1674 def max return @def.max end |
#min ⇒ Object
Gets the type min value if any. Default: not defined.
1680 1681 1682 |
# File 'lib/HDLRuby/hruby_low.rb', line 1680 def min return @def.min end |
#range ⇒ Object
Gets the range of the type, by default range is not defined.
1695 1696 1697 |
# File 'lib/HDLRuby/hruby_low.rb', line 1695 def range return @def.range end |
#range? ⇒ Boolean
Tells if the type has a range.
1690 1691 1692 |
# File 'lib/HDLRuby/hruby_low.rb', line 1690 def range? return @def.range? end |
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
1715 1716 1717 |
# File 'lib/HDLRuby/hruby_low.rb', line 1715 def regular? return @def.regular? end |
#set_def!(type) ⇒ Object
Sets the type definition to +type+.
294 295 296 297 298 299 300 301 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 294 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.
1637 1638 1639 |
# File 'lib/HDLRuby/hruby_low.rb', line 1637 def signed? return @def.signed? end |
#struct? ⇒ Boolean
Tells if the type has named sub types.
1720 1721 1722 |
# File 'lib/HDLRuby/hruby_low.rb', line 1720 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)
596 597 598 599 600 601 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 596 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.
184 185 186 187 |
# 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 ⇒ Object
Creates a new high type definition.
70 71 72 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 70 def to_high return HDLRuby::High::Typdef.new(self.name,self.type.to_high) end |
#to_vector ⇒ Object
Converts to a bit vector.
1738 1739 1740 |
# File 'lib/HDLRuby/hruby_low.rb', line 1738 def to_vector return @def.to_vector end |
#to_verilog ⇒ Object
Converts the type to verilog code.
1800 1801 1802 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1800 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.
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# 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 |
#types? ⇒ Boolean
Tells if the type has sub types.
1710 1711 1712 |
# File 'lib/HDLRuby/hruby_low.rb', line 1710 def types? return @def.types? end |
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
1642 1643 1644 |
# File 'lib/HDLRuby/hruby_low.rb', line 1642 def unsigned? return @def.unsigned? end |
#vector? ⇒ Boolean
Tells if the type of of vector kind.
1662 1663 1664 |
# File 'lib/HDLRuby/hruby_low.rb', line 1662 def vector? return @def.vector? end |
#width ⇒ Object
Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float base have a width of 1.
1668 1669 1670 |
# File 'lib/HDLRuby/hruby_low.rb', line 1668 def width return @def.width end |