Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8CONFIG_H_ |
| 6 | #define V8CONFIG_H_ |
| 7 | |
| 8 | // Platform headers for feature detection below. |
| 9 | #if defined(__ANDROID__) |
| 10 | # include <sys/cdefs.h> |
| 11 | #elif defined(__APPLE__) |
| 12 | # include <TargetConditionals.h> |
| 13 | #elif defined(__linux__) |
| 14 | # include <features.h> |
| 15 | #endif |
| 16 | |
| 17 | |
| 18 | // This macro allows to test for the version of the GNU C library (or |
| 19 | // a compatible C library that masquerades as glibc). It evaluates to |
| 20 | // 0 if libc is not GNU libc or compatible. |
| 21 | // Use like: |
| 22 | // #if V8_GLIBC_PREREQ(2, 3) |
| 23 | // ... |
| 24 | // #endif |
| 25 | #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) |
| 26 | # define V8_GLIBC_PREREQ(major, minor) \ |
| 27 | ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor))) |
| 28 | #else |
| 29 | # define V8_GLIBC_PREREQ(major, minor) 0 |
| 30 | #endif |
| 31 | |
| 32 | |
| 33 | // This macro allows to test for the version of the GNU C++ compiler. |
| 34 | // Note that this also applies to compilers that masquerade as GCC, |
| 35 | // for example clang and the Intel C++ compiler for Linux. |
| 36 | // Use like: |
| 37 | // #if V8_GNUC_PREREQ(4, 3, 1) |
| 38 | // ... |
| 39 | // #endif |
| 40 | #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) |
| 41 | # define V8_GNUC_PREREQ(major, minor, patchlevel) \ |
| 42 | ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ |
| 43 | ((major) * 10000 + (minor) * 100 + (patchlevel))) |
| 44 | #elif defined(__GNUC__) && defined(__GNUC_MINOR__) |
| 45 | # define V8_GNUC_PREREQ(major, minor, patchlevel) \ |
| 46 | ((__GNUC__ * 10000 + __GNUC_MINOR__) >= \ |
| 47 | ((major) * 10000 + (minor) * 100 + (patchlevel))) |
| 48 | #else |
| 49 | # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
| 50 | #endif |
| 51 | |
| 52 | |
| 53 | |
| 54 | // ----------------------------------------------------------------------------- |
| 55 | // Operating system detection |
| 56 | // |
| 57 | // V8_OS_ANDROID - Android |
| 58 | // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD) |
| 59 | // V8_OS_CYGWIN - Cygwin |
| 60 | // V8_OS_DRAGONFLYBSD - DragonFlyBSD |
| 61 | // V8_OS_FREEBSD - FreeBSD |
| 62 | // V8_OS_LINUX - Linux |
| 63 | // V8_OS_MACOSX - Mac OS X |
| 64 | // V8_OS_NACL - Native Client |
| 65 | // V8_OS_NETBSD - NetBSD |
| 66 | // V8_OS_OPENBSD - OpenBSD |
| 67 | // V8_OS_POSIX - POSIX compatible (mostly everything except Windows) |
| 68 | // V8_OS_QNX - QNX Neutrino |
| 69 | // V8_OS_SOLARIS - Sun Solaris and OpenSolaris |
| 70 | // V8_OS_WIN - Microsoft Windows |
| 71 | |
| 72 | #if defined(__ANDROID__) |
| 73 | # define V8_OS_ANDROID 1 |
| 74 | # define V8_OS_LINUX 1 |
| 75 | # define V8_OS_POSIX 1 |
| 76 | #elif defined(__APPLE__) |
| 77 | # define V8_OS_BSD 1 |
| 78 | # define V8_OS_MACOSX 1 |
| 79 | # define V8_OS_POSIX 1 |
| 80 | #elif defined(__native_client__) |
| 81 | # define V8_OS_NACL 1 |
| 82 | # define V8_OS_POSIX 1 |
| 83 | #elif defined(__CYGWIN__) |
| 84 | # define V8_OS_CYGWIN 1 |
| 85 | # define V8_OS_POSIX 1 |
| 86 | #elif defined(__linux__) |
| 87 | # define V8_OS_LINUX 1 |
| 88 | # define V8_OS_POSIX 1 |
| 89 | #elif defined(__sun) |
| 90 | # define V8_OS_POSIX 1 |
| 91 | # define V8_OS_SOLARIS 1 |
| 92 | #elif defined(__FreeBSD__) |
| 93 | # define V8_OS_BSD 1 |
| 94 | # define V8_OS_FREEBSD 1 |
| 95 | # define V8_OS_POSIX 1 |
| 96 | #elif defined(__DragonFly__) |
| 97 | # define V8_OS_BSD 1 |
| 98 | # define V8_OS_DRAGONFLYBSD 1 |
| 99 | # define V8_OS_POSIX 1 |
| 100 | #elif defined(__NetBSD__) |
| 101 | # define V8_OS_BSD 1 |
| 102 | # define V8_OS_NETBSD 1 |
| 103 | # define V8_OS_POSIX 1 |
| 104 | #elif defined(__OpenBSD__) |
| 105 | # define V8_OS_BSD 1 |
| 106 | # define V8_OS_OPENBSD 1 |
| 107 | # define V8_OS_POSIX 1 |
| 108 | #elif defined(__QNXNTO__) |
| 109 | # define V8_OS_POSIX 1 |
| 110 | # define V8_OS_QNX 1 |
| 111 | #elif defined(_WIN32) |
| 112 | # define V8_OS_WIN 1 |
| 113 | #endif |
| 114 | |
| 115 | |
| 116 | // ----------------------------------------------------------------------------- |
| 117 | // C library detection |
| 118 | // |
| 119 | // V8_LIBC_MSVCRT - MSVC libc |
| 120 | // V8_LIBC_BIONIC - Bionic libc |
| 121 | // V8_LIBC_BSD - BSD libc derivate |
| 122 | // V8_LIBC_GLIBC - GNU C library |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 123 | // |
| 124 | // Note that testing for libc must be done using #if not #ifdef. For example, |
| 125 | // to test for the GNU C library, use: |
| 126 | // #if V8_LIBC_GLIBC |
| 127 | // ... |
| 128 | // #endif |
| 129 | |
| 130 | #if defined (_MSC_VER) |
| 131 | # define V8_LIBC_MSVCRT 1 |
| 132 | #elif defined(__BIONIC__) |
| 133 | # define V8_LIBC_BIONIC 1 |
| 134 | # define V8_LIBC_BSD 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 135 | #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__) |
| 136 | # define V8_LIBC_GLIBC 1 |
| 137 | #else |
| 138 | # define V8_LIBC_BSD V8_OS_BSD |
| 139 | #endif |
| 140 | |
| 141 | |
| 142 | // ----------------------------------------------------------------------------- |
| 143 | // Compiler detection |
| 144 | // |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 145 | // V8_CC_GNU - GCC, or clang in gcc mode |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | // V8_CC_INTEL - Intel C++ |
| 147 | // V8_CC_MINGW - Minimalist GNU for Windows |
| 148 | // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32) |
| 149 | // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 150 | // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | // |
| 152 | // C++11 feature detection |
| 153 | // |
| 154 | // V8_HAS_CXX11_ALIGNAS - alignas specifier supported |
| 155 | // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported |
| 156 | // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported |
| 157 | // V8_HAS_CXX11_DELETE - deleted functions supported |
| 158 | // V8_HAS_CXX11_FINAL - final marker supported |
| 159 | // V8_HAS_CXX11_OVERRIDE - override marker supported |
| 160 | // |
| 161 | // Compiler-specific feature detection |
| 162 | // |
| 163 | // V8_HAS___ALIGNOF - __alignof(type) operator supported |
| 164 | // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported |
| 165 | // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported |
| 166 | // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) |
| 167 | // supported |
| 168 | // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported |
| 169 | // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported |
| 170 | // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported |
| 171 | // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported |
| 172 | // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) |
| 173 | // supported |
| 174 | // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported |
| 175 | // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported |
| 176 | // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 177 | // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 178 | // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported |
| 179 | // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported |
| 180 | // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported |
| 181 | // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported |
| 182 | // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported |
| 183 | // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported |
| 184 | // V8_HAS___FINAL - __final supported in non-C++11 mode |
| 185 | // V8_HAS___FORCEINLINE - __forceinline supported |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | // |
| 187 | // Note that testing for compilers and/or features must be done using #if |
| 188 | // not #ifdef. For example, to test for Intel C++ Compiler, use: |
| 189 | // #if V8_CC_INTEL |
| 190 | // ... |
| 191 | // #endif |
| 192 | |
| 193 | #if defined(__clang__) |
| 194 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 195 | #if defined(__GNUC__) // Clang in gcc mode. |
| 196 | # define V8_CC_GNU 1 |
| 197 | #elif defined(_MSC_VER) // Clang in cl mode. |
| 198 | # define V8_CC_MSVC 1 |
| 199 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | |
| 201 | // Clang defines __alignof__ as alias for __alignof |
| 202 | # define V8_HAS___ALIGNOF 1 |
| 203 | # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF |
| 204 | |
| 205 | # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) |
| 206 | # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) |
| 207 | # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) |
| 208 | # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) |
| 209 | # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused)) |
| 210 | # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) |
| 211 | # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 212 | (__has_attribute(warn_unused_result)) |
| 213 | |
| 214 | # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz)) |
| 215 | # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz)) |
| 216 | # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 217 | # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address)) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount)) |
| 219 | # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow)) |
| 220 | # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow)) |
| 221 | |
| 222 | # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) |
| 223 | # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) |
| 224 | # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) |
| 225 | # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) |
| 226 | # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) |
| 227 | |
| 228 | #elif defined(__GNUC__) |
| 229 | |
| 230 | # define V8_CC_GNU 1 |
| 231 | // Intel C++ also masquerades as GCC 3.2.0 |
| 232 | # define V8_CC_INTEL (defined(__INTEL_COMPILER)) |
| 233 | # define V8_CC_MINGW32 (defined(__MINGW32__)) |
| 234 | # define V8_CC_MINGW64 (defined(__MINGW64__)) |
| 235 | # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64) |
| 236 | |
| 237 | # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) |
| 238 | |
| 239 | # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) |
| 240 | // always_inline is available in gcc 4.0 but not very reliable until 4.4. |
| 241 | // Works around "sorry, unimplemented: inlining failed" build errors with |
| 242 | // older compilers. |
| 243 | # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) |
| 244 | # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) |
| 245 | # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0)) |
| 246 | # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0)) |
| 247 | # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0)) |
| 248 | # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) |
| 249 | # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 250 | (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0)) |
| 251 | |
| 252 | # define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0)) |
| 253 | # define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0)) |
| 254 | # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 255 | # define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0)) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 256 | # define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0)) |
| 257 | |
| 258 | // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality |
| 259 | // without warnings (functionality used by the macros below). These modes |
| 260 | // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, |
| 261 | // more standardly, by checking whether __cplusplus has a C++11 or greater |
| 262 | // value. Current versions of g++ do not correctly set __cplusplus, so we check |
| 263 | // both for forward compatibility. |
| 264 | # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
| 265 | # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) |
| 266 | # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0)) |
| 267 | # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) |
| 268 | # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) |
| 269 | # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) |
| 270 | # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
| 271 | # else |
| 272 | // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. |
| 273 | # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
| 274 | # endif |
| 275 | |
| 276 | #elif defined(_MSC_VER) |
| 277 | |
| 278 | # define V8_CC_MSVC 1 |
| 279 | |
| 280 | # define V8_HAS___ALIGNOF 1 |
| 281 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 282 | # define V8_HAS_CXX11_FINAL 1 |
| 283 | # define V8_HAS_CXX11_OVERRIDE 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | |
| 285 | # define V8_HAS_DECLSPEC_ALIGN 1 |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 286 | # define V8_HAS_DECLSPEC_DEPRECATED 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 287 | # define V8_HAS_DECLSPEC_NOINLINE 1 |
| 288 | |
| 289 | # define V8_HAS___FORCEINLINE 1 |
| 290 | |
| 291 | #endif |
| 292 | |
| 293 | |
| 294 | // ----------------------------------------------------------------------------- |
| 295 | // Helper macros |
| 296 | |
| 297 | // A macro used to make better inlining. Don't bother for debug builds. |
| 298 | // Use like: |
| 299 | // V8_INLINE int GetZero() { return 0; } |
| 300 | #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE |
| 301 | # define V8_INLINE inline __attribute__((always_inline)) |
| 302 | #elif !defined(DEBUG) && V8_HAS___FORCEINLINE |
| 303 | # define V8_INLINE __forceinline |
| 304 | #else |
| 305 | # define V8_INLINE inline |
| 306 | #endif |
| 307 | |
| 308 | |
| 309 | // A macro used to tell the compiler to never inline a particular function. |
| 310 | // Don't bother for debug builds. |
| 311 | // Use like: |
| 312 | // V8_NOINLINE int GetMinusOne() { return -1; } |
| 313 | #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE |
| 314 | # define V8_NOINLINE __attribute__((noinline)) |
| 315 | #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE |
| 316 | # define V8_NOINLINE __declspec(noinline) |
| 317 | #else |
| 318 | # define V8_NOINLINE /* NOT SUPPORTED */ |
| 319 | #endif |
| 320 | |
| 321 | |
| 322 | // A macro to mark classes or functions as deprecated. |
| 323 | #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE |
| 324 | # define V8_DEPRECATED(message, declarator) \ |
| 325 | declarator __attribute__((deprecated(message))) |
| 326 | #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED |
| 327 | # define V8_DEPRECATED(message, declarator) \ |
| 328 | declarator __attribute__((deprecated)) |
| 329 | #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED |
| 330 | # define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator |
| 331 | #else |
| 332 | # define V8_DEPRECATED(message, declarator) declarator |
| 333 | #endif |
| 334 | |
| 335 | |
| 336 | // A macro to provide the compiler with branch prediction information. |
| 337 | #if V8_HAS_BUILTIN_EXPECT |
| 338 | # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) |
| 339 | # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) |
| 340 | #else |
| 341 | # define V8_UNLIKELY(condition) (condition) |
| 342 | # define V8_LIKELY(condition) (condition) |
| 343 | #endif |
| 344 | |
| 345 | |
| 346 | // A macro to specify that a method is deleted from the corresponding class. |
| 347 | // Any attempt to use the method will always produce an error at compile time |
| 348 | // when this macro can be implemented (i.e. if the compiler supports C++11). |
| 349 | // If the current compiler does not support C++11, use of the annotated method |
| 350 | // will still cause an error, but the error will most likely occur at link time |
| 351 | // rather than at compile time. As a backstop, method declarations using this |
| 352 | // macro should be private. |
| 353 | // Use like: |
| 354 | // class A { |
| 355 | // private: |
| 356 | // A(const A& other) V8_DELETE; |
| 357 | // A& operator=(const A& other) V8_DELETE; |
| 358 | // }; |
| 359 | #if V8_HAS_CXX11_DELETE |
| 360 | # define V8_DELETE = delete |
| 361 | #else |
| 362 | # define V8_DELETE /* NOT SUPPORTED */ |
| 363 | #endif |
| 364 | |
| 365 | |
| 366 | // This macro allows to specify memory alignment for structs, classes, etc. |
| 367 | // Use like: |
| 368 | // class V8_ALIGNED(16) MyClass { ... }; |
| 369 | // V8_ALIGNED(32) int array[42]; |
| 370 | #if V8_HAS_CXX11_ALIGNAS |
| 371 | # define V8_ALIGNED(n) alignas(n) |
| 372 | #elif V8_HAS_ATTRIBUTE_ALIGNED |
| 373 | # define V8_ALIGNED(n) __attribute__((aligned(n))) |
| 374 | #elif V8_HAS_DECLSPEC_ALIGN |
| 375 | # define V8_ALIGNED(n) __declspec(align(n)) |
| 376 | #else |
| 377 | # define V8_ALIGNED(n) /* NOT SUPPORTED */ |
| 378 | #endif |
| 379 | |
| 380 | |
| 381 | // This macro is similar to V8_ALIGNED(), but takes a type instead of size |
| 382 | // in bytes. If the compiler does not supports using the alignment of the |
| 383 | // |type|, it will align according to the |alignment| instead. For example, |
| 384 | // Visual Studio C++ cannot combine __declspec(align) and __alignof. The |
| 385 | // |alignment| must be a literal that is used as a kind of worst-case fallback |
| 386 | // alignment. |
| 387 | // Use like: |
| 388 | // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... }; |
| 389 | // V8_ALIGNAS(double, 8) int array[100]; |
| 390 | #if V8_HAS_CXX11_ALIGNAS |
| 391 | # define V8_ALIGNAS(type, alignment) alignas(type) |
| 392 | #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED |
| 393 | # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type)))) |
| 394 | #else |
| 395 | # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment) |
| 396 | #endif |
| 397 | |
| 398 | |
| 399 | // This macro returns alignment in bytes (an integer power of two) required for |
| 400 | // any instance of the given type, which is either complete type, an array type, |
| 401 | // or a reference type. |
| 402 | // Use like: |
| 403 | // size_t alignment = V8_ALIGNOF(double); |
| 404 | #if V8_HAS_CXX11_ALIGNOF |
| 405 | # define V8_ALIGNOF(type) alignof(type) |
| 406 | #elif V8_HAS___ALIGNOF |
| 407 | # define V8_ALIGNOF(type) __alignof(type) |
| 408 | #elif V8_HAS___ALIGNOF__ |
| 409 | # define V8_ALIGNOF(type) __alignof__(type) |
| 410 | #else |
| 411 | // Note that alignment of a type within a struct can be less than the |
| 412 | // alignment of the type stand-alone (because of ancient ABIs), so this |
| 413 | // should only be used as a last resort. |
| 414 | namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } |
| 415 | # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) |
| 416 | #endif |
| 417 | |
| 418 | #endif // V8CONFIG_H_ |