The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / include / v8config.h @ f230a1cf

History | View | Annotate | Download (16.4 KB)

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
// Platform headers for feature detection below.
32
#if defined(__ANDROID__)
33
# include <sys/cdefs.h>
34
#elif defined(__APPLE__)
35
# include <TargetConditionals.h>
36
#elif defined(__linux__)
37
# include <features.h>
38
#endif
39

    
40

    
41
// This macro allows to test for the version of the GNU C library (or
42
// a compatible C library that masquerades as glibc). It evaluates to
43
// 0 if libc is not GNU libc or compatible.
44
// Use like:
45
//  #if V8_GLIBC_PREREQ(2, 3)
46
//   ...
47
//  #endif
48
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
49
# define V8_GLIBC_PREREQ(major, minor)                                    \
50
    ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
51
#else
52
# define V8_GLIBC_PREREQ(major, minor) 0
53
#endif
54

    
55

    
56
// This macro allows to test for the version of the GNU C++ compiler.
57
// Note that this also applies to compilers that masquerade as GCC,
58
// for example clang and the Intel C++ compiler for Linux.
59
// Use like:
60
//  #if V8_GNUC_PREREQ(4, 3, 1)
61
//   ...
62
//  #endif
63
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
64
# define V8_GNUC_PREREQ(major, minor, patchlevel)                         \
65
    ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >=   \
66
     ((major) * 10000 + (minor) * 100 + (patchlevel)))
67
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
68
# define V8_GNUC_PREREQ(major, minor, patchlevel)       \
69
    ((__GNUC__ * 10000 + __GNUC_MINOR__) >=             \
70
     ((major) * 10000 + (minor) * 100 + (patchlevel)))
