Regression tests now run under scons!
[gem5.git] / 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
29 #ifndef __MISC_HH__
30 #define __MISC_HH__
31
32 #include <assert.h>
33 #include "base/cprintf.hh"
34
35 //
36 // This implements a cprintf based panic() function. panic() should
37 // be called when something happens that should never ever happen
38 // regardless of what the user does (i.e., an acutal m5 bug). panic()
39 // calls abort which can dump core or enter the debugger.
40 //
41 //
42 void __panic(const std::string&, cp::ArgList &, const char*, const char*, int)
43 __attribute__((noreturn));
44 #define __panic__(format, args...) \
45 __panic(format, (*(new cp::ArgList), args), \
46 __FUNCTION__, __FILE__, __LINE__)
47 #define panic(args...) \
48 __panic__(args, cp::ArgListNull())
49
50 //
51 // This implements a cprintf based fatal() function. fatal() should
52 // be called when the simulation cannot continue due to some condition
53 // that is the user's fault (bad configuration, invalid arguments,
54 // etc.) and not a simulator bug. fatal() calls exit(1), i.e., a
55 // "normal" exit with an error code, as opposed to abort() like
56 // panic() does.
57 //
58 void __fatal(const std::string&, cp::ArgList &, const char*, const char*, int)
59 __attribute__((noreturn));
60 #define __fatal__(format, args...) \
61 __fatal(format, (*(new cp::ArgList), args), \
62 __FUNCTION__, __FILE__, __LINE__)
63 #define fatal(args...) \
64 __fatal__(args, cp::ArgListNull())
65
66 //
67 // This implements a cprintf based warn
68 //
69 void __warn(const std::string&, cp::ArgList &, const char*, const char*, int);
70 #define __warn__(format, args...) \
71 __warn(format, (*(new cp::ArgList), args), \
72 __FUNCTION__, __FILE__, __LINE__)
73 #define warn(args...) \
74 __warn__(args, cp::ArgListNull())
75
76 //
77 // assert() that prints out the current cycle
78 //
79 #define m5_assert(TEST) \
80 if (!(TEST)) { \
81 std::cerr << "Assertion failure, curTick = " << curTick << std::endl; \
82 } \
83 assert(TEST);
84
85 #endif // __MISC_HH__