Identifier
Identifier.
All symbols within a hardware module are identifier and derived from Ident. Identifier should be stored in Idents. Identifier are itself part of an expression and therefore a child of Expr.
Identifier Examples
Basics:
>>> import ucdp as u
>>> class ModeType(u.AEnumType):
... keytype: u.AScalarType = u.UintType(2)
... def _build(self) -> None:
... self._add(0, "add")
... self._add(1, "sub")
... self._add(2, "max")
>>> class MyType(u.AStructType):
... def _build(self) -> None:
... self._add("mode", ModeType())
... self._add("send", u.ArrayType(u.UintType(8), 3))
... self._add("return", u.UintType(4), u.BWD)
>>> idents = u.Idents([
... u.Ident(u.UintType(8), "vec_a_i"),
... u.Ident(u.UintType(8), "vec_a_o"),
... u.Ident(u.UintType(4), "vec_c_s"),
... u.Ident(MyType(), "my_a_s"),
... u.Ident(u.ArrayType(MyType(), 4), "my_b_s"),
... ])
Retrieve An Item
Retrieve an item:
>>> idents['vec_a_i']
Ident(UintType(8), 'vec_a_i')
>>> idents['my_a_mode_s']
Ident(ModeType(), 'my_a_mode_s')
Simple Iteration
Simple iteration:
>>> for ident in idents:
... ident
Ident(UintType(8), 'vec_a_i')
Ident(UintType(8), 'vec_a_o')
Ident(UintType(4), 'vec_c_s')
Ident(MyType(), 'my_a_s')
Ident(ArrayType(MyType(), 4), 'my_b_s')
Unrolling Iteration
Unrolling iteration:
>>> for ident in idents.iter():
... ident
Ident(UintType(8), 'vec_a_i')
Ident(UintType(8), 'vec_a_o')
Ident(UintType(4), 'vec_c_s')
Ident(MyType(), 'my_a_s')
Ident(ModeType(), 'my_a_mode_s')
Ident(ArrayType(UintType(8), 3), 'my_a_send_s')
Ident(UintType(4), 'my_a_return_s')
Ident(ArrayType(MyType(), 4), 'my_b_s')
Ident(ArrayType(UintType(4), 4), 'my_b_return_s')
Ident(ArrayType(ArrayType(UintType(8), 3), 4), 'my_b_send_s')
Ident(ArrayType(ModeType(), 4), 'my_b_mode_s')
Some Features
Some features:
>>> idents['my_b_send_s']
Ident(ArrayType(ArrayType(UintType(8), 3), 4), 'my_b_send_s')
>>> 'my_b_send_s' in idents
True
>>> 'my_b_send' in idents
False
Ident
Bases: Expr, NamedObject, Light
Identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ |
BaseType
|
Type. |
required |
name |
str
|
Name. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
AOrientation | None
|
Direction. |
doc |
Doc
|
Documentation Container |
ifdef |
str | None
|
IFDEF encapsulation |
Ident Examples
Attributes:
>>> import ucdp as u
>>> ident = Ident(u.UintType(32), 'base_sub_i')
>>> ident.type_
UintType(32)
>>> ident.name
'base_sub_i'
>>> ident.direction
>>> ident.doc
Doc()
Calculated Properties:
>>> ident.basename
'base_sub'
>>> ident.suffix
'_i'
Idents
get_ident
Retrieve identifier by name, without iterating over the entire identifier tree.