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
typeis 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
namefromtype. -
#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!, #to_low, #to_viz_name
Methods included from Low2Symbol
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.
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 |
# File 'lib/HDLRuby/hruby_low.rb', line 1571 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.
1566 1567 1568 |
# File 'lib/HDLRuby/hruby_low.rb', line 1566 def def @def end |
Instance Method Details
#base ⇒ Object
Gets the base type, by default base type is not defined.
1692 1693 1694 |
# File 'lib/HDLRuby/hruby_low.rb', line 1692 def base return @def.base end |
#base? ⇒ Boolean
Tells if the type has a base.
1687 1688 1689 |
# File 'lib/HDLRuby/hruby_low.rb', line 1687 def base? return @def.base? end |
#direction ⇒ Object
Get the direction of the type, little or big endian.
1672 1673 1674 |
# File 'lib/HDLRuby/hruby_low.rb', line 1672 def direction return @def.direction end |
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1612 1613 1614 1615 1616 1617 1618 1619 |
# File 'lib/HDLRuby/hruby_low.rb', line 1612 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.
1596 1597 1598 1599 1600 1601 1602 1603 1604 |
# File 'lib/HDLRuby/hruby_low.rb', line 1596 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.
1720 1721 1722 |
# File 'lib/HDLRuby/hruby_low.rb', line 1720 def equivalent?(type) return @def.equivalent?(type) end |
#fixed? ⇒ Boolean
Tells if the type is fixed point.
1634 1635 1636 |
# File 'lib/HDLRuby/hruby_low.rb', line 1634 def fixed? return @def.fixed? end |
#float? ⇒ Boolean
Tells if the type is floating point.
1639 1640 1641 |
# File 'lib/HDLRuby/hruby_low.rb', line 1639 def float? return @def.float? end |
#hash ⇒ Object
Hash function.
1607 1608 1609 |
# File 'lib/HDLRuby/hruby_low.rb', line 1607 def hash return [super,@def].hash end |
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
1712 1713 1714 |
# File 'lib/HDLRuby/hruby_low.rb', line 1712 def hierarchical? return @def.hierarchical? end |
#leaf? ⇒ Boolean
Tells if the type is a leaf.
1644 1645 1646 |
# File 'lib/HDLRuby/hruby_low.rb', line 1644 def leaf? return @def.leaf? end |
#max ⇒ Object
Gets the type max value if any. Default: not defined.
1661 1662 1663 |
# File 'lib/HDLRuby/hruby_low.rb', line 1661 def max return @def.max end |
#min ⇒ Object
Gets the type min value if any. Default: not defined.
1667 1668 1669 |
# File 'lib/HDLRuby/hruby_low.rb', line 1667 def min return @def.min end |
#range ⇒ Object
Gets the range of the type, by default range is not defined.
1682 1683 1684 |
# File 'lib/HDLRuby/hruby_low.rb', line 1682 def range return @def.range end |
#range? ⇒ Boolean
Tells if the type has a range.
1677 1678 1679 |
# File 'lib/HDLRuby/hruby_low.rb', line 1677 def range? return @def.range? end |
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
1702 1703 1704 |
# File 'lib/HDLRuby/hruby_low.rb', line 1702 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.
1624 1625 1626 |
# File 'lib/HDLRuby/hruby_low.rb', line 1624 def signed? return @def.signed? end |
#struct? ⇒ Boolean
Tells if the type has named sub types.
1707 1708 1709 |
# File 'lib/HDLRuby/hruby_low.rb', line 1707 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_high ⇒ Object
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_vector ⇒ Object
Converts to a bit vector.
1725 1726 1727 |
# File 'lib/HDLRuby/hruby_low.rb', line 1725 def to_vector return @def.to_vector end |
#to_verilog ⇒ Object
Converts the type to verilog code.
1945 1946 1947 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1945 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.
1697 1698 1699 |
# File 'lib/HDLRuby/hruby_low.rb', line 1697 def types? return @def.types? end |
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
1629 1630 1631 |
# File 'lib/HDLRuby/hruby_low.rb', line 1629 def unsigned? return @def.unsigned? end |
#vector? ⇒ Boolean
Tells if the type of of vector kind.
1649 1650 1651 |
# File 'lib/HDLRuby/hruby_low.rb', line 1649 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.
1655 1656 1657 |
# File 'lib/HDLRuby/hruby_low.rb', line 1655 def width return @def.width end |