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