@@ -98,23 +98,29 @@ Function: verilog_preprocessort::include
98
98
99
99
\*******************************************************************/
100
100
101
- std::string
102
- verilog_preprocessort::find_include_file (const std::string &filename)
101
+ std::string verilog_preprocessort::find_include_file (
102
+ const std::string &including_file,
103
+ const std::string &given_filename)
103
104
{
104
- // first try filename as is
105
- if (std::filesystem::directory_entry (filename).exists ())
106
- return filename; // done
105
+ {
106
+ // First try given filename relative to the path of the
107
+ // including file.
108
+ auto path = std::filesystem::path (including_file);
109
+ path.replace_filename (given_filename);
110
+ if (std::filesystem::directory_entry (path).exists ())
111
+ return path; // done
112
+ }
107
113
108
114
// try include paths in given order
109
115
for (const auto &path : config.verilog .include_paths )
110
116
{
111
- auto full_name = std::filesystem::path (path).append (filename );
117
+ auto full_name = std::filesystem::path (path).append (given_filename );
112
118
if (std::filesystem::directory_entry (full_name).exists ())
113
119
return full_name; // done
114
120
}
115
121
116
122
throw verilog_preprocessor_errort ()
117
- << " include file `" << filename << " ' not found" ;
123
+ << " include file `" << given_filename << " ' not found" ;
118
124
}
119
125
120
126
/* ******************************************************************\
@@ -507,8 +513,8 @@ void verilog_preprocessort::directive()
507
513
<< " expecting a string literal after `include" ;
508
514
509
515
// strip quotes off string literal, escaping, etc.
510
- auto filename = file_token.string_literal_value ();
511
- auto full_path = find_include_file (filename);
516
+ auto given_filename = file_token.string_literal_value ();
517
+ auto full_path = find_include_file (context (). filename , given_filename );
512
518
513
519
#ifdef _MSC_VER
514
520
auto in = new std::ifstream (widen (full_path));
@@ -522,7 +528,7 @@ void verilog_preprocessort::directive()
522
528
tokenizer ().skip_until_eol ();
523
529
tokenizer ().next_token (); // eat the \n
524
530
525
- context_stack.emplace_back (true , in, filename );
531
+ context_stack.emplace_back (true , in, full_path );
526
532
emit_line_directive (1 ); // 'enter'
527
533
// we now continue in the new context
528
534
}
0 commit comments