Skip to content

[ImportVerilog] Support use-before-declare across module bodies#10350

Open
AmurG wants to merge 1 commit intollvm:mainfrom
AmurG:amurg/uvm-pr3-importverilog-testbench-compat
Open

[ImportVerilog] Support use-before-declare across module bodies#10350
AmurG wants to merge 1 commit intollvm:mainfrom
AmurG:amurg/uvm-pr3-importverilog-testbench-compat

Conversation

@AmurG
Copy link
Copy Markdown
Contributor

@AmurG AmurG commented Apr 28, 2026

This is a frontend-only follow-up to the recent ImportVerilog virtual-interface work. It makes --allow-use-before-declare usable across more module-body contexts without changing the default diagnostics when the option is absent.

The importer now predeclares module-scope variables and nets through generated scopes, expands interface instances after storage predeclaration, and pre-instantiates module instances so earlier procedural code can resolve later hierarchical references. Declaration initializers and net declaration assignments are lowered after the module body has populated the value map, then attached back to the original Moore declaration ops.

The implementation stays behind --allow-use-before-declare and does not add Arcilator/runtime behavior. The tests cover direct module declarations, generated scopes, interface instances, module instances, and broader expression/procedural compatibility matrices for common testbench-style patterns.

Testing:

  • cmake --build build --target circt-verilog -- -j2
  • cmake --build build --target circt-translate -- -j2
  • focused ImportVerilog lit coverage over the use-before-declare, testbench-compat, interface expansion, and virtual-interface tests
  • build/bin/llvm-lit -sv test/Conversion/ImportVerilog

@AmurG AmurG force-pushed the amurg/uvm-pr3-importverilog-testbench-compat branch from 74a9c58 to 8cfb5b6 Compare April 29, 2026 09:39
@AmurG AmurG changed the title [ImportVerilog] Support use-before-declare in module bodies [ImportVerilog] Support use-before-declare across module bodies Apr 29, 2026
@AmurG AmurG force-pushed the amurg/uvm-pr3-importverilog-testbench-compat branch from 8cfb5b6 to ae8a0a6 Compare May 5, 2026 07:00
Predeclare module-scope variables, nets, interface instances, and module instances when slang is allowed to resolve names before their declarations. The predeclaration walk recurses through generated scopes, creates storage before expanding interfaces, and instantiates modules before earlier procedural code lowers, so forward references through local names, interface members, and hierarchical instance paths can resolve.

Declaration initializers and net declaration assignments are lowered after the module body has populated the value map, then attached back to the original Moore declaration ops. This keeps the compatibility behavior behind --allow-use-before-declare and preserves existing diagnostics when the flag is absent.

Add focused regression coverage for direct module declarations, generated scopes, interface instances, and module instances, plus broader expression/procedural compatibility matrices for common testbench patterns.
@AmurG AmurG force-pushed the amurg/uvm-pr3-importverilog-testbench-compat branch from ae8a0a6 to 5eeb624 Compare May 6, 2026 04:23
@AmurG
Copy link
Copy Markdown
Contributor Author

AmurG commented May 9, 2026

@fabianschuiki Sorry about the prev PR state. Can this be reviewed ?

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