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_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

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

#hierarchy, #scope

Methods included from Ltype

included, #ltype?

Constructor Details

#initialize(name) ⇒ Type

Creates a new type named +name+.



1266
1267
1268
1269
# File 'lib/HDLRuby/hruby_low.rb', line 1266

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

Instance Attribute Details

#nameObject (readonly)

The name of the type



1263
1264
1265
# File 'lib/HDLRuby/hruby_low.rb', line 1263

def name
  @name
end

Instance Method Details

#baseObject

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

Raises:



1360
1361
1362
# File 'lib/HDLRuby/hruby_low.rb', line 1360

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

#base?Boolean

Tells if the type has a base.

Returns:

  • (Boolean)


1355
1356
1357
# File 'lib/HDLRuby/hruby_low.rb', line 1355

def base?
    return false
end

#boolean?Boolean

Tells if it is a boolean type.

Returns:

  • (Boolean)


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.



289
290
291
292
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 289

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

#directionObject

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



1339
1340
1341
1342
# File 'lib/HDLRuby/hruby_low.rb', line 1339

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.



1394
1395
1396
1397
1398
1399
1400
# File 'lib/HDLRuby/hruby_low.rb', line 1394

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.

Returns:

  • (Boolean)


1275
1276
1277
1278
1279
# File 'lib/HDLRuby/hruby_low.rb', line 1275

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.

Returns:

  • (Boolean)


1388
1389
1390
1391
# File 'lib/HDLRuby/hruby_low.rb', line 1388

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.

Returns:

  • (Boolean)


1297
1298
1299
# File 'lib/HDLRuby/hruby_low.rb', line 1297

def fixed?
    return false
end

#float?Boolean

Tells if the type is floating point.

Returns:

  • (Boolean)


1302
1303
1304
# File 'lib/HDLRuby/hruby_low.rb', line 1302

def float?
    return false
end

#hashObject

Hash function.



1282
1283
1284
# File 'lib/HDLRuby/hruby_low.rb', line 1282

def hash
    return [@name].hash
end

#hierarchical?Boolean

Tells if the type is hierarchical.

Returns:

  • (Boolean)


1380
1381
1382
# File 'lib/HDLRuby/hruby_low.rb', line 1380

def hierarchical?
    return self.base? || self.types?
end

#leaf?Boolean

Tells if the type is a leaf.

Returns:

  • (Boolean)


1307
1308
1309
# File 'lib/HDLRuby/hruby_low.rb', line 1307

def leaf?
    return false
end

#maxObject

Gets the type max value if any. Default: not defined.

Raises:



1328
1329
1330
# File 'lib/HDLRuby/hruby_low.rb', line 1328

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

#minObject

Gets the type min value if any. Default: not defined.

Raises:



1334
1335
1336
# File 'lib/HDLRuby/hruby_low.rb', line 1334

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

#rangeObject

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

Raises:



1350
1351
1352
# File 'lib/HDLRuby/hruby_low.rb', line 1350

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

#range?Boolean

Tells if the type has a range.

Returns:

  • (Boolean)


1345
1346
1347
# File 'lib/HDLRuby/hruby_low.rb', line 1345

def range?
    return false
end

#regular?Boolean

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

Returns:

  • (Boolean)


1370
1371
1372
# File 'lib/HDLRuby/hruby_low.rb', line 1370

def regular?
    return false
end

#set_name!(name) ⇒ Object

Sets the +name+.



280
281
282
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 280

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

#signed?Boolean

Tells if the type signed.

Returns:

  • (Boolean)


1287
1288
1289
# File 'lib/HDLRuby/hruby_low.rb', line 1287

def signed?
    return false
end

#struct?Boolean

Tells if the type has named sub types.

Returns:

  • (Boolean)


1375
1376
1377
# File 'lib/HDLRuby/hruby_low.rb', line 1375

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)



575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/HDLRuby/hruby_low2c.rb', line 575

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_highObject

Creates a new high type.



61
62
63
# File 'lib/HDLRuby/hruby_low2high.rb', line 61

def to_high
    return HDLRuby::High::Type.new(self.name)
end

#to_vectorObject

Converts to a bit vector.



1404
1405
1406
# File 'lib/HDLRuby/hruby_low.rb', line 1404

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

#to_verilogObject

Converts the type to Verilog code.



1758
1759
1760
# File 'lib/HDLRuby/hruby_verilog.rb', line 1758

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

#types?Boolean

Tells if the type has sub types.

Returns:

  • (Boolean)


1365
1366
1367
# File 'lib/HDLRuby/hruby_low.rb', line 1365

def types?
    return false
end

#unsigned?Boolean

Tells if the type is unsigned.

Returns:

  • (Boolean)


1292
1293
1294
# File 'lib/HDLRuby/hruby_low.rb', line 1292

def unsigned?
    return false
end

#vector?Boolean

Tells if the type of of vector kind.

Returns:

  • (Boolean)


1312
1313
1314
# File 'lib/HDLRuby/hruby_low.rb', line 1312

def vector?
    return false
end

#widthObject

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



1318
1319
1320
1321
1322
1323
1324
# File 'lib/HDLRuby/hruby_low.rb', line 1318

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