Skip to content

Verilog: introduce $unit scope to parser#1808

Merged
kroening merged 1 commit intomainfrom
verilog-top-scope-cleanup
Apr 22, 2026
Merged

Verilog: introduce $unit scope to parser#1808
kroening merged 1 commit intomainfrom
verilog-top-scope-cleanup

Conversation

@kroening
Copy link
Copy Markdown
Collaborator

@kroening kroening commented Apr 17, 2026

This adds the $unit scope to the parser scope stack.

The parser to explicitly put modules and packages into the top (definitions) scope, not the current scope, which is now the $unit scope.

@kroening kroening force-pushed the verilog-top-scope-cleanup branch from 71456ec to 3fdb43e Compare April 17, 2026 22:42
@kroening kroening changed the title Verilog: explicitly put modules into top scope Verilog: explicitly put modules, primitive, program, interface, packages into top scope Apr 17, 2026
@kroening kroening changed the title Verilog: explicitly put modules, primitive, program, interface, packages into top scope Verilog: explicitly put modules, primitives, programs, interfaces, packages into top scope Apr 17, 2026
@kroening kroening changed the title Verilog: explicitly put modules, primitives, programs, interfaces, packages into top scope Verilog: explicitly put modules and packages into top scope Apr 17, 2026
@kroening kroening force-pushed the verilog-top-scope-cleanup branch from 3fdb43e to 83ee108 Compare April 17, 2026 22:51
@kroening kroening marked this pull request as ready for review April 17, 2026 22:51
Copy link
Copy Markdown
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Why does this not affect any test? Are all our tests too simple?

@kroening kroening force-pushed the verilog-top-scope-cleanup branch from 83ee108 to 503821c Compare April 22, 2026 15:29
@kroening
Copy link
Copy Markdown
Collaborator Author

The problem here is that the name resolution done by most (but not all) tools is contextual. E.g., most tools accept

int some_identifier;

module some_identifier;
  initial assert(some_identifier == 0);
endmodule

@kroening
Copy link
Copy Markdown
Collaborator Author

I.e., the right thing to do is likely to switch to a recursive descent parser, and then do lookups in different name spaces depending on syntax.

@tautschnig
Copy link
Copy Markdown
Collaborator

Does the Verilog standard not specify what the lookup rules are? Or perhaps it does and tools just ignore what the standard says?

@kroening
Copy link
Copy Markdown
Collaborator Author

The clarity of the standard leaves room for improvement. See comments on test in #1818. ChatGPT says it's not valid. Claude says it's valid.

@kroening kroening force-pushed the verilog-top-scope-cleanup branch from 503821c to e222ac7 Compare April 22, 2026 20:45
This adds the $unit scope to the parser scope stack.

The parser to explicitly put modules and packages into the top (definitions)
scope, not the current scope, which is now the $unit scope.
@kroening kroening force-pushed the verilog-top-scope-cleanup branch from e222ac7 to 36e5d4f Compare April 22, 2026 21:00
@kroening kroening changed the title Verilog: explicitly put modules and packages into top scope Verilog: introduce $unit scope to parser Apr 22, 2026
@kroening kroening changed the title Verilog: introduce $unit scope to parser Verilog: introduce $unit scope to parser Apr 22, 2026
@kroening kroening merged commit 25342ef into main Apr 22, 2026
11 checks passed
@kroening kroening deleted the verilog-top-scope-cleanup branch April 22, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants