diff options
Diffstat (limited to 'src/base/misc.hh')
-rw-r--r-- | src/base/misc.hh | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/src/base/misc.hh b/src/base/misc.hh index de44dc3f5..23ecf736b 100644 --- a/src/base/misc.hh +++ b/src/base/misc.hh @@ -39,40 +39,58 @@ * * Authors: Nathan Binkert * Dave Greene + * Andreas Sandberg */ #ifndef __BASE_MISC_HH__ #define __BASE_MISC_HH__ +#include <iostream> + #include "base/compiler.hh" #include "base/cprintf.hh" -#include "base/varargs.hh" #if defined(__SUNPRO_CC) #define __FUNCTION__ "how to fix me?" #endif +void __exit_epilogue(int code, + const char *func, const char *file, int line, + const char *format) M5_ATTR_NORETURN; + // General exit message, these functions will never return and will // either abort() if code is < 0 or exit with the code if >= 0 -void __exit_message(const char *prefix, int code, - const char *func, const char *file, int line, - const char *format, CPRINTF_DECLARATION) M5_ATTR_NORETURN; +template<typename ...Args> void +__exit_message(const char *prefix, int code, + const char *func, const char *file, int line, + const char *format, const Args &...args) M5_ATTR_NORETURN; +template<typename ...Args> void +__exit_message(const char *prefix, int code, + const char *func, const char *file, int line, + const std::string &format, const Args &...args) M5_ATTR_NORETURN; + +template<typename ...Args> void +__exit_message(const char *prefix, int code, + const char *func, const char *file, int line, + const char *format, const Args &...args) +{ + std::cerr << prefix << ": "; + ccprintf(std::cerr, format, args...); -void __exit_message(const char *prefix, int code, - const char *func, const char *file, int line, - const std::string &format, CPRINTF_DECLARATION) M5_ATTR_NORETURN; + __exit_epilogue(code, func, file, line, format); +} -inline void +template<typename ...Args> void __exit_message(const char *prefix, int code, - const char *func, const char *file, int line, - const std::string& format, CPRINTF_DEFINITION) + const char *func, const char *file, int line, + const std::string &format, const Args &...args) { __exit_message(prefix, code, func, file, line, format.c_str(), - VARARGS_ALLARGS); + args...); } -#define exit_message(prefix, code, ...) \ - __exit_message(prefix, code, __FUNCTION__, __FILE__, __LINE__, \ +#define exit_message(prefix, code, ...) \ + __exit_message(prefix, code, __FUNCTION__, __FILE__, __LINE__, \ __VA_ARGS__) // @@ -125,17 +143,28 @@ __exit_message(const char *prefix, int code, void +__base_message_epilogue(std::ostream &stream, bool verbose, + const char *func, const char *file, int line, + const char *format); + +template<typename ...Args> void __base_message(std::ostream &stream, const char *prefix, bool verbose, - const char *func, const char *file, int line, - const char *format, CPRINTF_DECLARATION); + const char *func, const char *file, int line, + const char *format, const Args &...args) +{ + stream << prefix << ": "; + ccprintf(stream, format, args...); + + __base_message_epilogue(stream, verbose, func, file, line, format); +} -inline void +template<typename ...Args> void __base_message(std::ostream &stream, const char *prefix, bool verbose, - const char *func, const char *file, int line, - const std::string &format, CPRINTF_DECLARATION) + const char *func, const char *file, int line, + const std::string &format, const Args &...args) { __base_message(stream, prefix, verbose, func, file, line, format.c_str(), - VARARGS_ALLARGS); + args...); } #define base_message(stream, prefix, verbose, ...) \ |