Class: HDLRuby::Low::Type

Inherits:
Base::Type
  • Object
show all
Includes:
Hparent, Low2Symbol, Ltype
Defined in:
lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2sym.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,
lib/HDLRuby/hruby_low_with_bool.rb,
lib/HDLRuby/hruby_low_without_namespace.rb

Overview

Extends the Type class with functionality for breaking hierarchical types.

Direct Known Subclasses

High::Type, TypeDef, TypeStruct, TypeTuple, TypeVector

Constant Summary

Constants included from Low2Symbol

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

Instance Attribute Summary collapse

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#scope

Methods included from Ltype

included, #ltype?

Constructor Details

#initialize(name) ⇒ Type

Creates a new type named +name+.



1140
1141
1142
1143
# File 'lib/HDLRuby/hruby_low.rb', line 1140

def initialize(name)
    # Check and set the name.
    @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

The name of the type



1137
1138
1139
# File 'lib/HDLRuby/hruby_low.rb', line 1137

def name
  @name
end

Instance Method Details

#baseObject

Gets the base type, by default base type is not defined.

Raises:



1214
1215
1216
# File 'lib/HDLRuby/hruby_low.rb', line 1214

def base
    raise AnyError, "No base type for type #{self}"
end

#base?Boolean

Tells if the type has a base.



1209
1210
1211
# File 'lib/HDLRuby/hruby_low.rb', line 1209

def base?
    return false
end

#boolean?Boolean

Tells if it is a boolean type.



20
21
22
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 20

def boolean?
    return false
end

#break_types!(types) ⇒ Object

Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. +types+ include the resulting types.



284
285
286
287
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 284

def break_types!(types)
    # By default, nothing to do.
    return self
end

#directionObject

Get the direction of the type, little or big endian.



1193
1194
1195
1196
# File 'lib/HDLRuby/hruby_low.rb', line 1193

def direction
    # By default, little endian.
    return :little
end

#each_type_deep(&ruby_block) ⇒ Object

Iterates over the types deeply if any.



1243
1244
1245
1246
1247
1248
1249
# File 'lib/HDLRuby/hruby_low.rb', line 1243

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

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.



1146
1147
1148
1149
1150
# File 'lib/HDLRuby/hruby_low.rb', line 1146

def eql?(obj)
    return false unless obj.is_a?(Type)
    return false unless @name.eql?(obj.name)
    return true
end

#equivalent?(type) ⇒ Boolean

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.



1237
1238
1239
1240
# File 'lib/HDLRuby/hruby_low.rb', line 1237

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

#fixed?Boolean

Tells if the type is fixed point.



1168
1169
1170
# File 'lib/HDLRuby/hruby_low.rb', line 1168

def fixed?
    return false
end

#float?Boolean

Tells if the type is floating point.



1173
1174
1175
# File 'lib/HDLRuby/hruby_low.rb', line 1173

def float?
    return false
end

#hashObject

Hash function.



1153
1154
1155
# File 'lib/HDLRuby/hruby_low.rb', line 1153

def hash
    return [@name].hash
end

#leaf?Boolean

Tells if the type is a leaf.



1178
1179
1180
# File 'lib/HDLRuby/hruby_low.rb', line 1178

def leaf?
    return false
end

#rangeObject

Gets the range of the type, by default range is not defined.

Raises:



1204
1205
1206
# File 'lib/HDLRuby/hruby_low.rb', line 1204

def range
    raise AnyError, "No range for type #{self}"
end

#range?Boolean

Tells if the type has a range.



1199
1200
1201
# File 'lib/HDLRuby/hruby_low.rb', line 1199

def range?
    return false
end

#regular?Boolean

Tells if the type is regular (applies for tuples).



1224
1225
1226
# File 'lib/HDLRuby/hruby_low.rb', line 1224

def regular?
    return false
end

#set_name!(name) ⇒ Object

Sets the +name+.



241
242
243
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 241

def set_name!(name)
    @name = name.to_sym
end

#signed?Boolean

Tells if the type signed.



1158
1159
1160
# File 'lib/HDLRuby/hruby_low.rb', line 1158

def signed?
    return false
end

#struct?Boolean

Tells if the type has named sub types.



1229
1230
1231
# File 'lib/HDLRuby/hruby_low.rb', line 1229

def struct?
    return false
end

#to_c(level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/HDLRuby/hruby_low2c.rb', line 503

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

#to_high(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



174
175
176
# File 'lib/HDLRuby/hruby_low2high.rb', line 174

def to_high(level = 0)
    return Low2High.high_use_name(self.name)
end

#to_vectorObject

Converts to a bit vector.



1252
1253
1254
# File 'lib/HDLRuby/hruby_low.rb', line 1252

def to_vector
    return TypeVector.new(:"", Bit, self.width-1..0)
end

#to_verilogObject

Converts the system to Verilog code.



1566
1567
1568
# File 'lib/HDLRuby/hruby_verilog.rb', line 1566

def to_verilog
    return self.name == :signed ? "#{self.name.to_s} " : ""
end

#to_vhdl(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



606
607
608
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 606

def to_vhdl(level = 0)
    return self.boolean? ? "boolean" : "std_logic"
end

#types?Boolean

Tells if the type has sub types.



1219
1220
1221
# File 'lib/HDLRuby/hruby_low.rb', line 1219

def types?
    return false
end

#unsigned?Boolean

Tells if the type is unsigned.



1163
1164
1165
# File 'lib/HDLRuby/hruby_low.rb', line 1163

def unsigned?
    return false
end

#widthObject

Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float base have a width of 1.



1184
1185
1186
1187
1188
1189
1190
# File 'lib/HDLRuby/hruby_low.rb', line 1184

def width
    if [:bit, :signed, :unsigned, :float ].include?(@name) then
        return 1
    else
        return 0
    end
end