Skip to content

Module Parameter

Module Parameter .

Parameter Examples

Usage:

>>> from tabulate import tabulate
>>> import ucdp as u
>>> u.Param(u.UintType(6), "param_p")
Param(UintType(6), 'param_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 parameter:

>>> param = u.Param(BType(), "param_p")
>>> for item in param:
...     print(repr(item))
Param(BType(), 'param_p')
Param(AType(), 'param_foo_p')
Param(BitType(), 'param_foo_req_p')
Param(ArrayType(UintType(16), 5), 'param_foo_data_p')
Param(BitType(), 'param_foo_ack_p')
Param(MType(), 'param_mode_p')
Param(ArrayType(AType(), 3), 'param_bar_p')
Param(ArrayType(BitType(), 3), 'param_bar_ack_p')
Param(ArrayType(ArrayType(UintType(16), 5), 3), 'param_bar_data_p')
Param(ArrayType(BitType(), 3), 'param_bar_req_p')

Value:

>>> for item in u.Param(u.UintType(6), "param_p").iter():
...     print(repr(item))
Param(UintType(6), 'param_p')
>>> for item in u.Param(u.UintType(6), "param_p").iter(value=42):
...     print(repr(item))
Param(UintType(6, default=42), 'param_p')

Param

Bases: Ident

Module Parameter.

Parameters:

Name Type Description Default
type_ AType

Type.

required
name Name

Name.

required

Other Parameters:

Name Type Description
doc Doc

Documentation Container

value

Value.

Note

Parameter names should end with '_p', but must not.

Param Examples

Example:

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

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

>>> int(u.Param(u.UintType(6, default=2), "cnt_p"))
2
>>> int(u.Param(u.UintType(6, default=2), "cnt_p", value=4))
4

Parameter are Singleton:

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

iter

iter(filter_=None, stop=None, value=None)

Iterate over Hierarchy.