Skip to content

Commit c20afa1

Browse files
authored
Merge pull request #77 from diffblue/multi-line-define
Verilog preprocessor: implement multi-line defines
2 parents 2388a12 + 778dbc8 commit c20afa1

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
@@ -336,13 +336,23 @@ void verilog_preprocessort::directive()
336336
// skip whitespace
337337
tokenizer().skip_ws();
338338

339-
// Read any tokens until end of line.
339+
// Read any tokens until end of line,
340+
// but note that \n can be escaped with a backslash.
340341
// Note that any defines in this sequence
341342
// are not expanded at this point.
342343
while(!tokenizer().eof() && tokenizer().peek() != '\n')
343344
{
344345
auto token = tokenizer().next_token();
345-
define.tokens.push_back(std::move(token));
346+
if(token == '\\' && tokenizer().peek() == '\n')
347+
{
348+
// Eat the newline, which is escaped.
349+
// Not clear whether the newline is meant to show
350+
// in the expansion.
351+
auto nl = tokenizer().next_token();
352+
define.tokens.push_back(std::move(nl));
353+
}
354+
else
355+
define.tokens.push_back(std::move(token));
346356
}
347357

348358
#ifdef DEBUG

0 commit comments

Comments
 (0)