Skip to content

Verilog: allow whitespace between macro and arguments #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions regression/verilog/preprocessor/define1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ value

x-y-z
x-y-value
moo-foo-bar
^EXIT=0$
^SIGNAL=0$
--
Expand Down
3 changes: 3 additions & 0 deletions regression/verilog/preprocessor/define1.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
`define with_parameter(a, b, c) a-b-c
`with_parameter(x, y, z)
`with_parameter(x, y, `with_value)
`with_parameter (moo, foo, bar)
`define no_parameter (1+2)
`no_parameter
8 changes: 5 additions & 3 deletions src/verilog/verilog_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ auto verilog_preprocessort::parse_define_arguments(const definet &define)
if(define.parameters.empty())
return {};

// skip whitespace
tokenizer().skip_ws();

if(tokenizer().next_token() != '(')
throw verilog_preprocessor_errort() << "expecting define arguments";

Expand Down Expand Up @@ -362,11 +365,10 @@ void verilog_preprocessort::directive()
auto &identifier = identifier_token.text;
auto &define = defines[identifier];

// skip whitespace
tokenizer().skip_ws();

// Is there a parameter list?
// These have been introduced in Verilog 2001.
// 1800-2017: "The left parenthesis shall follow the text macro name
// immediately, with no space in between."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious: does this mean that tools don't actually observe this? I'm a bit confused as the PR suggests the opposite of what the standard says is now being supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

The commit message gives more detail. There are two separate cases, and both were broken, and are fixed here simultaneously.

  1. When using a macro with parameters, Verilog does allow whitespace between the macro identifier and the parentheses. The implementation did not allow this before this PR.

  2. When defining a macro with parameters, Verilog disallows whitespace between the macro identifier and the
    parentheses. The implementation did allow this, which resulted in wrongly interpreted macro definitions.

if(tokenizer().peek() == '(')
define.parameters = parse_define_parameters();

Expand Down