Skip to content

Commit

Permalink
Verilog: allow whitespace between macro and arguments
Browse files Browse the repository at this point in the history
Verilog allows whitespace between the macro identifier and the parentheses
when using a macro with parameters.

Verilog disallows whitespace between the macro identifier and the
parentheses when defining a macro with parameters.  When whitespace is
present, the macro is interpreted as a macro without parameters.
  • Loading branch information
kroening committed Apr 22, 2024
1 parent d3071f4 commit 9daf51d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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."
if(tokenizer().peek() == '(')
define.parameters = parse_define_parameters();

Expand Down

0 comments on commit 9daf51d

Please sign in to comment.