Skip to content

Commit

Permalink
Verilog preprocessor: implement multi-line defines
Browse files Browse the repository at this point in the history
This implements multi-line macros in the Verilog preprocessor.
  • Loading branch information
kroening committed Sep 25, 2023
1 parent beefd88 commit 778dbc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions regression/verilog/preprocessor/multi-line-define1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CORE
multi-line-define1.v
--preprocess
// Enable multi-line checking
activate-multi-line-match
`line 1 "multi-line-define1.v" 0

A
B
C
^EXIT=0$
^SIGNAL=0$
--
^PREPROCESSING FAILED$
4 changes: 4 additions & 0 deletions regression/verilog/preprocessor/multi-line-define1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`define foo A \
B \
C
`foo
14 changes: 12 additions & 2 deletions src/verilog/verilog_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,23 @@ void verilog_preprocessort::directive()
// skip whitespace
tokenizer().skip_ws();

// Read any tokens until end of line.
// Read any tokens until end of line,
// but note that \n can be escaped with a backslash.
// Note that any defines in this sequence
// are not expanded at this point.
while(!tokenizer().eof() && tokenizer().peek() != '\n')
{
auto token = tokenizer().next_token();
define.tokens.push_back(std::move(token));
if(token == '\\' && tokenizer().peek() == '\n')
{
// Eat the newline, which is escaped.
// Not clear whether the newline is meant to show
// in the expansion.
auto nl = tokenizer().next_token();
define.tokens.push_back(std::move(nl));
}
else
define.tokens.push_back(std::move(token));
}

#ifdef DEBUG
Expand Down

0 comments on commit 778dbc8

Please sign in to comment.