diff options
author | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2014-08-26 10:13:45 -0400 |
---|---|---|
committer | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2014-08-26 10:13:45 -0400 |
commit | 70176fecd1ff04f7b8957f3110497d758310b569 (patch) | |
tree | ec2f32ee03a8a43a31bcfedd164b1ec3ee229532 /src/base/misc.hh | |
parent | f3e5fee74373d16849a58a80827c54c773aa05e2 (diff) | |
download | gem5-70176fecd1ff04f7b8957f3110497d758310b569.tar.xz |
base: Replace the internal varargs stuff with C++11 constructs
We currently use our own home-baked support for type-safe variadic
functions. This is confusing and somewhat limited (e.g., cprintf only
supports a limited number of arguments). This changeset converts all
uses of our internal varargs support to use C++11 variadic macros.
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, ...) \ |