summaryrefslogtreecommitdiff
path: root/frontends/verilog/preproc.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-08-20 09:38:31 -0700
committerClifford Wolf <clifford@clifford.at>2013-08-20 09:38:31 -0700
commit459e8964fd5ff115c3fdd1c4487f0fe62bd46137 (patch)
tree27eef28e2a9c52c42fb08425b3a1a9dc96874034 /frontends/verilog/preproc.cc
parent8e31a924070ede11967cce8c3161ffc79847932d (diff)
parenta99c22415783f5c829be5fd2ba77246b15a2734b (diff)
Merge pull request #9 from hansiglaser/master
Added support for include directories with the new '-I' argument of the 'read_verilog' command
Diffstat (limited to 'frontends/verilog/preproc.cc')
-rw-r--r--frontends/verilog/preproc.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index 2dcc9104..2033a290 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -38,7 +38,6 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
-#include <list>
static std::list<std::string> output_code;
static std::list<std::string> input_buffer;
@@ -206,7 +205,7 @@ static std::string define_to_feature(std::string defname)
return std::string();
}
-std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::map<std::string, std::string> pre_defines_map)
+std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::map<std::string, std::string> pre_defines_map, const std::list<std::string> include_dirs)
{
std::map<std::string, std::string> defines_map(pre_defines_map);
int ifdef_fail_level = 0;
@@ -273,9 +272,20 @@ std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::m
}
FILE *fp = fopen(fn.c_str(), "r");
if (fp == NULL && 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
std::string fn2 = filename.substr(0, filename.rfind('/')+1) + fn;
fp = fopen(fn2.c_str(), "r");
}
+ if (fp == NULL && 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) {
+ std::string fn2 = incdir + '/' + fn;
+ fp = fopen(fn2.c_str(), "r");
+ if (fp != NULL) break;
+ }
+ }
if (fp != NULL) {
input_file(fp, fn);
fclose(fp);