Class: HDLRuby::High::TypeGen

Inherits:
Type show all
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Describes a high-level generic type definition.

NOTE: this type does not correspond to any low-level type

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary

Attributes inherited from Type

#rctype

Attributes inherited from Low::Type

#name

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods inherited from Type

#to_rcsim

Methods included from Htype

#[], #binary, #comp_operator, #constant, #define_operator, #each_overload, #htype?, included, #inner, #inout, #input, #left, #name=, #output, #register, #right, #to_type, #typedef, #unary

Methods included from Tprocess

#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~

Methods inherited from Low::Type

#base, #base?, #boolean?, #break_types!, #direction, #each_type_deep, #eql?, #equivalent?, #fixed?, #float?, #hash, #hierarchical?, #leaf?, #max, #min, #range, #range?, #regular?, #set_name!, #signed?, #struct?, #to_c, #to_hdr, #to_high, #to_vector, #to_verilog, #to_vhdl, #types?, #unsigned?, #vector?, #width

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #no_parent!, #scope

Methods included from Low::Ltype

included, #ltype?

Constructor Details

#initialize(name, &ruby_block) ⇒ TypeGen

Creates a new generic type definition producing a new type by executing +ruby_block+.



1926
1927
1928
1929
1930
1931
1932
# File 'lib/HDLRuby/hruby_high.rb', line 1926

def initialize(name,&ruby_block)
    # Initialize the type structure.
    super(name)

    # Sets the block to execute when instantiating the type.
    @instance_proc = ruby_block
end

Instance Method Details

#generate(*args) ⇒ Object

Generates the type with +args+ generic parameters.



1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
# File 'lib/HDLRuby/hruby_high.rb', line 1935

def generate(*args)
    # Generate the resulting type.
    gtype = High.top_user.instance_exec(*args,&@instance_proc)
    # Ensures a type has been produced.
    gtype = gtype.to_type if gtype.respond_to?(:to_type)
    unless gtype.is_a?(HDLRuby::Low::Type) then
        raise AnyError, "Generic type #{self.name} did not produce a valid type: #{gtype.class}"
    end
    # Create a new type definition from it.
    gtype = TypeDef.new(self.name.to_s + "_#{args.join(":")}",
                           gtype)
    # Adds the possible overloaded operators.
    self.each_overload do |op,ruby_block|
        gtype.define_operator(op,&(ruby_block.curry[*args]))
    end
    # Returns the resulting type
    return gtype
end

#to_low(name = self.name) ⇒ Object

Converts the type to HDLRuby::Low and set its +name+.

NOTE: should be overridden by other type classes.



1957
1958
1959
1960
1961
1962
1963
1964
# File 'lib/HDLRuby/hruby_high.rb', line 1957

def to_low(name = self.name)
    # return HDLRuby::Low::TypeDef.new(name,self.def.to_low)
    typeDefL = HDLRuby::Low::TypeDef.new(name,self.def.to_low)
    # # For debugging: set the source high object 
    # typeDefL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = typeDefL
    return typeDefL
end