diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/driver.cc | 18 | ||||
-rw-r--r-- | kernel/log.cc | 20 | ||||
-rw-r--r-- | kernel/log.h | 5 | ||||
-rw-r--r-- | kernel/register.cc | 2 |
4 files changed, 36 insertions, 9 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc index a41d0e8cb..0844eaa2e 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -213,6 +213,10 @@ int main(int argc, char **argv) printf(" -A\n"); printf(" will call abort() at the end of the script. for debugging\n"); printf("\n"); + printf(" -D <header_id>[:<filename>]\n"); + printf(" dump the design when printing the specified log header to a file.\n"); + printf(" yosys_dump_<header_id>.il is used as filename if none is specified.\n"); + printf("\n"); printf(" -V\n"); printf(" print version information and exit\n"); printf("\n"); @@ -233,7 +237,7 @@ int main(int argc, char **argv) } int opt; - while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:")) != -1) + while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:D:")) != -1) { switch (opt) { @@ -315,6 +319,18 @@ int main(int argc, char **argv) scriptfile = optarg; scriptfile_tcl = true; break; + case 'D': + { + auto args = split_tokens(optarg, ":"); + if (GetSize(args) == 1) + args.push_back("yosys_dump_" + args[0] + ".il"); + if (GetSize(args) != 2) { + fprintf(stderr, "Invalid number of tokens in -D.\n"); + exit(1); + } + log_hdump[args[0]].insert(args[1]); + } + break; default: fprintf(stderr, "Run '%s -h' for help.\n", argv[0]); exit(1); diff --git a/kernel/log.cc b/kernel/log.cc index 4f395c751..f2b343dff 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -40,6 +40,7 @@ YOSYS_NAMESPACE_BEGIN std::vector<FILE*> log_files; std::vector<std::ostream*> log_streams; +std::map<std::string, std::set<std::string>> log_hdump; FILE *log_errfile = NULL; SHA1 *log_hasher = NULL; @@ -136,7 +137,7 @@ void logv(const char *format, va_list ap) *f << str; } -void logv_header(const char *format, va_list ap) +void logv_header(RTLIL::Design *design, const char *format, va_list ap) { bool pop_errfile = false; @@ -149,12 +150,21 @@ void logv_header(const char *format, va_list ap) pop_errfile = true; } + std::string header_id; + for (int c : header_count) - log("%d.", c); - log(" "); + header_id += stringf("%s%d", header_id.empty() ? "" : ".", c); + + log("%s. ", header_id.c_str()); logv(format, ap); log_flush(); + if (log_hdump.count(header_id) && design != nullptr) + for (auto &filename : log_hdump.at(header_id)) { + log("Dumping current design to '%s'.\n", filename.c_str()); + Pass::call(design, {"dump", "-o", filename}); + } + if (pop_errfile) log_files.pop_back(); } @@ -206,11 +216,11 @@ void log(const char *format, ...) va_end(ap); } -void log_header(const char *format, ...) +void log_header(RTLIL::Design *design, const char *format, ...) { va_list ap; va_start(ap, format); - logv_header(format, ap); + logv_header(design, format, ap); va_end(ap); } diff --git a/kernel/log.h b/kernel/log.h index c0be23b08..6090f8273 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -47,6 +47,7 @@ struct log_cmd_error_exception { }; extern std::vector<FILE*> log_files; extern std::vector<std::ostream*> log_streams; +extern std::map<std::string, std::set<std::string>> log_hdump; extern FILE *log_errfile; extern SHA1 *log_hasher; @@ -58,12 +59,12 @@ extern int log_verbose_level; extern string log_last_error; void logv(const char *format, va_list ap); -void logv_header(const char *format, va_list ap); +void logv_header(RTLIL::Design *design, const char *format, va_list ap); void logv_warning(const char *format, va_list ap); YS_NORETURN void logv_error(const char *format, va_list ap) YS_ATTRIBUTE(noreturn); void log(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); -void log_header(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); +void log_header(RTLIL::Design *design, const char *format, ...) YS_ATTRIBUTE(format(printf, 2, 3)); void log_warning(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); YS_NORETURN void log_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2), noreturn); YS_NORETURN void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2), noreturn); diff --git a/kernel/register.cc b/kernel/register.cc index ebe3055ac..115880ed6 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -165,7 +165,7 @@ void Pass::call(RTLIL::Design *design, std::string command) while (!cmd_buf.empty() && (cmd_buf.back() == ' ' || cmd_buf.back() == '\t' || cmd_buf.back() == '\r' || cmd_buf.back() == '\n')) cmd_buf.resize(cmd_buf.size()-1); - log_header("Shell command: %s\n", cmd_buf.c_str()); + log_header(design, "Shell command: %s\n", cmd_buf.c_str()); int retCode = run_command(cmd_buf); if (retCode != 0) log_cmd_error("Shell command returned error code %d.\n", retCode); |