diff --git a/kernel/log.cc b/kernel/log.cc index fabbe09fd..e49c3cd0f 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -361,6 +361,21 @@ static void logv_error_with_prefix(const char *prefix, log_check_expected(); + int lineno = 1; + if ( !log_line_number.empty() ) { + log("Error while executing script:\n\t"); + log( log_line_number.begin()->c_str() ); + log("\n"); + log_line_number.erase(log_line_number.begin()); + log("---------------------------------\n"); + for(const std::string& script_line : log_line_number) { + const char* pfx = (lineno == log_line_number.size()) ? "-->" : " "; + log("%s%d %s\n",pfx,lineno++,script_line.c_str()); + } + log("---------------------------------\n"); + } + + if (log_error_atexit) log_error_atexit(); diff --git a/kernel/log.h b/kernel/log.h index e26ef072c..bf6f1e621 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -43,6 +43,7 @@ # endif #endif + #if defined(_MSC_VER) // At least this is not in MSVC++ 2013. # define __PRETTY_FUNCTION__ __FUNCTION__ @@ -95,6 +96,7 @@ YOSYS_NAMESPACE_BEGIN struct log_cmd_error_exception { }; extern std::vector log_files; +extern std::vector log_line_number; extern std::vector log_streams; extern std::vector log_scratchpads; extern std::map> log_hdump; diff --git a/kernel/yosys.cc b/kernel/yosys.cc index d39acf9d9..0f80fdacf 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -303,7 +303,7 @@ int run_command(const std::string &command, std::function log_line_number; bool run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *from_to_label) { + log_line_number.clear(); if (design == nullptr) design = yosys_design; @@ -1078,7 +1080,6 @@ bool run_frontend(std::string filename, std::string command, RTLIL::Design *desi { std::string run_from, run_to; bool from_to_active = true; - if (from_to_label != NULL) { size_t pos = from_to_label->find(':'); if (pos == std::string::npos) { @@ -1103,13 +1104,19 @@ bool run_frontend(std::string filename, std::string command, RTLIL::Design *desi if (f == NULL) log_error("Can't open script file `%s' for reading: %s\n", filename.c_str(), strerror(errno)); + { + std::stringstream ss; + ss << "Running " << command << " on file '" << filename << "'"; + log_line_number.push_back(ss.str()); + } FILE *backup_script_file = Frontend::current_script_file; Frontend::current_script_file = f; try { std::string command; while (fgetline(f, command)) { - while (!command.empty() && command[command.size()-1] == '\\') { + log_line_number.push_back(command); + while (!command.empty() && command[command.size()-1] == '\\') { std::string next_line; if (!fgetline(f, next_line)) break;