Skip to content

Commit 086c9d8

Browse files
authored
Merge pull request #62 from diffblue/include-not-found
Verilog: output source location when an include file is not found
2 parents 1aed3d8 + 8c49b78 commit 086c9d8

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`include "file_that_does_not_exist.v"

regression/verilog/include/test.desc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
not_found1.v
3+
4+
^file not_found1\.v line 1: include file .file_that_does_not_exist\.v. not found$
5+
^EXIT=1$
6+
^SIGNAL=0$
7+
--

src/verilog/verilog_preprocessor.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ Author: Daniel Kroening, [email protected]
1414

1515
/*******************************************************************\
1616
17+
Function: verilog_preprocessort::filet::make_source_location
18+
19+
Inputs:
20+
21+
Outputs:
22+
23+
Purpose:
24+
25+
\*******************************************************************/
26+
27+
source_locationt verilog_preprocessort::filet::make_source_location() const
28+
{
29+
source_locationt result;
30+
31+
result.set_file(filename);
32+
result.set_line(line);
33+
34+
return result;
35+
}
36+
37+
/*******************************************************************\
38+
1739
Function: verilog_preprocessort::getline
1840
1941
Inputs:
@@ -178,7 +200,9 @@ Function: verilog_preprocessort::include
178200
179201
\*******************************************************************/
180202

181-
void verilog_preprocessort::include(const std::string &filename)
203+
void verilog_preprocessort::include(
204+
const std::string &filename,
205+
const source_locationt &source_location)
182206
{
183207
{
184208
filet tmp_file;
@@ -209,6 +233,7 @@ void verilog_preprocessort::include(const std::string &filename)
209233
file.close=false;
210234
}
211235

236+
error().source_location = source_location;
212237
error() << "include file `" << filename << "' not found" << eom;
213238
throw 0;
214239
}
@@ -504,6 +529,9 @@ void verilog_preprocessort::directive()
504529
}
505530
else if(text=="include")
506531
{
532+
// remember the source location
533+
auto source_location = files.back().make_source_location();
534+
507535
files.back().getline(line);
508536

509537
const char *tptr=line.c_str();
@@ -534,7 +562,7 @@ void verilog_preprocessort::directive()
534562
tptr++;
535563
}
536564

537-
include(filename);
565+
include(filename, source_location);
538566
}
539567
else if(text=="resetall")
540568
{

src/verilog/verilog_preprocessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class verilog_preprocessort:public preprocessort
3232

3333
virtual void directive();
3434
virtual void replace_macros(std::string &s);
35-
virtual void include(const std::string &filename);
35+
virtual void include(const std::string &filename, const source_locationt &);
3636

3737
static std::string build_path(
3838
const std::string &path,
@@ -89,6 +89,8 @@ class verilog_preprocessort:public preprocessort
8989
void print_line(std::ostream &out, unsigned level)
9090
{ out << "`line " << line << " \""
9191
<<filename << "\" " << level << std::endl; }
92+
93+
source_locationt make_source_location() const;
9294
};
9395

9496
std::list<filet> files;

0 commit comments

Comments
 (0)