diff options
author | Nathan Binkert <nate@binkert.org> | 2008-10-10 10:18:28 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2008-10-10 10:18:28 -0700 |
commit | afb279b1bb8f7c01a74c4fe783ce14365916e920 (patch) | |
tree | bac1446af4bc5241c2d94e98e86346dff505b43b /src/base/misc.cc | |
parent | b25e56b32a3af5d11680b465f6443c73156ddf86 (diff) | |
download | gem5-afb279b1bb8f7c01a74c4fe783ce14365916e920.tar.xz |
output: Make panic/fatal/warn more flexible so we can add some new ones.
The major thrust of this change is to limit the amount of code
duplication surrounding the code for these functions. This code also
adds two new message types called info and hack. Info is meant to be
less harsh than warn so people don't get confused and start thinking
that the simulator is broken. Hack is a way for people to add runtime
messages indicating that the simulator just executed a code "hack"
that should probably be fixed. The benefit of knowing about these
code hacks is that it will let people know what sorts of inaccuracies
or potential bugs might be entering their experiments. Finally, I've
added some flags to turn on and off these message types so command
line options can change them.
Diffstat (limited to 'src/base/misc.cc')
-rw-r--r-- | src/base/misc.cc | 79 |
1 files changed, 31 insertions, 48 deletions
diff --git a/src/base/misc.cc b/src/base/misc.cc index 7d284a378..b0c769ac6 100644 --- a/src/base/misc.cc +++ b/src/base/misc.cc @@ -43,42 +43,24 @@ using namespace std; -void -__panic(const char *func, const char *file, int line, const char *fmt, - CPRINTF_DEFINITION) -{ - string format = "panic: "; - format += fmt; - switch (format[format.size() - 1]) { - case '\n': - case '\r': - break; - default: - format += "\n"; - } +bool want_warn = true; +bool want_info = true; +bool want_hack = true; - format += " @ cycle %d\n[%s:%s, line %d]\n"; - - CPrintfArgsList args(VARARGS_ALLARGS); - - args.push_back(curTick); - args.push_back(func); - args.push_back(file); - args.push_back(line); - - ccprintf(cerr, format.c_str(), args); - - abort(); -} +bool warn_verbose = false; +bool info_verbose = false; +bool hack_verbose = false; void -__fatal(const char *func, const char *file, int line, const char *fmt, - CPRINTF_DEFINITION) +__exit_message(const char *prefix, int code, + const char *func, const char *file, int line, + const char *fmt, CPRINTF_DEFINITION) { CPrintfArgsList args(VARARGS_ALLARGS); - string format = "fatal: "; - format += fmt; + string format = prefix; + format += ": "; + format += fmt; switch (format[format.size() - 1]) { case '\n': case '\r': @@ -98,16 +80,22 @@ __fatal(const char *func, const char *file, int line, const char *fmt, ccprintf(cerr, format.c_str(), args); - exit(1); + if (code < 0) + abort(); + else + exit(code); } void -__warn(const char *func, const char *file, int line, const char *fmt, - CPRINTF_DEFINITION) +__base_message(std::ostream &stream, const char *prefix, bool verbose, + const char *func, const char *file, int line, + const char *fmt, CPRINTF_DEFINITION) { - string format = "warn: "; - format += fmt; + CPrintfArgsList args(VARARGS_ALLARGS); + string format = prefix; + format += ": "; + format += fmt; switch (format[format.size() - 1]) { case '\n': case '\r': @@ -116,18 +104,13 @@ __warn(const char *func, const char *file, int line, const char *fmt, format += "\n"; } -#ifdef VERBOSE_WARN - format += " @ cycle %d\n[%s:%s, line %d]\n"; -#endif - - CPrintfArgsList args(VARARGS_ALLARGS); - -#ifdef VERBOSE_WARN - args.push_back(curTick); - args.push_back(func); - args.push_back(file); - args.push_back(line); -#endif + 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(cerr, format.c_str(), args); + ccprintf(stream, format.c_str(), args); } |