From 726aff678fead980a103bc542cf560aaa013cd39 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 31 Aug 2026 11:20:21 +0200 Subject: [PATCH] log: remove log_ prefix and unified some namings --- frontends/ast/ast.cc | 2 +- kernel/log.cc | 202 +++++++++++++++++++------------------- kernel/log.h | 194 ++++++++++++++++++------------------ kernel/log_compat.cc | 12 +-- kernel/register.cc | 2 +- kernel/tclapi.cc | 2 +- kernel/yosys.cc | 2 +- passes/cmds/tee.cc | 2 +- passes/cmds/trace.cc | 2 +- passes/techmap/techmap.cc | 2 +- pyosys/wrappers_tpl.cc | 16 +-- 11 files changed, 219 insertions(+), 219 deletions(-) diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index 3ee7c4d9a..e9934f504 100644 --- a/frontends/ast/ast.cc +++ b/frontends/ast/ast.cc @@ -1944,7 +1944,7 @@ void AstModule::loadconfig() const void AstNode::formatted_input_error(std::string_view format, std::string str) const { - logger().log_formatted_file_error(*location.begin.filename, location.begin.line, format, std::move(str)); + logger().formatted_file_error(*location.begin.filename, location.begin.line, format, std::move(str)); } YOSYS_NAMESPACE_END diff --git a/kernel/log.cc b/kernel/log.cc index 1c7ecb3be..3c9c42cc1 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -184,15 +184,15 @@ void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std: size_t nnl_pos = str.find_last_not_of('\n'); if (nnl_pos == std::string::npos) - log_newline_count += GetSize(str); + newline_count += GetSize(str); else - log_newline_count = GetSize(str) - nnl_pos - 1; + newline_count = GetSize(str) - nnl_pos - 1; - if (log_hasher) - log_hasher->update(str); + if (hasher) + hasher->update(str); auto msg = LogMessage(severity, prefix, format, str_in); - for (auto &sink : log_sinks) { + for (auto &sink : sinks) { if (sink->should_log(msg)) sink->log(msg); } @@ -201,13 +201,13 @@ void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std: str = str_in; static std::string linebuffer; - static bool log_warn_regex_recusion_guard = false; + static bool warn_regex_recusion_guard = false; - if (!log_warn_regex_recusion_guard) + if (!warn_regex_recusion_guard) { - log_warn_regex_recusion_guard = true; + warn_regex_recusion_guard = true; - if (log_warn_regexes.empty() && log_expect_log.empty() && log_expect_prefix_log.empty()) + if (warn_regexes.empty() && expect_log.empty() && expect_prefix_log.empty()) { linebuffer.clear(); } @@ -216,11 +216,11 @@ void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std: linebuffer += str; if (!linebuffer.empty() && linebuffer.back() == '\n') { - for (auto &re : log_warn_regexes) + for (auto &re : warn_regexes) if (std::regex_search(linebuffer, re)) log_warning("Found log message matching -W regex:\n%s", str); - for (auto &[_, item] : log_expect_log) + for (auto &[_, item] : expect_log) if (std::regex_search(linebuffer, item.pattern)) item.current_count++; @@ -228,28 +228,28 @@ void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std: } } - log_warn_regex_recusion_guard = false; + warn_regex_recusion_guard = false; } } -void LogManager::log_formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str) +void LogManager::formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str) { log_assert(!Multithreading::active()); - if (log_make_debug && !is_debug(1)) + if (make_debug && !is_debug(1)) return; logv_string(severity, prefix, format, std::move(str)); } -void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str) +void LogManager::formatted_header(RTLIL::Design *design, std::string_view format, std::string str) { log_assert(!Multithreading::active()); - log_spacer(); + spacer(); if (header_count.size() > 0) header_count.back()++; - if (int(header_count.size()) <= log_verbose_level) { + if (int(header_count.size()) <= verbose_level) { log_stderr_sink_forced = true; } @@ -258,14 +258,14 @@ void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view fo for (int c : header_count) header_id += stringf("%s%d", header_id.empty() ? "" : ".", c); - log_formatted_string(LogSeverity::Header, stringf("%s. ", header_id), format, std::move(str)); + formatted_string(LogSeverity::Header, stringf("%s. ", header_id), format, std::move(str)); flush(); - if (log_hdump_all) - log_hdump[header_id].insert("yosys_dump_" + header_id + ".il"); + if (hdump_all) + hdump[header_id].insert("yosys_dump_" + header_id + ".il"); - if (log_hdump.count(header_id) && design != nullptr) - for (auto &filename : log_hdump.at(header_id)) { + if (hdump.count(header_id) && design != nullptr) + for (auto &filename : hdump.at(header_id)) { log("Dumping current design to '%s'.\n", filename); if (yosys_xtrace) IdString::xtrace_db_dump(); @@ -276,13 +276,13 @@ void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view fo log_stderr_sink_forced = false; } -void LogManager::log_formatted_warning(std::string_view prefix, std::string_view format, std::string message) +void LogManager::formatted_warning(std::string_view prefix, std::string_view format, std::string message) { log_assert(!Multithreading::active()); bool suppressed = false; - for (auto &re : log_nowarn_regexes) + for (auto &re : nowarn_regexes) if (std::regex_search(message, re)) suppressed = true; @@ -292,86 +292,86 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string_view } else { - int bak_log_make_debug = log_make_debug; - log_make_debug = 0; + int bak_make_debug = make_debug; + make_debug = 0; - for (auto &re : log_werror_regexes) + for (auto &re : werror_regexes) if (std::regex_search(message, re)) - log_formatted_error(format, message); + formatted_error(format, message); bool warning_match = false; - for (auto &[_, item] : log_expect_warning) + for (auto &[_, item] : expect_warning) if (std::regex_search(message, item.pattern)) { item.current_count++; warning_match = true; } - for (auto &[_, item] : log_expect_prefix_warning) + for (auto &[_, item] : expect_prefix_warning) if (std::regex_search(string(prefix) + message, item.pattern)) { item.current_count++; warning_match = true; } - if (log_warnings.count(message)) + if (warnings.count(message)) { - log_formatted_string(LogSeverity::Info, prefix, format, message); + formatted_string(LogSeverity::Info, prefix, format, message); flush(); } else { - log_formatted_string(LogSeverity::Warning, prefix, format, message); + formatted_string(LogSeverity::Warning, prefix, format, message); flush(); - log_warnings.insert(message); + warnings.insert(message); } if (!warning_match) - log_warnings_count_noexpect++; - log_warnings_count++; - log_make_debug = bak_log_make_debug; + warnings_count_noexpect++; + warnings_count++; + make_debug = bak_make_debug; } } -void LogManager::log_formatted_file_warning(std::string_view filename, int lineno, std::string_view format, std::string str) +void LogManager::formatted_file_warning(std::string_view filename, int lineno, std::string_view format, std::string str) { std::string prefix = stringf("%s:%d: Warning: ", filename, lineno); - log_formatted_warning(prefix, format, std::move(str)); + formatted_warning(prefix, format, std::move(str)); } -void LogManager::log_formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str) +void LogManager::formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str) { std::string prefix = stringf("%s:%d: Info: ", filename, lineno); - log_formatted_string(LogSeverity::Info, prefix, format, std::move(str)); + formatted_string(LogSeverity::Info, prefix, format, std::move(str)); } -void LogManager::log_suppressed() { - if (log_debug_suppressed && !log_make_debug) { +void LogManager::suppressed() { + if (debug_suppressed && !make_debug) { constexpr const char* format = "\n"; - logv_string(LogSeverity::Info, {}, format, stringf(format, log_debug_suppressed)); - log_debug_suppressed = 0; + logv_string(LogSeverity::Info, {}, format, stringf(format, debug_suppressed)); + debug_suppressed = 0; } } [[noreturn]] -void LogManager::log_error_with_prefix(std::string_view prefix, std::string_view format, std::string message) +void LogManager::error_with_prefix(std::string_view prefix, std::string_view format, std::string message) { - int bak_log_make_debug = log_make_debug; - log_make_debug = 0; - log_suppressed(); + int bak_make_debug = make_debug; + make_debug = 0; + suppressed(); - log_formatted_string(LogSeverity::Error, prefix, format, message); + formatted_string(LogSeverity::Error, prefix, format, message); flush(); - log_make_debug = bak_log_make_debug; + make_debug = bak_make_debug; - for (auto &[_, item] : log_expect_error) + for (auto &[_, item] : expect_error) if (std::regex_search(message, item.pattern)) item.current_count++; - for (auto &[_, item] : log_expect_prefix_error) + for (auto &[_, item] : expect_prefix_error) if (std::regex_search(string(prefix) + message, item.pattern)) item.current_count++; - log_errors_count++; + errors_count++; check_expected(); @@ -390,13 +390,13 @@ void LogManager::log_error_with_prefix(std::string_view prefix, std::string_view #endif } -void LogManager::log_formatted_file_error(std::string_view filename, int lineno, std::string_view format, std::string str) +void LogManager::formatted_file_error(std::string_view filename, int lineno, std::string_view format, std::string str) { std::string prefix = stringf("%s:%d: ERROR: ", filename, lineno); - log_error_with_prefix(prefix, format, str); + error_with_prefix(prefix, format, str); } -void LogManager::log_experimental(const std::string &str) +void LogManager::add_experimental(const std::string &str) { if (experimental_ignored.count(str) == 0 && experimental.count(str) == 0) { log_warning("Feature '%s' is experimental.\n", str); @@ -404,7 +404,7 @@ void LogManager::log_experimental(const std::string &str) } } -void LogManager::log_deprecated(const std::string &str) +void LogManager::add_deprecated(const std::string &str) { if (deprecated.count(str) == 0) { log_warning("Feature '%s' is deprecated.\n", str); @@ -412,9 +412,9 @@ void LogManager::log_deprecated(const std::string &str) } } -void LogManager::log_formatted_error(std::string_view format, std::string str) +void LogManager::formatted_error(std::string_view format, std::string str) { - log_error_with_prefix("ERROR: ", format, std::move(str)); + error_with_prefix("ERROR: ", format, std::move(str)); } void log_assert_failure(const char *expr, const char *file, int line) @@ -432,30 +432,30 @@ void log_yosys_abort_message(std::string_view file, int line, std::string_view f log_error("Abort in %s:%d (%s): %s\n", file, line, func, message); } -void LogManager::log_formatted_cmd_error(std::string_view format, std::string message) +void LogManager::formatted_cmd_error(std::string_view format, std::string message) { - if (log_cmd_error_throw) { - log_formatted_string(LogSeverity::Error, "ERROR: ", format, message); + if (cmd_error_throw) { + formatted_string(LogSeverity::Error, "ERROR: ", format, message); flush(); throw log_cmd_error_exception(); } - log_formatted_error(format, message); + formatted_error(format, message); } -void LogManager::log_spacer() +void LogManager::spacer() { - if (log_newline_count < 2) log("\n"); - if (log_newline_count < 2) log("\n"); + if (newline_count < 2) log("\n"); + if (newline_count < 2) log("\n"); } -void LogManager::log_push() +void LogManager::push() { header_count.push_back(0); } -void LogManager::log_pop() +void LogManager::pop() { header_count.pop_back(); log_id_cache_clear(); @@ -559,7 +559,7 @@ void log_backtrace(const char *prefix, int levels) void log_backtrace(const char*, int) { } #endif -void LogManager::log_reset_stack() +void LogManager::reset_stack() { while (header_count.size() > 1) header_count.pop_back(); @@ -626,39 +626,39 @@ void LogManager::check_expected() { // copy out all of the expected logs so that they cannot be re-checked // or match against themselves - dict expect_log, expect_warning, expect_error; - dict expect_prefix_log, expect_prefix_warning, expect_prefix_error; - std::swap(expect_warning, log_expect_warning); - std::swap(expect_log, log_expect_log); - std::swap(expect_error, log_expect_error); - std::swap(expect_prefix_warning, log_expect_prefix_warning); - std::swap(expect_prefix_log, log_expect_prefix_log); - std::swap(expect_prefix_error, log_expect_prefix_error); + dict expect_log_copy, expect_warning_copy, expect_error_copy; + dict expect_prefix_log_copy, expect_prefix_warning_copy, expect_prefix_error_copy; + std::swap(expect_warning_copy, expect_warning); + std::swap(expect_log_copy, expect_log); + std::swap(expect_error_copy, expect_error); + std::swap(expect_prefix_warning_copy, expect_prefix_warning); + std::swap(expect_prefix_log_copy, expect_prefix_log); + std::swap(expect_prefix_error_copy, expect_prefix_error); auto check = [&](const std::string kind, std::string pattern, LogExpectedItem item) { if (item.current_count == 0) { - log_warn_regexes.clear(); + warn_regexes.clear(); log_error("Expected %s pattern '%s' not found !\n", kind, pattern); } if (item.current_count != item.expected_count) { - log_warn_regexes.clear(); + warn_regexes.clear(); log_error("Expected %s pattern '%s' found %d time(s), instead of %d time(s) !\n", kind.c_str(), pattern.c_str(), item.current_count, item.expected_count); } }; - for (auto &[pattern, item] : expect_warning) + for (auto &[pattern, item] : expect_warning_copy) check("warning", pattern, item); - for (auto &[pattern, item] : expect_prefix_warning) + for (auto &[pattern, item] : expect_prefix_warning_copy) check("prefixed warning", pattern, item); - for (auto &[pattern, item] : expect_log) + for (auto &[pattern, item] : expect_log_copy) check("log", pattern, item); - for (auto &[pattern, item] : expect_prefix_log) + for (auto &[pattern, item] : expect_prefix_log_copy) check("prefixed log", pattern, item); auto check_err = [&](const std::string kind, std::string pattern, LogExpectedItem item) { if (item.current_count == item.expected_count) { - log_warn_regexes.clear(); + warn_regexes.clear(); log("Expected %s pattern '%s' found !!!\n", kind, pattern); yosys_shutdown(); #if defined(_MSC_VER) @@ -667,52 +667,52 @@ void LogManager::check_expected() _Exit(0); #endif } else { - log_warn_regexes.clear(); + warn_regexes.clear(); log_error("Expected %s pattern '%s' not found !\n", kind, pattern); } }; - for (auto &[pattern, item] : expect_error) + for (auto &[pattern, item] : expect_error_copy) check_err("error", pattern, item); - for (auto &[pattern, item] : expect_prefix_error) + for (auto &[pattern, item] : expect_prefix_error_copy) check_err("prefixed error", pattern, item); } void LogManager::report_unexpected_error() { - if (log_expect_no_warnings && log_warnings_count_noexpect) - log_error("Unexpected warnings found: %d unique messages, %d total, %d expected\n", GetSize(log_warnings), - log_warnings_count, log_warnings_count - log_warnings_count_noexpect); + if (expect_no_warnings && warnings_count_noexpect) + log_error("Unexpected warnings found: %d unique messages, %d total, %d expected\n", GetSize(warnings), + warnings_count, warnings_count - warnings_count_noexpect); } void LogManager::add_expect(std::string type, std::string pattern, int count) { if (type == "error") - log_expect_error[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_error[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else if (type == "prefix-error") - log_expect_prefix_error[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_prefix_error[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else if (type == "warning") - log_expect_warning[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_warning[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else if (type == "prefix-warning") - log_expect_prefix_warning[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_prefix_warning[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else if (type == "log") - log_expect_log[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_log[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else if (type == "prefix-log") - log_expect_prefix_log[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); + expect_prefix_log[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); else log_abort(); } void LogManager::start_hasher() { - log_hasher = std::make_unique(); + hasher = std::make_unique(); } std::string LogManager::finish_hasher() { - if (!log_hasher) + if (!hasher) return {}; - std::string hash = log_hasher->final().substr(0, 10); - log_hasher.reset(); + std::string hash = hasher->final().substr(0, 10); + hasher.reset(); return hash; } diff --git a/kernel/log.h b/kernel/log.h index 1726e2ff7..f31f37a58 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -205,44 +205,44 @@ public: { auto sink = std::make_unique(std::forward(args)...); T &ref = *sink; - log_sinks.push_back(std::move(sink)); + sinks.push_back(std::move(sink)); return ref; } template void for_each_sink(F &&func) { - for (auto &sink : log_sinks) + for (auto &sink : sinks) func(*sink); } - bool empty() { return log_sinks.empty(); } - void clear() { log_sinks.clear(); } + bool empty() { return sinks.empty(); } + void clear() { sinks.clear(); } void clear_original() { - std::erase_if(log_sinks, [](const auto &sink) { return dynamic_cast(sink.get()) != nullptr; }); + std::erase_if(sinks, [](const auto &sink) { return dynamic_cast(sink.get()) != nullptr; }); } - void flush() { for (auto &sink : log_sinks) sink->flush(); } + void flush() { for (auto &sink : sinks) sink->flush(); } class Scoped { public: explicit Scoped(LogManager &manager) : manager(manager), - backup_log_sinks(std::move(manager.log_sinks)), - backup_log_verbose_level(manager.log_verbose_level) + backup_sinks(std::move(manager.sinks)), + backup_verbose_level(manager.verbose_level) { - manager.log_sinks.reserve(backup_log_sinks.size()); + manager.sinks.reserve(backup_sinks.size()); - for (const auto &sink : backup_log_sinks) - manager.log_sinks.push_back(std::make_unique(sink.get())); + for (const auto &sink : backup_sinks) + manager.sinks.push_back(std::make_unique(sink.get())); } ~Scoped() { - manager.log_sinks.clear(); - manager.log_sinks = std::move(backup_log_sinks); - manager.log_verbose_level = backup_log_verbose_level; + manager.sinks.clear(); + manager.sinks = std::move(backup_sinks); + manager.verbose_level = backup_verbose_level; } Scoped(const Scoped &) = delete; @@ -250,11 +250,11 @@ public: private: LogManager &manager; - std::vector> backup_log_sinks; - int backup_log_verbose_level; + std::vector> backup_sinks; + int backup_verbose_level; }; - Scoped scoped() + Scoped sink_scope() { return Scoped(*this); } @@ -263,14 +263,14 @@ public: { public: explicit ScopedCmdErrorThrow(LogManager &manager) - : manager(manager), previous(manager.log_cmd_error_throw) + : manager(manager), previous(manager.cmd_error_throw) { - manager.log_cmd_error_throw = true; + manager.cmd_error_throw = true; } ~ScopedCmdErrorThrow() { - manager.log_cmd_error_throw = previous; + manager.cmd_error_throw = previous; } private: @@ -278,7 +278,7 @@ public: bool previous; }; - ScopedCmdErrorThrow scoped_cmd_error_throw() + ScopedCmdErrorThrow error_throw_scope() { return ScopedCmdErrorThrow(*this); } @@ -303,7 +303,7 @@ public: if (status) return; status = true; - manager.log_make_debug++; + manager.make_debug++; } void off_silent() @@ -311,7 +311,7 @@ public: if (!status) return; status = false; - manager.log_make_debug--; + manager.make_debug--; } void off() @@ -323,7 +323,7 @@ public: bool status = false; }; - LogMakeDebugHdl make_debug(bool start_on = false) + LogMakeDebugHdl make_debug_scope(bool start_on = false) { return LogMakeDebugHdl(*this, start_on); } @@ -349,7 +349,7 @@ public: return; active = true; - manager.log_force_debug++; + manager.force_debug++; } void off() @@ -358,68 +358,68 @@ public: return; active = false; - manager.log_force_debug--; + manager.force_debug--; } private: LogManager &manager; bool active = false; }; - ForceDebug force_debug(bool start_on = false) + ForceDebug force_debug_scope(bool start_on = false) { return ForceDebug(*this, start_on); } - void force_debug_on() { log_force_debug++; } - void force_debug_off() { if (log_force_debug > 0) log_force_debug--; } - void set_force_debug(bool enabled) { log_force_debug = enabled ? 1 : 0; } + void force_debug_on() { force_debug++; } + void force_debug_off() { if (force_debug > 0) force_debug--; } + void set_force_debug(bool enabled) { force_debug = enabled ? 1 : 0; } void report_unexpected_error(); void add_experimental_ignore(std::string name) { experimental_ignored.insert(name); } - void add_warn(std::string pattern) { log_warn_regexes.push_back(YS_REGEX_COMPILE(pattern)); } - void add_nowarn(std::string pattern) { log_nowarn_regexes.push_back(YS_REGEX_COMPILE(pattern)); } - void add_werror(std::string pattern) { log_werror_regexes.push_back(YS_REGEX_COMPILE(pattern)); } + void add_warn(std::string pattern) { warn_regexes.push_back(YS_REGEX_COMPILE(pattern)); } + void add_nowarn(std::string pattern) { nowarn_regexes.push_back(YS_REGEX_COMPILE(pattern)); } + void add_werror(std::string pattern) { werror_regexes.push_back(YS_REGEX_COMPILE(pattern)); } void add_expect(std::string type, std::string pattern, int count); - void set_verbose_level(int level) { log_verbose_level = level; } - void add_verbose_level(int level) { log_verbose_level += level; } - void set_expect_no_warnings(bool value) { log_expect_no_warnings = value; } + void set_verbose_level(int level) { verbose_level = level; } + void add_verbose_level(int level) { verbose_level += level; } + void set_expect_no_warnings(bool value) { expect_no_warnings = value; } void set_log_time(bool value) { log_time = value; } - void set_cmd_error_throw(bool value) { log_cmd_error_throw = value; } - void set_hdump_all(bool value) { log_hdump_all = value; } - int get_verbose_level() const { return log_verbose_level; } + void set_cmd_error_throw(bool value) { cmd_error_throw = value; } + void set_hdump_all(bool value) { hdump_all = value; } + int get_verbose_level() const { return verbose_level; } bool get_log_time() const { return log_time; } - int get_warnings_unique() const { return GetSize(log_warnings); } - int get_warnings_total() const { return log_warnings_count; } - int get_errors_total() const { return log_errors_count; } + int get_warnings_unique() const { return GetSize(warnings); } + int get_warnings_total() const { return warnings_count; } + int get_errors_total() const { return errors_count; } const std::set &get_experimental() const { return experimental; } const std::set &get_deprecated() const { return deprecated; } std::chrono::steady_clock::time_point get_initial_time() const; - void add_hdump(std::string name, std::string value) { log_hdump[name].insert(value); } + void add_hdump(std::string name, std::string value) { hdump[name].insert(value); } - void log_formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str); - void log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str); - void log_formatted_warning(std::string_view prefix, std::string_view format, std::string message); - void log_formatted_file_warning(std::string_view filename, int lineno, std::string_view format, std::string str); - void log_formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str); - void log_suppressed(); - [[noreturn]] void log_formatted_file_error(std::string_view filename, int lineno, std::string_view format, std::string str); - void log_experimental(const std::string &str); - void log_deprecated(const std::string &str); - [[noreturn]] void log_formatted_error(std::string_view format, std::string str); - [[noreturn]] void log_formatted_cmd_error(std::string_view format, std::string message); - void log_spacer(); - void log_push(); - void log_pop(); + void formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str); + void formatted_header(RTLIL::Design *design, std::string_view format, std::string str); + void formatted_warning(std::string_view prefix, std::string_view format, std::string message); + void formatted_file_warning(std::string_view filename, int lineno, std::string_view format, std::string str); + void formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str); + [[noreturn]] void formatted_file_error(std::string_view filename, int lineno, std::string_view format, std::string str); + [[noreturn]] void formatted_error(std::string_view format, std::string str); + [[noreturn]] void formatted_cmd_error(std::string_view format, std::string message); + void suppressed(); + void add_experimental(const std::string &str); + void add_deprecated(const std::string &str); + void spacer(); + void push(); + void pop(); - void log_reset_stack(); + void reset_stack(); void check_expected(); - bool expects_error() { return (log_expect_error.size() + log_expect_prefix_error.size())>0; } + bool expects_error() { return (expect_error.size() + expect_prefix_error.size())>0; } #ifndef NDEBUG - bool is_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; } + bool is_debug(int n = 0) { if (force_debug) return true; debug_suppressed += n; return false; } #else bool is_debug(int = 0) { return false; } #endif @@ -428,30 +428,30 @@ public: private: void logv_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str_in); - [[noreturn]] void log_error_with_prefix(std::string_view prefix, std::string_view format, std::string message); + [[noreturn]] void error_with_prefix(std::string_view prefix, std::string_view format, std::string message); - std::vector> log_sinks; - int log_verbose_level = 0; - int log_newline_count = 0; + std::vector> sinks; + int verbose_level = 0; + int newline_count = 0; vector header_count; - int log_errors_count = 0; - int log_warnings_count = 0; - int log_warnings_count_noexpect = 0; - std::set log_warnings, experimental, experimental_ignored, deprecated; + int errors_count = 0; + int warnings_count = 0; + int warnings_count_noexpect = 0; + std::set warnings, experimental, experimental_ignored, deprecated; - std::vector log_warn_regexes, log_nowarn_regexes, log_werror_regexes; - dict log_expect_log, log_expect_warning, log_expect_error; - dict log_expect_prefix_log, log_expect_prefix_warning, log_expect_prefix_error; - bool log_expect_no_warnings = false; + std::vector warn_regexes, nowarn_regexes, werror_regexes; + dict expect_log, expect_warning, expect_error; + dict expect_prefix_log, expect_prefix_warning, expect_prefix_error; + bool expect_no_warnings = false; bool log_time = false; - bool log_cmd_error_throw = false; - std::map> log_hdump; - bool log_hdump_all = false; + bool cmd_error_throw = false; + std::map> hdump; + bool hdump_all = false; - int log_debug_suppressed = 0; - int log_make_debug = 0; - int log_force_debug = 0; - std::unique_ptr log_hasher; + int debug_suppressed = 0; + int make_debug = 0; + int force_debug = 0; + std::unique_ptr hasher; }; LogManager &logger(); @@ -470,20 +470,20 @@ static inline bool ys_debug(int = 0) { return false; } template inline void log(FmtString...> fmt, const Args &... args) { - logger().log_formatted_string(LogSeverity::Info, {}, fmt.format_string(), fmt.format(args...)); + logger().formatted_string(LogSeverity::Info, {}, fmt.format_string(), fmt.format(args...)); } template inline void log_comment(FmtString...> fmt, const Args &... args) { - logger().log_formatted_string(LogSeverity::Comment, {}, fmt.format_string(), fmt.format(args...)); + logger().formatted_string(LogSeverity::Comment, {}, fmt.format_string(), fmt.format(args...)); } template inline void log_formatted_string(LogSeverity severity, std::string_view prefix, FmtString...> fmt, const Args &... args) { - logger().log_formatted_string(severity, prefix, fmt.format_string(), fmt.format(args...)); + logger().formatted_string(severity, prefix, fmt.format_string(), fmt.format(args...)); } #define log_debug(...) do { if (ys_debug(1)) YOSYS_NAMESPACE_PREFIX log_formatted_string(YOSYS_NAMESPACE_PREFIX LogSeverity::Debug, {}, __VA_ARGS__); } while (0) @@ -491,72 +491,72 @@ inline void log_formatted_string(LogSeverity severity, std::string_view prefix, template inline void log_header(RTLIL::Design *design, FmtString...> fmt, const Args &... args) { - logger().log_formatted_header(design, fmt.format_string(), fmt.format(args...)); + logger().formatted_header(design, fmt.format_string(), fmt.format(args...)); } template inline void log_warning(FmtString...> fmt, const Args &... args) { - logger().log_formatted_warning("Warning: ", fmt.format_string(), fmt.format(args...)); + logger().formatted_warning("Warning: ", fmt.format_string(), fmt.format(args...)); } template inline void log_warning_noprefix(FmtString...> fmt, const Args &... args) { - logger().log_formatted_warning({}, fmt.format_string(), fmt.format(args...)); + logger().formatted_warning({}, fmt.format_string(), fmt.format(args...)); } inline void log_experimental(const std::string &str) { - logger().log_experimental(str); + logger().add_experimental(str); } inline void log_deprecated(const std::string &str) { - logger().log_deprecated(str); + logger().add_deprecated(str); } // Log with filename to report a problem in a source file. template void log_file_warning(std::string_view filename, int lineno, FmtString...> fmt, const Args &... args) { - logger().log_formatted_file_warning(filename, lineno, fmt.format_string(), fmt.format(args...)); + logger().formatted_file_warning(filename, lineno, fmt.format_string(), fmt.format(args...)); } template void log_file_info(std::string_view filename, int lineno, FmtString...> fmt, const Args &... args) { - logger().log_formatted_file_info(filename, lineno, fmt.format_string(), fmt.format(args...)); + logger().formatted_file_info(filename, lineno, fmt.format_string(), fmt.format(args...)); } template [[noreturn]] void log_error(FmtString...> fmt, const Args &... args) { - logger().log_formatted_error(fmt.format_string(), fmt.format(args...)); + logger().formatted_error(fmt.format_string(), fmt.format(args...)); } template [[noreturn]] void log_file_error(std::string_view filename, int lineno, FmtString...> fmt, const Args &... args) { - logger().log_formatted_file_error(filename, lineno, fmt.format_string(), fmt.format(args...)); + logger().formatted_file_error(filename, lineno, fmt.format_string(), fmt.format(args...)); } template [[noreturn]] void log_cmd_error(FmtString...> fmt, const Args &... args) { - logger().log_formatted_cmd_error(fmt.format_string(), fmt.format(args...)); + logger().formatted_cmd_error(fmt.format_string(), fmt.format(args...)); } inline void log_suppressed() { - logger().log_suppressed(); + logger().suppressed(); } -inline void log_spacer() { logger().log_spacer(); } -inline void log_push() { logger().log_push(); } -inline void log_pop() { logger().log_pop(); } +inline void log_spacer() { logger().spacer(); } +inline void log_push() { logger().push(); } +inline void log_pop() { logger().pop(); } -inline void log_reset_stack() { logger().log_reset_stack(); } +inline void log_reset_stack() { logger().reset_stack(); } inline void log_flush() { logger().flush(); } void log_backtrace(const char *prefix, int levels); diff --git a/kernel/log_compat.cc b/kernel/log_compat.cc index 65f5105c1..835185e1a 100644 --- a/kernel/log_compat.cc +++ b/kernel/log_compat.cc @@ -37,7 +37,7 @@ void log_cmd_error(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_cmd_error(format, formatted); + logger().formatted_cmd_error(format, formatted); } void log_warning(const char *format, ...) @@ -46,7 +46,7 @@ void log_warning(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_warning("Warning: ", format, formatted); + logger().formatted_warning("Warning: ", format, formatted); } void log_warning_noprefix(const char *format, ...) @@ -55,7 +55,7 @@ void log_warning_noprefix(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_warning({}, format, formatted); + logger().formatted_warning({}, format, formatted); } void log_error(const char *format, ...) @@ -64,7 +64,7 @@ void log_error(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_error(format, formatted); + logger().formatted_error(format, formatted); } void log(const char *format, ...) @@ -73,7 +73,7 @@ void log(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_string(LogSeverity::Info, {}, format, formatted); + logger().formatted_string(LogSeverity::Info, {}, format, formatted); } void log_compat(const char *format, ...) @@ -82,7 +82,7 @@ void log_compat(const char *format, ...) va_start(ap, format); std::string formatted = vstringf(format, ap); va_end(ap); - logger().log_formatted_string(LogSeverity::Info, {}, format, formatted); + logger().formatted_string(LogSeverity::Info, {}, format, formatted); } YOSYS_NAMESPACE_END diff --git a/kernel/register.cc b/kernel/register.cc index d9dbc34c9..14484c25a 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -806,7 +806,7 @@ struct HelpPass : public Pass { // dump command help std::ostringstream buf; { - auto log_scope = logger().scoped(); + auto log_scope = logger().sink_scope(); logger().add_sink(buf); pass->help(); } diff --git a/kernel/tclapi.cc b/kernel/tclapi.cc index bcc65cc9e..47c1303a1 100644 --- a/kernel/tclapi.cc +++ b/kernel/tclapi.cc @@ -100,7 +100,7 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a yosys_get_design()->scratchpad_unset("result.string"); bool in_repl = yosys_tcl_repl_active; - auto guard = logger().scoped_cmd_error_throw(); + auto guard = logger().error_throw_scope(); try { if (args.size() == 1) { Pass::call(yosys_get_design(), args[0]); diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 6fa7fd4fc..27c082b1d 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -995,7 +995,7 @@ void shell(RTLIL::Design *design) static int recursion_counter = 0; recursion_counter++; - auto guard = logger().scoped_cmd_error_throw(); + auto guard = logger().error_throw_scope(); #if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) rl_readline_name = (char*)"yosys"; diff --git a/passes/cmds/tee.cc b/passes/cmds/tee.cc index 272f36edc..456bc221c 100644 --- a/passes/cmds/tee.cc +++ b/passes/cmds/tee.cc @@ -58,7 +58,7 @@ struct TeePass : public Pass { } void execute(std::vector args, RTLIL::Design *design) override { - auto log_scope = logger().scoped(); + auto log_scope = logger().sink_scope(); size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) diff --git a/passes/cmds/trace.cc b/passes/cmds/trace.cc index 7b4e82ec3..e8bbd5840 100644 --- a/passes/cmds/trace.cc +++ b/passes/cmds/trace.cc @@ -153,7 +153,7 @@ struct DebugPass : public Pass { return; } - auto force_debug = logger().force_debug(true); + auto force_debug = logger().force_debug_scope(true); std::vector new_args(args.begin() + argidx, args.end()); Pass::call(design, new_args); diff --git a/passes/techmap/techmap.cc b/passes/techmap/techmap.cc index a919b2f2a..2dbeef7a3 100644 --- a/passes/techmap/techmap.cc +++ b/passes/techmap/techmap.cc @@ -419,7 +419,7 @@ struct TechmapWorker bool log_continue = false; bool did_something = false; - auto mkdebug = logger().make_debug(); + auto mkdebug = logger().make_debug_scope(); SigMap sigmap(module); FfInitVals initvals(&sigmap, module); diff --git a/pyosys/wrappers_tpl.cc b/pyosys/wrappers_tpl.cc index 53bc055d1..327b21ff7 100644 --- a/pyosys/wrappers_tpl.cc +++ b/pyosys/wrappers_tpl.cc @@ -178,14 +178,14 @@ namespace pyosys { } // Logging Methods - m.def("log_header", [](Design *d, std::string s) { logger().log_formatted_header(d, "%s", s); }); - m.def("log", [](std::string s) { logger().log_formatted_string({}, "%s", s, LogSeverity::Info); }); - m.def("log_file_info", [](std::string_view file, int line, std::string s) { logger().log_formatted_file_info(file, line, "%s", s); }); - m.def("log_warning", [](std::string s) { logger().log_formatted_warning("Warning: ", "%s", s); }); - m.def("log_warning_noprefix", [](std::string s) { logger().log_formatted_warning("", "%s", s); }); - m.def("log_file_warning", [](std::string_view file, int line, std::string s) { logger().log_formatted_file_warning(file, line, "%s", s); }); - m.def("log_error", [](std::string s) { logger().log_formatted_error("%s", s); }); - m.def("log_file_error", [](std::string_view file, int line, std::string s) { logger().log_formatted_file_error(file, line, "%s", s); }); + m.def("log_header", [](Design *d, std::string s) { logger().formatted_header(d, "%s", s); }); + m.def("log", [](std::string s) { logger().formatted_string(LogSeverity::Info, {}, "%s", s); }); + m.def("log_file_info", [](std::string_view file, int line, std::string s) { logger().formatted_file_info(file, line, "%s", s); }); + m.def("log_warning", [](std::string s) { logger().formatted_warning("Warning: ", "%s", s); }); + m.def("log_warning_noprefix", [](std::string s) { logger().formatted_warning("", "%s", s); }); + m.def("log_file_warning", [](std::string_view file, int line, std::string s) { logger().formatted_file_warning(file, line, "%s", s); }); + m.def("log_error", [](std::string s) { logger().formatted_error("%s", s); }); + m.def("log_file_error", [](std::string_view file, int line, std::string s) { logger().formatted_file_error(file, line, "%s", s); }); // Namespace to host global objects auto global_variables = py::class_(m, "Globals");