Constants
Constants are defined using the Constant
type and are declared directly within
the package. They carry a fixed value, which may be computed from
other constants, and may be given an explicit bit width.
Example
The Packtype definition can either use a Python dataclass style or the Packtype custom grammar:
As rendered to SystemVerilog:
Syntax
Unsized Constants
A constant defined without an explicit size will be treated as unsized and it will be left to the target language template to decide what size container to allocate it.
Implicit Constants
Unsized constants may be declared implicitly by omitting the : Constant
keyword
from the declaration:
Note
This is only supported in the Python dataclass style syntax
Sized Constants
Constants may be defined with an explicit bit width, in which case Packtype will respect the request bit width internally and target language templates will allocate the nearest possible size large enough to hold the full range of that number of bits.
Expressions
Both the width and value assignment for a constant declaration may be computed from other constant definitions within the package.
Note
Both Python (.py) and Packtype (.pt) syntaxes use Python's arithmetic and logical operators
Oversized Values
When using explicitly sized constants, if a value is allocated to the constant
that is outside the legal range a ValueError
will be raised:
Will lead to: