OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_GLOBALS_H_ | 28 #ifndef V8_GLOBALS_H_ |
29 #define V8_GLOBALS_H_ | 29 #define V8_GLOBALS_H_ |
30 | 30 |
31 // ---------------------------------------------------------------------------- | 31 // Define V8_INFINITY |
32 // Operating system detection (V8_OS_x) | 32 #define V8_INFINITY INFINITY |
33 // | |
34 // ANDROID - Android | |
35 // BSD4 - Any BSD 4.4 system | |
36 // CYGWIN - Cygwin | |
37 // DARWIN - Darwin / Mac OS X | |
38 // FREEBSD - FreeBSD | |
39 // LINUX - Linux | |
40 // NACL - Native Client | |
41 // NETBSD - NetBSD | |
42 // OPENBSD - OpenBSD | |
43 // SOLARIS - Solaris | |
44 // UNIX - Any UNIX BSD/SYSV system | |
45 // WIN32 - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008) | |
46 | 33 |
47 #if defined(ANDROID) || defined(__ANDROID__) | 34 // GCC specific stuff |
48 # define V8_OS_ANDROID 1 | 35 #ifdef __GNUC__ |
49 # define V8_OS_LINUX 1 | 36 |
50 # define V8_OS_UNIX 1 | 37 #define __GNUC_VERSION_FOR_INFTY__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) |
51 #elif defined(__APPLE__) && defined(__MACH__) | 38 |
52 # define V8_OS_DARWIN 1 | 39 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' |
53 # define V8_OS_BSD4 1 | 40 // warning flag and certain versions of GCC due to a bug: |
54 # define V8_OS_UNIX 1 | 41 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 |
55 #elif defined(__CYGWIN__) | 42 // For now, we use the more involved template-based version from <limits>, but |
56 # define V8_OS_CYGWIN 1 | 43 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) |
57 # define V8_OS_UNIX 1 | 44 // __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro |
58 #elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__) | 45 #if __GNUC_VERSION_FOR_INFTY__ >= 29600 && __GNUC_VERSION_FOR_INFTY__ < 40100 |
59 # define V8_OS_WIN32 1 | 46 #include <limits> |
60 # define V8_OS_WIN64 1 | 47 #undef V8_INFINITY |
61 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \ | 48 #define V8_INFINITY std::numeric_limits<double>::infinity() |
62 (defined(__MWERKS__) && defined(__INTEL__)) | 49 #endif |
63 # define V8_OS_WIN32 1 | 50 #undef __GNUC_VERSION_FOR_INFTY__ |
64 #elif defined(__sun) || defined(sun) | 51 |
65 # define V8_OS_SOLARIS 1 | 52 #endif // __GNUC__ |
66 # define V8_OS_UNIX 1 | 53 |
67 #elif defined(__native_client__) | 54 #ifdef _MSC_VER |
68 # define V8_OS_NACL 1 | 55 #undef V8_INFINITY |
69 #elif defined(__linux__) || defined(__linux) | 56 #define V8_INFINITY HUGE_VAL |
70 # define V8_OS_LINUX 1 | |
71 # define V8_OS_UNIX 1 | |
72 #elif defined(__FreeBSD__) || defined(__DragonFly__) | |
73 # define V8_OS_FREEBSD 1 | |
74 # define V8_OS_BSD4 1 | |
75 # define V8_OS_UNIX 1 | |
76 #elif defined(__NetBSD__) | |
77 # define V8_OS_NETBSD 1 | |
78 # define V8_OS_BSD4 1 | |
79 # define V8_OS_UNIX 1 | |
80 #elif defined(__OpenBSD__) | |
81 # define V8_OS_OPENBSD 1 | |
82 # define V8_OS_BSD4 1 | |
83 # define V8_OS_UNIX 1 | |
84 #else | |
85 # error Operating system was not detected as supported by v8 | |
86 #endif | 57 #endif |
87 | 58 |
88 | 59 |
89 // ---------------------------------------------------------------------------- | 60 #include "../include/v8stdint.h" |
90 // Compiler detection (V8_CC_x) | |
91 // | |
92 // CLANG - C++ front-end for the LLVM compiler | |
93 // GNU - GNU C++ or compatible | |
94 // INTEL - Intel C++ for Linux or Windows | |
95 // MINGW - Minimalistic GNU for Windows Compiler | |
96 // MIPS - MIPSpro C++ | |
97 // MSVC - Microsoft Visual C/C++ or compatible | |
98 // RVCT - ARM Realview Compiler Suite | |
99 | 61 |
100 #if defined(_MSC_VER) | 62 namespace v8 { |
101 # define V8_CC_MSVC 1 | 63 namespace internal { |
102 # if defined(__INTEL_COMPILER) | |
103 # define V8_CC_INTEL 1 | |
104 # endif | |
105 #elif defined(__GNUC__) | |
106 # define V8_CC_GNU 1 | |
107 # if defined(__MINGW64__) | |
108 # define V8_CC_MINGW 1 | |
109 # define V8_CC_MINGW64 1 | |
110 # elif defined(__MINGW32__) | |
111 # define V8_CC_MINGW 1 | |
112 # define V8_CC_MINGW32 1 | |
113 # elif defined(__ARMCC__) || defined(__CC_ARM) | |
114 # define V8_CC_RVCT 1 // ARM Realview Compiler Suite also masquerades as GCC | |
115 # elif defined(__INTEL_COMPILER) | |
116 # define V8_CC_INTEL 1 // Intel C++ also masquerades as GCC 3.2.0 | |
117 # elif defined(__clang__) | |
118 # define V8_CC_CLANG 1 // Clang also masquerades as GCC 4.2.1 | |
119 # endif | |
120 #elif defined(__ARMCC__) || defined(__CC_ARM) | |
121 # define V8_CC_RVCT 1 | |
122 #elif defined(__INTEL_COMPILER) | |
123 # define V8_CC_INTEL 1 | |
124 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) | |
125 # define V8_CC_SUN 1 | |
126 #else | |
127 # error Compiler was not detected as supported by v8 | |
128 #endif | |
129 | 64 |
130 #if V8_CC_GNU | 65 // Processor architecture detection. For more info on what's defined, see: |
131 # define V8_GNUC_PREREQ(major, minor) \ | |
132 (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) | |
133 #else | |
134 # define V8_GNUC_PREREQ(major, minor) 0 | |
135 #endif // V8_CC_GNU | |
136 | |
137 | |
138 // ---------------------------------------------------------------------------- | |
139 // Compiler features | |
140 | |
141 // C++11 deleted functions | |
142 #if __cplusplus >= 201103L | |
143 # define V8_CXX_DELETED_FUNCTIONS 1 | |
144 #elif V8_CC_CLANG | |
145 # define V8_CXX_DELETED_FUNCTIONS __has_feature(cxx_deleted_functions) | |
146 #else | |
147 # define V8_CXX_DELETED_FUNCTIONS (defined(__GXX_EXPERIMENTAL_CXX0X__) && \ | |
148 V8_GNUC_PREREQ(4, 4)) | |
149 #endif | |
150 | |
151 // C++11 static_assert() | |
152 #if __cplusplus >= 201103L | |
153 # define V8_CXX_STATIC_ASSERT 1 | |
154 #elif V8_CC_CLANG | |
155 # define V8_CXX_STATIC_ASSERT (__has_extension(cxx_static_assert) || \ | |
156 __has_feature(cxx_static_assert)) | |
157 #else | |
158 # define V8_CXX_STATIC_ASSERT (defined(__GXX_EXPERIMENTAL_CXX0X__) && \ | |
159 V8_GNUC_PREREQ(4, 3)) | |
160 #endif | |
161 | |
162 | |
163 // ---------------------------------------------------------------------------- | |
164 // Host architecture detection. For more info on what's defined, see: | |
165 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx | 66 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
166 // http://www.agner.org/optimize/calling_conventions.pdf | 67 // http://www.agner.org/optimize/calling_conventions.pdf |
167 // or with gcc, run: "echo | gcc -E -dM -" | 68 // or with gcc, run: "echo | gcc -E -dM -" |
168 | |
169 #if defined(_M_X64) || defined(__x86_64__) | 69 #if defined(_M_X64) || defined(__x86_64__) |
170 # if V8_OS_NACL | 70 #if defined(__native_client__) |
171 // For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8 | 71 // For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8 |
172 // generates ARM machine code, together with a portable ARM simulator | 72 // generates ARM machine code, together with a portable ARM simulator |
173 // compiled for the host architecture in question. | 73 // compiled for the host architecture in question. |
174 // | 74 // |
175 // Since Native Client is ILP-32 on all architectures we use | 75 // Since Native Client is ILP-32 on all architectures we use |
176 // V8_HOST_ARCH_IA32 on both 32- and 64-bit x86. | 76 // V8_HOST_ARCH_IA32 on both 32- and 64-bit x86. |
177 # define V8_HOST_ARCH_IA32 1 | 77 #define V8_HOST_ARCH_IA32 1 |
178 # define V8_HOST_ARCH_32_BIT 1 | 78 #define V8_HOST_ARCH_32_BIT 1 |
179 # define V8_HOST_CAN_READ_UNALIGNED 1 | 79 #define V8_HOST_CAN_READ_UNALIGNED 1 |
180 # else | 80 #else |
181 # define V8_HOST_ARCH_X64 1 | 81 #define V8_HOST_ARCH_X64 1 |
182 # define V8_HOST_ARCH_64_BIT 1 | 82 #define V8_HOST_ARCH_64_BIT 1 |
183 # define V8_HOST_CAN_READ_UNALIGNED 1 | 83 #define V8_HOST_CAN_READ_UNALIGNED 1 |
184 # endif // V8_OS_NACL | 84 #endif // __native_client__ |
185 #elif defined(_M_IX86) || defined(__i386__) | 85 #elif defined(_M_IX86) || defined(__i386__) |
186 # define V8_HOST_ARCH_IA32 1 | 86 #define V8_HOST_ARCH_IA32 1 |
187 # define V8_HOST_ARCH_32_BIT 1 | 87 #define V8_HOST_ARCH_32_BIT 1 |
188 # define V8_HOST_CAN_READ_UNALIGNED 1 | 88 #define V8_HOST_CAN_READ_UNALIGNED 1 |
189 #elif defined(__ARMEL__) | 89 #elif defined(__ARMEL__) |
190 # define V8_HOST_ARCH_ARM 1 | 90 #define V8_HOST_ARCH_ARM 1 |
191 # define V8_HOST_ARCH_32_BIT 1 | 91 #define V8_HOST_ARCH_32_BIT 1 |
192 #elif defined(__MIPSEL__) | 92 #elif defined(__MIPSEL__) |
193 # define V8_HOST_ARCH_MIPS 1 | 93 #define V8_HOST_ARCH_MIPS 1 |
194 # define V8_HOST_ARCH_32_BIT 1 | 94 #define V8_HOST_ARCH_32_BIT 1 |
195 #else | 95 #else |
196 # error Host architecture was not detected as supported by v8 | 96 #error Host architecture was not detected as supported by v8 |
197 #endif | 97 #endif |
198 | 98 |
199 #if defined(__ARM_ARCH_7A__) || \ | 99 #if defined(__ARM_ARCH_7A__) || \ |
200 defined(__ARM_ARCH_7R__) || \ | 100 defined(__ARM_ARCH_7R__) || \ |
201 defined(__ARM_ARCH_7__) | 101 defined(__ARM_ARCH_7__) |
202 # define CAN_USE_ARMV7_INSTRUCTIONS 1 | 102 # define CAN_USE_ARMV7_INSTRUCTIONS 1 |
203 # ifndef CAN_USE_VFP3_INSTRUCTIONS | 103 # ifndef CAN_USE_VFP3_INSTRUCTIONS |
204 # define CAN_USE_VFP3_INSTRUCTIONS 1 | 104 # define CAN_USE_VFP3_INSTRUCTIONS |
205 # endif | 105 # endif |
206 #endif | 106 #endif |
207 | 107 |
208 | 108 |
209 // ---------------------------------------------------------------------------- | |
210 // Target architecture detection. This may be set externally. If not, detect | 109 // Target architecture detection. This may be set externally. If not, detect |
211 // in the same way as the host architecture, that is, target the native | 110 // in the same way as the host architecture, that is, target the native |
212 // environment as presented by the compiler. | 111 // environment as presented by the compiler. |
213 | |
214 #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && \ | 112 #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && \ |
215 !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS | 113 !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS |
216 # if V8_HOST_ARCH_X64 | 114 #if defined(_M_X64) || defined(__x86_64__) |
217 # define V8_TARGET_ARCH_X64 1 | 115 #define V8_TARGET_ARCH_X64 1 |
218 # elif V8_HOST_ARCH_IA32 | 116 #elif defined(_M_IX86) || defined(__i386__) |
219 # define V8_TARGET_ARCH_IA32 1 | 117 #define V8_TARGET_ARCH_IA32 1 |
220 # elif V8_HOST_ARCH_ARM | 118 #elif defined(__ARMEL__) |
221 # define V8_TARGET_ARCH_ARM 1 | 119 #define V8_TARGET_ARCH_ARM 1 |
222 # elif V8_HOST_ARCH_MIPS | 120 #elif defined(__MIPSEL__) |
223 # define V8_TARGET_ARCH_MIPS 1 | 121 #define V8_TARGET_ARCH_MIPS 1 |
224 # else | 122 #else |
225 # error Target architecture was not detected as supported by v8 | 123 #error Target architecture was not detected as supported by v8 |
226 # endif | 124 #endif |
227 #endif | 125 #endif |
228 | 126 |
229 // Check for supported combinations of host and target architectures. | 127 // Check for supported combinations of host and target architectures. |
230 #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32 | 128 #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32 |
231 # error Target architecture ia32 is only supported on ia32 host | 129 #error Target architecture ia32 is only supported on ia32 host |
232 #elif V8_TARGET_ARCH_X64 && !V8_HOST_ARCH_X64 | 130 #endif |
233 # error Target architecture x64 is only supported on x64 host | 131 #if V8_TARGET_ARCH_X64 && !V8_HOST_ARCH_X64 |
234 #elif V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM) | 132 #error Target architecture x64 is only supported on x64 host |
235 # error Target architecture arm is only supported on arm and ia32 host | 133 #endif |
236 #elif V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS) | 134 #if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM)) |
237 # error Target architecture mips is only supported on mips and ia32 host | 135 #error Target architecture arm is only supported on arm and ia32 host |
| 136 #endif |
| 137 #if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS)) |
| 138 #error Target architecture mips is only supported on mips and ia32 host |
238 #endif | 139 #endif |
239 | 140 |
240 // Determine whether we are running in a simulated environment. | 141 // Determine whether we are running in a simulated environment. |
241 // Setting USE_SIMULATOR explicitly from the build script will force | 142 // Setting USE_SIMULATOR explicitly from the build script will force |
242 // the use of a simulated environment. | 143 // the use of a simulated environment. |
243 #if !defined(USE_SIMULATOR) | 144 #if !defined(USE_SIMULATOR) |
244 # if V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM | 145 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM) |
245 # define USE_SIMULATOR 1 | 146 #define USE_SIMULATOR 1 |
246 # elif V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS | 147 #endif |
247 # define USE_SIMULATOR 1 | 148 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS) |
248 # endif | 149 #define USE_SIMULATOR 1 |
| 150 #endif |
249 #endif | 151 #endif |
250 | 152 |
251 // Determine architecture endiannes (we only support little-endian). | 153 // Determine architecture endiannes (we only support little-endian). |
252 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64 || \ | 154 #if V8_TARGET_ARCH_IA32 |
253 V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | 155 #define V8_TARGET_LITTLE_ENDIAN 1 |
254 # define V8_TARGET_LITTLE_ENDIAN 1 | 156 #elif V8_TARGET_ARCH_X64 |
| 157 #define V8_TARGET_LITTLE_ENDIAN 1 |
| 158 #elif V8_TARGET_ARCH_ARM |
| 159 #define V8_TARGET_LITTLE_ENDIAN 1 |
| 160 #elif V8_TARGET_ARCH_MIPS |
| 161 #define V8_TARGET_LITTLE_ENDIAN 1 |
255 #else | 162 #else |
256 # error Unknown target architecture endiannes | 163 #error Unknown target architecture endiannes |
257 #endif | 164 #endif |
258 | 165 |
259 | |
260 // ---------------------------------------------------------------------------- | |
261 // Define our own macros for writing 64-bit constants. This is less fragile | |
262 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it | |
263 // works on compilers that don't have it (like MSVC). | |
264 #if V8_HOST_ARCH_64_BIT | |
265 # if V8_CC_MSVC | |
266 # define V8_UINT64_C(x) (x ## UI64) | |
267 # define V8_INT64_C(x) (x ## I64) | |
268 # define V8_INTPTR_C(x) (x ## I64) | |
269 # define V8_PTR_PREFIX "ll" | |
270 # elif V8_CC_MINGW | |
271 # define V8_UINT64_C(x) (x ## ULL) | |
272 # define V8_INT64_C(x) (x ## LL) | |
273 # define V8_INTPTR_C(x) (x ## LL) | |
274 # define V8_PTR_PREFIX "I64" | |
275 # else | |
276 # define V8_UINT64_C(x) (x ## UL) | |
277 # define V8_INT64_C(x) (x ## L) | |
278 # define V8_INTPTR_C(x) (x ## L) | |
279 # define V8_PTR_PREFIX "l" | |
280 # endif | |
281 #else // V8_HOST_ARCH_64_BIT | |
282 # define V8_INTPTR_C(x) (x) | |
283 # define V8_PTR_PREFIX "" | |
284 #endif // V8_HOST_ARCH_64_BIT | |
285 | |
286 // The following macro works on both 32 and 64-bit platforms. | |
287 // Usage: instead of writing 0x1234567890123456 | |
288 // write V8_2PART_UINT64_C(0x12345678,90123456); | |
289 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) | |
290 | |
291 #if V8_OS_DARWIN | |
292 // Fix for Mac OS X defining uintptr_t as "unsigned long": | |
293 # define V8PRIxPTR "lx" | |
294 #else | |
295 # define V8PRIxPTR V8_PTR_PREFIX "x" | |
296 #endif // V8_OS_DARWIN | |
297 #define V8PRIdPTR V8_PTR_PREFIX "d" | |
298 #define V8PRIuPTR V8_PTR_PREFIX "u" | |
299 | |
300 | |
301 // ---------------------------------------------------------------------------- | |
302 // Define V8_INFINITY | |
303 #if V8_GNUC_PREREQ(2, 96) && !V8_GNUC_PREREQ(4, 1) | |
304 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' | |
305 // warning flag and certain versions of GCC due to a bug: | |
306 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 | |
307 // For now, we use the more involved template-based version from <limits>, but | |
308 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) | |
309 # include <limits> | |
310 # define V8_INFINITY std::numeric_limits<double>::infinity() | |
311 #elif V8_CC_MSVC | |
312 # define V8_INFINITY HUGE_VAL | |
313 #else | |
314 # define V8_INFINITY INFINITY | |
315 #endif | |
316 | |
317 | |
318 #include "../include/v8stdint.h" | |
319 | |
320 namespace v8 { | |
321 namespace internal { | |
322 | |
323 // Support for alternative bool type. This is only enabled if the code is | 166 // Support for alternative bool type. This is only enabled if the code is |
324 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. | 167 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. |
325 // For instance, 'bool b = "false";' results in b == true! This is a hidden | 168 // For instance, 'bool b = "false";' results in b == true! This is a hidden |
326 // source of bugs. | 169 // source of bugs. |
327 // However, redefining the bool type does have some negative impact on some | 170 // However, redefining the bool type does have some negative impact on some |
328 // platforms. It gives rise to compiler warnings (i.e. with | 171 // platforms. It gives rise to compiler warnings (i.e. with |
329 // MSVC) in the API header files when mixing code that uses the standard | 172 // MSVC) in the API header files when mixing code that uses the standard |
330 // bool with code that uses the redefined version. | 173 // bool with code that uses the redefined version. |
331 // This does not actually belong in the platform code, but needs to be | 174 // This does not actually belong in the platform code, but needs to be |
332 // defined here because the platform code uses bool, and platform.h is | 175 // defined here because the platform code uses bool, and platform.h is |
333 // include very early in the main include file. | 176 // include very early in the main include file. |
334 | 177 |
335 #ifdef USE_MYBOOL | 178 #ifdef USE_MYBOOL |
336 typedef unsigned int __my_bool__; | 179 typedef unsigned int __my_bool__; |
337 #define bool __my_bool__ // use 'indirection' to avoid name clashes | 180 #define bool __my_bool__ // use 'indirection' to avoid name clashes |
338 #endif | 181 #endif |
339 | 182 |
340 typedef uint8_t byte; | 183 typedef uint8_t byte; |
341 typedef byte* Address; | 184 typedef byte* Address; |
342 | 185 |
| 186 // Define our own macros for writing 64-bit constants. This is less fragile |
| 187 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it |
| 188 // works on compilers that don't have it (like MSVC). |
| 189 #if V8_HOST_ARCH_64_BIT |
| 190 #if defined(_MSC_VER) |
| 191 #define V8_UINT64_C(x) (x ## UI64) |
| 192 #define V8_INT64_C(x) (x ## I64) |
| 193 #define V8_INTPTR_C(x) (x ## I64) |
| 194 #define V8_PTR_PREFIX "ll" |
| 195 #elif defined(__MINGW64__) |
| 196 #define V8_UINT64_C(x) (x ## ULL) |
| 197 #define V8_INT64_C(x) (x ## LL) |
| 198 #define V8_INTPTR_C(x) (x ## LL) |
| 199 #define V8_PTR_PREFIX "I64" |
| 200 #else |
| 201 #define V8_UINT64_C(x) (x ## UL) |
| 202 #define V8_INT64_C(x) (x ## L) |
| 203 #define V8_INTPTR_C(x) (x ## L) |
| 204 #define V8_PTR_PREFIX "l" |
| 205 #endif |
| 206 #else // V8_HOST_ARCH_64_BIT |
| 207 #define V8_INTPTR_C(x) (x) |
| 208 #define V8_PTR_PREFIX "" |
| 209 #endif // V8_HOST_ARCH_64_BIT |
| 210 |
| 211 // The following macro works on both 32 and 64-bit platforms. |
| 212 // Usage: instead of writing 0x1234567890123456 |
| 213 // write V8_2PART_UINT64_C(0x12345678,90123456); |
| 214 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) |
| 215 |
| 216 #define V8PRIxPTR V8_PTR_PREFIX "x" |
| 217 #define V8PRIdPTR V8_PTR_PREFIX "d" |
| 218 #define V8PRIuPTR V8_PTR_PREFIX "u" |
| 219 |
| 220 // Fix for Mac OS X defining uintptr_t as "unsigned long": |
| 221 #if defined(__APPLE__) && defined(__MACH__) |
| 222 #undef V8PRIxPTR |
| 223 #define V8PRIxPTR "lx" |
| 224 #endif |
| 225 |
| 226 #if (defined(__APPLE__) && defined(__MACH__)) || \ |
| 227 defined(__FreeBSD__) || defined(__OpenBSD__) |
| 228 #define USING_BSD_ABI |
| 229 #endif |
| 230 |
343 // ----------------------------------------------------------------------------- | 231 // ----------------------------------------------------------------------------- |
344 // Constants | 232 // Constants |
345 | 233 |
346 const int KB = 1024; | 234 const int KB = 1024; |
347 const int MB = KB * KB; | 235 const int MB = KB * KB; |
348 const int GB = KB * KB * KB; | 236 const int GB = KB * KB * KB; |
349 const int kMaxInt = 0x7FFFFFFF; | 237 const int kMaxInt = 0x7FFFFFFF; |
350 const int kMinInt = -kMaxInt - 1; | 238 const int kMinInt = -kMaxInt - 1; |
351 | 239 |
352 const uint32_t kMaxUInt32 = 0xFFFFFFFFu; | 240 const uint32_t kMaxUInt32 = 0xFFFFFFFFu; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 323 |
436 | 324 |
437 // FUNCTION_CAST<F>(addr) casts an address into a function | 325 // FUNCTION_CAST<F>(addr) casts an address into a function |
438 // of type F. Used to invoke generated code from within C. | 326 // of type F. Used to invoke generated code from within C. |
439 template <typename F> | 327 template <typename F> |
440 F FUNCTION_CAST(Address addr) { | 328 F FUNCTION_CAST(Address addr) { |
441 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); | 329 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); |
442 } | 330 } |
443 | 331 |
444 | 332 |
445 #if V8_CXX_DELETED_FUNCTIONS | 333 #if __cplusplus >= 201103L |
446 # define DISALLOW_BY_DELETE = delete | 334 #define DISALLOW_BY_DELETE = delete |
447 #else | 335 #else |
448 # define DISALLOW_BY_DELETE | 336 #define DISALLOW_BY_DELETE |
449 #endif | 337 #endif |
450 | 338 |
451 | 339 |
452 // A macro to disallow the evil copy constructor and operator= functions | 340 // A macro to disallow the evil copy constructor and operator= functions |
453 // This should be used in the private: declarations for a class | 341 // This should be used in the private: declarations for a class |
454 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 342 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
455 TypeName(const TypeName&) DISALLOW_BY_DELETE; \ | 343 TypeName(const TypeName&) DISALLOW_BY_DELETE; \ |
456 void operator=(const TypeName&) DISALLOW_BY_DELETE | 344 void operator=(const TypeName&) DISALLOW_BY_DELETE |
457 | 345 |
458 | 346 |
459 // A macro to disallow all the implicit constructors, namely the | 347 // A macro to disallow all the implicit constructors, namely the |
460 // default constructor, copy constructor and operator= functions. | 348 // default constructor, copy constructor and operator= functions. |
461 // | 349 // |
462 // This should be used in the private: declarations for a class | 350 // This should be used in the private: declarations for a class |
463 // that wants to prevent anyone from instantiating it. This is | 351 // that wants to prevent anyone from instantiating it. This is |
464 // especially useful for classes containing only static methods. | 352 // especially useful for classes containing only static methods. |
465 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 353 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
466 TypeName() DISALLOW_BY_DELETE; \ | 354 TypeName() DISALLOW_BY_DELETE; \ |
467 DISALLOW_COPY_AND_ASSIGN(TypeName) | 355 DISALLOW_COPY_AND_ASSIGN(TypeName) |
468 | 356 |
469 | 357 |
470 // Define used for helping GCC to make better inlining. Don't bother for debug | 358 // Define used for helping GCC to make better inlining. Don't bother for debug |
471 // builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation | 359 // builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation |
472 // errors in debug build. | 360 // errors in debug build. |
473 #if V8_GNUC_PREREQ(4, 0) && !defined(DEBUG) | 361 #if defined(__GNUC__) && !defined(DEBUG) |
474 # define INLINE(header) inline header __attribute__((always_inline)) | 362 #if (__GNUC__ >= 4) |
475 # define NO_INLINE(header) header __attribute__((noinline)) | 363 #define INLINE(header) inline header __attribute__((always_inline)) |
476 #elif V8_CC_GNU && !defined(DEBUG) | 364 #define NO_INLINE(header) header __attribute__((noinline)) |
477 # define INLINE(header) inline __attribute__((always_inline)) header | |
478 # define NO_INLINE(header) __attribute__((noinline)) header | |
479 #elif V8_CC_MSVC && !defined(DEBUG) | |
480 # define INLINE(header) __forceinline header | |
481 # define NO_INLINE(header) header | |
482 #else | 365 #else |
483 # define INLINE(header) inline header | 366 #define INLINE(header) inline __attribute__((always_inline)) header |
484 # define NO_INLINE(header) header | 367 #define NO_INLINE(header) __attribute__((noinline)) header |
| 368 #endif |
| 369 #elif defined(_MSC_VER) && !defined(DEBUG) |
| 370 #define INLINE(header) __forceinline header |
| 371 #define NO_INLINE(header) header |
| 372 #else |
| 373 #define INLINE(header) inline header |
| 374 #define NO_INLINE(header) header |
485 #endif | 375 #endif |
486 | 376 |
487 | 377 |
488 #if V8_GNUC_PREREQ(4, 0) | 378 #if defined(__GNUC__) && __GNUC__ >= 4 |
489 #define MUST_USE_RESULT __attribute__ ((warn_unused_result)) | 379 #define MUST_USE_RESULT __attribute__ ((warn_unused_result)) |
490 #else | 380 #else |
491 #define MUST_USE_RESULT | 381 #define MUST_USE_RESULT |
492 #endif | 382 #endif |
493 | 383 |
494 | 384 |
495 // Define DISABLE_ASAN macros. | 385 // Define DISABLE_ASAN macros. |
496 #if defined(__has_feature) | 386 #if defined(__has_feature) |
497 #if __has_feature(address_sanitizer) | 387 #if __has_feature(address_sanitizer) |
498 #define DISABLE_ASAN __attribute__((no_address_safety_analysis)) | 388 #define DISABLE_ASAN __attribute__((no_address_safety_analysis)) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 // the backend, so both modes are represented by the kStrictMode value. | 443 // the backend, so both modes are represented by the kStrictMode value. |
554 enum StrictModeFlag { | 444 enum StrictModeFlag { |
555 kNonStrictMode, | 445 kNonStrictMode, |
556 kStrictMode | 446 kStrictMode |
557 }; | 447 }; |
558 | 448 |
559 | 449 |
560 } } // namespace v8::internal | 450 } } // namespace v8::internal |
561 | 451 |
562 #endif // V8_GLOBALS_H_ | 452 #endif // V8_GLOBALS_H_ |
OLD | NEW |