Skip to content

Commit

Permalink
Merge pull request #291 from antmicro/fix-visit-debug
Browse files Browse the repository at this point in the history
Systemverilog: visit_object only when report or debug flag is preset
  • Loading branch information
kamilrakoczy authored Apr 6, 2022
2 parents 10815d6 + 547947a commit 7bbc62f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
8 changes: 5 additions & 3 deletions systemverilog-plugin/uhdmastfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ struct UhdmAstFrontend : public UhdmCommonFrontend {
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);
Expand Down
11 changes: 9 additions & 2 deletions systemverilog-plugin/uhdmcommonfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::ve
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;
Expand Down Expand Up @@ -107,9 +108,15 @@ void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::ve
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;
Expand Down
32 changes: 22 additions & 10 deletions systemverilog-plugin/uhdmsurelogastfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,22 @@ std::vector<vpiHandle> executeCompilation(SURELOG::SymbolTable *symbolTable, SUR
}
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();
}
Expand All @@ -117,6 +113,12 @@ struct UhdmSurelogAstFrontend : public UhdmCommonFrontend {

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;
Expand All @@ -125,8 +127,8 @@ struct UhdmSurelogAstFrontend : public UhdmCommonFrontend {

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;
Expand All @@ -136,6 +138,16 @@ struct UhdmSurelogAstFrontend : public UhdmCommonFrontend {

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

0 comments on commit 7bbc62f

Please sign in to comment.