Skip to content

Commit 9daf51d

Browse files
committed
Verilog: allow whitespace between macro and arguments
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.
1 parent d3071f4 commit 9daf51d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

regression/verilog/preprocessor/define1.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ value
1313

1414
x-y-z
1515
x-y-value
16+
moo-foo-bar
1617
^EXIT=0$
1718
^SIGNAL=0$
1819
--

regression/verilog/preprocessor/define1.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
`define with_parameter(a, b, c) a-b-c
88
`with_parameter(x, y, z)
99
`with_parameter(x, y, `with_value)
10+
`with_parameter (moo, foo, bar)
11+
`define no_parameter (1+2)
12+
`no_parameter

src/verilog/verilog_preprocessor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ auto verilog_preprocessort::parse_define_arguments(const definet &define)
277277
if(define.parameters.empty())
278278
return {};
279279

280+
// skip whitespace
281+
tokenizer().skip_ws();
282+
280283
if(tokenizer().next_token() != '(')
281284
throw verilog_preprocessor_errort() << "expecting define arguments";
282285

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

365-
// skip whitespace
366-
tokenizer().skip_ws();
367-
368368
// Is there a parameter list?
369369
// These have been introduced in Verilog 2001.
370+
// 1800-2017: "The left parenthesis shall follow the text macro name
371+
// immediately, with no space in between."
370372
if(tokenizer().peek() == '(')
371373
define.parameters = parse_define_parameters();
372374

0 commit comments

Comments
 (0)