From a99c22415783f5c829be5fd2ba77246b15a2734b Mon Sep 17 00:00:00 2001 From: Johann Glaser Date: Tue, 20 Aug 2013 15:48:16 +0200 Subject: Added support for include directories with the new '-I' argument of the 'read_verilog' command --- frontends/verilog/preproc.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'frontends/verilog/preproc.cc') 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 #include #include -#include static std::list output_code; static std::list 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 pre_defines_map) +std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::map pre_defines_map, const std::list include_dirs) { std::map 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); -- cgit v1.2.3