c12c2fe202247cd91bc4295e6d7d734f87891264
[gem5.git] / src / base / misc.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 * Dave Greene
30 */
31
32 #ifndef __MISC_HH__
33 #define __MISC_HH__
34
35 #include <assert.h>
36 #include "base/compiler.hh"
37 #include "base/cprintf.hh"
38
39 #if defined(__SUNPRO_CC)
40 #define __FUNCTION__ "how to fix me?"
41 #endif
42
43 //
44 // This implements a cprintf based panic() function. panic() should
45 // be called when something happens that should never ever happen
46 // regardless of what the user does (i.e., an acutal m5 bug). panic()
47 // calls abort which can dump core or enter the debugger.
48 //
49 //
50 void __panic(const std::string&, cp::ArgList &, const char*, const char*, int)
51 M5_ATTR_NORETURN;
52 #define __panic__(format, ...) \
53 __panic(format, (*(new cp::ArgList), __VA_ARGS__), \
54 __FUNCTION__ , __FILE__, __LINE__)
55 #define panic(...) \
56 __panic__(__VA_ARGS__, cp::ArgListNull())
57 M5_PRAGMA_NORETURN(__panic)
58
59 //
60 // This implements a cprintf based fatal() function. fatal() should
61 // be called when the simulation cannot continue due to some condition
62 // that is the user's fault (bad configuration, invalid arguments,
63 // etc.) and not a simulator bug. fatal() calls exit(1), i.e., a
64 // "normal" exit with an error code, as opposed to abort() like
65 // panic() does.
66 //
67 void __fatal(const std::string&, cp::ArgList &, const char*, const char*, int)
68 M5_ATTR_NORETURN;
69 #define __fatal__(format, ...) \
70 __fatal(format, (*(new cp::ArgList), __VA_ARGS__), \
71 __FUNCTION__ , __FILE__, __LINE__)
72 #define fatal(...) \
73 __fatal__(__VA_ARGS__, cp::ArgListNull())
74 M5_PRAGMA_NORETURN(__fatal)
75
76 //
77 // This implements a cprintf based warn
78 //
79 void __warn(const std::string&, cp::ArgList &, const char*, const char*, int);
80 #define __warn__(format, ...) \
81 __warn(format, (*(new cp::ArgList), __VA_ARGS__), \
82 __FUNCTION__ , __FILE__, __LINE__)
83 #define warn(...) \
84 __warn__(__VA_ARGS__, cp::ArgListNull())
85
86 // Only print the warning message the first time it is seen. This
87 // doesn't check the warning string itself, it just only lets one
88 // warning come from the statement. So, even if the arguments change
89 // and that would have resulted in a different warning message,
90 // subsequent messages would still be supressed.
91 #define warn_once(...) do { \
92 static bool once = false; \
93 if (!once) { \
94 __warn__(__VA_ARGS__, cp::ArgListNull()); \
95 once = true; \
96 } \
97 } while (0)
98
99 //
100 // assert() that prints out the current cycle
101 //
102 #define m5_assert(TEST) \
103 if (!(TEST)) { \
104 std::cerr << "Assertion failure, curTick = " << curTick << std::endl; \
105 } \
106 assert(TEST);
107
108 #endif // __MISC_HH__