Scalars
Scalars are the most simple definition of a type as they describe a single
dimensioned bitvector. They are declared using the Scalar
type and can be
declared within packages or structs.
Example
The Packtype definition can either use a Python dataclass style or the Packtype custom grammar:
As rendered to SystemVerilog:
Note
Packtype currently processes the width of the scalar at the point of definition,
hence when rendered it does not visibly refer to TYPE_A_W
but it is internally
consistent with the definition.
Syntax
Scalars must be defined with an explicit bit width expressed within the square
brackets ([...]
) following the Scalar
keyword. The width must be a positive
integer value, and may be either hardcoded or refer to a constant
or an expression. A second optional boolean parameter may be provided that
encodes whether the scalar is signed (True
) or unsigned (False
), defaulting
to unsigned.
@packtype.package()
class MyPackage:
# Format: <NAME> : Scalar[<WIDTH>, <SIGNED>]
MyType : Scalar[123, False]
Helper Properties and Methods
Scalar definitions expose a collection of helper functions for properties related to the type:
<Scalar>._pt_width
- property that returns the bit width of the type;<Scalar>._pt_signed
- property that returns whether the scalar expresses a signed or unsigned type;<Scalar>._pt_mask
- property that returns a bit mask matched to the width of the type (i.e.(1 << MyScalar._pt_width) - 1
).