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
-
#each_type_deep(&ruby_block) ⇒ Object
(also: #each_deep)
Iterates over the types deeply if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#hash ⇒ Object
Hash function.
-
#initialize(name, type) ⇒ TypeDef
constructor
Creates a new type definition named +name+ from +type+.
-
#set_def!(type) ⇒ Object
Sets the type definition to +type+.
-
#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_verilog ⇒ Object
Converts the type to verilog code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods inherited from Type
#base, #base?, #boolean?, #break_types!, #direction, #equivalent?, #fixed?, #float?, #hierarchical?, #leaf?, #max, #min, #range, #range?, #regular?, #set_name!, #signed?, #struct?, #to_vector, #types?, #unsigned?, #vector?, #width
Methods included from Low2Symbol
Methods included from Hparent
Methods included from Ltype
Constructor Details
#initialize(name, type) ⇒ TypeDef
Creates a new type definition named +name+ from +type+.
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 |
# File 'lib/HDLRuby/hruby_low.rb', line 1550 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.
1545 1546 1547 |
# File 'lib/HDLRuby/hruby_low.rb', line 1545 def def @def end |
Instance Method Details
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1590 1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/HDLRuby/hruby_low.rb', line 1590 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.
1575 1576 1577 1578 1579 1580 1581 1582 |
# File 'lib/HDLRuby/hruby_low.rb', line 1575 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 ⇒ Object
Hash function.
1585 1586 1587 |
# File 'lib/HDLRuby/hruby_low.rb', line 1585 def hash return [super,@def].hash 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 |
#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)
595 596 597 598 599 600 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 595 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_verilog ⇒ Object
Converts the type to verilog code.
1766 1767 1768 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1766 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 |