Skip to content

Commit 12b3d47

Browse files
authored
Merge pull request #879 from diffblue/verilog-include-with-directive
Verilog: directives inside ``include` argument
2 parents a7e28cd + e4082d1 commit 12b3d47

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

examples/Hazard3/Hazard3-vlindex.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ Number of functions.......: 7
2929
Number of tasks...........: 0
3030
Number of properties......: 0
3131
Number of sequences.......: 0
32-
Number of module instances: 71
32+
Number of module instances: 70
3333
Number of configurations..: 0
3434
EOM
+4-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
KNOWNBUG
2-
include2.v
1+
CORE
2+
include3.v
33
--preprocess
4-
// Enable multi-line checking
5-
activate-multi-line-match
6-
`line 1 "include3\.v" 0
7-
`line 1 "include_file2\.vh" 1
8-
9-
`line 2 "include3\.v" 2
10-
^EXIT=0$
4+
^file include3.v line 2: preprocessor directive inside `include directive$
5+
^EXIT=1$
116
^SIGNAL=0$
127
--
13-
Giving the include file name as a macro doesn't work.

src/verilog/verilog_preprocessor.cpp

+33-18
Original file line numberDiff line numberDiff line change
@@ -572,34 +572,49 @@ void verilog_preprocessort::directive()
572572
// skip whitespace
573573
tokenizer().skip_ws();
574574

575-
// We expect one of:
575+
std::string argument;
576+
577+
// Read any tokens until end of line.
578+
// 1800-2017 is silent on whether further directives are
579+
// processed. We emit an error.
580+
// 1800-2017 is silent wether file names in quotes are processed
581+
// as string literals. We assume not so.
582+
while(!tokenizer().eof() && tokenizer().peek() != '\n')
583+
{
584+
auto token = tokenizer().next_token();
585+
586+
if(token == '`')
587+
{
588+
throw verilog_preprocessor_errort()
589+
<< "preprocessor directive inside `include directive";
590+
}
591+
592+
argument += token.text;
593+
}
594+
595+
// We expect the argument to be one of:
576596
// <filename> -- include paths only
577597
// "filename" -- relative path, then include paths.
578598
std::string given_filename;
579599
bool include_paths_only;
580600

581-
if(tokenizer().peek().is_string_literal())
601+
if(!argument.empty() && argument[0] == '"')
582602
{
583603
include_paths_only = false;
584-
const auto file_token = tokenizer().next_token();
585-
CHECK_RETURN(file_token.is_string_literal());
586-
// strip quotes off string literal, escaping, etc.
587-
given_filename = file_token.string_literal_value();
604+
auto quote_pos = argument.find('"', 1);
605+
if(quote_pos == std::string::npos)
606+
throw verilog_preprocessor_errort()
607+
<< "expected closing \" in include directive";
608+
given_filename = std::string(argument, 1, quote_pos - 1);
588609
}
589-
else if(tokenizer().peek() == '<')
610+
else if(!argument.empty() && argument[0] == '<')
590611
{
591-
tokenizer().next_token(); // <
592612
include_paths_only = true;
593-
594-
while(tokenizer().peek() != '>')
595-
{
596-
if(tokenizer().peek().is_eof())
597-
throw verilog_preprocessor_errort() << "eof in include directive";
598-
599-
given_filename += tokenizer().next_token().text;
600-
}
601-
602-
tokenizer().next_token(); // >
613+
auto quote_pos = argument.find('>', 1);
614+
if(quote_pos == std::string::npos)
615+
throw verilog_preprocessor_errort()
616+
<< "expected closing > in include directive";
617+
given_filename = std::string(argument, 1, quote_pos - 1);
603618
}
604619
else
605620
{

0 commit comments

Comments
 (0)