Skip to content

Constant

Module Constant.

Constant Examples

Usage:

>>> from tabulate import tabulate
>>> import ucdp as u
>>> u.Const(u.UintType(6), "const_p")
Const(UintType(6), 'const_p')

Also complex types can simply be used:

>>> class AType(u.AStructType):
...     def _build(self) -> None:
...         self._add("req", u.BitType())
...         self._add("data", u.ArrayType(u.UintType(16), 5))
...         self._add("ack", u.BitType(), u.BWD)
>>> class MType(u.AEnumType):
...     keytype: u.AScalarType = u.UintType(2)
...     def _build(self) -> None:
...         self._add(0, "Linear")
...         self._add(1, "Cyclic")
>>> class BType(u.AStructType):
...     def _build(self) -> None:
...         self._add("foo", AType())
...         self._add("mode", MType())
...         self._add("bar", u.ArrayType(AType(), 3), u.BWD)

These types are automatically resolved by iterating over the Constant:

>>> const = u.Const(BType(), "const_p")
>>> for item in const:
...     print(repr(item))
Const(BType(), 'const_p')
Const(AType(), 'const_foo_p')
Const(BitType(), 'const_foo_req_p')
Const(ArrayType(UintType(16), 5), 'const_foo_data_p')
Const(BitType(), 'const_foo_ack_p')
Const(MType(), 'const_mode_p')
Const(ArrayType(AType(), 3), 'const_bar_p')
Const(ArrayType(BitType(), 3), 'const_bar_ack_p')
Const(ArrayType(ArrayType(UintType(16), 5), 3), 'const_bar_data_p')
Const(ArrayType(BitType(), 3), 'const_bar_req_p')

Const

Bases: Ident

Module Constant.

Parameters:

Name Type Description Default
type_ BaseType

Type.

required
name str

Name.

required

Attributes:

Name Type Description
direction

Direction.

doc

Documentation Container

ifdef

IFDEF encapsulation

Constant Examples

Basics:

>>> import ucdp as u
>>> cnt = u.Const(u.UintType(6), "cnt_p")
>>> cnt
Const(UintType(6), 'cnt_p')
>>> cnt.type_
UintType(6)
>>> cnt.name
'cnt_p'
>>> cnt.basename
'cnt'
>>> cnt.suffix
'_p'
>>> cnt.doc
Doc()
Casting Constant

If the constant is casted via int() it returns value if set, other type_.default.

>>> int(u.Const(u.UintType(6, default=2), "cnt_p"))
2
Constant are Singleton

Constant are Singleton:

>>> u.Const(u.UintType(6), "cnt_p") is u.Const(u.UintType(6), "cnt_p")
True