[codex] Allow DUT-only builds and export C-model scaffolds#46
[codex] Allow DUT-only builds and export C-model scaffolds#46
Conversation
There was a problem hiding this comment.
Code Review
This pull request makes the @testbench decorator optional during the build process and introduces a new cmodel scaffold generation feature. This feature provides a C++ bridge, a main entry point, and a README to facilitate the integration of the generated Design Under Test (DUT) into external C++ or TLM environments. The changes include updates to the CLI logic, manifest generation, and comprehensive documentation. Feedback indicates that the width_of helper function in the new port metadata logic should be updated to support !pyc.clock types to ensure correct metadata generation.
| def width_of(ty: str) -> int: | ||
| if ty == "!pyc.reset": | ||
| return 1 | ||
| if ty.startswith("i"): | ||
| try: | ||
| return int(ty[1:]) | ||
| except ValueError: | ||
| return 0 | ||
| return 0 |
There was a problem hiding this comment.
The width_of helper function is missing support for the !pyc.clock type. In pyCircuit, both !pyc.clock and !pyc.reset are 1-bit signals. Currently, !pyc.clock will fall through to the default return of 0, which will result in incorrect metadata in the generated project manifest and README.
Consider aligning this logic with _as_int_width defined earlier in the file.
| def width_of(ty: str) -> int: | |
| if ty == "!pyc.reset": | |
| return 1 | |
| if ty.startswith("i"): | |
| try: | |
| return int(ty[1:]) | |
| except ValueError: | |
| return 0 | |
| return 0 | |
| def width_of(ty: str) -> int: | |
| if ty in ("!pyc.reset", "!pyc.clock"): | |
| return 1 | |
| if ty.startswith("i"): | |
| try: | |
| return int(ty[1:]) | |
| except ValueError: | |
| return 0 | |
| return 0 |
Summary
This PR addresses the two remaining open issues around external verification and C++ model integration.
pycircuit buildto succeed whentb(...)is absent@testbenchis presentcmodel/bridge for external C++ / TLM driverscmodel/tb_program.jsonwhen a pyCircuit TB exists so external models can replay the same stimulusgen_cmake_from_manifest.pyto consume a genericentry_cppand configurable executable nameIssue coverage
Closes #42
Closes #44
Validation
python3 -m py_compile compiler/frontend/pycircuit/cli.py flows/tools/gen_cmake_from_manifest.py compiler/frontend/pycircuit/tests/test_cli_cmodel.pyPYTHONPATH=compiler/frontend python3 -m pycircuit.cli build /tmp/pyc_issue42_smoke/top_only.py --out-dir /tmp/pyc_issue42_smoke/out_top_only --target cpp --jobs 1PYTHONPATH=compiler/frontend python3 -m pycircuit.cli build /tmp/pyc_issue42_smoke/top_tb.py --out-dir /tmp/pyc_issue42_smoke/out_top_tb --target cpp --jobs 1mkdocs buildNotes
python3 flows/tools/check_api_hygiene.py compiler/frontend/pycircuit docs README.mdstill fails on pre-existing historical docs (docs/designs_upgrade_to_v5.md, legacy V5 tutorial docs), not on this diff.pytestis not installed in the current environment, so the added unit test file was syntax-checked but not executed under pytest.