fix various warnings reported by cparser
[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 /**
31  * Asserts that the constant expression x is not zero at compiletime. name has
32  * to be a unique identifier.
33  *
34  * @note This uses the fact, that double case labels are not allowed.
35  */
36 #define COMPILETIME_ASSERT(x, name) \
37     static __attribute__((unused)) void compiletime_assert_##name (int h) { \
38         switch(h) { case 0: case (x): {} } \
39     }
40
41 #ifdef __GNUC__
42 /**
43  * Indicates to the compiler that the value of x is very likely 1
44  * @note Only use this in speed critical code and when you are sure x is often 1
45  */
46 #define LIKELY(x)   __builtin_expect((x), 1)
47
48 /**
49  * Indicates to the compiler that it's very likely that x is 0
50  * @note Only use this in speed critical code and when you are sure x is often 0
51  */
52 #define UNLIKELY(x) __builtin_expect((x), 0)
53
54 /**
55  * Tell the compiler, that a function is pure, i.e. it only
56  * uses its parameters and never modifies the "state".
57  * Add this macro after the return type.
58  */
59 #define PURE        __attribute__((const))
60
61 #else
62 #define LIKELY(x)   x
63 #define UNLIKELY(x) x
64 #define PURE
65 #endif
66
67 #endif