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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_MINGW - Minimalist GNU for Windows | 94 // V8_CC_MINGW - Minimalist GNU for Windows |
95 // V8_CC_MSVC - Microsoft Visual C/C++ | 95 // V8_CC_MSVC - Microsoft Visual C/C++ |
96 // | 96 // |
97 // C++11 feature detection | 97 // C++11 feature detection |
98 // | 98 // |
99 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported | 99 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported |
| 100 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported |
100 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported | 101 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported |
101 // V8_HAS_CXX11_DELETE - deleted functions supported | 102 // V8_HAS_CXX11_DELETE - deleted functions supported |
102 // V8_HAS_CXX11_FINAL - final marker supported | 103 // V8_HAS_CXX11_FINAL - final marker supported |
103 // V8_HAS_CXX11_OVERRIDE - override marker supported | 104 // V8_HAS_CXX11_OVERRIDE - override marker supported |
104 // | 105 // |
105 // Compiler-specific feature detection | 106 // Compiler-specific feature detection |
106 // | 107 // |
107 // V8_HAS_ATTRIBUTE___ALIGNED__ - __attribute__((__aligned__(n))) supported | 108 // V8_HAS___ALIGNOF - __alignof(type) operator supported |
| 109 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported |
| 110 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported |
108 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) supported | 111 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) supported |
109 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported | 112 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported |
110 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported | 113 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported |
111 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported | 114 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported |
112 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported | 115 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported |
113 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported | 116 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported |
114 // V8_HAS___FINAL - __final supported in non-C++11 mode | 117 // V8_HAS___FINAL - __final supported in non-C++11 mode |
115 // V8_HAS___FORCEINLINE - __forceinline supported | 118 // V8_HAS___FORCEINLINE - __forceinline supported |
116 // V8_HAS_SEALED - MSVC style sealed marker supported | 119 // V8_HAS_SEALED - MSVC style sealed marker supported |
117 | 120 |
118 #if defined(__clang__) | 121 #if defined(__clang__) |
119 | 122 |
120 // Don't treat clang as GCC. | 123 // Don't treat clang as GCC. |
121 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 | 124 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
122 | 125 |
123 # define V8_CC_CLANG 1 | 126 # define V8_CC_CLANG 1 |
124 | 127 |
125 # define V8_HAS_ATTRIBUTE___ALIGNED__ (__has_attribute(__aligned__)) | 128 // Clang defines __alignof__ as alias for __alignof |
| 129 # define V8_HAS___ALIGNOF 1 |
| 130 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF |
| 131 |
| 132 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) |
126 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) | 133 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) |
127 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) | 134 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) |
128 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) | 135 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) |
129 | 136 |
130 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) | 137 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) |
131 | 138 |
132 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) | 139 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) |
133 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) | 140 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) |
134 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) | 141 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) |
135 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) | 142 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) |
136 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) | 143 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) |
137 | 144 |
138 #elif defined(__GNUC__) | 145 #elif defined(__GNUC__) |
139 | 146 |
140 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ | 147 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ |
141 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ | 148 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ |
142 ((major) * 10000 + (minor) * 100 + (patchlevel))) | 149 ((major) * 10000 + (minor) * 100 + (patchlevel))) |
143 | 150 |
144 # define V8_CC_GNU 1 | 151 # define V8_CC_GNU 1 |
145 # if defined(__MINGW32__) | 152 # if defined(__MINGW32__) |
146 # define V8_CC_MINGW 1 | 153 # define V8_CC_MINGW 1 |
147 # endif | 154 # endif |
148 | 155 |
149 # define V8_HAS_ATTRIBUTE___ALIGNED__ (V8_GNUC_PREREQ(2, 95, 0)) | 156 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) |
| 157 |
| 158 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) |
150 // always_inline is available in gcc 4.0 but not very reliable until 4.4. | 159 // always_inline is available in gcc 4.0 but not very reliable until 4.4. |
151 // Works around "sorry, unimplemented: inlining failed" build errors with | 160 // Works around "sorry, unimplemented: inlining failed" build errors with |
152 // older compilers. | 161 // older compilers. |
153 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) | 162 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) |
154 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) | 163 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) |
155 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) | 164 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) |
156 | 165 |
157 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) | 166 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) |
158 | 167 |
159 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality | 168 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality |
160 // without warnings (functionality used by the macros below). These modes | 169 // without warnings (functionality used by the macros below). These modes |
161 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, | 170 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, |
162 // more standardly, by checking whether __cplusplus has a C++11 or greater | 171 // more standardly, by checking whether __cplusplus has a C++11 or greater |
163 // value. Current versions of g++ do not correctly set __cplusplus, so we check | 172 // value. Current versions of g++ do not correctly set __cplusplus, so we check |
164 // both for forward compatibility. | 173 // both for forward compatibility. |
165 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L | 174 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
166 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) | 175 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) |
| 176 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0)) |
167 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) | 177 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) |
168 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) | 178 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) |
169 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) | 179 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) |
170 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) | 180 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
171 # else | 181 # else |
172 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. | 182 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. |
173 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) | 183 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
174 # endif | 184 # endif |
175 | 185 |
176 #elif defined(_MSC_VER) | 186 #elif defined(_MSC_VER) |
177 | 187 |
178 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 | 188 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
179 | 189 |
180 # define V8_CC_MSVC 1 | 190 # define V8_CC_MSVC 1 |
181 | 191 |
| 192 # define V8_HAS___ALIGNOF 1 |
| 193 |
182 // Override control was added with Visual Studio 2005, but | 194 // Override control was added with Visual Studio 2005, but |
183 // Visual Studio 2010 and earlier spell "final" as "sealed". | 195 // Visual Studio 2010 and earlier spell "final" as "sealed". |
184 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700) | 196 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700) |
185 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400) | 197 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400) |
186 # define V8_HAS_SEALED (_MSC_VER >= 1400) | 198 # define V8_HAS_SEALED (_MSC_VER >= 1400) |
187 | 199 |
188 # define V8_HAS_DECLSPEC_ALIGN 1 | 200 # define V8_HAS_DECLSPEC_ALIGN 1 |
189 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300) | 201 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300) |
190 | 202 |
191 # define V8_HAS___FORCEINLINE 1 | 203 # define V8_HAS___FORCEINLINE 1 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 # define V8_FINAL __final | 280 # define V8_FINAL __final |
269 #elif V8_HAS_SEALED | 281 #elif V8_HAS_SEALED |
270 # define V8_FINAL sealed | 282 # define V8_FINAL sealed |
271 #else | 283 #else |
272 # define V8_FINAL /* NOT SUPPORTED */ | 284 # define V8_FINAL /* NOT SUPPORTED */ |
273 #endif | 285 #endif |
274 | 286 |
275 | 287 |
276 // This macro allows to specify memory alignment for structs, classes, etc. | 288 // This macro allows to specify memory alignment for structs, classes, etc. |
277 // Use like: | 289 // Use like: |
278 // class V8_ALIGNAS(16) MyClass { ... }; | 290 // class V8_ALIGNED(16) MyClass { ... }; |
279 // V8_ALIGNAS(32) int array[42]; | 291 // V8_ALIGNED(32) int array[42]; |
280 #if V8_HAS_CXX11_ALIGNAS | 292 #if V8_HAS_CXX11_ALIGNAS |
281 # define V8_ALIGNAS(n) alignas(n) | 293 # define V8_ALIGNED(n) alignas(n) |
282 #elif V8_HAS_ATTRIBUTE___ALIGNED__ | 294 #elif V8_HAS_ATTRIBUTE_ALIGNED |
283 # define V8_ALIGNAS(n) __attribute__((__aligned__(n))) | 295 # define V8_ALIGNED(n) __attribute__((aligned(n))) |
284 #elif V8_HAS_DECLSPEC_ALIGN | 296 #elif V8_HAS_DECLSPEC_ALIGN |
285 # define V8_ALIGNAS(n) __declspec(align(n)) | 297 # define V8_ALIGNED(n) __declspec(align(n)) |
286 #else | 298 #else |
287 # define V8_ALIGNAS(n) /* NOT SUPPORTED */ | 299 # define V8_ALIGNED(n) /* NOT SUPPORTED */ |
| 300 #endif |
| 301 |
| 302 |
| 303 // This macro is similar to V8_ALIGNED(), but takes a type instead of size |
| 304 // in bytes. If the compiler does not supports using the alignment of the |
| 305 // |type|, it will align according to the |alignment| instead. For example, |
| 306 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The |
| 307 // |alignment| must be a literal that is used as a kind of worst-case fallback |
| 308 // alignment. |
| 309 // Use like: |
| 310 // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... }; |
| 311 // V8_ALIGNAS(double, 8) int array[100]; |
| 312 #if V8_HAS_CXX11_ALIGNAS |
| 313 # define V8_ALIGNAS(type, alignment) alignas(type) |
| 314 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED |
| 315 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type)))) |
| 316 #else |
| 317 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment) |
| 318 #endif |
| 319 |
| 320 |
| 321 // This macro returns alignment in bytes (an integer power of two) required for |
| 322 // any instance of the given type, which is either complete type, an array type, |
| 323 // or a reference type. |
| 324 // Use like: |
| 325 // size_t alignment = V8_ALIGNOF(double); |
| 326 #if V8_HAS_CXX11_ALIGNOF |
| 327 # define V8_ALIGNOF(type) alignof(type) |
| 328 #elif V8_HAS___ALIGNOF |
| 329 # define V8_ALIGNOF(type) __alignof(type) |
| 330 #elif V8_HAS___ALIGNOF__ |
| 331 # define V8_ALIGNOF(type) __alignof__(type) |
| 332 #else |
| 333 // 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 |
| 335 // should only be used as a last resort. |
| 336 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } |
| 337 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) |
288 #endif | 338 #endif |
289 | 339 |
290 #endif // V8CONFIG_H_ | 340 #endif // V8CONFIG_H_ |
OLD | NEW |