tee: Allow logging command output to a given scratchpad value

This commit is contained in:
Jannis Harder 2022-11-28 19:03:27 +01:00
parent a64ed824ed
commit ed02d52f30
3 changed files with 20 additions and 0 deletions

View File

@ -40,6 +40,7 @@ YOSYS_NAMESPACE_BEGIN
std::vector<FILE*> log_files;
std::vector<std::ostream*> log_streams;
std::vector<std::string> log_scratchpads;
std::map<std::string, std::set<std::string>> log_hdump;
std::vector<YS_REGEX_TYPE> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
dict<std::string, LogExpectedItem> log_expect_log, log_expect_warning, log_expect_error;
@ -158,6 +159,11 @@ void logv(const char *format, va_list ap)
for (auto f : log_streams)
*f << str;
RTLIL::Design *design = yosys_get_design();
if (design != nullptr)
for (auto &scratchpad : log_scratchpads)
design->scratchpad[scratchpad].append(str);
static std::string linebuffer;
static bool log_warn_regex_recusion_guard = false;

View File

@ -133,6 +133,7 @@ struct log_cmd_error_exception { };
extern std::vector<FILE*> log_files;
extern std::vector<std::ostream*> log_streams;
extern std::vector<std::string> log_scratchpads;
extern std::map<std::string, std::set<std::string>> log_hdump;
extern std::vector<YS_REGEX_TYPE> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
extern std::set<std::string> log_warnings, log_experimentals, log_experimentals_ignored;

View File

@ -45,6 +45,9 @@ struct TeePass : public Pass {
log(" -a logfile\n");
log(" Write output to this file, append if exists.\n");
log("\n");
log(" -s scratchpad\n");
log(" Write output to this scratchpad value, truncate if it exists.\n");
log("\n");
log(" +INT, -INT\n");
log(" Add/subtract INT from the -v setting for this command.\n");
log("\n");
@ -53,9 +56,11 @@ struct TeePass : public Pass {
{
std::vector<FILE*> backup_log_files, files_to_close;
std::vector<std::ostream*> backup_log_streams;
std::vector<std::string> backup_log_scratchpads;
int backup_log_verbose_level = log_verbose_level;
backup_log_streams = log_streams;
backup_log_files = log_files;
backup_log_scratchpads = log_scratchpads;
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++)
@ -78,6 +83,12 @@ struct TeePass : public Pass {
files_to_close.push_back(f);
continue;
}
if (args[argidx] == "-s" && argidx+1 < args.size()) {
auto name = args[++argidx];
design->scratchpad[name] = "";
log_scratchpads.push_back(name);
continue;
}
if (GetSize(args[argidx]) >= 2 && (args[argidx][0] == '-' || args[argidx][0] == '+') && args[argidx][1] >= '0' && args[argidx][1] <= '9') {
log_verbose_level += atoi(args[argidx].c_str());
continue;
@ -93,6 +104,7 @@ struct TeePass : public Pass {
fclose(cf);
log_files = backup_log_files;
log_streams = backup_log_streams;
log_scratchpads = backup_log_scratchpads;
throw;
}
@ -102,6 +114,7 @@ struct TeePass : public Pass {
log_verbose_level = backup_log_verbose_level;
log_files = backup_log_files;
log_streams = backup_log_streams;
log_scratchpads = backup_log_scratchpads;
}
} TeePass;