aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2017-03-14 17:27:28 +0100
committerClifford Wolf <clifford@clifford.at>2017-03-14 17:30:20 +0100
commit088f9c9cab8db27076385e6f3242369499247b9f (patch)
treedaeb306f9ac20a26e89c99d12df9a0171dac0056
parentc8553539866128279897336795f00248eb527ffa (diff)
downloadyosys-088f9c9cab8db27076385e6f3242369499247b9f.tar.gz
yosys-088f9c9cab8db27076385e6f3242369499247b9f.tar.bz2
yosys-088f9c9cab8db27076385e6f3242369499247b9f.zip
Fix verilog pre-processor for multi-level relative includes
-rw-r--r--frontends/verilog/preproc.cc30
1 files changed, 26 insertions, 4 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index df1005d10..41b5eac19 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -215,6 +215,7 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
{
std::set<std::string> defines_with_args;
std::map<std::string, std::string> defines_map(pre_defines_map);
+ std::vector<std::string> filename_stack;
int ifdef_fail_level = 0;
bool in_elseif = false;
@@ -305,26 +306,47 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
}
std::ifstream ff;
ff.clear();
- ff.open(fn.c_str());
+ std::string fixed_fn = fn;
+ ff.open(fixed_fn.c_str());
if (ff.fail() && fn.size() > 0 && fn[0] != '/' && filename.find('/') != std::string::npos) {
// if the include file was not found, it is not given with an absolute path, and the
// currently read file is given with a path, then try again relative to its directory
ff.clear();
- ff.open(filename.substr(0, filename.rfind('/')+1) + fn);
+ fixed_fn = filename.substr(0, filename.rfind('/')+1) + fn;
+ ff.open(fixed_fn);
}
if (ff.fail() && fn.size() > 0 && fn[0] != '/') {
// if the include file was not found and it is not given with an absolute path, then
// search it in the include path
for (auto incdir : include_dirs) {
ff.clear();
- ff.open(incdir + '/' + fn);
+ fixed_fn = incdir + '/' + fn;
+ ff.open(fixed_fn);
if (!ff.fail()) break;
}
}
if (ff.fail())
output_code.push_back("`file_notfound " + fn);
else
- input_file(ff, fn);
+ input_file(ff, fixed_fn);
+ continue;
+ }
+
+ if (tok == "`file_push") {
+ skip_spaces();
+ std::string fn = next_token(true);
+ if (!fn.empty() && fn.front() == '"' && fn.back() == '"')
+ fn = fn.substr(1, fn.size()-2);
+ output_code.push_back(tok + " \"" + fn + "\"");
+ filename_stack.push_back(filename);
+ filename = fn;
+ continue;
+ }
+
+ if (tok == "`file_pop") {
+ output_code.push_back(tok);
+ filename = filename_stack.back();
+ filename_stack.pop_back();
continue;
}