changeset 933dfb9d8279 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=933dfb9d8279
description:
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:
src/arch/generic/debugfaults.hh | 5 +-
src/arch/x86/bios/intelmp.cc | 2 +-
src/base/cprintf.hh | 76 ++++-----
src/base/misc.cc | 80 ++++-----
src/base/misc.hh | 67 ++++++--
src/base/trace.cc | 55 +-----
src/base/trace.hh | 28 +++-
src/base/varargs.hh | 308 ----------------------------------------
8 files changed, 167 insertions(+), 454 deletions(-)
diffs (truncated from 840 to 300 lines):
diff -r 56772eb01583 -r 933dfb9d8279 src/arch/generic/debugfaults.hh
--- a/src/arch/generic/debugfaults.hh Tue Aug 26 10:13:33 2014 -0400
+++ b/src/arch/generic/debugfaults.hh Tue Aug 26 10:13:45 2014 -0400
@@ -112,8 +112,9 @@
class M5VarArgsFault : public M5DebugFault
{
public:
- M5VarArgsFault(const std::string &format, CPRINTF_DECLARATION) :
- M5DebugFault((DebugFunc)Func, csprintf(format, VARARGS_ALLARGS))
+ template<typename ...Args>
+ M5VarArgsFault(const std::string &format, const Args &...args) :
+ M5DebugFault((DebugFunc)Func, csprintf(format, args...))
{}
};
diff -r 56772eb01583 -r 933dfb9d8279 src/arch/x86/bios/intelmp.cc
--- a/src/arch/x86/bios/intelmp.cc Tue Aug 26 10:13:33 2014 -0400
+++ b/src/arch/x86/bios/intelmp.cc Tue Aug 26 10:13:45 2014 -0400
@@ -92,7 +92,7 @@
if (str.length() > length) {
memcpy(cleanedString, str.c_str(), length);
warn("Intel MP configuration table string \"%s\" "
- "will be truncated to \"%s\".\n", str, cleanedString);
+ "will be truncated to \"%s\".\n", str, (char *)&cleanedString);
} else {
memcpy(cleanedString, str.c_str(), str.length());
memset(cleanedString + str.length(), 0, length - str.length());
diff -r 56772eb01583 -r 933dfb9d8279 src/base/cprintf.hh
--- a/src/base/cprintf.hh Tue Aug 26 10:13:33 2014 -0400
+++ b/src/base/cprintf.hh Tue Aug 26 10:13:45 2014 -0400
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2014 ARM Limited
* Copyright (c) 2002-2006 The Regents of The University of Michigan
* All rights reserved.
*
@@ -27,6 +28,7 @@
*
* Authors: Nathan Binkert
* Steve Reinhardt
+ * Andreas Sandberg
*/
#ifndef __BASE_CPRINTF_HH__
@@ -38,13 +40,9 @@
#include <string>
#include "base/cprintf_formats.hh"
-#include "base/varargs.hh"
namespace cp {
-#define CPRINTF_DECLARATION VARARGS_DECLARATION(cp::Print)
-#define CPRINTF_DEFINITION VARARGS_DEFINITION(cp::Print)
-
struct Print
{
protected:
@@ -128,33 +126,42 @@
} // namespace cp
-typedef VarArgs::List<cp::Print> CPrintfArgsList;
+inline void
+ccprintf(cp::Print &print)
+{
+ print.end_args();
+}
-inline void
-ccprintf(std::ostream &stream, const char *format, const CPrintfArgsList &args)
+
+template<typename T, typename ...Args> void
+ccprintf(cp::Print &print, const T &value, const Args &...args)
+{
+ print.add_arg(value);
+
+ ccprintf(print, args...);
+}
+
+
+template<typename ...Args> void
+ccprintf(std::ostream &stream, const char *format, const Args &...args)
{
cp::Print print(stream, format);
- args.add_args(print);
+
+ ccprintf(print, args...);
}
-inline void
-ccprintf(std::ostream &stream, const char *format, CPRINTF_DECLARATION)
+
+template<typename ...Args> void
+cprintf(const char *format, const Args &...args)
{
- cp::Print print(stream, format);
- VARARGS_ADDARGS(print);
+ ccprintf(std::cout, format, args...);
}
-inline void
-cprintf(const char *format, CPRINTF_DECLARATION)
-{
- ccprintf(std::cout, format, VARARGS_ALLARGS);
-}
-
-inline std::string
-csprintf(const char *format, CPRINTF_DECLARATION)
+template<typename ...Args> std::string
+csprintf(const char *format, const Args &...args)
{
std::stringstream stream;
- ccprintf(stream, format, VARARGS_ALLARGS);
+ ccprintf(stream, format, args...);
return stream.str();
}
@@ -163,31 +170,22 @@
* time converting const char * to std::string since we don't take
* advantage of it.
*/
-inline void
-ccprintf(std::ostream &stream, const std::string &format,
- const CPrintfArgsList &args)
+template<typename ...Args> void
+ccprintf(std::ostream &stream, const std::string &format, const Args &...args)
{
- ccprintf(stream, format.c_str(), args);
+ ccprintf(stream, format.c_str(), args...);
}
-inline void
-ccprintf(std::ostream &stream, const std::string &format, CPRINTF_DECLARATION)
+template<typename ...Args> void
+cprintf(const std::string &format, const Args &...args)
{
- ccprintf(stream, format.c_str(), VARARGS_ALLARGS);
+ ccprintf(std::cout, format.c_str(), args...);
}
-inline void
-cprintf(const std::string &format, CPRINTF_DECLARATION)
+template<typename ...Args> std::string
+csprintf(const std::string &format, const Args &...args)
{
- ccprintf(std::cout, format.c_str(), VARARGS_ALLARGS);
-}
-
-inline std::string
-csprintf(const std::string &format, CPRINTF_DECLARATION)
-{
- std::stringstream stream;
- ccprintf(stream, format.c_str(), VARARGS_ALLARGS);
- return stream.str();
+ return csprintf(format.c_str(), args...);
}
#endif // __CPRINTF_HH__
diff -r 56772eb01583 -r 933dfb9d8279 src/base/misc.cc
--- a/src/base/misc.cc Tue Aug 26 10:13:33 2014 -0400
+++ b/src/base/misc.cc Tue Aug 26 10:13:45 2014 -0400
@@ -1,4 +1,16 @@
/*
+ * Copyright (c) 2014 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* All rights reserved.
*
@@ -26,10 +38,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
+ * Andreas Sandberg
*/
#include <cstdlib>
-#include <iostream>
+#include <cstring>
#include <string>
#include "base/cprintf.hh"
@@ -38,7 +51,6 @@
#include "base/output.hh"
#include "base/trace.hh"
#include "base/types.hh"
-#include "base/varargs.hh"
#include "sim/core.hh"
using namespace std;
@@ -51,34 +63,32 @@
bool info_verbose = false;
bool hack_verbose = false;
-void
-__exit_message(const char *prefix, int code,
- const char *func, const char *file, int line,
- const char *fmt, CPRINTF_DEFINITION)
+static void
+newline_if_needed(std::ostream &stream, const char *format)
{
- CPrintfArgsList args(VARARGS_ALLARGS);
+ const size_t format_len(strlen(format));
- string format = prefix;
- format += ": ";
- format += fmt;
- switch (format[format.size() - 1]) {
+ switch (format_len ? format[format_len - 1] : '\0') {
case '\n':
case '\r':
break;
default:
- format += "\n";
+ stream << std::endl;
}
+}
- format += " @ tick %d\n[%s:%s, line %d]\n";
- format += "Memory Usage: %ld KBytes\n";
+void
+__exit_epilogue(int code,
+ const char *func, const char *file, int line,
+ const char *format)
+{
+ newline_if_needed(std::cerr, format);
- args.push_back(curTick());
- args.push_back(func);
- args.push_back(file);
- args.push_back(line);
- args.push_back(memUsage());
-
- ccprintf(cerr, format.c_str(), args);
+ ccprintf(std::cerr,
+ " @ tick %d\n"
+ "[%s:%s, line %d]\n"
+ "Memory Usage: %ld KBytes\n",
+ curTick(), func, file, line, memUsage());
if (code < 0)
abort();
@@ -87,30 +97,14 @@
}
void
-__base_message(std::ostream &stream, const char *prefix, bool verbose,
- const char *func, const char *file, int line,
- const char *fmt, CPRINTF_DEFINITION)
+__base_message_epilogue(std::ostream &stream, bool verbose,
+ const char *func, const char *file, int line,
+ const char *format)
{
- CPrintfArgsList args(VARARGS_ALLARGS);
-
- string format = prefix;
- format += ": ";
- format += fmt;
- switch (format[format.size() - 1]) {
- case '\n':
- case '\r':
- break;
- default:
- format += "\n";
- }
+ newline_if_needed(stream, format);
if (verbose) {
- format += " @ cycle %d\n[%s:%s, line %d]\n";
- args.push_back(curTick());
- args.push_back(func);
- args.push_back(file);
- args.push_back(line);
+ ccprintf(stream, " @ cycle %d\n[%s:%s, line %d]\n",
+ curTick(), func, file, line);
}
-
- ccprintf(stream, format.c_str(), args);
}
diff -r 56772eb01583 -r 933dfb9d8279 src/base/misc.hh
--- a/src/base/misc.hh Tue Aug 26 10:13:33 2014 -0400
+++ b/src/base/misc.hh Tue Aug 26 10:13:45 2014 -0400
@@ -39,40 +39,58 @@
*
* Authors: Nathan Binkert
* Dave Greene
+ * Andreas Sandberg
*/
#ifndef __BASE_MISC_HH__
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev