Skip to content

Commit

Permalink
Verilog preprocessor: fix include buffering
Browse files Browse the repository at this point in the history
To prevent scanning beyond an `include directive, we abort read-ahead
whenever we see a newline.
  • Loading branch information
kroening committed Sep 26, 2023
1 parent beefd88 commit 5de0c61
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
16 changes: 16 additions & 0 deletions regression/verilog/preprocessor/include1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CORE
include1.v
--preprocess
// Enable multi-line checking
activate-multi-line-match
`line 1 "include1.v" 0
`line 1 "include1b.v" 1
line b 1
line b 2
`line 1 "include1.v" 2

line 2
line 3
^EXIT=0$
^SIGNAL=0$
--
3 changes: 3 additions & 0 deletions regression/verilog/preprocessor/include1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`include "include1b.v"
line 2
line 3
2 changes: 2 additions & 0 deletions regression/verilog/preprocessor/include1b.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
line b 1
line b 2
14 changes: 10 additions & 4 deletions src/verilog/verilog_preprocessor_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ verilog_preprocessor_tokenizert::verilog_preprocessor_tokenizert(
std::size_t
verilog_preprocessor_tokenizert::yy_input(char *buffer, std::size_t max_size)
{
std::size_t result;
for(result = 0; result < max_size; result++)
std::size_t result = 0;
while(result < max_size)
{
char ch;
if(!in.get(ch))
return result; // eof
buffer[result] = ch;
break; // eof
buffer[result++] = ch;
if(ch == '\n')
{
// We need to abort prematurely to enable
// switching input streams on `include.
break;
}
}
return result;
}
Expand Down

0 comments on commit 5de0c61

Please sign in to comment.