71
#else
72
# define V8_GNUC_PREREQ(major, minor, patchlevel) 0
73
#endif
74

    
75

    
76

    
77
// -----------------------------------------------------------------------------
78
// Operating system detection
79
//
80
//  V8_OS_ANDROID       - Android
81
//  V8_OS_BSD           - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD)
82
//  V8_OS_CYGWIN        - Cygwin
83
//  V8_OS_DRAGONFLYBSD  - DragonFlyBSD
84
//  V8_OS_FREEBSD       - FreeBSD
85
//  V8_OS_LINUX         - Linux
86
//  V8_OS_MACOSX        - Mac OS X
87
//  V8_OS_NACL          - Native Client
88
//  V8_OS_NETBSD        - NetBSD
89
//  V8_OS_OPENBSD       - OpenBSD
90
//  V8_OS_POSIX         - POSIX compatible (mostly everything except Windows)
91
//  V8_OS_SOLARIS       - Sun Solaris and OpenSolaris
92
//  V8_OS_WIN           - Microsoft Windows
93

    
94
#if defined(__ANDROID__)
95
# define V8_OS_ANDROID 1
96
# define V8_OS_LINUX 1
97
# define V8_OS_POSIX 1
98
#elif defined(__APPLE__)
99
# define V8_OS_BSD 1
100
# define V8_OS_MACOSX 1
101
# define V8_OS_POSIX 1
102
#elif defined(__native_client__)
103
# define V8_OS_NACL 1
104
# define V8_OS_POSIX 1
105
#elif defined(__CYGWIN__)
106
# define V8_OS_CYGWIN 1
107
# define V8_OS_POSIX 1
108
#elif defined(__linux__)
109
# define V8_OS_LINUX 1
110
# define V8_OS_POSIX 1
111
#elif defined(__sun)
112
# define V8_OS_POSIX 1
113
# define V8_OS_SOLARIS 1
114
#elif defined(__FreeBSD__)
115
# define V8_OS_BSD 1
116
# define V8_OS_FREEBSD 1
117
# define V8_OS_POSIX 1
118
#elif defined(__DragonFly__)
119
# define V8_OS_BSD 1
120
# define V8_OS_DRAGONFLYBSD 1
121
# define V8_OS_POSIX 1
122
#elif defined(__NetBSD__)
123
# define V8_OS_BSD 1
124
# define V8_OS_NETBSD 1
125
# define V8_OS_POSIX 1
126
#elif defined(__OpenBSD__)
127
# define V8_OS_BSD 1
128
# define V8_OS_OPENBSD 1
129
# define V8_OS_POSIX 1
130
#elif defined(_WIN32)
131
# define V8_OS_WIN 1
132
#endif
133

    
134

    
135
// -----------------------------------------------------------------------------
136
// C library detection
137
//
138
//  V8_LIBC_BIONIC  - Bionic libc
139
//  V8_LIBC_BSD     - BSD libc derivate
140
//  V8_LIBC_GLIBC   - GNU C library
141
//  V8_LIBC_UCLIBC  - uClibc
142
//
143
// Note that testing for libc must be done using #if not #ifdef. For example,
144
// to test for the GNU C library, use:
145
//  #if V8_LIBC_GLIBC
146
//   ...
147
//  #endif
148

    
149
#if defined(__BIONIC__)
150
# define V8_LIBC_BIONIC 1
151
# define V8_LIBC_BSD 1
152
#elif defined(__UCLIBC__)
153
# define V8_LIBC_UCLIBC 1
154
#elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
155
# define V8_LIBC_GLIBC 1
156
#else
157
# define V8_LIBC_BSD V8_OS_BSD
158
#endif
159

    
160

    
161
// -----------------------------------------------------------------------------
162
// Compiler detection
163
//
164
//  V8_CC_CLANG   - Clang
165
//  V8_CC_GNU     - GNU C++
166
//  V8_CC_INTEL   - Intel C++
167
//  V8_CC_MINGW   - Minimalist GNU for Windows
168
//  V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
169
//  V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
170
//  V8_CC_MSVC    - Microsoft Visual C/C++
171
//
172
// C++11 feature detection
173
//
174
//  V8_HAS_CXX11_ALIGNAS        - alignas specifier supported
175
//  V8_HAS_CXX11_ALIGNOF        - alignof(type) operator supported
176
//  V8_HAS_CXX11_STATIC_ASSERT  - static_assert() supported
177
//  V8_HAS_CXX11_DELETE         - deleted functions supported
178
//  V8_HAS_CXX11_FINAL          - final marker supported
179
//  V8_HAS_CXX11_OVERRIDE       - override marker supported
180
//
181
// Compiler-specific feature detection
182
//
183
//  V8_HAS___ALIGNOF                    - __alignof(type) operator supported
184
//  V8_HAS___ALIGNOF__                  - __alignof__(type) operator supported
185
//  V8_HAS_ATTRIBUTE_ALIGNED            - __attribute__((aligned(n))) supported
186
//  V8_HAS_ATTRIBUTE_ALWAYS_INLINE      - __attribute__((always_inline))
187
//                                        supported
188
//  V8_HAS_ATTRIBUTE_DEPRECATED         - __attribute__((deprecated)) supported
189
//  V8_HAS_ATTRIBUTE_NOINLINE           - __attribute__((noinline)) supported
190
//  V8_HAS_ATTRIBUTE_VISIBILITY         - __attribute__((visibility)) supported
191
//  V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
192
//                                        supported
193
//  V8_HAS_BUILTIN_EXPECT               - __builtin_expect() supported
194
//  V8_HAS_DECLSPEC_ALIGN               - __declspec(align(n)) supported
195
//  V8_HAS_DECLSPEC_DEPRECATED          - __declspec(deprecated) supported
196
//  V8_HAS_DECLSPEC_NOINLINE            - __declspec(noinline) supported
197
//  V8_HAS___FINAL                      - __final supported in non-C++11 mode
198
//  V8_HAS___FORCEINLINE                - __forceinline supported
199
//  V8_HAS_SEALED                       - MSVC style sealed marker supported
200
//
201
// Note that testing for compilers and/or features must be done using #if
202
// not #ifdef. For example, to test for Intel C++ Compiler, use:
203
//  #if V8_CC_INTEL
204
//   ...
205
//  #endif
206

    
207
#if defined(__clang__)
208

    
209
# define V8_CC_CLANG 1
210

    
211
// Clang defines __alignof__ as alias for __alignof
212
# define V8_HAS___ALIGNOF 1
213
# define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
214

    
215
# define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
216
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
217
# define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
218
# define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
219
# define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
220
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
221
    (__has_attribute(warn_unused_result))
