aboutsummaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorWilliam D. Jones <thor0505@comcast.net>2017-11-14 16:16:24 -0500
committerWilliam D. Jones <thor0505@comcast.net>2017-11-14 16:16:24 -0500
commitabc5b4b8cebff1bd27b2a1766a251319b70115c6 (patch)
treea83a7bac083e1e25803f13c8d4dd6cb3cf96a271 /frontends
parent9ae25039fb6e28db639372d67c1b72c4170feaa3 (diff)
downloadyosys-abc5b4b8cebff1bd27b2a1766a251319b70115c6.tar.gz
yosys-abc5b4b8cebff1bd27b2a1766a251319b70115c6.tar.bz2
yosys-abc5b4b8cebff1bd27b2a1766a251319b70115c6.zip
Accommodate Windows-style paths during include-file processing.
Diffstat (limited to 'frontends')
-rw-r--r--frontends/verilog/preproc.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index ee742d485..00bdcee43 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -366,14 +366,31 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
ff.clear();
std::string fixed_fn = fn;
ff.open(fixed_fn.c_str());
- if (ff.fail() && fn.size() > 0 && fn[0] != '/' && filename.find('/') != std::string::npos) {
+
+ bool filename_path_sep_found;
+ bool fn_relative;
+#ifdef _WIN32
+ // Both forward and backslash are acceptable separators on Windows.
+ filename_path_sep_found = (filename.find_first_of("/\\") != std::string::npos);
+ // Easier just to invert the check for an absolute path (e.g. C:\ or C:/)
+ fn_relative = !(fn[1] == ':' && (fn[2] == '/' || fn[2] == '\\'));
+#else
+ filename_path_sep_found = (filename.find('/') != std::string::npos);
+ fn_relative = (fn[0] != '/');
+#endif
+
+ if (ff.fail() && fn.size() > 0 && fn_relative && filename_path_sep_found) {
// 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();
+#ifdef _WIN32
+ fixed_fn = filename.substr(0, filename.find_last_of("/\\")+1) + fn;
+#else
fixed_fn = filename.substr(0, filename.rfind('/')+1) + fn;
+#endif
ff.open(fixed_fn);
}
- if (ff.fail() && fn.size() > 0 && fn[0] != '/') {
+ if (ff.fail() && fn.size() > 0 && fn_relative) {
// 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) {
@@ -505,7 +522,7 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
if (try_expand_macro(defines_with_args, defines_map, tok))
continue;
-
+
output_code.push_back(tok);
}
@@ -521,4 +538,3 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
}
YOSYS_NAMESPACE_END
-