| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #ifndef V8CONFIG_H_ |
| 29 #define V8CONFIG_H_ |
| 30 |
| 31 // ----------------------------------------------------------------------------- |
| 32 // Operating system detection |
| 33 // |
| 34 // V8_OS_ANDROID - Android |
| 35 // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD) |
| 36 // V8_OS_CYGWIN - Cygwin |
| 37 // V8_OS_DRAGONFLYBSD - DragonFlyBSD |
| 38 // V8_OS_FREEBSD - FreeBSD |
| 39 // V8_OS_LINUX - Linux |
| 40 // V8_OS_MACOSX - Mac OS X |
| 41 // V8_OS_NACL - Native Client |
| 42 // V8_OS_NETBSD - NetBSD |
| 43 // V8_OS_OPENBSD - OpenBSD |
| 44 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows) |
| 45 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris |
| 46 // V8_OS_WIN - Microsoft Windows |
| 47 |
| 48 #if defined(__ANDROID__) |
| 49 # define V8_OS_ANDROID 1 |
| 50 # define V8_OS_LINUX 1 |
| 51 # define V8_OS_POSIX 1 |
| 52 #elif defined(__APPLE__) |
| 53 # define V8_OS_BSD 1 |
| 54 # define V8_OS_MACOSX 1 |
| 55 # define V8_OS_POSIX 1 |
| 56 #elif defined(__native_client__) |
| 57 # define V8_OS_NACL 1 |
| 58 # define V8_OS_POSIX 1 |
| 59 #elif defined(__CYGWIN__) |
| 60 # define V8_OS_CYGWIN 1 |
| 61 # define V8_OS_POSIX 1 |
| 62 #elif defined(__linux__) |
| 63 # define V8_OS_LINUX 1 |
| 64 # define V8_OS_POSIX 1 |
| 65 #elif defined(__sun) |
| 66 # define V8_OS_POSIX 1 |
| 67 # define V8_OS_SOLARIS 1 |
| 68 #elif defined(__FreeBSD__) |
| 69 # define V8_OS_BSD 1 |
| 70 # define V8_OS_FREEBSD 1 |
| 71 # define V8_OS_POSIX 1 |
| 72 #elif defined(__DragonFly__) |
| 73 # define V8_OS_BSD 1 |
| 74 # define V8_OS_DRAGONFLYBSD 1 |
| 75 # define V8_OS_POSIX 1 |
| 76 #elif defined(__NetBSD__) |
| 77 # define V8_OS_BSD 1 |
| 78 # define V8_OS_NETBSD 1 |
| 79 # define V8_OS_POSIX 1 |
| 80 #elif defined(__OpenBSD__) |
| 81 # define V8_OS_BSD 1 |
| 82 # define V8_OS_OPENBSD 1 |
| 83 # define V8_OS_POSIX 1 |
| 84 #elif defined(_WIN32) |
| 85 # define V8_OS_WIN 1 |
| 86 #endif |
| 87 |
| 88 |
| 89 // ----------------------------------------------------------------------------- |
| 90 // Compiler detection |
| 91 // |
| 92 // V8_CC_CLANG - Clang |
| 93 // V8_CC_GNU - GNU C++ |
| 94 // V8_CC_INTEL - Intel C++ |
| 95 // V8_CC_MINGW - Minimalist GNU for Windows |
| 96 // V8_CC_MSVC - Microsoft Visual C/C++ |
| 97 // |
| 98 // C++11 feature detection |
| 99 // |
| 100 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported |
| 101 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported |
| 102 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported |
| 103 // V8_HAS_CXX11_DELETE - deleted functions supported |
| 104 // V8_HAS_CXX11_FINAL - final marker supported |
| 105 // V8_HAS_CXX11_OVERRIDE - override marker supported |
| 106 // |
| 107 // Compiler-specific feature detection |
| 108 // |
| 109 // V8_HAS___ALIGNOF - __alignof(type) operator supported |
| 110 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported |
| 111 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported |
| 112 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) |
| 113 // supported |
| 114 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported |
| 115 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported |
| 116 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported |
| 117 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) |
| 118 // supported |
| 119 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported |
| 120 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported |
| 121 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported |
| 122 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported |
| 123 // V8_HAS___FINAL - __final supported in non-C++11 mode |
| 124 // V8_HAS___FORCEINLINE - __forceinline supported |
| 125 // V8_HAS_SEALED - MSVC style sealed marker supported |
| 126 // |
| 127 // Note that testing for compilers and/or features must be done using #if |
| 128 // not #ifdef. For example, to test for Intel C++ Compiler, use: |
| 129 // #if V8_CC_INTEL |
| 130 // ... |
| 131 // #endif |
| 132 |
| 133 #if defined(__clang__) |
| 134 |
| 135 // Don't treat clang as GCC. |
| 136 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
| 137 |
| 138 # define V8_CC_CLANG 1 |
| 139 |
| 140 // Clang defines __alignof__ as alias for __alignof |
| 141 # define V8_HAS___ALIGNOF 1 |
| 142 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF |
| 143 |
| 144 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) |
| 145 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) |
| 146 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) |
| 147 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) |
| 148 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) |
| 149 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 150 (__has_attribute(warn_unused_result)) |
| 151 |
| 152 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) |
| 153 |
| 154 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) |
| 155 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) |
| 156 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) |
| 157 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) |
| 158 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) |
| 159 |
| 160 #elif defined(__GNUC__) |
| 161 |
| 162 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ |
| 163 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ |
| 164 ((major) * 10000 + (minor) * 100 + (patchlevel))) |
| 165 |
| 166 # define V8_CC_GNU 1 |
| 167 // Intel C++ also masquerades as GCC 3.2.0 |
| 168 # define V8_CC_INTEL (defined(__INTEL_COMPILER)) |
| 169 # define V8_CC_MINGW (defined(__MINGW32__)) |
| 170 |
| 171 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) |
| 172 |
| 173 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) |
| 174 // always_inline is available in gcc 4.0 but not very reliable until 4.4. |
| 175 // Works around "sorry, unimplemented: inlining failed" build errors with |
| 176 // older compilers. |
| 177 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) |
| 178 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) |
| 179 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0)) |
| 180 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) |
| 181 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ |
| 182 (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0)) |
| 183 |
| 184 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) |
| 185 |
| 186 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality |
| 187 // without warnings (functionality used by the macros below). These modes |
| 188 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, |
| 189 // more standardly, by checking whether __cplusplus has a C++11 or greater |
| 190 // value. Current versions of g++ do not correctly set __cplusplus, so we check |
| 191 // both for forward compatibility. |
| 192 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
| 193 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) |
| 194 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0)) |
| 195 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) |
| 196 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) |
| 197 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) |
| 198 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
| 199 # else |
| 200 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. |
| 201 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) |
| 202 # endif |
| 203 |
| 204 #elif defined(_MSC_VER) |
| 205 |
| 206 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 |
| 207 |
| 208 # define V8_CC_MSVC 1 |
| 209 |
| 210 # define V8_HAS___ALIGNOF 1 |
| 211 |
| 212 // Override control was added with Visual Studio 2005, but |
| 213 // Visual Studio 2010 and earlier spell "final" as "sealed". |
| 214 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700) |
| 215 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400) |
| 216 # define V8_HAS_SEALED (_MSC_VER >= 1400) |
| 217 |
| 218 # define V8_HAS_DECLSPEC_ALIGN 1 |
| 219 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300) |
| 220 # define V8_HAS_DECLSPEC_NOINLINE 1 |
| 221 |
| 222 # define V8_HAS___FORCEINLINE 1 |
| 223 |
| 224 #endif |
| 225 |
| 226 |
| 227 // ----------------------------------------------------------------------------- |
| 228 // Helper macros |
| 229 |
| 230 // A macro used to make better inlining. Don't bother for debug builds. |
| 231 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE |
| 232 # define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 233 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE |
| 234 # define V8_INLINE(declarator) __forceinline declarator |
| 235 #else |
| 236 # define V8_INLINE(declarator) inline declarator |
| 237 #endif |
| 238 |
| 239 |
| 240 // A macro used to tell the compiler to never inline a particular function. |
| 241 // Don't bother for debug builds. |
| 242 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE |
| 243 # define V8_NOINLINE(declarator) __attribute__((noinline)) declarator |
| 244 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE |
| 245 # define V8_NOINLINE(declarator) __declspec(noinline) declarator |
| 246 #else |
| 247 # define V8_NOINLINE(declarator) declarator |
| 248 #endif |
| 249 |
| 250 |
| 251 // A macro to mark classes or functions as deprecated. |
| 252 #if !V8_DISABLE_DEPRECATIONS && V8_HAS_ATTRIBUTE_DEPRECATED |
| 253 # define V8_DEPRECATED(declarator) declarator __attribute__((deprecated)) |
| 254 #elif !V8_DISABLE_DEPRECATIONS && V8_HAS_DECLSPEC_DEPRECATED |
| 255 # define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 256 #else |
| 257 # define V8_DEPRECATED(declarator) declarator |
| 258 #endif |
| 259 |
| 260 |
| 261 // Annotate a function indicating the caller must examine the return value. |
| 262 // Use like: |
| 263 // int foo() V8_WARN_UNUSED_RESULT; |
| 264 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT |
| 265 # define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 266 #else |
| 267 # define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */ |
| 268 #endif |
| 269 |
| 270 |
| 271 // A macro to provide the compiler with branch prediction information. |
| 272 #if V8_HAS_BUILTIN_EXPECT |
| 273 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) |
| 274 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) |
| 275 #else |
| 276 # define V8_UNLIKELY(condition) (condition) |
| 277 # define V8_LIKELY(condition) (condition) |
| 278 #endif |
| 279 |
| 280 |
| 281 // A macro to specify that a method is deleted from the corresponding class. |
| 282 // Any attempt to use the method will always produce an error at compile time |
| 283 // when this macro can be implemented (i.e. if the compiler supports C++11). |
| 284 // If the current compiler does not support C++11, use of the annotated method |
| 285 // will still cause an error, but the error will most likely occur at link time |
| 286 // rather than at compile time. As a backstop, method declarations using this |
| 287 // macro should be private. |
| 288 // Use like: |
| 289 // class A { |
| 290 // private: |
| 291 // A(const A& other) V8_DELETE; |
| 292 // A& operator=(const A& other) V8_DELETE; |
| 293 // }; |
| 294 #if V8_HAS_CXX11_DELETE |
| 295 # define V8_DELETE = delete |
| 296 #else |
| 297 # define V8_DELETE /* NOT SUPPORTED */ |
| 298 #endif |
| 299 |
| 300 |
| 301 // Annotate a virtual method indicating it must be overriding a virtual |
| 302 // method in the parent class. |
| 303 // Use like: |
| 304 // virtual void bar() V8_OVERRIDE; |
| 305 #if V8_HAS_CXX11_OVERRIDE |
| 306 # define V8_OVERRIDE override |
| 307 #else |
| 308 # define V8_OVERRIDE /* NOT SUPPORTED */ |
| 309 #endif |
| 310 |
| 311 |
| 312 // Annotate a virtual method indicating that subclasses must not override it, |
| 313 // or annotate a class to indicate that it cannot be subclassed. |
| 314 // Use like: |
| 315 // class B V8_FINAL : public A {}; |
| 316 // virtual void bar() V8_FINAL; |
| 317 #if V8_HAS_CXX11_FINAL |
| 318 # define V8_FINAL final |
| 319 #elif V8_HAS___FINAL |
| 320 # define V8_FINAL __final |
| 321 #elif V8_HAS_SEALED |
| 322 # define V8_FINAL sealed |
| 323 #else |
| 324 # define V8_FINAL /* NOT SUPPORTED */ |
| 325 #endif |
| 326 |
| 327 |
| 328 // This macro allows to specify memory alignment for structs, classes, etc. |
| 329 // Use like: |
| 330 // class V8_ALIGNED(16) MyClass { ... }; |
| 331 // V8_ALIGNED(32) int array[42]; |
| 332 #if V8_HAS_CXX11_ALIGNAS |
| 333 # define V8_ALIGNED(n) alignas(n) |
| 334 #elif V8_HAS_ATTRIBUTE_ALIGNED |
| 335 # define V8_ALIGNED(n) __attribute__((aligned(n))) |
| 336 #elif V8_HAS_DECLSPEC_ALIGN |
| 337 # define V8_ALIGNED(n) __declspec(align(n)) |
| 338 #else |
| 339 # define V8_ALIGNED(n) /* NOT SUPPORTED */ |
| 340 #endif |
| 341 |
| 342 |
| 343 // This macro is similar to V8_ALIGNED(), but takes a type instead of size |
| 344 // in bytes. If the compiler does not supports using the alignment of the |
| 345 // |type|, it will align according to the |alignment| instead. For example, |
| 346 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The |
| 347 // |alignment| must be a literal that is used as a kind of worst-case fallback |
| 348 // alignment. |
| 349 // Use like: |
| 350 // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... }; |
| 351 // V8_ALIGNAS(double, 8) int array[100]; |
| 352 #if V8_HAS_CXX11_ALIGNAS |
| 353 # define V8_ALIGNAS(type, alignment) alignas(type) |
| 354 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED |
| 355 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type)))) |
| 356 #else |
| 357 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment) |
| 358 #endif |
| 359 |
| 360 |
| 361 // This macro returns alignment in bytes (an integer power of two) required for |
| 362 // any instance of the given type, which is either complete type, an array type, |
| 363 // or a reference type. |
| 364 // Use like: |
| 365 // size_t alignment = V8_ALIGNOF(double); |
| 366 #if V8_HAS_CXX11_ALIGNOF |
| 367 # define V8_ALIGNOF(type) alignof(type) |
| 368 #elif V8_HAS___ALIGNOF |
| 369 # define V8_ALIGNOF(type) __alignof(type) |
| 370 #elif V8_HAS___ALIGNOF__ |
| 371 # define V8_ALIGNOF(type) __alignof__(type) |
| 372 #else |
| 373 // Note that alignment of a type within a struct can be less than the |
| 374 // alignment of the type stand-alone (because of ancient ABIs), so this |
| 375 // should only be used as a last resort. |
| 376 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } |
| 377 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) |
| 378 #endif |
| 379 |
| 380 #endif // V8CONFIG_H_ |
| OLD | NEW |