222

    
223
# define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
224

    
225
# define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
226
# define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert))
227
# define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions))
228
# define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control))
229
# define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control))
230

    
231
#elif defined(__GNUC__)
232

    
233
# define V8_CC_GNU 1
234
// Intel C++ also masquerades as GCC 3.2.0
235
# define V8_CC_INTEL (defined(__INTEL_COMPILER))
236
# define V8_CC_MINGW32 (defined(__MINGW32__))
237
# define V8_CC_MINGW64 (defined(__MINGW64__))
238
# define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
239

    
240
# define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
241

    
242
# define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
243
// always_inline is available in gcc 4.0 but not very reliable until 4.4.
244
// Works around "sorry, unimplemented: inlining failed" build errors with
245
// older compilers.
246
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
247
# define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
248
# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
249
# define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
250
# define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
251
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
252
    (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
253

    
254
# define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
255

    
256
// g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
257
// without warnings (functionality used by the macros below).  These modes
258
// are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
259
// more standardly, by checking whether __cplusplus has a C++11 or greater
260
// value. Current versions of g++ do not correctly set __cplusplus, so we check
261
// both for forward compatibility.
262
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
263
#  define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
264
#  define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
265
#  define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0))
266
#  define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0))
267
#  define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0))
268
#  define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0))
269
# else
270
// '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
271
#  define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0))
272
# endif
273

    
274
#elif defined(_MSC_VER)
275

    
276
# define V8_CC_MSVC 1
277

    
278
# define V8_HAS___ALIGNOF 1
279

    
280
// Override control was added with Visual Studio 2005, but
281
// Visual Studio 2010 and earlier spell "final" as "sealed".
282
# define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700)
283
# define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400)
284
# define V8_HAS_SEALED (_MSC_VER >= 1400)
285

    
286
# define V8_HAS_DECLSPEC_ALIGN 1
287
# define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300)
288
# define V8_HAS_DECLSPEC_NOINLINE 1
289

    
290
# define V8_HAS___FORCEINLINE 1
291

    
292
#endif
293

    
294

    
295
// -----------------------------------------------------------------------------
296
// Helper macros
297

    
298
// A macro used to make better inlining. Don't bother for debug builds.
299
// Use like:
300
//   V8_INLINE int GetZero() { return 0; }
301
#if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
302
# define V8_INLINE inline __attribute__((always_inline))
303
#elif !defined(DEBUG) && V8_HAS___FORCEINLINE
304
# define V8_INLINE __forceinline
305
#else
306
# define V8_INLINE inline
307
#endif
308

    
309

    
310
// A macro used to tell the compiler to never inline a particular function.
311
// Don't bother for debug builds.
312
// Use like:
313
//   V8_NOINLINE int GetMinusOne() { return -1; }
314
#if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
315
# define V8_NOINLINE __attribute__((noinline))
316
#elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
317
# define V8_NOINLINE __declspec(noinline)
318
#else
319
# define V8_NOINLINE /* NOT SUPPORTED */
320
#endif
321

    
322

    
323
// A macro to mark classes or functions as deprecated.
324
#if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
325
# define V8_DEPRECATED(message, declarator) \
326
declarator __attribute__((deprecated(message)))
327
#elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
328
# define V8_DEPRECATED(message, declarator) \
329
declarator __attribute__((deprecated))
330
#elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
331
# define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator
332
#else
333
# define V8_DEPRECATED(message, declarator) declarator
334
#endif
335

    
336

    
337
// Annotate a function indicating the caller must examine the return value.
338
// Use like:
339
//   int foo() V8_WARN_UNUSED_RESULT;
340
#if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
341
# define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
342
#else
343
# define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
344
#endif
345

    
346

    
347
// A macro to provide the compiler with branch prediction information.
348
#if V8_HAS_BUILTIN_EXPECT
349
# define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
350
# define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
351
#else
352
# define V8_UNLIKELY(condition) (condition)
353
# define V8_LIKELY(condition) (condition)
354
#endif
355

    
356

    
357
// A macro to specify that a method is deleted from the corresponding class.
358
// Any attempt to use the method will always produce an error at compile time
359
// when this macro can be implemented (i.e. if the compiler supports C++11).
360
// If the current compiler does not support C++11, use of the annotated method
361
// will still cause an error, but the error will most likely occur at link time
362
// rather than at compile time. As a backstop, method declarations using this
363
// macro should be private.
364
// Use like:
365
//   class A {
366
//    private:
367
//     A(const A& other) V8_DELETE;
368
//     A& operator=(const A& other) V8_DELETE;
369
//   };
370
#if V8_HAS_CXX11_DELETE
371
# define V8_DELETE = delete
372
#else
373
# define V8_DELETE /* NOT SUPPORTED */
374
#endif
375

    
376

    
377
// Annotate a virtual method indicating it must be overriding a virtual
378
// method in the parent class.
379
// Use like:
380
//   virtual void bar() V8_OVERRIDE;
381
#if V8_HAS_CXX11_OVERRIDE
382
# define V8_OVERRIDE override
383
#else
384
# define V8_OVERRIDE /* NOT SUPPORTED */
385
#endif
386

    
387

    
388
// Annotate a virtual method indicating that subclasses must not override it,
389
// or annotate a class to indicate that it cannot be subclassed.
390
// Use like:
391
//   class B V8_FINAL : public A {};
392
//   virtual void bar() V8_FINAL;
393
#if V8_HAS_CXX11_FINAL
394
# define V8_FINAL final
395
#elif V8_HAS___FINAL
396
# define V8_FINAL __final
397
#elif V8_HAS_SEALED
398
# define V8_FINAL sealed
399
#else
400
# define V8_FINAL /* NOT SUPPORTED */
401
#endif
402

    
403

    
404
// This macro allows to specify memory alignment for structs, classes, etc.
405
// Use like:
406
//   class V8_ALIGNED(16) MyClass { ... };
407
//   V8_ALIGNED(32) int array[42];
408
#if V8_HAS_CXX11_ALIGNAS
409
# define V8_ALIGNED(n) alignas(n)
410
#elif V8_HAS_ATTRIBUTE_ALIGNED
411
# define V8_ALIGNED(n) __attribute__((aligned(n)))
412
#elif V8_HAS_DECLSPEC_ALIGN
413
# define V8_ALIGNED(n) __declspec(align(n))
414
#else
415
# define V8_ALIGNED(n) /* NOT SUPPORTED */
416
#endif
417

    
418

    
419
// This macro is similar to V8_ALIGNED(), but takes a type instead of size
420
// in bytes. If the compiler does not supports using the alignment of the
421
// |type|, it will align according to the |alignment| instead. For example,
422
// Visual Studio C++ cannot combine __declspec(align) and __alignof. The
423
// |alignment| must be a literal that is used as a kind of worst-case fallback
424
// alignment.
425
// Use like:
426
//   struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... };
427
//   V8_ALIGNAS(double, 8) int array[100];
428
#if V8_HAS_CXX11_ALIGNAS
429
# define V8_ALIGNAS(type, alignment) alignas(type)
430
#elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED
431
# define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type))))
432
#else
433
# define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment)
434
#endif
435

    
436

    
437
// This macro returns alignment in bytes (an integer power of two) required for
438
// any instance of the given type, which is either complete type, an array type,
439
// or a reference type.
440
// Use like:
441
//   size_t alignment = V8_ALIGNOF(double);
442
#if V8_HAS_CXX11_ALIGNOF
443
# define V8_ALIGNOF(type) alignof(type)
444
#elif V8_HAS___ALIGNOF
445
# define V8_ALIGNOF(type) __alignof(type)
446
#elif V8_HAS___ALIGNOF__
447
# define V8_ALIGNOF(type) __alignof__(type)
448
#else
449
// Note that alignment of a type within a struct can be less than the
450
// alignment of the type stand-alone (because of ancient ABIs), so this
451
// should only be used as a last resort.
452
namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; }
453
# define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type))
454
#endif
455

    
456
#endif  // V8CONFIG_H_