aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-05-19 16:07:55 -0700
committerClifford Wolf <clifford@clifford.at>2013-05-19 16:07:55 -0700
commit63e6a35ce274c2251349e0f67011b5705d48a5e8 (patch)
tree1064f0b795b69a2d6e996c6b2a5c307b6cc3af32
parentfbadb54b9bf4f5c1920bc35381d40ef988ea1f76 (diff)
parent10a195c0a1be96a6e8e769110bafeeaa2b45478a (diff)
downloadyosys-63e6a35ce274c2251349e0f67011b5705d48a5e8.tar.gz
yosys-63e6a35ce274c2251349e0f67011b5705d48a5e8.tar.bz2
yosys-63e6a35ce274c2251349e0f67011b5705d48a5e8.zip
Merge pull request #6 from hansiglaser/master
added option '-Dname[=definition]' to command 'read_verilog'
-rw-r--r--frontends/verilog/preproc.cc4
-rw-r--r--frontends/verilog/verilog_frontend.cc17
-rw-r--r--frontends/verilog/verilog_frontend.h2
3 files changed, 19 insertions, 4 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index e6fdc1ffd..2dcc91043 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -206,9 +206,9 @@ static std::string define_to_feature(std::string defname)
return std::string();
}
-std::string frontend_verilog_preproc(FILE *f, std::string filename)
+std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::map<std::string, std::string> pre_defines_map)
{
- std::map<std::string, std::string> defines_map;
+ std::map<std::string, std::string> defines_map(pre_defines_map);
int ifdef_fail_level = 0;
output_code.clear();
diff --git a/frontends/verilog/verilog_frontend.cc b/frontends/verilog/verilog_frontend.cc
index f9731cbc2..d14783c58 100644
--- a/frontends/verilog/verilog_frontend.cc
+++ b/frontends/verilog/verilog_frontend.cc
@@ -92,6 +92,10 @@ struct VerilogFrontend : public Frontend {
log(" -lib\n");
log(" only create empty placeholder modules\n");
log("\n");
+ log(" -Dname[=definition]\n");
+ log(" define the preprocessor symbol 'name' and set its optional value\n");
+ log(" 'definition'\n");
+ log("\n");
}
virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
{
@@ -104,6 +108,7 @@ struct VerilogFrontend : public Frontend {
bool flag_ppdump = false;
bool flag_nopp = false;
bool flag_lib = false;
+ std::map<std::string, std::string> defines_map;
frontend_verilog_yydebug = false;
log_header("Executing Verilog-2005 frontend.\n");
@@ -152,6 +157,16 @@ struct VerilogFrontend : public Frontend {
flag_lib = true;
continue;
}
+ if (arg.compare(0,2,"-D") == 0) {
+ size_t equal = arg.find('=',2); // returns string::npos it not found
+ std::string name = arg.substr(2,equal-2);
+ std::string value;
+ if (equal != std::string::npos) {
+ value = arg.substr(equal+1,std::string::npos);
+ }
+ defines_map[name] = value;
+ continue;
+ }
break;
}
extra_args(f, filename, args, argidx);
@@ -168,7 +183,7 @@ struct VerilogFrontend : public Frontend {
std::string code_after_preproc;
if (!flag_nopp) {
- code_after_preproc = frontend_verilog_preproc(f, filename);
+ code_after_preproc = frontend_verilog_preproc(f, filename, defines_map);
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 808edfc7d..244e2f582 100644
--- a/frontends/verilog/verilog_frontend.h
+++ b/frontends/verilog/verilog_frontend.h
@@ -47,7 +47,7 @@ namespace VERILOG_FRONTEND
}
// the pre-processor
-std::string frontend_verilog_preproc(FILE *f, std::string filename);
+std::string frontend_verilog_preproc(FILE *f, std::string filename, const std::map<std::string, std::string> pre_defines_map);
// the usual bison/flex stuff
extern int frontend_verilog_yydebug;