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

#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

#to_sym

Methods included from Hparent

#hierarchy, #no_parent!, #scope

Methods included from Ltype

included, #ltype?

Constructor Details

#initialize(name, type) ⇒ TypeDef

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



1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
# File 'lib/HDLRuby/hruby_low.rb', line 1583

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.



1578
1579
1580
# File 'lib/HDLRuby/hruby_low.rb', line 1578

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.



1624
1625
1626
1627
1628
1629
1630
1631
# File 'lib/HDLRuby/hruby_low.rb', line 1624

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)


1608
1609
1610
1611
1612
1613
1614
1615
1616
# File 'lib/HDLRuby/hruby_low.rb', line 1608

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

#hashObject

Hash function.



1619
1620
1621
# File 'lib/HDLRuby/hruby_low.rb', line 1619

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_highObject

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_verilogObject

Converts the type to verilog code.



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

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