initial import
[vuplus_webkit] / Source / JavaScriptCore / wtf / Compiler.h
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. 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  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef WTF_Compiler_h
27 #define WTF_Compiler_h
28
29 /* COMPILER() - the compiler being used to build the project */
30 #define COMPILER(WTF_FEATURE) (defined WTF_COMPILER_##WTF_FEATURE  && WTF_COMPILER_##WTF_FEATURE)
31
32 /* ==== COMPILER() - the compiler being used to build the project ==== */
33
34 /* COMPILER(CLANG) - Clang  */
35 #if defined(__clang__)
36 #define WTF_COMPILER_CLANG 1
37 #endif
38
39 /* COMPILER(MSVC) - Microsoft Visual C++ */
40 /* COMPILER(MSVC7_OR_LOWER) - Microsoft Visual C++ 2003 or lower*/
41 /* COMPILER(MSVC9_OR_LOWER) - Microsoft Visual C++ 2008 or lower*/
42 #if defined(_MSC_VER)
43 #define WTF_COMPILER_MSVC 1
44 #if _MSC_VER < 1400
45 #define WTF_COMPILER_MSVC7_OR_LOWER 1
46 #elif _MSC_VER < 1600
47 #define WTF_COMPILER_MSVC9_OR_LOWER 1
48 #endif
49 #endif
50
51 /* COMPILER(RVCT) - ARM RealView Compilation Tools */
52 /* COMPILER(RVCT4_OR_GREATER) - ARM RealView Compilation Tools 4.0 or greater */
53 #if defined(__CC_ARM) || defined(__ARMCC__)
54 #define WTF_COMPILER_RVCT 1
55 #define RVCT_VERSION_AT_LEAST(major, minor, patch, build) (__ARMCC_VERSION >= (major * 100000 + minor * 10000 + patch * 1000 + build))
56 #else
57 /* Define this for !RVCT compilers, just so we can write things like RVCT_VERSION_AT_LEAST(3, 0, 0, 0). */
58 #define RVCT_VERSION_AT_LEAST(major, minor, patch, build) 0
59 #endif
60
61 /* COMPILER(GCCE) - GNU Compiler Collection for Embedded */
62 #if defined(__GCCE__)
63 #define WTF_COMPILER_GCCE 1
64 #define GCCE_VERSION (__GCCE__ * 10000 + __GCCE_MINOR__ * 100 + __GCCE_PATCHLEVEL__)
65 #define GCCE_VERSION_AT_LEAST(major, minor, patch) (GCCE_VERSION >= (major * 10000 + minor * 100 + patch))
66 #endif
67
68 /* COMPILER(GCC) - GNU Compiler Collection */
69 /* --gnu option of the RVCT compiler also defines __GNUC__ */
70 #if defined(__GNUC__) && !COMPILER(RVCT)
71 #define WTF_COMPILER_GCC 1
72 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
73 #define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
74 #else
75 /* Define this for !GCC compilers, just so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
76 #define GCC_VERSION_AT_LEAST(major, minor, patch) 0
77 #endif
78
79 /* COMPILER(MINGW) - MinGW GCC */
80 /* COMPILER(MINGW64) - mingw-w64 GCC - only used as additional check to exclude mingw.org specific functions */
81 #if defined(__MINGW32__)
82 #define WTF_COMPILER_MINGW 1
83 #include <_mingw.h> /* private MinGW header */
84     #if defined(__MINGW64_VERSION_MAJOR) /* best way to check for mingw-w64 vs mingw.org */
85         #define WTF_COMPILER_MINGW64 1
86     #endif /* __MINGW64_VERSION_MAJOR */
87 #endif /* __MINGW32__ */
88
89 /* COMPILER(WINSCW) - CodeWarrior for Symbian emulator */
90 #if defined(__WINSCW__)
91 #define WTF_COMPILER_WINSCW 1
92 /* cross-compiling, it is not really windows */
93 #undef WIN32
94 #undef _WIN32
95 #endif
96
97 /* COMPILER(INTEL) - Intel C++ Compiler */
98 #if defined(__INTEL_COMPILER)
99 #define WTF_COMPILER_INTEL 1
100 #endif
101
102 /* COMPILER(SUNCC) */
103 #if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
104 #define WTF_COMPILER_SUNCC 1
105 #endif
106
107
108 /* ==== Compiler features ==== */
109
110
111 /* ALWAYS_INLINE */
112
113 #ifndef ALWAYS_INLINE
114 #if COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
115 #define ALWAYS_INLINE inline __attribute__((__always_inline__))
116 #elif (COMPILER(MSVC) || COMPILER(RVCT)) && defined(NDEBUG)
117 #define ALWAYS_INLINE __forceinline
118 #else
119 #define ALWAYS_INLINE inline
120 #endif
121 #endif
122
123
124 /* NEVER_INLINE */
125
126 #ifndef NEVER_INLINE
127 #if COMPILER(GCC)
128 #define NEVER_INLINE __attribute__((__noinline__))
129 #elif COMPILER(RVCT)
130 #define NEVER_INLINE __declspec(noinline)
131 #else
132 #define NEVER_INLINE
133 #endif
134 #endif
135
136
137 /* UNLIKELY */
138
139 #ifndef UNLIKELY
140 #if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
141 #define UNLIKELY(x) __builtin_expect((x), 0)
142 #else
143 #define UNLIKELY(x) (x)
144 #endif
145 #endif
146
147
148 /* LIKELY */
149
150 #ifndef LIKELY
151 #if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
152 #define LIKELY(x) __builtin_expect((x), 1)
153 #else
154 #define LIKELY(x) (x)
155 #endif
156 #endif
157
158
159 /* NO_RETURN */
160
161
162 #ifndef NO_RETURN
163 #if COMPILER(GCC)
164 #define NO_RETURN __attribute((__noreturn__))
165 #elif COMPILER(MSVC) || COMPILER(RVCT)
166 #define NO_RETURN __declspec(noreturn)
167 #else
168 #define NO_RETURN
169 #endif
170 #endif
171
172
173 /* NO_RETURN_WITH_VALUE */
174
175 #ifndef NO_RETURN_WITH_VALUE
176 #if !COMPILER(MSVC)
177 #define NO_RETURN_WITH_VALUE NO_RETURN
178 #else
179 #define NO_RETURN_WITH_VALUE
180 #endif
181 #endif
182
183
184 /* WARN_UNUSED_RETURN */
185
186 #if COMPILER(GCC)
187 #define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
188 #else
189 #define WARN_UNUSED_RETURN
190 #endif
191
192
193 #endif /* WTF_Compiler_h */