Class: HDLRuby::Low::TypeDef
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.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
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(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code.
-
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#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?, #leaf?, #range, #range?, #regular?, #set_name!, #signed?, #struct?, #to_vector, #types?, #unsigned?, #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+.
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 |
# File 'lib/HDLRuby/hruby_low.rb', line 1401 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?, :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.
1396 1397 1398 |
# File 'lib/HDLRuby/hruby_low.rb', line 1396 def def @def end |
Instance Method Details
#each_type_deep(&ruby_block) ⇒ Object
Iterates over the types deeply if any.
1441 1442 1443 1444 1445 1446 1447 1448 |
# File 'lib/HDLRuby/hruby_low.rb', line 1441 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.
1426 1427 1428 1429 1430 1431 1432 1433 |
# File 'lib/HDLRuby/hruby_low.rb', line 1426 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.
1436 1437 1438 |
# File 'lib/HDLRuby/hruby_low.rb', line 1436 def hash return [super,@def].hash end |
#set_def!(type) ⇒ Object
Sets the type definition to +type+.
282 283 284 285 286 287 288 289 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 282 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(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
523 524 525 526 527 528 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 523 def to_c(level = 0) # # Simply use the name of the type. # return Low2C.type_name(self.name) + "()" # Simply return the defined type. return self.def.to_c(level) end |
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
184 185 186 187 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 184 def to_high(level = 0) # Simply generates the redefined type. self.def.to_high(level) end |
#to_verilog ⇒ Object
Converts the type to verilog code.
1642 1643 1644 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1642 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.
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 619 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 |