Skip to main content

PeakRDL exporter that generates C++ register maps

Project description

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 sw access rules:
    • sw=r: no write()
    • sw=w: no read()
  • 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_shadow or wr_shadow).
  • Error handling style:
    • --error-style exceptions throws std::runtime_error
    • --error-style status records errors and exposes ok()/last_error()/clear_error()
    • In exceptions mode these status methods still exist, but are mainly useful in status mode.
  • Write range validation:
    • enabled by default
    • disable with --no-write-range-check to skip generated runtime range checks on write() and wr_shadow.write()
    • write()/wr_shadow.write() accept both signed and unsigned integral input types regardless of field signedness.
  • Access width:
    • data_t is deduced from SystemRDL accesswidth.
    • If more than one numeric accesswidth is present in the design, generation fails.
    • Registers may be wider than accesswidth up to 64 bits. Multiword readable registers require buffer_reads=true; multiword writable registers require buffer_writes=true.
    • Fields wider than data_t use compact std::array<data_t, N> values in generated read/write/shadow APIs.
    • addr_t is fixed to std::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

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).

See PERMISSION.generated-output-exception.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peakrdl_cpp-0.2.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

peakrdl_cpp-0.2.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file peakrdl_cpp-0.2.0.tar.gz.

File metadata

  • Download URL: peakrdl_cpp-0.2.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for peakrdl_cpp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b9bc3477e0ba47a1845b951ed274bad6f56eda5f387c40d7dc785c6eab27edd2
MD5 367758d6e73be721d79535bce73bd501
BLAKE2b-256 5ee112827c8ed774e64f0f748a5c1d75b7574c82d46aae971884b7de5773eea3

See more details on using hashes here.

File details

Details for the file peakrdl_cpp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: peakrdl_cpp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for peakrdl_cpp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16f70138791a65f36837cae65a1dc8a009d205d3e6c5eeb4f4ca037520ece423
MD5 acb730b04a3f39e1fada3b11fc5dbdc5
BLAKE2b-256 8bbb68cd3692f618ba233f56e9bc9000dab558f3fd1c3d39ed35a43ee7213d17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page