OLD | NEW |
1 // Copyright (c) 2012, 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 BIN_DARTUTILS_H_ | 5 #ifndef BIN_DARTUTILS_H_ |
6 #define BIN_DARTUTILS_H_ | 6 #define BIN_DARTUTILS_H_ |
7 | 7 |
8 #include "bin/isolate_data.h" | 8 #include "bin/isolate_data.h" |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_native_api.h" | 10 #include "include/dart_native_api.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 * functions can also be nested without this error check, since all | 26 * functions can also be nested without this error check, since all |
27 * API functions return any error handles passed in as arguments, unchanged. | 27 * API functions return any error handles passed in as arguments, unchanged. |
28 */ | 28 */ |
29 static inline Dart_Handle ThrowIfError(Dart_Handle handle) { | 29 static inline Dart_Handle ThrowIfError(Dart_Handle handle) { |
30 if (Dart_IsError(handle)) { | 30 if (Dart_IsError(handle)) { |
31 Dart_PropagateError(handle); | 31 Dart_PropagateError(handle); |
32 } | 32 } |
33 return handle; | 33 return handle; |
34 } | 34 } |
35 | 35 |
| 36 // Tries to read [script_uri] as a Kernel IR file. If successful this function |
| 37 // returns `true` and sets [kernel_file] and [kernel_length] to be the memory |
| 38 // contents. |
| 39 // |
| 40 // The caller is responsible for free()ing [kernel_file] if `true` was returned. |
| 41 bool TryReadKernel(const char* script_uri, |
| 42 const uint8_t** kernel_file, |
| 43 intptr_t* kernel_length); |
| 44 |
36 class CommandLineOptions { | 45 class CommandLineOptions { |
37 public: | 46 public: |
38 explicit CommandLineOptions(int max_count) | 47 explicit CommandLineOptions(int max_count) |
39 : count_(0), max_count_(max_count), arguments_(NULL) { | 48 : count_(0), max_count_(max_count), arguments_(NULL) { |
40 static const int kWordSize = sizeof(intptr_t); | 49 static const int kWordSize = sizeof(intptr_t); |
41 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); | 50 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); |
42 if (arguments_ == NULL) { | 51 if (arguments_ == NULL) { |
43 max_count_ = 0; | 52 max_count_ = 0; |
44 } | 53 } |
45 } | 54 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 202 } |
194 | 203 |
195 static bool SetOriginalWorkingDirectory(); | 204 static bool SetOriginalWorkingDirectory(); |
196 static Dart_Handle GetCanonicalizableWorkingDirectory(); | 205 static Dart_Handle GetCanonicalizableWorkingDirectory(); |
197 | 206 |
198 static const char* MapLibraryUrl(const char* url_string); | 207 static const char* MapLibraryUrl(const char* url_string); |
199 | 208 |
200 static Dart_Handle ResolveUriInWorkingDirectory(Dart_Handle script_uri); | 209 static Dart_Handle ResolveUriInWorkingDirectory(Dart_Handle script_uri); |
201 static Dart_Handle ResolveScript(Dart_Handle url); | 210 static Dart_Handle ResolveScript(Dart_Handle url); |
202 | 211 |
| 212 enum MagicNumber { |
| 213 kSnapshotMagicNumber, |
| 214 kKernelMagicNumber, |
| 215 kUnknownMagicNumber |
| 216 }; |
| 217 |
| 218 // static const uint8_t* GetMagicNumber(MagicNumber number); |
| 219 |
203 // Sniffs the specified text_buffer to see if it contains the magic number | 220 // Sniffs the specified text_buffer to see if it contains the magic number |
204 // representing a script snapshot. If the text_buffer is a script snapshot | 221 // representing a script snapshot. If the text_buffer is a script snapshot |
205 // the return value is an updated pointer to the text_buffer pointing past | 222 // the return value is an updated pointer to the text_buffer pointing past |
206 // the magic number value. The 'buffer_len' parameter is also appropriately | 223 // the magic number value. The 'buffer_len' parameter is also appropriately |
207 // adjusted. | 224 // adjusted. |
208 static const uint8_t* SniffForMagicNumber(const uint8_t* text_buffer, | 225 static MagicNumber SniffForMagicNumber(const uint8_t** text_buffer, |
209 intptr_t* buffer_len, | 226 intptr_t* buffer_len); |
210 bool* is_snapshot); | |
211 | 227 |
212 // Write a magic number to indicate a script snapshot file. | 228 // Write a magic number to indicate a script snapshot file. |
213 static void WriteMagicNumber(File* file); | 229 static void WriteMagicNumber(File* file); |
214 | 230 |
215 // Global state that stores the original working directory.. | 231 // Global state that stores the original working directory.. |
216 static const char* original_working_directory; | 232 static const char* original_working_directory; |
217 | 233 |
218 // Global state that captures the URL mappings specified on the command line. | 234 // Global state that captures the URL mappings specified on the command line. |
219 static CommandLineOptions* url_mapping; | 235 static CommandLineOptions* url_mapping; |
220 | 236 |
221 static const char* const kDartScheme; | 237 static const char* const kDartScheme; |
222 static const char* const kDartExtensionScheme; | 238 static const char* const kDartExtensionScheme; |
223 static const char* const kAsyncLibURL; | 239 static const char* const kAsyncLibURL; |
224 static const char* const kBuiltinLibURL; | 240 static const char* const kBuiltinLibURL; |
225 static const char* const kCoreLibURL; | 241 static const char* const kCoreLibURL; |
226 static const char* const kInternalLibURL; | 242 static const char* const kInternalLibURL; |
227 static const char* const kIsolateLibURL; | 243 static const char* const kIsolateLibURL; |
228 static const char* const kIOLibURL; | 244 static const char* const kIOLibURL; |
229 static const char* const kIOLibPatchURL; | 245 static const char* const kIOLibPatchURL; |
230 static const char* const kUriLibURL; | 246 static const char* const kUriLibURL; |
231 static const char* const kHttpScheme; | 247 static const char* const kHttpScheme; |
232 static const char* const kVMServiceLibURL; | 248 static const char* const kVMServiceLibURL; |
233 | 249 |
234 static const uint8_t magic_number[]; | |
235 | |
236 static Dart_Handle LibraryFilePath(Dart_Handle library_uri); | 250 static Dart_Handle LibraryFilePath(Dart_Handle library_uri); |
237 | 251 |
238 private: | 252 private: |
239 static Dart_Handle SetWorkingDirectory(); | 253 static Dart_Handle SetWorkingDirectory(); |
240 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 254 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
241 Dart_Handle internal_lib, | 255 Dart_Handle internal_lib, |
242 bool is_service_isolate, | 256 bool is_service_isolate, |
243 bool trace_loading); | 257 bool trace_loading); |
244 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, | 258 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, |
245 Dart_Handle builtin_lib, | 259 Dart_Handle builtin_lib, |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 bool is_typed_data_; | 680 bool is_typed_data_; |
667 | 681 |
668 DISALLOW_ALLOCATION(); | 682 DISALLOW_ALLOCATION(); |
669 DISALLOW_COPY_AND_ASSIGN(ScopedMemBuffer); | 683 DISALLOW_COPY_AND_ASSIGN(ScopedMemBuffer); |
670 }; | 684 }; |
671 | 685 |
672 } // namespace bin | 686 } // namespace bin |
673 } // namespace dart | 687 } // namespace dart |
674 | 688 |
675 #endif // BIN_DARTUTILS_H_ | 689 #endif // BIN_DARTUTILS_H_ |
OLD | NEW |