Merge pull request #291 from antmicro/fix-visit-debug

Systemverilog: visit_object only when report or debug flag is preset
diff --git a/systemverilog-plugin/uhdmastfrontend.cc b/systemverilog-plugin/uhdmastfrontend.cc
index ae7f319..660b4c2 100644
--- a/systemverilog-plugin/uhdmastfrontend.cc
+++ b/systemverilog-plugin/uhdmastfrontend.cc
@@ -44,9 +44,11 @@
         UHDM::Serializer serializer;
 
         std::vector<vpiHandle> restoredDesigns = serializer.Restore(filename);
-        for (auto design : restoredDesigns) {
-            std::stringstream strstr;
-            UHDM::visit_object(design, 1, "", &this->shared.report.unhandled, this->shared.debug_flag ? std::cout : strstr);
+        if (this->shared.debug_flag || !this->report_directory.empty()) {
+            for (auto design : restoredDesigns) {
+                std::stringstream strstr;
+                UHDM::visit_object(design, 1, "", &this->shared.report.unhandled, this->shared.debug_flag ? std::cout : strstr);
+            }
         }
         UhdmAst uhdm_ast(this->shared);
         AST::AstNode *current_ast = uhdm_ast.visit_designs(restoredDesigns);
diff --git a/systemverilog-plugin/uhdmcommonfrontend.cc b/systemverilog-plugin/uhdmcommonfrontend.cc
index fe7433d..53214c5 100644
--- a/systemverilog-plugin/uhdmcommonfrontend.cc
+++ b/systemverilog-plugin/uhdmcommonfrontend.cc
@@ -78,8 +78,9 @@
     bool dump_vlog2 = false;
     bool no_dump_ptr = false;
     bool dump_rtlil = false;
+    std::vector<std::string> unhandled_args;
 
-    for (size_t i = 1; i < args.size(); i++) {
+    for (size_t i = 0; i < args.size(); i++) {
         if (args[i] == "-debug") {
             dump_ast1 = true;
             dump_ast2 = true;
@@ -107,9 +108,15 @@
             dump_rtlil = true;
         } else if (args[i] == "-yydebug") {
             this->shared.debug_flag = true;
+        } else {
+            unhandled_args.push_back(args[i]);
         }
     }
-    extra_args(f, filename, args, args.size() - 1);
+    // pass only unhandled args to Surelog
+    // unhandled args starts with command name,
+    // but Surelog expects args[0] to be program name
+    // and skips it
+    this->args = unhandled_args;
 
     AST::current_filename = filename;
     AST::set_line_num = &set_line_num;
diff --git a/systemverilog-plugin/uhdmsurelogastfrontend.cc b/systemverilog-plugin/uhdmsurelogastfrontend.cc
index 2f2a89f..82f04e4 100644
--- a/systemverilog-plugin/uhdmsurelogastfrontend.cc
+++ b/systemverilog-plugin/uhdmsurelogastfrontend.cc
@@ -72,26 +72,22 @@
     }
     if ((!noFatalErrors) || (!success))
         codedReturn |= 1;
+    if (codedReturn) {
+        log_error("Encoraged fatal error when executing Surelog. Aborting!\n");
+    }
     return the_design;
 }
 
 struct UhdmSurelogAstFrontend : public UhdmCommonFrontend {
     UhdmSurelogAstFrontend(std::string name, std::string short_help) : UhdmCommonFrontend(name, short_help) {}
     UhdmSurelogAstFrontend() : UhdmCommonFrontend("verilog_with_uhdm", "generate/read UHDM file") {}
-    void print_read_options() override
-    {
-        log("    -process\n");
-        log("        loads design from given UHDM file\n");
-        log("\n");
-        UhdmCommonFrontend::print_read_options();
-    }
     void help() override
     {
         //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
         log("\n");
         log("    read_verilog_with_uhdm [options] [filenames]\n");
         log("\n");
-        log("Generate or load design from a UHDM file into the current design\n");
+        log("Read SystemVerilog files using Surelog into the current design\n");
         log("\n");
         this->print_read_options();
     }
@@ -117,6 +113,12 @@
 
         SURELOG::scompiler *compiler = nullptr;
         const std::vector<vpiHandle> uhdm_design = executeCompilation(symbolTable, errors, clp, compiler);
+        if (this->shared.debug_flag || !this->report_directory.empty()) {
+            for (auto design : uhdm_design) {
+                std::stringstream strstr;
+                UHDM::visit_object(design, 1, "", &this->shared.report.unhandled, this->shared.debug_flag ? std::cout : strstr);
+            }
+        }
 
         SURELOG::shutdown_compiler(compiler);
         delete clp;
@@ -125,8 +127,8 @@
 
         UhdmAst uhdm_ast(this->shared);
         AST::AstNode *current_ast = uhdm_ast.visit_designs(uhdm_design);
-        if (report_directory != "") {
-            shared.report.write(report_directory);
+        if (!this->report_directory.empty()) {
+            this->shared.report.write(this->report_directory);
         }
 
         return current_ast;
@@ -136,6 +138,16 @@
 
 struct UhdmSystemVerilogFrontend : public UhdmSurelogAstFrontend {
     UhdmSystemVerilogFrontend() : UhdmSurelogAstFrontend("systemverilog", "read SystemVerilog files") {}
+    void help() override
+    {
+        //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
+        log("\n");
+        log("    read_systemverilog [options] [filenames]\n");
+        log("\n");
+        log("Read SystemVerilog files using Surelog into the current design\n");
+        log("\n");
+        this->print_read_options();
+    }
 } UhdmSystemVerilogFrontend;
 
 YOSYS_NAMESPACE_END