OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_GLOBALS_H_ | 5 #ifndef VM_GLOBALS_H_ |
6 #define VM_GLOBALS_H_ | 6 #define VM_GLOBALS_H_ |
7 | 7 |
8 // __STDC_FORMAT_MACROS has to be defined to enable platform independent printf. | 8 // This file contains global definitions for the VM library only. Anything that |
9 #ifndef __STDC_FORMAT_MACROS | 9 // is more globally useful should be added to 'vm/globals.h'. |
10 #define __STDC_FORMAT_MACROS | 10 |
11 #endif | 11 #include "platform/globals.h" |
12 | 12 |
13 #if defined(_WIN32) | 13 #if defined(_WIN32) |
14 // Cut down on the amount of stuff that gets included via windows.h. | |
15 #define WIN32_LEAN_AND_MEAN | |
16 #define NOMINMAX | |
17 #define NOKERNEL | |
18 #define NOUSER | |
19 #define NOSERVICE | |
20 #define NOSOUND | |
21 #define NOMCX | |
22 | |
23 #include <windows.h> | |
24 | |
25 // Undef conflicting defines. | 14 // Undef conflicting defines. |
26 #undef PARITY_EVEN | 15 #undef PARITY_EVEN |
27 #undef PARITY_ODD | 16 #undef PARITY_ODD |
28 #undef near | 17 #undef near |
29 #endif | 18 #endif |
30 | 19 |
31 #if !defined(_WIN32) | |
32 #include <inttypes.h> | |
33 #include <stdint.h> | |
34 #endif | |
35 | |
36 #include <float.h> | |
37 #include <limits.h> | |
38 #include <math.h> | |
39 #include <openssl/bn.h> | |
40 #include <stdarg.h> | |
41 #include <stddef.h> | |
42 #include <stdio.h> | |
43 #include <stdlib.h> | |
44 #include <string.h> | |
45 #include <sys/types.h> | |
46 | |
47 #if defined(_WIN32) | |
48 #include "vm/c99_support_win.h" | |
49 #include "vm/inttypes_support_win.h" | |
50 #endif | |
51 | |
52 // The following #defines are invalidated. | 20 // The following #defines are invalidated. |
53 #undef OVERFLOW // From math.h conflicts in constants_ia32.h | 21 #undef OVERFLOW // From math.h conflicts in constants_ia32.h |
54 | 22 |
55 namespace dart { | 23 namespace dart { |
56 | 24 |
57 // Processor architecture detection. For more info on what's defined, see: | 25 // Processor architecture detection. For more info on what's defined, see: |
58 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx | 26 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
59 // http://www.agner.org/optimize/calling_conventions.pdf | 27 // http://www.agner.org/optimize/calling_conventions.pdf |
60 // or with gcc, run: "echo | gcc -E -dM -" | 28 // or with gcc, run: "echo | gcc -E -dM -" |
61 #if defined(_M_X64) || defined(__x86_64__) | 29 #if defined(_M_X64) || defined(__x86_64__) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #if !defined(ARCH_IS_64_BIT) | 62 #if !defined(ARCH_IS_64_BIT) |
95 #error Mismatched Host/Target architectures. | 63 #error Mismatched Host/Target architectures. |
96 #endif | 64 #endif |
97 #elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) | 65 #elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) |
98 #if !defined(ARCH_IS_32_BIT) | 66 #if !defined(ARCH_IS_32_BIT) |
99 #error Mismatched Host/Target architectures. | 67 #error Mismatched Host/Target architectures. |
100 #endif | 68 #endif |
101 #endif | 69 #endif |
102 | 70 |
103 | 71 |
104 // Target OS detection. | |
105 // for more information on predefined macros: | |
106 // - http://msdn.microsoft.com/en-us/library/b0084kay.aspx | |
107 // - with gcc, run: "echo | gcc -E -dM -" | |
108 #if defined(__linux__) || defined(__FreeBSD__) | |
109 #define TARGET_OS_LINUX 1 | |
110 #elif defined(__APPLE__) | |
111 #define TARGET_OS_MACOS 1 | |
112 #elif defined(_WIN32) | |
113 #define TARGET_OS_WINDOWS 1 | |
114 #else | |
115 #error Automatic target os detection failed. | |
116 #endif | |
117 | |
118 | |
119 // Printf format for intptr_t on Windows. | 72 // Printf format for intptr_t on Windows. |
120 #if !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) | 73 #if !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) |
121 #if defined(ARCH_IS_32_BIT) | 74 #if defined(ARCH_IS_32_BIT) |
122 #define PRIxPTR "x" | 75 #define PRIxPTR "x" |
123 #else | 76 #else |
124 #define PRIxPTR "llx" | 77 #define PRIxPTR "llx" |
125 #endif // defined(ARCH_IS_32_BIT) | 78 #endif // defined(ARCH_IS_32_BIT) |
126 #endif // !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) | 79 #endif // !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) |
127 | 80 |
128 | 81 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 const int kMillisecondsPerSecond = 1000; | 130 const int kMillisecondsPerSecond = 1000; |
178 const int kMicrosecondsPerMillisecond = 1000; | 131 const int kMicrosecondsPerMillisecond = 1000; |
179 const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * | 132 const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * |
180 kMillisecondsPerSecond); | 133 kMillisecondsPerSecond); |
181 const int kNanosecondsPerMicrosecond = 1000; | 134 const int kNanosecondsPerMicrosecond = 1000; |
182 const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * | 135 const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * |
183 kMicrosecondsPerMillisecond); | 136 kMicrosecondsPerMillisecond); |
184 const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * | 137 const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * |
185 kMicrosecondsPerSecond); | 138 kMicrosecondsPerSecond); |
186 | 139 |
187 // A macro to disallow the copy constructor and operator= functions. | |
188 // This should be used in the private: declarations for a class. | |
189 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
190 private: \ | |
191 TypeName(const TypeName&); \ | |
192 void operator=(const TypeName&) | |
193 | |
194 | |
195 // A macro to disallow all the implicit constructors, namely the default | |
196 // constructor, copy constructor and operator= functions. This should be | |
197 // used in the private: declarations for a class that wants to prevent | |
198 // anyone from instantiating it. This is especially useful for classes | |
199 // containing only static methods. | |
200 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | |
201 private: \ | |
202 TypeName(); \ | |
203 DISALLOW_COPY_AND_ASSIGN(TypeName) | |
204 | |
205 | |
206 // Macro to disallow allocation in the C++ heap. This should be used | |
207 // in the private section for a class. | |
208 #define DISALLOW_ALLOCATION() \ | |
209 public: \ | |
210 void operator delete(void* pointer) { UNREACHABLE(); } \ | |
211 private: \ | |
212 void* operator new(size_t size); | |
213 | |
214 | |
215 // The expression ARRAY_SIZE(array) is a compile-time constant of type | 140 // The expression ARRAY_SIZE(array) is a compile-time constant of type |
216 // size_t which represents the number of elements of the given | 141 // size_t which represents the number of elements of the given |
217 // array. You should only use ARRAY_SIZE on statically allocated | 142 // array. You should only use ARRAY_SIZE on statically allocated |
218 // arrays. | 143 // arrays. |
219 #define ARRAY_SIZE(array) \ | 144 #define ARRAY_SIZE(array) \ |
220 ((sizeof(array) / sizeof(*(array))) / \ | 145 ((sizeof(array) / sizeof(*(array))) / \ |
221 static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) | 146 static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) |
222 | 147 |
223 | 148 |
224 // The expression OFFSET_OF(type, field) computes the byte-offset of | 149 // The expression OFFSET_OF(type, field) computes the byte-offset of |
225 // the specified field relative to the containing type. | 150 // the specified field relative to the containing type. |
226 // | 151 // |
227 // The expression OFFSET_OF_RETURNED_VALUE(type, accessor) computes the | 152 // The expression OFFSET_OF_RETURNED_VALUE(type, accessor) computes the |
228 // byte-offset of the return value of the accessor to the containing type. | 153 // byte-offset of the return value of the accessor to the containing type. |
229 // | 154 // |
230 // None of these use 0 or NULL, which causes a problem with the compiler | 155 // None of these use 0 or NULL, which causes a problem with the compiler |
231 // warnings we have enabled (which is also why 'offsetof' doesn't seem to work). | 156 // warnings we have enabled (which is also why 'offsetof' doesn't seem to work). |
232 // The workaround is to use the non-zero value kOffsetOfPtr. | 157 // The workaround is to use the non-zero value kOffsetOfPtr. |
233 const intptr_t kOffsetOfPtr = 32; | 158 const intptr_t kOffsetOfPtr = 32; |
234 | 159 |
235 #define OFFSET_OF(type, field) \ | 160 #define OFFSET_OF(type, field) \ |
236 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(kOffsetOfPtr)->field)) \ | 161 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(kOffsetOfPtr)->field)) \ |
237 - kOffsetOfPtr) | 162 - kOffsetOfPtr) |
238 | 163 |
239 #define OFFSET_OF_RETURNED_VALUE(type, accessor) \ | 164 #define OFFSET_OF_RETURNED_VALUE(type, accessor) \ |
240 (reinterpret_cast<intptr_t>( \ | 165 (reinterpret_cast<intptr_t>( \ |
241 (reinterpret_cast<type*>(kOffsetOfPtr)->accessor())) - kOffsetOfPtr) | 166 (reinterpret_cast<type*>(kOffsetOfPtr)->accessor())) - kOffsetOfPtr) |
242 | 167 |
243 | 168 |
244 // The USE(x) template is used to silence C++ compiler warnings issued | |
245 // for unused variables. | |
246 template <typename T> | |
247 static inline void USE(T) { } | |
248 | |
249 | |
250 // Use implicit_cast as a safe version of static_cast or const_cast | 169 // Use implicit_cast as a safe version of static_cast or const_cast |
251 // for upcasting in the type hierarchy (i.e. casting a pointer to Foo | 170 // for upcasting in the type hierarchy (i.e. casting a pointer to Foo |
252 // to a pointer to SuperclassOfFoo or casting a pointer to Foo to | 171 // to a pointer to SuperclassOfFoo or casting a pointer to Foo to |
253 // a const pointer to Foo). | 172 // a const pointer to Foo). |
254 // When you use implicit_cast, the compiler checks that the cast is safe. | 173 // When you use implicit_cast, the compiler checks that the cast is safe. |
255 // Such explicit implicit_casts are necessary in surprisingly many | 174 // Such explicit implicit_casts are necessary in surprisingly many |
256 // situations where C++ demands an exact type match instead of an | 175 // situations where C++ demands an exact type match instead of an |
257 // argument type convertable to a target type. | 176 // argument type convertable to a target type. |
258 // | 177 // |
259 // The From type can be inferred, so the preferred syntax for using | 178 // The From type can be inferred, so the preferred syntax for using |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // contants are 16 byte aligned. | 274 // contants are 16 byte aligned. |
356 #if defined(TARGET_OS_WINDOWS) | 275 #if defined(TARGET_OS_WINDOWS) |
357 #define ALIGN16 __declspec(align(16)) | 276 #define ALIGN16 __declspec(align(16)) |
358 #else | 277 #else |
359 #define ALIGN16 __attribute__((aligned(16))) | 278 #define ALIGN16 __attribute__((aligned(16))) |
360 #endif | 279 #endif |
361 | 280 |
362 } // namespace dart | 281 } // namespace dart |
363 | 282 |
364 #endif // VM_GLOBALS_H_ | 283 #endif // VM_GLOBALS_H_ |
OLD | NEW |