class HDLRuby::Low::Type
Describes a data type.
Describes a data type.
Extends the Type
class with generation of C text.
Extends the Type
class with generation of hdr text.
Add the conversion to high.
Extends the Type
class with conversion to symbol.
Extends the Type
class with generation of HDLRuby::High
text.
Describes a data type.
Extend Type
with check telling if it is a boolean type.
Extends the Type
class with functionality for breaking hierarchical types.
If
it is signed, it outputs signed. Enhance Type
with generation of verilog code.
Attributes
The name of the type
Public Class Methods
Creates a new type named name
.
# File lib/HDLRuby/hruby_low.rb, line 1219 def initialize(name) # Check and set the name. @name = name.to_sym end
Public Instance Methods
Gets the base type, by default base type is not defined.
# File lib/HDLRuby/hruby_low.rb, line 1313 def base raise AnyError, "No base type for type #{self}" end
Tells if the type has a base.
# File lib/HDLRuby/hruby_low.rb, line 1308 def base? return false end
Tells if it is a boolean type.
# File lib/HDLRuby/hruby_low_with_bool.rb, line 20 def boolean? return false end
Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. types
include the resulting types.
# File lib/HDLRuby/hruby_low_without_namespace.rb, line 284 def break_types!(types) # By default, nothing to do. return self end
Get the direction of the type, little or big endian.
# File lib/HDLRuby/hruby_low.rb, line 1292 def direction # By default, little endian. return :little end
Iterates over the types deeply if any.
# File lib/HDLRuby/hruby_low.rb, line 1347 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 that's all by default. end
Comparison for hash: structural comparison.
# File lib/HDLRuby/hruby_low.rb, line 1228 def eql?(obj) return false unless obj.is_a?(Type) return false unless @name.eql?(obj.name) return true end
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.
# File lib/HDLRuby/hruby_low.rb, line 1341 def equivalent?(type) # By default, types are equivalent iff they have the same name. return (type.is_a?(Type) and self.name == type.name) end
Tells if the type is fixed point.
# File lib/HDLRuby/hruby_low.rb, line 1250 def fixed? return false end
Tells if the type is floating point.
# File lib/HDLRuby/hruby_low.rb, line 1255 def float? return false end
Hash
function.
# File lib/HDLRuby/hruby_low.rb, line 1235 def hash return [@name].hash end
Tells if the type is hierarchical.
# File lib/HDLRuby/hruby_low.rb, line 1333 def hierarchical? return self.base? || self.types? end
Tells if the type is a leaf.
# File lib/HDLRuby/hruby_low.rb, line 1260 def leaf? return false end
Gets the type max value if any. Default: not defined.
# File lib/HDLRuby/hruby_low.rb, line 1281 def max raise AnyError, "No max value for type #{self}" end
Gets the type min value if any. Default: not defined.
# File lib/HDLRuby/hruby_low.rb, line 1287 def min raise AnyError, "No min value for type #{self}" end
Gets the range of the type, by default range is not defined.
# File lib/HDLRuby/hruby_low.rb, line 1303 def range raise AnyError, "No range for type #{self}" end
Tells if the type has a range.
# File lib/HDLRuby/hruby_low.rb, line 1298 def range? return false end
Tells if the type is regular (applies for tuples).
# File lib/HDLRuby/hruby_low.rb, line 1323 def regular? return false end
Sets the name
.
# File lib/HDLRuby/hruby_low_mutable.rb, line 268 def set_name!(name) @name = name.to_sym end
Tells if the type signed.
# File lib/HDLRuby/hruby_low.rb, line 1240 def signed? return false end
Tells if the type has named sub types.
# File lib/HDLRuby/hruby_low.rb, line 1328 def struct? return false end
Generates the C text of the equivalent HDLRuby
code. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2c.rb, line 513 def to_c(level = 0) # return Low2C.c_name(self.name) # return Low2C.type_name(Bit) + "()" if self.name == :bit || self.name == :unsigned then return "get_type_bit()" elsif self.name == :signed then return "get_type_signed()" else raise "Unknown type: #{self.name}" end end
Generates the text of the equivalent hdr text. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2hdr.rb, line 174 def to_hdr(level = 0) return Low2HDR.hdr_use_name(self.name) end
Creates a new high type.
# File lib/HDLRuby/hruby_low2high.rb, line 61 def to_high return HDLRuby::High::Type.new(self.name) end
Converts to a bit vector.
# File lib/HDLRuby/hruby_low.rb, line 1357 def to_vector return TypeVector.new(:"", Bit, self.width-1..0) end
Converts the type to Verilog
code.
# File lib/HDLRuby/hruby_verilog.rb, line 1689 def to_verilog return self.name == :signed ? "#{self.name.to_s} " : "" end
Generates the text of the equivalent HDLRuby::High
code. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2vhd.rb, line 619 def to_vhdl(level = 0) return self.boolean? ? "boolean" : "std_logic" end
Tells if the type has sub types.
# File lib/HDLRuby/hruby_low.rb, line 1318 def types? return false end
Tells if the type is unsigned.
# File lib/HDLRuby/hruby_low.rb, line 1245 def unsigned? return false end
Tells if the type of of vector kind.
# File lib/HDLRuby/hruby_low.rb, line 1265 def vector? return false end
Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float
base have a width of 1.
# File lib/HDLRuby/hruby_low.rb, line 1271 def width if [:bit, :signed, :unsigned, :float ].include?(@name) then return 1 else return 0 end end