OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #elif defined(_WIN32) | 84 #elif defined(_WIN32) |
85 # define V8_OS_WIN 1 | 85 # define V8_OS_WIN 1 |
86 #endif | 86 #endif |
87 | 87 |
88 | 88 |
89 // ----------------------------------------------------------------------------- | 89 // ----------------------------------------------------------------------------- |
90 // Compiler detection | 90 // Compiler detection |
91 // | 91 // |
92 // V8_CC_CLANG - Clang | 92 // V8_CC_CLANG - Clang |
93 // V8_CC_GNU - GNU C++ | 93 // V8_CC_GNU - GNU C++ |
| 94 // V8_CC_INTEL - Intel C++ |
94 // V8_CC_MINGW - Minimalist GNU for Windows | 95 // V8_CC_MINGW - Minimalist GNU for Windows |
95 // V8_CC_MSVC - Microsoft Visual C/C++ | 96 // V8_CC_MSVC - Microsoft Visual C/C++ |
96 // | 97 // |
97 // C++11 feature detection | 98 // C++11 feature detection |
98 // | 99 // |
99 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported | 100 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported |
100 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported | 101 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported |
101 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported | 102 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported |
102 // V8_HAS_CXX11_DELETE - deleted functions supported | 103 // V8_HAS_CXX11_DELETE - deleted functions supported |
103 // V8_HAS_CXX11_FINAL - final marker supported | 104 // V8_HAS_CXX11_FINAL - final marker supported |
104 // V8_HAS_CXX11_OVERRIDE - override marker supported | 105 // V8_HAS_CXX11_OVERRIDE - override marker supported |
105 // | 106 // |
106 // Compiler-specific feature detection | 107 // Compiler-specific feature detection |
107 // | 108 // |
108 // V8_HAS___ALIGNOF - __alignof(type) operator supported | 109 // V8_HAS___ALIGNOF - __alignof(type) operator supported |
109 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported | 110 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported |
110 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported | 111 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported |
111 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) supported | 112 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) |
112 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported | 113 // supported |
113 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported | 114 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported |
114 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported | 115 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported |
115 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported | 116 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) |
116 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported | 117 // supported |
117 // V8_HAS___FINAL - __final supported in non-C++11 mode | 118 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported |
118 // V8_HAS___FORCEINLINE - __forceinline supported | 119 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported |
119 // V8_HAS_SEALED - MSVC style sealed marker supported | 120 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported |
| 121 // V8_HAS___FINAL - __final supported in non-C++11 mode |
| 122 // V8_HAS___FORCEINLINE - __forceinline supported |
| 123 // V8_HAS_SEALED - MSVC style sealed marker supported |
| 124 // |
| 125 // Note that testing for compilers and/or features must be done using #if |
| 126 // not #ifdef. For example, to test for Intel C++ Compiler, use: |
| 127 // #if V8_CC_INTEL |
| 128 // ... |
| 129 // #endif |
120 | 130 |
121 #if defined(__clang__) | 131 #if defined(__clang__) |
122 | 132 |
123 // Don't treat clang as GCC. | 133 // Don't treat clang as GCC. |
124 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 | 134 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
125 | 135 |
126 # define V8_CC_CLANG 1 | 136 # define V8_CC_CLANG 1 |
127 | 137 |
128 // Clang defines __alignof__ as alias for __alignof | 138 // Clang defines __alignof__ as alias for __alignof |
129 # define V8_HAS___ALIGNOF 1 | 139 # define V8_HAS___ALIGNOF 1 |
130 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF | 140 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF |
131 | 141 |
132 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) | 142 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) |
133 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) | 143 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) |
134 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) | 144 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) |
135 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) | 145 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) |
| 146 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 147 (__has_attribute(warn_unused_result)) |
136 | 148 |
137 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) | 149 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) |
138 | 150 |
139 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) | 151 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) |
140 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) | 152 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) |
141 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) | 153 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) |
142 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) | 154 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) |
143 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) | 155 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) |
144 | 156 |
145 #elif defined(__GNUC__) | 157 #elif defined(__GNUC__) |
146 | 158 |
147 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ | 159 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ |
148 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ | 160 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ |
149 ((major) * 10000 + (minor) * 100 + (patchlevel))) | 161 ((major) * 10000 + (minor) * 100 + (patchlevel))) |
150 | 162 |
151 # define V8_CC_GNU 1 | 163 # define V8_CC_GNU 1 |
152 # if defined(__MINGW32__) | 164 // Intel C++ also masquerades as GCC 3.2.0 |
153 # define V8_CC_MINGW 1 | 165 # define V8_CC_INTEL (defined(__INTEL_COMPILER)) |
154 # endif | 166 # define V8_CC_MINGW (defined(__MINGW32__)) |
155 | 167 |
156 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) | 168 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) |
157 | 169 |
158 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) | 170 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) |
159 // always_inline is available in gcc 4.0 but not very reliable until 4.4. | 171 // always_inline is available in gcc 4.0 but not very reliable until 4.4. |
160 // Works around "sorry, unimplemented: inlining failed" build errors with | 172 // Works around "sorry, unimplemented: inlining failed" build errors with |
161 // older compilers. | 173 // older compilers. |
162 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) | 174 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) |
163 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) | 175 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) |
164 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) | 176 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) |
| 177 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 178 (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0)) |
165 | 179 |
166 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) | 180 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) |
167 | 181 |
168 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality | 182 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality |
169 // without warnings (functionality used by the macros below). These modes | 183 // without warnings (functionality used by the macros below). These modes |
170 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, | 184 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, |
171 // more standardly, by checking whether __cplusplus has a C++11 or greater | 185 // more standardly, by checking whether __cplusplus has a C++11 or greater |
172 // value. Current versions of g++ do not correctly set __cplusplus, so we check | 186 // value. Current versions of g++ do not correctly set __cplusplus, so we check |
173 // both for forward compatibility. | 187 // both for forward compatibility. |
174 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L | 188 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // A macro to mark classes or functions as deprecated. | 235 // A macro to mark classes or functions as deprecated. |
222 #if !V8_DISABLE_DEPRECATIONS && V8_HAS_ATTRIBUTE_DEPRECATED | 236 #if !V8_DISABLE_DEPRECATIONS && V8_HAS_ATTRIBUTE_DEPRECATED |
223 # define V8_DEPRECATED(declarator) declarator __attribute__((deprecated)) | 237 # define V8_DEPRECATED(declarator) declarator __attribute__((deprecated)) |
224 #elif !V8_DISABLE_DEPRECATIONS && V8_HAS_DECLSPEC_DEPRECATED | 238 #elif !V8_DISABLE_DEPRECATIONS && V8_HAS_DECLSPEC_DEPRECATED |
225 # define V8_DEPRECATED(declarator) __declspec(deprecated) declarator | 239 # define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
226 #else | 240 #else |
227 # define V8_DEPRECATED(declarator) declarator | 241 # define V8_DEPRECATED(declarator) declarator |
228 #endif | 242 #endif |
229 | 243 |
230 | 244 |
| 245 // Annotate a function indicating the caller must examine the return value. |
| 246 // Use like: |
| 247 // int foo() V8_WARN_UNUSED_RESULT; |
| 248 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT |
| 249 # define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 250 #else |
| 251 # define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */ |
| 252 #endif |
| 253 |
| 254 |
231 // A macro to provide the compiler with branch prediction information. | 255 // A macro to provide the compiler with branch prediction information. |
232 #if V8_HAS_BUILTIN_EXPECT | 256 #if V8_HAS_BUILTIN_EXPECT |
233 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) | 257 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) |
234 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) | 258 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) |
235 #else | 259 #else |
236 # define V8_UNLIKELY(condition) (condition) | 260 # define V8_UNLIKELY(condition) (condition) |
237 # define V8_LIKELY(condition) (condition) | 261 # define V8_LIKELY(condition) (condition) |
238 #endif | 262 #endif |
239 | 263 |
240 | 264 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 # define V8_ALIGNOF(type) __alignof__(type) | 355 # define V8_ALIGNOF(type) __alignof__(type) |
332 #else | 356 #else |
333 // Note that alignment of a type within a struct can be less than the | 357 // Note that alignment of a type within a struct can be less than the |
334 // alignment of the type stand-alone (because of ancient ABIs), so this | 358 // alignment of the type stand-alone (because of ancient ABIs), so this |
335 // should only be used as a last resort. | 359 // should only be used as a last resort. |
336 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } | 360 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } |
337 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) | 361 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) |
338 #endif | 362 #endif |
339 | 363 |
340 #endif // V8CONFIG_H_ | 364 #endif // V8CONFIG_H_ |
OLD | NEW |