diff -r 86c5d97f11d6 -r fc78856486a9 src/base/misc.hh --- a/src/base/misc.hh Thu Feb 27 13:53:34 2014 +0000 +++ b/src/base/misc.hh Thu Feb 27 13:53:45 2014 +0000 @@ -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. * @@ -82,6 +94,36 @@ // #define fatal(...) exit_message("fatal", -1, __VA_ARGS__) +/** + * Conditional panic macro that checks the supplied condition and only panics + * if the condition is true and allows the programmer to specify diagnostic + * printout. Useful to replace if + panic, or if + print + assert, etc. + * + * @param cond Condition that is checked; if true -> panic + * @param ... Printf-based format string with arguments, extends printout. + */ +#define panic_if(cond, ...) \ + do { \ + if ((cond)) \ + exit_message("panic condition "#cond" occurred", -1, __VA_ARGS__); \ + } while (0) + + +/** + * Conditional fatal macro that checks the supplied condition and only causes a + * fatal error if the condition is true and allows the programmer to specify + * diagnostic printout. Useful to replace if + fatal, or if + print + assert, + * etc. + * + * @param cond Condition that is checked; if true -> fatal + * @param ... Printf-based format string with arguments, extends printout. + */ +#define fatal_if(cond, ...) \ + do { \ + if ((cond)) \ + exit_message("fatal condition "#cond" occurred", 1, __VA_ARGS__); \ + } while (0) + void __base_message(std::ostream &stream, const char *prefix, bool verbose, const char *func, const char *file, int line,