Skip to content

[codex] Allow DUT-only builds and export C-model scaffolds#46

Draft
zhoubot wants to merge 1 commit intomainfrom
codex/issue-42-44-fixes
Draft

[codex] Allow DUT-only builds and export C-model scaffolds#46
zhoubot wants to merge 1 commit intomainfrom
codex/issue-42-44-fixes

Conversation

@zhoubot
Copy link
Copy Markdown
Collaborator

@zhoubot zhoubot commented Apr 2, 2026

Summary

This PR addresses the two remaining open issues around external verification and C++ model integration.

  • allow pycircuit build to succeed when tb(...) is absent
  • keep the existing generated pyCircuit TB flow when @testbench is present
  • emit a generated cmodel/ bridge for external C++ / TLM drivers
  • export cmodel/tb_program.json when a pyCircuit TB exists so external models can replay the same stimulus
  • teach gen_cmake_from_manifest.py to consume a generic entry_cpp and configurable executable name
  • document the DUT-only / external-driver flow

Issue 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.py
  • PYTHONPATH=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 1
  • PYTHONPATH=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 1
  • mkdocs build

Notes

  • python3 flows/tools/check_api_hygiene.py compiler/frontend/pycircuit docs README.md still fails on pre-existing historical docs (docs/designs_upgrade_to_v5.md, legacy V5 tutorial docs), not on this diff.
  • pytest is not installed in the current environment, so the added unit test file was syntax-checked but not executed under pytest.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1349 to +1357
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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

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.

Performance Benchmark: Pure C++ Cycle-Accurate TLM against pyCircuit Simulator [RFC] Testbench architecture: expressiveness vs. compilation model

1 participant