mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	Make log_warning()/log_warning_noprefix() use variadic templates.
This commit is contained in:
		
							parent
							
								
									66d2c2af08
								
							
						
					
					
						commit
						25cba6181e
					
				
					 2 changed files with 17 additions and 35 deletions
				
			
		|  | @ -256,10 +256,8 @@ void log_formatted_header(RTLIL::Design *design, std::string_view format, std::s | ||||||
| 		log_files.pop_back(); | 		log_files.pop_back(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void logv_warning_with_prefix(const char *prefix, | void log_formatted_warning(std::string_view prefix, std::string message) | ||||||
|                                      const char *format, va_list ap) |  | ||||||
| { | { | ||||||
| 	std::string message = vstringf(format, ap); |  | ||||||
| 	bool suppressed = false; | 	bool suppressed = false; | ||||||
| 
 | 
 | ||||||
| 	for (auto &re : log_nowarn_regexes) | 	for (auto &re : log_nowarn_regexes) | ||||||
|  | @ -268,7 +266,7 @@ static void logv_warning_with_prefix(const char *prefix, | ||||||
| 
 | 
 | ||||||
| 	if (suppressed) | 	if (suppressed) | ||||||
| 	{ | 	{ | ||||||
| 		log("Suppressed %s%s", prefix, message.c_str()); | 		log("Suppressed %s%s", prefix, message); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | @ -294,7 +292,7 @@ static void logv_warning_with_prefix(const char *prefix, | ||||||
| 
 | 
 | ||||||
| 		if (log_warnings.count(message)) | 		if (log_warnings.count(message)) | ||||||
| 		{ | 		{ | ||||||
| 			log("%s%s", prefix, message.c_str()); | 			log("%s%s", prefix, message); | ||||||
| 			log_flush(); | 			log_flush(); | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
|  | @ -302,7 +300,7 @@ static void logv_warning_with_prefix(const char *prefix, | ||||||
| 			if (log_errfile != NULL && !log_quiet_warnings) | 			if (log_errfile != NULL && !log_quiet_warnings) | ||||||
| 				log_files.push_back(log_errfile); | 				log_files.push_back(log_errfile); | ||||||
| 
 | 
 | ||||||
| 			log("%s%s", prefix, message.c_str()); | 			log("%s%s", prefix, message); | ||||||
| 			log_flush(); | 			log_flush(); | ||||||
| 
 | 
 | ||||||
| 			if (log_errfile != NULL && !log_quiet_warnings) | 			if (log_errfile != NULL && !log_quiet_warnings) | ||||||
|  | @ -318,16 +316,6 @@ static void logv_warning_with_prefix(const char *prefix, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void logv_warning(const char *format, va_list ap) |  | ||||||
| { |  | ||||||
| 	logv_warning_with_prefix("Warning: ", format, ap); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void logv_warning_noprefix(const char *format, va_list ap) |  | ||||||
| { |  | ||||||
| 	logv_warning_with_prefix("", format, ap); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void log_file_warning(const std::string &filename, int lineno, | void log_file_warning(const std::string &filename, int lineno, | ||||||
|                       const char *format, ...) |                       const char *format, ...) | ||||||
| { | { | ||||||
|  | @ -335,7 +323,7 @@ void log_file_warning(const std::string &filename, int lineno, | ||||||
| 	va_start(ap, format); | 	va_start(ap, format); | ||||||
| 	std::string prefix = stringf("%s:%d: Warning: ", | 	std::string prefix = stringf("%s:%d: Warning: ", | ||||||
| 			filename.c_str(), lineno); | 			filename.c_str(), lineno); | ||||||
| 	logv_warning_with_prefix(prefix.c_str(), format, ap); | 	log_formatted_warning(prefix, vstringf(format, ap)); | ||||||
| 	va_end(ap); | 	va_end(ap); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -425,14 +413,6 @@ void log_file_error(const string &filename, int lineno, | ||||||
| 	logv_file_error(filename, lineno, format, ap); | 	logv_file_error(filename, lineno, format, ap); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void log_warning(const char *format, ...) |  | ||||||
| { |  | ||||||
| 	va_list ap; |  | ||||||
| 	va_start(ap, format); |  | ||||||
| 	logv_warning(format, ap); |  | ||||||
| 	va_end(ap); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void log_experimental(const char *format, ...) | void log_experimental(const char *format, ...) | ||||||
| { | { | ||||||
| 	va_list ap; | 	va_list ap; | ||||||
|  | @ -446,14 +426,6 @@ void log_experimental(const char *format, ...) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void log_warning_noprefix(const char *format, ...) |  | ||||||
| { |  | ||||||
| 	va_list ap; |  | ||||||
| 	va_start(ap, format); |  | ||||||
| 	logv_warning_noprefix(format, ap); |  | ||||||
| 	va_end(ap); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void log_error(const char *format, ...) | void log_error(const char *format, ...) | ||||||
| { | { | ||||||
| 	va_list ap; | 	va_list ap; | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								kernel/log.h
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								kernel/log.h
									
										
									
									
									
								
							|  | @ -122,7 +122,6 @@ extern int log_debug_suppressed; | ||||||
| [[noreturn]] void logv_file_error(const string &filename, int lineno, const char *format, va_list ap); | [[noreturn]] void logv_file_error(const string &filename, int lineno, const char *format, va_list ap); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| void log_warning(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); |  | ||||||
| void log_experimental(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | void log_experimental(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | ||||||
| 
 | 
 | ||||||
| void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg)); | void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg)); | ||||||
|  | @ -132,7 +131,6 @@ extern void (*log_verific_callback)(int msg_type, const char *message_id, const | ||||||
| void log_file_warning(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | void log_file_warning(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | ||||||
| void log_file_info(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | void log_file_info(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | ||||||
| 
 | 
 | ||||||
| void log_warning_noprefix(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); |  | ||||||
| [[noreturn]] void log_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | [[noreturn]] void log_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | ||||||
| [[noreturn]] void log_file_error(const string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | [[noreturn]] void log_file_error(const string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); | ||||||
| [[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | [[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); | ||||||
|  | @ -160,6 +158,18 @@ inline void log_header(RTLIL::Design *design, FmtString<TypeIdentity<Args>...> f | ||||||
| 	log_formatted_header(design, fmt.format_string(), fmt.format(args...)); | 	log_formatted_header(design, fmt.format_string(), fmt.format(args...)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void log_formatted_warning(std::string_view prefix, std::string str); | ||||||
|  | template <typename... Args> | ||||||
|  | inline void log_warning(FmtString<TypeIdentity<Args>...> fmt, const Args &... args) | ||||||
|  | { | ||||||
|  | 	log_formatted_warning("Warning: ", fmt.format(args...)); | ||||||
|  | } | ||||||
|  | template <typename... Args> | ||||||
|  | inline void log_warning_noprefix(FmtString<TypeIdentity<Args>...> fmt, const Args &... args) | ||||||
|  | { | ||||||
|  | 	log_formatted_warning("", fmt.format(args...)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static inline void log_suppressed() { | static inline void log_suppressed() { | ||||||
| 	if (log_debug_suppressed && !log_make_debug) { | 	if (log_debug_suppressed && !log_make_debug) { | ||||||
| 		log("<suppressed ~%d debug messages>\n", log_debug_suppressed); | 		log("<suppressed ~%d debug messages>\n", log_debug_suppressed); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue