Skip to content

Commit 778dbc8

Browse files
committed
Verilog preprocessor: implement multi-line defines
This implements multi-line macros in the Verilog preprocessor.
1 parent beefd88 commit 778dbc8

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
multi-line-define1.v
3+
--preprocess
4+
// Enable multi-line checking
5+
activate-multi-line-match
6+
`line 1 "multi-line-define1.v" 0
7+
8+
A
9+
B
10+
C
11+
^EXIT=0$
12+
^SIGNAL=0$
13+
--
14+
^PREPROCESSING FAILED$
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`define foo A \
2+
B \
3+
C
4+
`foo

src/verilog/verilog_preprocessor.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,23 @@ void verilog_preprocessort::directive()
362362
// skip whitespace
363363
tokenizer().skip_ws();
364364

365-
// Read any tokens until end of line.
365+
// Read any tokens until end of line,
366+
// but note that \n can be escaped with a backslash.
366367
// Note that any defines in this sequence
367368
// are not expanded at this point.
368369
while(!tokenizer().eof() && tokenizer().peek() != '\n')
369370
{
370371
auto token = tokenizer().next_token();
371-
define.tokens.push_back(std::move(token));
372+
if(token == '\\' && tokenizer().peek() == '\n')
373+
{
374+
// Eat the newline, which is escaped.
375+
// Not clear whether the newline is meant to show
376+
// in the expansion.
377+
auto nl = tokenizer().next_token();
378+
define.tokens.push_back(std::move(nl));
379+
}
380+
else
381+
define.tokens.push_back(std::move(token));
372382
}
373383

374384
#ifdef DEBUG

0 commit comments

Comments
 (0)