kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 28 | #ifndef V8_GLOBALS_H_ |
| 29 | #define V8_GLOBALS_H_ |
| 30 | |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 31 | #include "../include/v8stdint.h" |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 32 | |
danno@chromium.org | 935781b | 2013-07-30 11:09:46 +0000 | [diff] [blame] | 33 | // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' |
| 34 | // warning flag and certain versions of GCC due to a bug: |
| 35 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 |
| 36 | // For now, we use the more involved template-based version from <limits>, but |
| 37 | // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 38 | #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0) |
| 39 | # include <limits> // NOLINT |
| 40 | # define V8_INFINITY std::numeric_limits<double>::infinity() |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 41 | #elif V8_CC_MSVC |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 42 | # define V8_INFINITY HUGE_VAL |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 43 | #else |
| 44 | # define V8_INFINITY INFINITY |
danno@chromium.org | 935781b | 2013-07-30 11:09:46 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
danno@chromium.org | 935781b | 2013-07-30 11:09:46 +0000 | [diff] [blame] | 47 | namespace v8 { |
| 48 | namespace internal { |
| 49 | |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 50 | // Processor architecture detection. For more info on what's defined, see: |
| 51 | // http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
| 52 | // http://www.agner.org/optimize/calling_conventions.pdf |
| 53 | // or with gcc, run: "echo | gcc -E -dM -" |
| 54 | #if defined(_M_X64) || defined(__x86_64__) |
| 55 | #if defined(__native_client__) |
| 56 | // For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8 |
| 57 | // generates ARM machine code, together with a portable ARM simulator |
| 58 | // compiled for the host architecture in question. |
| 59 | // |
| 60 | // Since Native Client is ILP-32 on all architectures we use |
| 61 | // V8_HOST_ARCH_IA32 on both 32- and 64-bit x86. |
| 62 | #define V8_HOST_ARCH_IA32 1 |
| 63 | #define V8_HOST_ARCH_32_BIT 1 |
| 64 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 65 | #else |
| 66 | #define V8_HOST_ARCH_X64 1 |
| 67 | #define V8_HOST_ARCH_64_BIT 1 |
| 68 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 69 | #endif // __native_client__ |
| 70 | #elif defined(_M_IX86) || defined(__i386__) |
| 71 | #define V8_HOST_ARCH_IA32 1 |
| 72 | #define V8_HOST_ARCH_32_BIT 1 |
| 73 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 74 | #elif defined(__ARMEL__) |
| 75 | #define V8_HOST_ARCH_ARM 1 |
| 76 | #define V8_HOST_ARCH_32_BIT 1 |
| 77 | #elif defined(__MIPSEL__) |
| 78 | #define V8_HOST_ARCH_MIPS 1 |
| 79 | #define V8_HOST_ARCH_32_BIT 1 |
| 80 | #else |
| 81 | #error Host architecture was not detected as supported by v8 |
| 82 | #endif |
| 83 | |
| 84 | #if defined(__ARM_ARCH_7A__) || \ |
| 85 | defined(__ARM_ARCH_7R__) || \ |
| 86 | defined(__ARM_ARCH_7__) |
| 87 | # define CAN_USE_ARMV7_INSTRUCTIONS 1 |
| 88 | # ifndef CAN_USE_VFP3_INSTRUCTIONS |
| 89 | # define CAN_USE_VFP3_INSTRUCTIONS |
| 90 | # endif |
| 91 | #endif |
| 92 | |
| 93 | |
| 94 | // Target architecture detection. This may be set externally. If not, detect |
| 95 | // in the same way as the host architecture, that is, target the native |
| 96 | // environment as presented by the compiler. |
| 97 | #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && \ |
| 98 | !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS |
| 99 | #if defined(_M_X64) || defined(__x86_64__) |
| 100 | #define V8_TARGET_ARCH_X64 1 |
| 101 | #elif defined(_M_IX86) || defined(__i386__) |
| 102 | #define V8_TARGET_ARCH_IA32 1 |
| 103 | #elif defined(__ARMEL__) |
| 104 | #define V8_TARGET_ARCH_ARM 1 |
| 105 | #elif defined(__MIPSEL__) |
| 106 | #define V8_TARGET_ARCH_MIPS 1 |
| 107 | #else |
| 108 | #error Target architecture was not detected as supported by v8 |
| 109 | #endif |
| 110 | #endif |
| 111 | |
| 112 | // Check for supported combinations of host and target architectures. |
| 113 | #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32 |
| 114 | #error Target architecture ia32 is only supported on ia32 host |
| 115 | #endif |
| 116 | #if V8_TARGET_ARCH_X64 && !V8_HOST_ARCH_X64 |
| 117 | #error Target architecture x64 is only supported on x64 host |
| 118 | #endif |
| 119 | #if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM)) |
| 120 | #error Target architecture arm is only supported on arm and ia32 host |
| 121 | #endif |
| 122 | #if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS)) |
| 123 | #error Target architecture mips is only supported on mips and ia32 host |
| 124 | #endif |
| 125 | |
| 126 | // Determine whether we are running in a simulated environment. |
| 127 | // Setting USE_SIMULATOR explicitly from the build script will force |
| 128 | // the use of a simulated environment. |
| 129 | #if !defined(USE_SIMULATOR) |
| 130 | #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM) |
| 131 | #define USE_SIMULATOR 1 |
| 132 | #endif |
| 133 | #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS) |
| 134 | #define USE_SIMULATOR 1 |
| 135 | #endif |
| 136 | #endif |
| 137 | |
| 138 | // Determine architecture endiannes (we only support little-endian). |
| 139 | #if V8_TARGET_ARCH_IA32 |
| 140 | #define V8_TARGET_LITTLE_ENDIAN 1 |
| 141 | #elif V8_TARGET_ARCH_X64 |
| 142 | #define V8_TARGET_LITTLE_ENDIAN 1 |
| 143 | #elif V8_TARGET_ARCH_ARM |
| 144 | #define V8_TARGET_LITTLE_ENDIAN 1 |
| 145 | #elif V8_TARGET_ARCH_MIPS |
| 146 | #define V8_TARGET_LITTLE_ENDIAN 1 |
| 147 | #else |
| 148 | #error Unknown target architecture endiannes |
| 149 | #endif |
| 150 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 151 | // Support for alternative bool type. This is only enabled if the code is |
| 152 | // compiled with USE_MYBOOL defined. This catches some nasty type bugs. |
| 153 | // For instance, 'bool b = "false";' results in b == true! This is a hidden |
| 154 | // source of bugs. |
| 155 | // However, redefining the bool type does have some negative impact on some |
| 156 | // platforms. It gives rise to compiler warnings (i.e. with |
| 157 | // MSVC) in the API header files when mixing code that uses the standard |
| 158 | // bool with code that uses the redefined version. |
| 159 | // This does not actually belong in the platform code, but needs to be |
| 160 | // defined here because the platform code uses bool, and platform.h is |
| 161 | // include very early in the main include file. |
| 162 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | #ifdef USE_MYBOOL |
| 164 | typedef unsigned int __my_bool__; |
| 165 | #define bool __my_bool__ // use 'indirection' to avoid name clashes |
| 166 | #endif |
| 167 | |
| 168 | typedef uint8_t byte; |
| 169 | typedef byte* Address; |
| 170 | |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 171 | // Define our own macros for writing 64-bit constants. This is less fragile |
| 172 | // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it |
| 173 | // works on compilers that don't have it (like MSVC). |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 174 | #if V8_CC_MSVC |
| 175 | # define V8_UINT64_C(x) (x ## UI64) |
| 176 | # define V8_INT64_C(x) (x ## I64) |
| 177 | # if V8_HOST_ARCH_64_BIT |
| 178 | # define V8_INTPTR_C(x) (x ## I64) |
| 179 | # define V8_PTR_PREFIX "ll" |
| 180 | # else |
| 181 | # define V8_INTPTR_C(x) (x) |
| 182 | # define V8_PTR_PREFIX "" |
| 183 | # endif // V8_HOST_ARCH_64_BIT |
| 184 | #elif V8_CC_MINGW64 |
| 185 | # define V8_UINT64_C(x) (x ## ULL) |
| 186 | # define V8_INT64_C(x) (x ## LL) |
| 187 | # define V8_INTPTR_C(x) (x ## LL) |
| 188 | # define V8_PTR_PREFIX "I64" |
| 189 | #elif V8_HOST_ARCH_64_BIT |
| 190 | # define V8_UINT64_C(x) (x ## UL) |
| 191 | # define V8_INT64_C(x) (x ## L) |
| 192 | # define V8_INTPTR_C(x) (x ## L) |
| 193 | # define V8_PTR_PREFIX "l" |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 194 | #else |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 195 | # define V8_UINT64_C(x) (x ## ULL) |
| 196 | # define V8_INT64_C(x) (x ## LL) |
| 197 | # define V8_INTPTR_C(x) (x) |
| 198 | # define V8_PTR_PREFIX "" |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 199 | #endif |
danno@chromium.org | c22f2d8 | 2013-07-31 07:47:18 +0000 | [diff] [blame] | 200 | |
| 201 | // The following macro works on both 32 and 64-bit platforms. |
| 202 | // Usage: instead of writing 0x1234567890123456 |
| 203 | // write V8_2PART_UINT64_C(0x12345678,90123456); |
| 204 | #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) |
| 205 | |
| 206 | #define V8PRIxPTR V8_PTR_PREFIX "x" |
| 207 | #define V8PRIdPTR V8_PTR_PREFIX "d" |
| 208 | #define V8PRIuPTR V8_PTR_PREFIX "u" |
| 209 | |
| 210 | // Fix for Mac OS X defining uintptr_t as "unsigned long": |
| 211 | #if defined(__APPLE__) && defined(__MACH__) |
| 212 | #undef V8PRIxPTR |
| 213 | #define V8PRIxPTR "lx" |
| 214 | #endif |
| 215 | |
| 216 | #if (defined(__APPLE__) && defined(__MACH__)) || \ |
| 217 | defined(__FreeBSD__) || defined(__OpenBSD__) |
| 218 | #define USING_BSD_ABI |
| 219 | #endif |
| 220 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | // ----------------------------------------------------------------------------- |
| 222 | // Constants |
| 223 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | const int KB = 1024; |
| 225 | const int MB = KB * KB; |
| 226 | const int GB = KB * KB * KB; |
| 227 | const int kMaxInt = 0x7FFFFFFF; |
| 228 | const int kMinInt = -kMaxInt - 1; |
| 229 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 230 | const uint32_t kMaxUInt32 = 0xFFFFFFFFu; |
| 231 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 232 | const int kCharSize = sizeof(char); // NOLINT |
| 233 | const int kShortSize = sizeof(short); // NOLINT |
| 234 | const int kIntSize = sizeof(int); // NOLINT |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 235 | const int kInt32Size = sizeof(int32_t); // NOLINT |
| 236 | const int kInt64Size = sizeof(int64_t); // NOLINT |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 237 | const int kDoubleSize = sizeof(double); // NOLINT |
| 238 | const int kIntptrSize = sizeof(intptr_t); // NOLINT |
| 239 | const int kPointerSize = sizeof(void*); // NOLINT |
| 240 | const int kRegisterSize = kPointerSize; |
| 241 | const int kPCOnStackSize = kRegisterSize; |
| 242 | const int kFPOnStackSize = kRegisterSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 244 | const int kDoubleSizeLog2 = 3; |
| 245 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 246 | // Size of the state of a the random number generator. |
| 247 | const int kRandomStateSize = 2 * kIntSize; |
| 248 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 249 | #if V8_HOST_ARCH_64_BIT |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 250 | const int kPointerSizeLog2 = 3; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 251 | const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 252 | const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 253 | const bool kIs64BitArch = true; |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 254 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | const int kPointerSizeLog2 = 2; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 256 | const intptr_t kIntptrSignBit = 0x80000000; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 257 | const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 258 | const bool kIs64BitArch = false; |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 259 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | const int kBitsPerByte = 8; |
| 262 | const int kBitsPerByteLog2 = 3; |
| 263 | const int kBitsPerPointer = kPointerSize * kBitsPerByte; |
| 264 | const int kBitsPerInt = kIntSize * kBitsPerByte; |
| 265 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 266 | // IEEE 754 single precision floating point number bit layout. |
| 267 | const uint32_t kBinary32SignMask = 0x80000000u; |
| 268 | const uint32_t kBinary32ExponentMask = 0x7f800000u; |
| 269 | const uint32_t kBinary32MantissaMask = 0x007fffffu; |
| 270 | const int kBinary32ExponentBias = 127; |
| 271 | const int kBinary32MaxExponent = 0xFE; |
| 272 | const int kBinary32MinExponent = 0x01; |
| 273 | const int kBinary32MantissaBits = 23; |
| 274 | const int kBinary32ExponentShift = 23; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 276 | // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no |
| 277 | // other bits set. |
| 278 | const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51; |
| 279 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 280 | // Latin1/UTF-16 constants |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 281 | // Code-point values in Unicode 4.0 are 21 bits wide. |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 282 | // Code units in UTF-16 are 16 bits wide. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 283 | typedef uint16_t uc16; |
| 284 | typedef int32_t uc32; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 285 | const int kOneByteSize = kCharSize; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 286 | const int kUC16Size = sizeof(uc16); // NOLINT |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 287 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 288 | |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 289 | // Round up n to be a multiple of sz, where sz is a power of 2. |
| 290 | #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) |
| 291 | |
| 292 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | // The expression OFFSET_OF(type, field) computes the byte-offset |
| 294 | // of the specified field relative to the containing type. This |
| 295 | // corresponds to 'offsetof' (in stddef.h), except that it doesn't |
| 296 | // use 0 or NULL, which causes a problem with the compiler warnings |
| 297 | // we have enabled (which is also why 'offsetof' doesn't seem to work). |
| 298 | // Here we simply use the non-zero value 4, which seems to work. |
| 299 | #define OFFSET_OF(type, field) \ |
| 300 | (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) |
| 301 | |
| 302 | |
| 303 | // The expression ARRAY_SIZE(a) is a compile-time constant of type |
| 304 | // size_t which represents the number of elements of the given |
| 305 | // array. You should only use ARRAY_SIZE on statically allocated |
| 306 | // arrays. |
| 307 | #define ARRAY_SIZE(a) \ |
| 308 | ((sizeof(a) / sizeof(*(a))) / \ |
| 309 | static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) |
| 310 | |
| 311 | |
| 312 | // The USE(x) template is used to silence C++ compiler warnings |
| 313 | // issued for (yet) unused variables (typically parameters). |
| 314 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 315 | inline void USE(T) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | |
| 317 | |
| 318 | // FUNCTION_ADDR(f) gets the address of a C function f. |
| 319 | #define FUNCTION_ADDR(f) \ |
| 320 | (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) |
| 321 | |
| 322 | |
| 323 | // FUNCTION_CAST<F>(addr) casts an address into a function |
| 324 | // of type F. Used to invoke generated code from within C. |
| 325 | template <typename F> |
| 326 | F FUNCTION_CAST(Address addr) { |
| 327 | return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | // A macro to disallow the evil copy constructor and operator= functions |
| 332 | // This should be used in the private: declarations for a class |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 333 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
| 334 | TypeName(const TypeName&) V8_DELETE; \ |
| 335 | void operator=(const TypeName&) V8_DELETE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | |
| 337 | |
| 338 | // A macro to disallow all the implicit constructors, namely the |
| 339 | // default constructor, copy constructor and operator= functions. |
| 340 | // |
| 341 | // This should be used in the private: declarations for a class |
| 342 | // that wants to prevent anyone from instantiating it. This is |
| 343 | // especially useful for classes containing only static methods. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 344 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
| 345 | TypeName() V8_DELETE; \ |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 346 | DISALLOW_COPY_AND_ASSIGN(TypeName) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | |
| 348 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 349 | // Newly written code should use V8_INLINE and V8_NOINLINE directly. |
| 350 | #define INLINE(declarator) V8_INLINE declarator |
| 351 | #define NO_INLINE(declarator) V8_NOINLINE declarator |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 352 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 353 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 354 | // Newly written code should use V8_WARN_UNUSED_RESULT. |
| 355 | #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 356 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 357 | |
| 358 | // Define DISABLE_ASAN macros. |
| 359 | #if defined(__has_feature) |
| 360 | #if __has_feature(address_sanitizer) |
| 361 | #define DISABLE_ASAN __attribute__((no_address_safety_analysis)) |
| 362 | #endif |
| 363 | #endif |
| 364 | |
| 365 | |
| 366 | #ifndef DISABLE_ASAN |
| 367 | #define DISABLE_ASAN |
| 368 | #endif |
| 369 | |
| 370 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 371 | // ----------------------------------------------------------------------------- |
| 372 | // Forward declarations for frequently used classes |
| 373 | // (sorted alphabetically) |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 374 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 375 | class FreeStoreAllocationPolicy; |
| 376 | template <typename T, class P = FreeStoreAllocationPolicy> class List; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 377 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 378 | // ----------------------------------------------------------------------------- |
| 379 | // Declarations for use in both the preparser and the rest of V8. |
| 380 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 381 | // The different language modes that V8 implements. ES5 defines two language |
| 382 | // modes: an unrestricted mode respectively a strict mode which are indicated by |
| 383 | // CLASSIC_MODE respectively STRICT_MODE in the enum. The harmony spec drafts |
| 384 | // for the next ES standard specify a new third mode which is called 'extended |
| 385 | // mode'. The extended mode is only available if the harmony flag is set. It is |
| 386 | // based on the 'strict mode' and adds new functionality to it. This means that |
| 387 | // most of the semantics of these two modes coincide. |
| 388 | // |
| 389 | // In the current draft the term 'base code' is used to refer to code that is |
| 390 | // neither in strict nor extended mode. However, the more distinguishing term |
| 391 | // 'classic mode' is used in V8 instead to avoid mix-ups. |
| 392 | |
| 393 | enum LanguageMode { |
| 394 | CLASSIC_MODE, |
| 395 | STRICT_MODE, |
| 396 | EXTENDED_MODE |
| 397 | }; |
| 398 | |
| 399 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 400 | // The Strict Mode (ECMA-262 5th edition, 4.2.2). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 401 | // |
| 402 | // This flag is used in the backend to represent the language mode. So far |
| 403 | // there is no semantic difference between the strict and the extended mode in |
| 404 | // the backend, so both modes are represented by the kStrictMode value. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 405 | enum StrictModeFlag { |
| 406 | kNonStrictMode, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 407 | kStrictMode |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 408 | }; |
| 409 | |
| 410 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | } } // namespace v8::internal |
| 412 | |
| 413 | #endif // V8_GLOBALS_H_ |