verify: Clarify assertion message.
[libfirm] / ir / adt / compiler.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @date   04.06.2007
23  * @author Matthias Braun, Sebastian Hack
24  * @brief  Macros to instruct the compiler compiling libFirm.
25  */
26
27 #ifndef FIRM_COMPILER_H
28 #define FIRM_COMPILER_H
29
30 #ifdef __GNUC__
31 /**
32  * Indicates to the compiler that the value of x is very likely 1
33  * @note Only use this in speed critical code and when you are sure x is often 1
34  */
35 #define LIKELY(x)   __builtin_expect((x), 1)
36
37 /**
38  * Indicates to the compiler that it's very likely that x is 0
39  * @note Only use this in speed critical code and when you are sure x is often 0
40  */
41 #define UNLIKELY(x) __builtin_expect((x), 0)
42
43 /**
44  * Tell the compiler, that a function is pure, i.e. it only
45  * uses its parameters and never modifies the "state".
46  * Add this macro after the return type.
47  */
48 #define PURE        __attribute__((const))
49
50 /**
51  * Tell the compiler, that a function is unused, no warning needed.
52  */
53 #define UNUSED      __attribute__((unused))
54
55 #else
56 #define LIKELY(x)   x
57 #define UNLIKELY(x) x
58 #define PURE
59 #define UNUSED
60 #endif
61
62 /**
63  * Asserts that the constant expression x is not zero at compiletime. name has
64  * to be a unique identifier.
65  *
66  * @note This uses the fact, that double case labels are not allowed.
67  */
68 #define COMPILETIME_ASSERT(x, name) \
69     static UNUSED void compiletime_assert_##name (int h) { \
70         switch(h) { case 0: case (x): {} } \
71     }
72
73 #endif