peakrdl-cpp
peakrdl-cpp is a PeakRDL exporter plugin that generates C++ register access APIs
from SystemRDL designs.
Setup
python3 -m venv .venv
. .venv/bin/activate
pip install -e .
Install from PyPI (after first release):
pip install peakrdl-cpp
Usage
Generate a C++ header from an RDL file:
peakrdl cpp design.rdl -o regs.hpp \
--namespace my_block \
--class-name MyBlock \
--error-style exceptions
Use the Python API directly:
from systemrdl import RDLCompiler
from peakrdl_cpp import CppExporter
compiler = RDLCompiler()
compiler.compile_file("design.rdl")
root = compiler.elaborate()
CppExporter().export(
root.top, # RootNode also works
"regs.hpp",
namespace="my_block",
class_name="MyBlock",
error_style="exceptions", # or "status"
check_write_range=True, # optional, defaults to True
)
Generated API shape:
- Hierarchical object access with array indexing:
my_root.regfile_1[3].sub_regfile.example_reg.field.write(13);auto v = my_root.regfile_1[3].sub_regfile.example_reg.field.read();
- Field APIs respect
swaccess rules:sw=r: nowrite()sw=w: noread()
- Shadow API:
field.rd_shadow.read()(reads register read-shadow)field.wr_shadow.read()/field.wr_shadow.write(...)(reads/updates register write-shadow)reg.rd_shadow.read_hw(),reg.wr_shadow.flush(),reg.wr_shadow.flush_always()regfile.rd_shadow.read_hw(),regfile.wr_shadow.flush(),regfile.wr_shadow.flush_always()addrmap.rd_shadow.read_hw(),addrmap.wr_shadow.flush(),addrmap.wr_shadow.flush_always()
- Hard generation error on reserved symbol conflicts (for example
rd_shadoworwr_shadow). - Error handling style:
--error-style exceptionsthrowsstd::runtime_error--error-style statusrecords errors and exposesok()/last_error()/clear_error()- In
exceptionsmode these status methods still exist, but are mainly useful instatusmode.
- Write range validation:
- enabled by default
- disable with
--no-write-range-checkto skip generated runtime range checks onwrite()andwr_shadow.write() - non-enum scalar fields accept both signed and unsigned integral input types for
write()andwr_shadow.write().
- Enum fields:
- SystemRDL fields with
encode = some_enum;emit a public C++enum class. - Encoded scalar field APIs use that enum type for
read(),write(...),rd_shadow.read(),wr_shadow.read(), andwr_shadow.write(...). - Raw integral writes are intentionally not part of the encoded field API.
- SystemRDL fields with
- Access width:
data_tis deduced from SystemRDLaccesswidth.- If more than one numeric
accesswidthis present in the design, generation fails. - Registers may be wider than
accesswidthup to 64 bits. Multiword readable registers requirebuffer_reads=true; multiword writable registers requirebuffer_writes=true. - Fields wider than
data_tuse compactstd::array<data_t, N>values in generated read/write/shadow APIs. addr_tis fixed tostd::uint32_t.
Bus adapter requirements:
data_t read(addr_t addr);void write(addr_t addr, data_t value);- This contract is currently documented but not yet enforced via C++ concepts/static constraints.
Example
See checked-in example case:
Development
. .venv/bin/activate
pip install -e ".[test]"
pytest
Run adaptive compile/run checks against an external RDL file:
PEAKRDL_CPP_TEST_RDL=/abs/path/to/design.rdl \
./.venv/bin/pytest -q tests/test_exporter_adaptive.py
Optional deterministic seed override:
PEAKRDL_CPP_TEST_RDL=/abs/path/to/design.rdl \
PEAKRDL_CPP_TEST_SEED=42 \
./.venv/bin/pytest -q tests/test_exporter_adaptive.py
The test suite includes end-to-end validation:
- compile RDL
- generate C++
- compile and link C++ test bench against generated headers
- execute runtime behavior checks
Maintainer Notes
Version history is documented in doc/VERSION_HISTORY.md.
Release instructions are documented in RELEASE.md.
License
LGPL-3.0 (GNU Lesser General Public License v3.0). See LICENSE.
Generated output exception:
- Output generated by this project (for example, generated C++ headers/sources) may be used, copied, modified, and distributed under terms of your choice, including proprietary terms.
- This exception does not change the license of this project's own source code.
- The exception is provided as an additional permission under GNU GPLv3 section 7 (as incorporated by LGPLv3).
Metadata
Release files for peakrdl-cpp 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| peakrdl_cpp-0.3.0.tar.gz | 38.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| peakrdl_cpp-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.1 kB
Release files / peakrdl_cpp-0.3.0.tar.gz
| Download URL | peakrdl_cpp-0.3.0.tar.gz |
|---|---|
| Size | 38.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
787848cb70ab6aa4f9e78d4d0e5f251066b63532f814034b2fcd79c224c4fd34
|
|
BLAKE2b-256 checksum How to use checksums |
37f5d4fb71c314765ae88d68193ecef5b309182723c79b93b31328e329a256e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / peakrdl_cpp-0.3.0-py3-none-any.whl
| Download URL | peakrdl_cpp-0.3.0-py3-none-any.whl |
|---|---|
| Size | 21.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cefce91ed5ce55cd3c045f8f7a62781f3fcc8b503d2e3f09e8e1c3f1d4428589
|
|
BLAKE2b-256 checksum How to use checksums |
2edb97b1b70cd548b04ca2f1f90a097302283c80cdb18a61905d33be26c2fdcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|