| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 Dart_ExitScope(); | 1263 Dart_ExitScope(); |
| 1264 Dart_ExitIsolate(); | 1264 Dart_ExitIsolate(); |
| 1265 | 1265 |
| 1266 // Now we create an isolate into which we load all the code that needs to | 1266 // Now we create an isolate into which we load all the code that needs to |
| 1267 // be in the snapshot. | 1267 // be in the snapshot. |
| 1268 isolate_data = new IsolateData(NULL, NULL, NULL); | 1268 isolate_data = new IsolateData(NULL, NULL, NULL); |
| 1269 const uint8_t* kernel = NULL; | 1269 const uint8_t* kernel = NULL; |
| 1270 intptr_t kernel_length = 0; | 1270 intptr_t kernel_length = 0; |
| 1271 const bool is_kernel_file = | 1271 const bool is_kernel_file = |
| 1272 TryReadKernel(app_script_name, &kernel, &kernel_length); | 1272 TryReadKernel(app_script_name, &kernel, &kernel_length); |
| 1273 |
| 1274 void* kernel_program = NULL; |
| 1275 if (is_kernel_file) { |
| 1276 kernel_program = Dart_ParseKernelBinary(kernel, kernel_length); |
| 1277 free(const_cast<uint8_t*>(kernel)); |
| 1278 } |
| 1279 |
| 1273 Dart_Isolate isolate = | 1280 Dart_Isolate isolate = |
| 1274 is_kernel_file | 1281 is_kernel_file |
| 1275 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel, kernel_length, | 1282 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, |
| 1276 NULL, isolate_data, &error) | 1283 NULL, isolate_data, &error) |
| 1277 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error); | 1284 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error); |
| 1278 if (isolate == NULL) { | 1285 if (isolate == NULL) { |
| 1279 fprintf(stderr, "%s", error); | 1286 fprintf(stderr, "%s", error); |
| 1280 free(error); | 1287 free(error); |
| 1281 exit(255); | 1288 exit(255); |
| 1282 } | 1289 } |
| 1283 Dart_EnterScope(); | 1290 Dart_EnterScope(); |
| 1284 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1291 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1285 CHECK_RESULT(result); | 1292 CHECK_RESULT(result); |
| 1286 | 1293 |
| 1287 // Set up the library tag handler in such a manner that it will use the | 1294 // Set up the library tag handler in such a manner that it will use the |
| 1288 // URL mapping specified on the command line to load the libraries. | 1295 // URL mapping specified on the command line to load the libraries. |
| 1289 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1296 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 1290 CHECK_RESULT(result); | 1297 CHECK_RESULT(result); |
| 1291 | 1298 |
| 1292 Dart_QualifiedFunctionName* entry_points = | 1299 Dart_QualifiedFunctionName* entry_points = |
| 1293 ParseEntryPointsManifestIfPresent(); | 1300 ParseEntryPointsManifestIfPresent(); |
| 1294 | 1301 |
| 1295 if (is_kernel_file) { | 1302 if (is_kernel_file) { |
| 1296 Dart_Handle library = Dart_LoadKernel(kernel, kernel_length); | 1303 Dart_Handle library = Dart_LoadKernel(kernel_program); |
| 1297 free(const_cast<uint8_t*>(kernel)); | |
| 1298 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); | 1304 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); |
| 1299 } else { | 1305 } else { |
| 1300 // Set up the library tag handler in such a manner that it will use the | 1306 // Set up the library tag handler in such a manner that it will use the |
| 1301 // URL mapping specified on the command line to load the libraries. | 1307 // URL mapping specified on the command line to load the libraries. |
| 1302 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1308 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 1303 CHECK_RESULT(result); | 1309 CHECK_RESULT(result); |
| 1304 } | 1310 } |
| 1305 | 1311 |
| 1306 SetupStubNativeResolversForPrecompilation(entry_points); | 1312 SetupStubNativeResolversForPrecompilation(entry_points); |
| 1307 | 1313 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 EventHandler::Stop(); | 1345 EventHandler::Stop(); |
| 1340 return 0; | 1346 return 0; |
| 1341 } | 1347 } |
| 1342 | 1348 |
| 1343 } // namespace bin | 1349 } // namespace bin |
| 1344 } // namespace dart | 1350 } // namespace dart |
| 1345 | 1351 |
| 1346 int main(int argc, char** argv) { | 1352 int main(int argc, char** argv) { |
| 1347 return dart::bin::main(argc, argv); | 1353 return dart::bin::main(argc, argv); |
| 1348 } | 1354 } |
| OLD | NEW |