Python API#
If you want to embed this tool into your own script, you can do so with the following API.
Example#
The following example shows how to compile a SystemRDL file and then generate the Rust code using the Python API.
from systemrdl import RDLCompiler
from peakrdl_rust.exporter import RustExporter
# compile the SystemRDL
rdlc = RDLCompiler()
rdlc.compile_file('example.rdl')
top = rdlc.elaborate()
# generate the Rust code
exporter = RustExporter()
exporter.export(node=top, path='registers')
Exporter Class#
- class peakrdl_rust.exporter.RustExporter#
- export(node: RootNode | AddrmapNode | list[AddrmapNode], path: str, **kwargs: Any) None#
- Parameters:
node (AddrmapNode) – Top-level SystemRDL node(s) to export.
path (str) – Output directory for generated crate. A subfolder with the name of the crate is generated in this directory.
force (bool) – Overwrite the contents of the output directory if it already exists.
fmt (bool) – Attempt to format the generated rust code using rustfmt.
byte_endian (Optional[Literal["big", "little"]]) – Ordering of bytes within accesswidth-sized accesses to the register file. Overrides the littleendian and bigendian addrmap properties.
word_endian (Optional[Literal["big", "little"]]) – Ordering of accesswidth-sized words within a wide register. Overrides the littleendian and bigendian addrmap properties.
access_mode (str) – Access mode for register/field access functions. One of: - software (default): Use software read/write access properties - hardware: Use hardware read/write access properties
read_only (bool) – Treat all registers and fields as read-only. Write-only registers and fields are not exposed.
For more information about configuration options, see the Configuring PeakRDL-rust page.