diff --git a/kernel/log.cc b/kernel/log.cc index 03da07aa0..62d954ee5 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -164,10 +164,10 @@ static void log_id_cache_clear() log_id_cache.clear(); } -void LogManager::logv_string(std::string_view prefix, std::string_view format, std::string str_in, LogSeverity severity) { +void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str_in) { size_t remove_leading = 0; while (format.size() > 1 && format[0] == '\n') { - logv_string(prefix, "\n", "\n", severity); + logv_string(severity, prefix, "\n", "\n"); format = format.substr(1); ++remove_leading; } @@ -230,13 +230,13 @@ void LogManager::logv_string(std::string_view prefix, std::string_view format, s } } -void LogManager::log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity) +void LogManager::log_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)) return; - logv_string(prefix, format, std::move(str), severity); + logv_string(severity, prefix, format, std::move(str)); } void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str) @@ -256,7 +256,7 @@ 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(stringf("%s. ", header_id), format, std::move(str), LogSeverity::Header); + log_formatted_string(LogSeverity::Header, stringf("%s. ", header_id), format, std::move(str)); flush(); if (log_hdump_all) @@ -312,12 +312,12 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string_view if (log_warnings.count(message)) { - log_formatted_string(prefix, format, message, LogSeverity::Info); + log_formatted_string(LogSeverity::Info, prefix, format, message); flush(); } else { - log_formatted_string(prefix, format, message, LogSeverity::Warning); + log_formatted_string(LogSeverity::Warning, prefix, format, message); flush(); log_warnings.insert(message); } @@ -338,13 +338,13 @@ void LogManager::log_formatted_file_warning(std::string_view filename, int linen void LogManager::log_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(prefix, format, std::move(str), LogSeverity::Info); + log_formatted_string(LogSeverity::Info, prefix, format, std::move(str)); } void LogManager::log_suppressed() { if (log_debug_suppressed && !log_make_debug) { constexpr const char* format = "\n"; - logv_string({}, format, stringf(format, log_debug_suppressed),LogSeverity::Info); + logv_string(LogSeverity::Info, {}, format, stringf(format, log_debug_suppressed)); log_debug_suppressed = 0; } } @@ -356,7 +356,7 @@ void LogManager::log_error_with_prefix(std::string_view prefix, std::string_view log_make_debug = 0; log_suppressed(); - log_formatted_string(prefix, format, message, LogSeverity::Error); + log_formatted_string(LogSeverity::Error, prefix, format, message); flush(); log_make_debug = bak_log_make_debug; @@ -433,7 +433,7 @@ void log_yosys_abort_message(std::string_view file, int line, std::string_view f void LogManager::log_formatted_cmd_error(std::string_view format, std::string message) { if (log_cmd_error_throw) { - log_formatted_string("ERROR: ", format, message, LogSeverity::Error); + log_formatted_string(LogSeverity::Error, "ERROR: ", format, message); flush(); throw log_cmd_error_exception(); diff --git a/kernel/log.h b/kernel/log.h index 5b82ee5f7..027128def 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -401,7 +401,7 @@ public: void add_hdump(std::string name, std::string value) { log_hdump[name].insert(value); } - void log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity); + 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); @@ -429,7 +429,7 @@ public: std::string finish_hasher(); private: - void logv_string(std::string_view prefix, std::string_view format, std::string str_in, LogSeverity severity); + 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); std::vector> log_sinks; @@ -473,23 +473,24 @@ static inline bool ys_debug(int = 0) { return false; } template inline void log(FmtString...> fmt, const Args &... args) { - logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Info); + logger().log_formatted_string(LogSeverity::Info, {}, fmt.format_string(), fmt.format(args...)); } template inline void log_comment(FmtString...> fmt, const Args &... args) { - logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Comment); + logger().log_formatted_string(LogSeverity::Comment, {}, fmt.format_string(), fmt.format(args...)); } template -inline void log_debug(FmtString...> fmt, const Args &... args) +inline void log_formatted_string(LogSeverity severity, std::string_view prefix, + FmtString...> fmt, const Args &... args) { - if (!ys_debug(1)) - return; - logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Debug); + logger().log_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) + template inline void log_header(RTLIL::Design *design, FmtString...> fmt, const Args &... args) { diff --git a/kernel/log_compat.cc b/kernel/log_compat.cc index 07977d3e2..65f5105c1 100644 --- a/kernel/log_compat.cc +++ b/kernel/log_compat.cc @@ -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({}, format, formatted, LogSeverity::Info); + logger().log_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({}, format, formatted, LogSeverity::Info); + logger().log_formatted_string(LogSeverity::Info, {}, format, formatted); } YOSYS_NAMESPACE_END