builder/gen: add full hierarchical Verilog generation - #2543
Open
hansfbaier wants to merge 1 commit into
Open
Conversation
Adds hierarchical Verilog output (--hierarchical-verilog / --no-flatten) that preserves internal module boundaries by lifting parent-driven child-internal signals to proper input ports instead of inlining subtrees. Implementation is structured in three phases: _analyze_hierarchy — tree walking, ownership, inline policies, lowering _emit_hierarchy — module generation with clock/reset aliasing _convert_hierarchical — orchestrator Key design decisions: - Reads ClockDomainsRenamer mappings from module.cd_remap_chain attribute (set by migen) instead of introspecting Python closures. - Adds ModulePort dataclass as foundation for explicit port abstraction. - Handles shared submodules, duplicate sibling names, memories, tristates, FSMs, renamed clock domains, reset-only constants, and structural invariants (no module assigns to its own input port). Comprehensive test suite (22 tests) covers port directions, clock/reset wiring, sibling driver conflicts, nested renamers, reset-less domains, deep 3-level hierarchies, and the cd_remap_chain metadata contract. Verified on Terasic DECA hardware with liteusb ACM serial and UAC2 audio.
hansfbaier
force-pushed
the
full-hierarchy-refactor
branch
from
July 27, 2026 11:59
ef52250 to
2ad18a3
Compare
Owner
|
Thanks @hansfbaier, I'll try to review this soon. |
Contributor
Author
|
@enjoy-digital The tests fail, because they need the corresponding migen commit mentioned above |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds hierarchical Verilog output (--hierarchical-verilog / --no-flatten) that preserves internal module boundaries by lifting parent-driven child-internal signals to proper input ports instead of inlining subtrees.
Implementation is structured in three phases:
_analyze_hierarchy — tree walking, ownership, inline policies, lowering
_emit_hierarchy — module generation with clock/reset aliasing
_convert_hierarchical — orchestrator
Key design decisions:
Comprehensive test suite (22 tests) covers port directions, clock/reset wiring, sibling driver conflicts, nested renamers, reset-less domains, deep 3-level hierarchies, and the cd_remap_chain metadata contract.
Verified on Terasic DECA hardware with liteusb ACM serial and UAC2 audio, also with a LiteX SoC over ACM serial.
Please note that this more elegant approach needs a small patch to migen:
m-labs/migen@a1e58a7