added option '-Dname[=definition]' to command 'read_verilog'
authorJohann Glaser <Johann.Glaser@gmx.at>
Sun, 19 May 2013 15:07:52 +0000 (17:07 +0200)
committerJohann Glaser <Johann.Glaser@gmx.at>
Sun, 19 May 2013 15:07:52 +0000 (17:07 +0200)
frontends/verilog/preproc.cc
frontends/verilog/verilog_frontend.cc
frontends/verilog/verilog_frontend.h

index e6fdc1ffdc778ef8ace60c7c116268b53255800a..2dcc910434ba3eaea52e62f03f23e519f0e148a3 100644 (file)
@@ -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();
index f9731cbc2390aa39cd68040d4e40d030cd4c1a7c..d14783c58793afb2c9c3643f8895253c2e100d5d 100644 (file)
@@ -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");
index 808edfc7db3d310976452a41d4a70c4114abcdd8..244e2f58273bbea595d2524b582d7ce31a1b1287 100644 (file)
@@ -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;