#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;
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;
}
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);
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)
{
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");
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);
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");
#include "frontends/ast/ast.h"
#include <stdio.h>
#include <stdint.h>
+#include <list>
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;