Packages
Packages separate aliases, constants, enumerations, structs, and unions into distinct namespaces - definitions cannot otherwise exist outside of a package.
Example
The Packtype definition can either use a Python dataclass style or the Packtype custom grammar:
As rendered to SystemVerilog:
Imports
Types and constants defined in one package may reference types and constants defined in another package and Packtype will track which entities are local and foreign.
When using the Python dataclass style syntax, packages may be referenced in the same fashion that normal imports operate:
package_a.py | |
---|---|
When using the Packtype custom grammar, packages may be referenced using the
import
keyword:
package_b.pt | |
---|---|
Note
When using the Packtype custom grammar, all packages that are referenced will need to be provided to Packtype in order for imports to be resolved
Python Decorators
Python package definitions expose a set of decorators for declaring attached types:
@<PACKAGE>.enum()
- used for declaring enumerations@<PACKAGE>.struct()
- used for declaring packed data structures@<PACKAGE>.union()
- used for declaring packed unions
Helper Properties and Methods
Package definitions expose a collection of helper functions for accessing members of the package:
<PACKAGE>._pt_foreign()
- function returning the ordered set of types referenced by other packages in fields of structs or unions;<PACKAGE>._pt_fields
- property that returns the dictionary of definitions attached to the package where key is the field instance, value is the field name;<PACKAGE>._pt_constants
- property that returns an iterable of all constants attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_scalars
- property that returns an iterable of all scalars attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_aliases
- property that returns an iterable of all type aliases attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_enums
- property that returns an iterable of all enumerations attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_structs
- property that returns an iterable of all structs attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_unions
- property that returns an iterable of all unions attached to the package, with each entry being a tuple of name and instance;<PACKAGE>._pt_structs_and_unions
- property that returns an iterable of all structs and unions attached to the package maintaining their order of declaration, with each entry being a tuple of name and instance;<PACKAGE>._pt_lookup()
- function that returns the name of a package field given its instance.