aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--frontends/verilog/preproc.cc14
-rw-r--r--frontends/verilog/verilog_frontend.cc11
-rw-r--r--frontends/verilog/verilog_frontend.h3
3 files changed, 24 insertions, 4 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index 2dcc91043..2033a290f 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);
diff --git a/frontends/verilog/verilog_frontend.cc b/frontends/verilog/verilog_frontend.cc
index 9c6a5b64e..fb2b57ad0 100644
--- a/frontends/verilog/verilog_frontend.cc
+++ b/frontends/verilog/verilog_frontend.cc
@@ -100,6 +100,10 @@ struct VerilogFrontend : public Frontend {
log(" define the preprocessor symbol 'name' and set its optional value\n");
log(" 'definition'\n");
log("\n");
+ log(" -Idir\n");
+ log(" add 'dir' to the directories which are used when searching include\n");
+ log(" files\n");
+ log("\n");
}
virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
{
@@ -114,6 +118,7 @@ struct VerilogFrontend : public Frontend {
bool flag_lib = false;
bool flag_noopt = false;
std::map<std::string, std::string> defines_map;
+ std::list<std::string> include_dirs;
frontend_verilog_yydebug = false;
log_header("Executing Verilog-2005 frontend.\n");
@@ -175,6 +180,10 @@ struct VerilogFrontend : public Frontend {
defines_map[name] = value;
continue;
}
+ if (arg.compare(0,2,"-I") == 0) {
+ include_dirs.push_back(arg.substr(2,std::string::npos));
+ continue;
+ }
break;
}
extra_args(f, filename, args, argidx);
@@ -191,7 +200,7 @@ struct VerilogFrontend : public Frontend {
std::string code_after_preproc;
if (!flag_nopp) {
- code_after_preproc = frontend_verilog_preproc(f, filename, defines_map);
+ code_after_preproc = frontend_verilog_preproc(f, filename, defines_map, include_dirs);
if (flag_ppdump)
log("-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
fp = fmemopen((void*)code_after_preproc.c_str(), code_after_preproc.size(), "r");
diff --git a/frontends/verilog/verilog_frontend.h b/frontends/verilog/verilog_frontend.h
index 244e2f582..222de7e7f 100644
--- a/frontends/verilog/verilog_frontend.h
+++ b/frontends/verilog/verilog_frontend.h
@@ -33,6 +33,7 @@
#include "frontends/ast/ast.h"
#include <stdio.h>
#include <stdint.h>
+#include <list>
namespace VERILOG_FRONTEND
{
@@ -47,7 +48,7 @@ namespace VERILOG_FRONTEND
}
// the pre-processor
-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);
// the usual bison/flex stuff
extern int frontend_verilog_yydebug;