Skip to content

feat(rtl): support Verilog module parameters in RTLWrapper#162

Merged
lanserge merged 4 commits intomainfrom
rtl/wrapper-parameters
Apr 22, 2026
Merged

feat(rtl): support Verilog module parameters in RTLWrapper#162
lanserge merged 4 commits intomainfrom
rtl/wrapper-parameters

Conversation

@lanserge
Copy link
Copy Markdown
Contributor

Summary

  • Add a top-level parameters table to the wrapper TOML and a parameters kwarg on load_wrapper_from_toml / RTLWrapper so callers can override Verilog parameter/localparam values.
  • Emit merged parameters as p_<NAME>=<value> kwargs on the wrapped Instance() at elaboration, and feed them into generator template substitution (SpinalHDL, sv2v, yosys-slang) so generated Verilog sees the final values.
  • Extend Port.params {name} resolution to consult the merged module parameters first, falling back to generate.parameters for back-compat.

Example

# wrapper.toml
name = "wb_timer"

[parameters]
DATA_WIDTH = 32
ADDR_WIDTH = 4
# caller override
w = load_wrapper_from_toml("wrapper.toml", parameters={"DATA_WIDTH": 64})
# -> Instance("wb_timer", p_DATA_WIDTH=64, p_ADDR_WIDTH=4, ...)

Test plan

  • pdm lint
  • pdm test
  • Manual: wrap a parameterized Verilog module with a [parameters] table, confirm the Instance emits matching p_* kwargs and yosys picks them up.
  • Manual: override via Python kwarg and confirm precedence (kwarg wins over TOML).
  • Manual with a generator (SpinalHDL or yosys-slang): confirm generator args see the merged parameters.

Expose Verilog `parameter`/`localparam` overrides through the RTL wrapper:
- New top-level `parameters` table in the wrapper TOML supplies defaults.
- `load_wrapper_from_toml(..., parameters=...)` and `RTLWrapper(..., parameters=...)`
  accept a caller override that merges on top of the TOML defaults.
- The merged set is emitted as `p_<NAME>=<value>` kwargs on `Instance()` at
  elaboration, and is also fed into generator template substitution (SpinalHDL,
  sv2v, yosys-slang) so generated Verilog sees the final values.
- `{name}` substitution in `Port.params` now resolves against the merged module
  parameters first, falling back to `generate.parameters` for back-compat.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

Tests Skipped Failures Errors Time
83 10 💤 0 ❌ 0 🔥 25.285s ⏱️

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-22 11:37 UTC

Add tests/test_rtl_wrapper.py covering:
- Parameter merge precedence: TOML defaults only, kwarg only, kwarg
  overrides TOML, kwarg adds to TOML.
- elaborate() emits merged parameters as p_<NAME> kwargs on the wrapped
  Instance(), and emits no p_* kwargs when no parameters are set.
- load_wrapper_from_toml() threads the caller override into the final
  _parameters set for both TOML-populated and empty [parameters] tables.
Add a short docs/rtl-wrapper.rst that introduces the RTL wrapper, points
to the in-depth usage guide and worked examples in chipflow-training,
and demonstrates the new [parameters] table plus Python override. Autoapi
continues to generate the full API reference for RTLWrapper,
load_wrapper_from_toml, and ExternalWrapConfig.
@lanserge lanserge merged commit 218878a into main Apr 22, 2026
6 checks passed
@lanserge lanserge deleted the rtl/wrapper-parameters branch April 22, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant