mirror of
https://github.com/YosysHQ/yosys.git
synced 2026-09-07 04:19:56 +02:00
log: propagate format information
This commit is contained in:
@@ -1942,9 +1942,9 @@ void AstModule::loadconfig() const
|
||||
flag_autowire = autowire;
|
||||
}
|
||||
|
||||
void AstNode::formatted_input_error(std::string str) const
|
||||
void AstNode::formatted_input_error(std::string_view format, std::string str) const
|
||||
{
|
||||
log_file_error(*location.begin.filename, location.begin.line, "%s", std::move(str));
|
||||
logger().log_formatted_file_error(*location.begin.filename, location.begin.line, format, std::move(str));
|
||||
}
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
+2
-2
@@ -379,11 +379,11 @@ namespace AST
|
||||
AstNode *get_struct_member() const;
|
||||
|
||||
// helper to print errors from simplify/genrtlil code
|
||||
[[noreturn]] void formatted_input_error(std::string str) const;
|
||||
[[noreturn]] void formatted_input_error(std::string_view format, std::string str) const;
|
||||
template <typename... Args>
|
||||
[[noreturn]] void input_error(FmtString<TypeIdentity<Args>...> fmt, const Args &... args) const
|
||||
{
|
||||
formatted_input_error(fmt.format(args...));
|
||||
formatted_input_error(fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+18
-17
@@ -273,7 +273,7 @@ void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view fo
|
||||
log_stderr_force = false;
|
||||
}
|
||||
|
||||
void LogManager::log_formatted_warning(std::string_view prefix, std::string message)
|
||||
void LogManager::log_formatted_warning(std::string_view prefix, std::string_view format, std::string message)
|
||||
{
|
||||
log_assert(!Multithreading::active());
|
||||
|
||||
@@ -294,7 +294,7 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string mess
|
||||
|
||||
for (auto &re : log_werror_regexes)
|
||||
if (std::regex_search(message, re))
|
||||
log_formatted_error(message);
|
||||
log_formatted_error(format, message);
|
||||
|
||||
bool warning_match = false;
|
||||
for (auto &[_, item] : log_expect_warning)
|
||||
@@ -311,12 +311,12 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string mess
|
||||
|
||||
if (log_warnings.count(message))
|
||||
{
|
||||
log_formatted_string(prefix, "%s", message, LogSeverity::LOG_INFO);
|
||||
log_formatted_string(prefix, format, message, LogSeverity::LOG_INFO);
|
||||
flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
log_formatted_string(prefix, "%s", message, LogSeverity::LOG_WARNING);
|
||||
log_formatted_string(prefix, format, message, LogSeverity::LOG_WARNING);
|
||||
flush();
|
||||
log_warnings.insert(message);
|
||||
}
|
||||
@@ -328,15 +328,16 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string mess
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::log_formatted_file_warning(std::string_view filename, int lineno, std::string str)
|
||||
void LogManager::log_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, std::move(str));
|
||||
log_formatted_warning(prefix, format, std::move(str));
|
||||
}
|
||||
|
||||
void LogManager::log_formatted_file_info(std::string_view filename, int lineno, std::string str)
|
||||
void LogManager::log_formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str)
|
||||
{
|
||||
log("%s:%d: Info: %s", filename, lineno, str);
|
||||
std::string prefix = stringf("%s:%d: Info: ", filename, lineno);
|
||||
log_formatted_string(prefix, format, std::move(str), LogSeverity::LOG_INFO);
|
||||
}
|
||||
|
||||
void LogManager::log_suppressed() {
|
||||
@@ -348,13 +349,13 @@ void LogManager::log_suppressed() {
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
void LogManager::log_error_with_prefix(std::string_view prefix, std::string message)
|
||||
void LogManager::log_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();
|
||||
|
||||
log_formatted_string(prefix, "%s", message, LogSeverity::LOG_ERROR);
|
||||
log_formatted_string(prefix, format, message, LogSeverity::LOG_ERROR);
|
||||
flush();
|
||||
|
||||
log_make_debug = bak_log_make_debug;
|
||||
@@ -384,10 +385,10 @@ void LogManager::log_error_with_prefix(std::string_view prefix, std::string mess
|
||||
#endif
|
||||
}
|
||||
|
||||
void LogManager::log_formatted_file_error(std::string_view filename, int lineno, std::string str)
|
||||
void LogManager::log_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, str);
|
||||
log_error_with_prefix(prefix, format, str);
|
||||
}
|
||||
|
||||
void LogManager::log_experimental(const std::string &str)
|
||||
@@ -398,9 +399,9 @@ void LogManager::log_experimental(const std::string &str)
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::log_formatted_error(std::string str)
|
||||
void LogManager::log_formatted_error(std::string_view format, std::string str)
|
||||
{
|
||||
log_error_with_prefix("ERROR: ", std::move(str));
|
||||
log_error_with_prefix("ERROR: ", format, std::move(str));
|
||||
}
|
||||
|
||||
void log_assert_failure(const char *expr, const char *file, int line)
|
||||
@@ -418,16 +419,16 @@ 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 message)
|
||||
void LogManager::log_formatted_cmd_error(std::string_view format, std::string message)
|
||||
{
|
||||
if (log_cmd_error_throw) {
|
||||
log_formatted_string("ERROR: ", "%s", message, LogSeverity::LOG_ERROR);
|
||||
log_formatted_string("ERROR: ", format, message, LogSeverity::LOG_ERROR);
|
||||
flush();
|
||||
|
||||
throw log_cmd_error_exception();
|
||||
}
|
||||
|
||||
log_formatted_error(message);
|
||||
log_formatted_error(format, message);
|
||||
}
|
||||
|
||||
void LogManager::log_spacer()
|
||||
|
||||
+14
-14
@@ -394,14 +394,14 @@ public:
|
||||
|
||||
void log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity);
|
||||
void log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str);
|
||||
void log_formatted_warning(std::string_view prefix, std::string message);
|
||||
void log_formatted_file_warning(std::string_view filename, int lineno, std::string str);
|
||||
void log_formatted_file_info(std::string_view filename, int lineno, 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 str);
|
||||
[[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);
|
||||
[[noreturn]] void log_formatted_error(std::string str);
|
||||
[[noreturn]] void log_formatted_cmd_error(std::string message);
|
||||
[[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();
|
||||
@@ -420,7 +420,7 @@ public:
|
||||
|
||||
private:
|
||||
void logv_string(std::string_view prefix, std::string_view format, std::string str_in, LogSeverity severity);
|
||||
[[noreturn]] void log_error_with_prefix(std::string_view prefix, std::string message);
|
||||
[[noreturn]] void log_error_with_prefix(std::string_view prefix, std::string_view format, std::string message);
|
||||
|
||||
std::vector<std::unique_ptr<LogSink>> log_sinks;
|
||||
int log_verbose_level = 0;
|
||||
@@ -488,13 +488,13 @@ inline void log_header(RTLIL::Design *design, FmtString<TypeIdentity<Args>...> f
|
||||
template <typename... Args>
|
||||
inline void log_warning(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_warning("Warning: ", fmt.format(args...));
|
||||
logger().log_formatted_warning("Warning: ", fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void log_warning_noprefix(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_warning({}, fmt.format(args...));
|
||||
logger().log_formatted_warning({}, fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
inline void log_experimental(const std::string &str)
|
||||
@@ -506,31 +506,31 @@ inline void log_experimental(const std::string &str)
|
||||
template <typename... Args>
|
||||
void log_file_warning(std::string_view filename, int lineno, FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_file_warning(filename, lineno, fmt.format(args...));
|
||||
logger().log_formatted_file_warning(filename, lineno, fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void log_file_info(std::string_view filename, int lineno, FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_file_info(filename, lineno, fmt.format(args...));
|
||||
logger().log_formatted_file_info(filename, lineno, fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
[[noreturn]] void log_error(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_error(fmt.format(args...));
|
||||
logger().log_formatted_error(fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
[[noreturn]] void log_file_error(std::string_view filename, int lineno, FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_file_error(filename, lineno, fmt.format(args...));
|
||||
logger().log_formatted_file_error(filename, lineno, fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
[[noreturn]] void log_cmd_error(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
|
||||
{
|
||||
logger().log_formatted_cmd_error(fmt.format(args...));
|
||||
logger().log_formatted_cmd_error(fmt.format_string(), fmt.format(args...));
|
||||
}
|
||||
|
||||
inline void log_suppressed()
|
||||
|
||||
+6
-13
@@ -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(formatted);
|
||||
logger().log_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: ", formatted);
|
||||
logger().log_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("", formatted);
|
||||
logger().log_formatted_warning({}, format, formatted);
|
||||
}
|
||||
|
||||
void log_error(const char *format, ...)
|
||||
@@ -64,14 +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(formatted);
|
||||
}
|
||||
|
||||
static inline void log_formatted(std::string const &str)
|
||||
{
|
||||
// We use this inline wrapper as the following becomes ambiguous as soon as
|
||||
// the `log` function below is declared.
|
||||
return log("%s", str);
|
||||
logger().log_formatted_error(format, formatted);
|
||||
}
|
||||
|
||||
void log(const char *format, ...)
|
||||
@@ -80,7 +73,7 @@ void log(const char *format, ...)
|
||||
va_start(ap, format);
|
||||
std::string formatted = vstringf(format, ap);
|
||||
va_end(ap);
|
||||
log_formatted(formatted);
|
||||
logger().log_formatted_string({}, format, formatted, LogSeverity::LOG_INFO);
|
||||
}
|
||||
|
||||
void log_compat(const char *format, ...)
|
||||
@@ -89,7 +82,7 @@ void log_compat(const char *format, ...)
|
||||
va_start(ap, format);
|
||||
std::string formatted = vstringf(format, ap);
|
||||
va_end(ap);
|
||||
log_formatted(formatted);
|
||||
logger().log_formatted_string({}, format, formatted, LogSeverity::LOG_INFO);
|
||||
}
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user