2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WTF_Compiler_h
27 #define WTF_Compiler_h
29 /* COMPILER() - the compiler being used to build the project */
30 #define COMPILER(WTF_FEATURE) (defined WTF_COMPILER_##WTF_FEATURE && WTF_COMPILER_##WTF_FEATURE)
32 /* ==== COMPILER() - the compiler being used to build the project ==== */
34 /* COMPILER(CLANG) - Clang */
35 #if defined(__clang__)
36 #define WTF_COMPILER_CLANG 1
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*/
43 #define WTF_COMPILER_MSVC 1
45 #define WTF_COMPILER_MSVC7_OR_LOWER 1
47 #define WTF_COMPILER_MSVC9_OR_LOWER 1
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))
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
61 /* COMPILER(GCCE) - GNU Compiler Collection for Embedded */
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))
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))
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
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__ */
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 */
97 /* COMPILER(INTEL) - Intel C++ Compiler */
98 #if defined(__INTEL_COMPILER)
99 #define WTF_COMPILER_INTEL 1
102 /* COMPILER(SUNCC) */
103 #if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
104 #define WTF_COMPILER_SUNCC 1
108 /* ==== Compiler features ==== */
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
119 #define ALWAYS_INLINE inline
128 #define NEVER_INLINE __attribute__((__noinline__))
130 #define NEVER_INLINE __declspec(noinline)
140 #if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
141 #define UNLIKELY(x) __builtin_expect((x), 0)
143 #define UNLIKELY(x) (x)
151 #if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
152 #define LIKELY(x) __builtin_expect((x), 1)
154 #define LIKELY(x) (x)
164 #define NO_RETURN __attribute((__noreturn__))
165 #elif COMPILER(MSVC) || COMPILER(RVCT)
166 #define NO_RETURN __declspec(noreturn)
173 /* NO_RETURN_WITH_VALUE */
175 #ifndef NO_RETURN_WITH_VALUE
177 #define NO_RETURN_WITH_VALUE NO_RETURN
179 #define NO_RETURN_WITH_VALUE
184 /* WARN_UNUSED_RETURN */
187 #define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
189 #define WARN_UNUSED_RETURN
193 #endif /* WTF_Compiler_h */