Class: HDLRuby::Low::Type
- Inherits:
-
Object
- Object
- HDLRuby::Low::Type
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_viz.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.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
Describes a data type.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the type.
Attributes included from Hparent
Instance Method Summary collapse
-
#base ⇒ Object
Gets the base type, by default base type is not defined.
-
#base? ⇒ Boolean
Tells if the type has a base.
-
#boolean? ⇒ Boolean
Tells if it is a boolean type.
-
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions.
-
#direction ⇒ Object
Get the direction of the type, little or big endian.
-
#each_type_deep(&ruby_block) ⇒ Object
(also: #each_deep)
Iterates over the types deeply if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#equivalent?(type) ⇒ Boolean
Tell if
typeis equivalent to current type. -
#fixed? ⇒ Boolean
Tells if the type is fixed point.
-
#float? ⇒ Boolean
Tells if the type is floating point.
-
#hash ⇒ Object
Hash function.
-
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
-
#initialize(name) ⇒ Type
constructor
Creates a new type named
name. -
#leaf? ⇒ Boolean
Tells if the type is a leaf.
-
#max ⇒ Object
Gets the type max value if any.
-
#min ⇒ Object
Gets the type min value if any.
-
#range ⇒ Object
Gets the range of the type, by default range is not defined.
-
#range? ⇒ Boolean
Tells if the type has a range.
-
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
-
#set_name!(name) ⇒ Object
Sets the
name. -
#signed? ⇒ Boolean
Tells if the type signed.
-
#struct? ⇒ Boolean
Tells if the type has named sub types.
-
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high type.
-
#to_low ⇒ Object
Converts the system to HDLRuby::Low.
-
#to_vector ⇒ Object
Converts to a bit vector.
-
#to_verilog ⇒ Object
Converts the type to Verilog code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_viz_name ⇒ Object
Convert to a name usable in a Viz representation.
-
#types? ⇒ Boolean
Tells if the type has sub types.
-
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
-
#vector? ⇒ Boolean
Tells if the type of of vector kind.
-
#width ⇒ Object
Gets the bitwidth of the type, by default 0.
Methods included from Low2Symbol
Methods included from Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(name) ⇒ Type
Creates a new type named name.
1283 1284 1285 1286 |
# File 'lib/HDLRuby/hruby_low.rb', line 1283 def initialize(name) # Check and set the name. @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the type
1280 1281 1282 |
# File 'lib/HDLRuby/hruby_low.rb', line 1280 def name @name end |
Instance Method Details
#base ⇒ Object
Gets the base type, by default base type is not defined.
1380 1381 1382 |
# File 'lib/HDLRuby/hruby_low.rb', line 1380 def base raise AnyError, "No base type for type #{self}" end |
#base? ⇒ Boolean
Tells if the type has a base.
1375 1376 1377 |
# File 'lib/HDLRuby/hruby_low.rb', line 1375 def base? return false end |
#boolean? ⇒ Boolean
Tells if it is a boolean type.
24 25 26 |
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 24 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.
302 303 304 305 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 302 def break_types!(types) # By default, nothing to do. return self end |
#direction ⇒ Object
Get the direction of the type, little or big endian.
1359 1360 1361 1362 |
# File 'lib/HDLRuby/hruby_low.rb', line 1359 def direction # By default, little endian. return :little end |
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1414 1415 1416 1417 1418 1419 1420 |
# File 'lib/HDLRuby/hruby_low.rb', line 1414 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.
1295 1296 1297 1298 1299 |
# File 'lib/HDLRuby/hruby_low.rb', line 1295 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.
1408 1409 1410 1411 |
# File 'lib/HDLRuby/hruby_low.rb', line 1408 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.
1317 1318 1319 |
# File 'lib/HDLRuby/hruby_low.rb', line 1317 def fixed? return false end |
#float? ⇒ Boolean
Tells if the type is floating point.
1322 1323 1324 |
# File 'lib/HDLRuby/hruby_low.rb', line 1322 def float? return false end |
#hash ⇒ Object
Hash function.
1302 1303 1304 |
# File 'lib/HDLRuby/hruby_low.rb', line 1302 def hash return [@name].hash end |
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
1400 1401 1402 |
# File 'lib/HDLRuby/hruby_low.rb', line 1400 def hierarchical? return self.base? || self.types? end |
#leaf? ⇒ Boolean
Tells if the type is a leaf.
1327 1328 1329 |
# File 'lib/HDLRuby/hruby_low.rb', line 1327 def leaf? return false end |
#max ⇒ Object
Gets the type max value if any. Default: not defined.
1348 1349 1350 |
# File 'lib/HDLRuby/hruby_low.rb', line 1348 def max raise AnyError, "No max value for type #{self}" end |
#min ⇒ Object
Gets the type min value if any. Default: not defined.
1354 1355 1356 |
# File 'lib/HDLRuby/hruby_low.rb', line 1354 def min raise AnyError, "No min value for type #{self}" end |
#range ⇒ Object
Gets the range of the type, by default range is not defined.
1370 1371 1372 |
# File 'lib/HDLRuby/hruby_low.rb', line 1370 def range raise AnyError, "No range for type #{self}" end |
#range? ⇒ Boolean
Tells if the type has a range.
1365 1366 1367 |
# File 'lib/HDLRuby/hruby_low.rb', line 1365 def range? return false end |
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
1390 1391 1392 |
# File 'lib/HDLRuby/hruby_low.rb', line 1390 def regular? return false end |
#set_name!(name) ⇒ Object
Sets the name.
276 277 278 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 276 def set_name!(name) @name = name.to_sym end |
#signed? ⇒ Boolean
Tells if the type signed.
1307 1308 1309 |
# File 'lib/HDLRuby/hruby_low.rb', line 1307 def signed? return false end |
#struct? ⇒ Boolean
Tells if the type has named sub types.
1395 1396 1397 |
# File 'lib/HDLRuby/hruby_low.rb', line 1395 def struct? return false 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)
576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 576 def to_c(res,level = 0) if self.name == :bit || self.name == :unsigned then # return "get_type_bit()" res << "get_type_bit()" elsif self.name == :signed then # return "get_type_signed()" res << "get_type_signed()" else raise "Unknown type: #{self.name}" end return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
level is the hierachical level of the object.
174 175 176 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 174 def to_hdr(level = 0) return Low2HDR.hdr_use_name(self.name) end |
#to_high ⇒ Object
Creates a new high type.
64 65 66 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 64 def to_high return HDLRuby::High::Type.new(self.name) end |
#to_low ⇒ Object
Converts the system to HDLRuby::Low. Here already low.
1290 1291 1292 |
# File 'lib/HDLRuby/hruby_low.rb', line 1290 def to_low return self end |
#to_vector ⇒ Object
Converts to a bit vector.
1424 1425 1426 |
# File 'lib/HDLRuby/hruby_low.rb', line 1424 def to_vector return TypeVector.new(:"", Bit, self.width-1..0) end |
#to_verilog ⇒ Object
Converts the type to Verilog code.
1935 1936 1937 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1935 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.
619 620 621 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 619 def to_vhdl(level = 0) return self.boolean? ? "boolean" : "std_logic" end |
#to_viz_name ⇒ Object
Convert to a name usable in a Viz representation.
5338 5339 5340 |
# File 'lib/HDLRuby/hruby_viz.rb', line 5338 def to_viz_name return self.name.to_s end |
#types? ⇒ Boolean
Tells if the type has sub types.
1385 1386 1387 |
# File 'lib/HDLRuby/hruby_low.rb', line 1385 def types? return false end |
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
1312 1313 1314 |
# File 'lib/HDLRuby/hruby_low.rb', line 1312 def unsigned? return false end |
#vector? ⇒ Boolean
Tells if the type of of vector kind.
1332 1333 1334 |
# File 'lib/HDLRuby/hruby_low.rb', line 1332 def vector? return false end |
#width ⇒ Object
Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float base have a width of 1.
1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/HDLRuby/hruby_low.rb', line 1338 def width if [:bit, :signed, :unsigned, :float ].include?(@name) then return 1 else return 0 end end |