| 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 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 // Set up the library tag handler for this isolate. | 714 // Set up the library tag handler for this isolate. |
| 715 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 715 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 716 CHECK_RESULT(result); | 716 CHECK_RESULT(result); |
| 717 | 717 |
| 718 if (Dart_IsServiceIsolate(isolate)) { | 718 if (Dart_IsServiceIsolate(isolate)) { |
| 719 // If this is the service isolate, load embedder specific bits and return. | 719 // If this is the service isolate, load embedder specific bits and return. |
| 720 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) { | 720 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) { |
| 721 *error = strdup(VmService::GetErrorMessage()); | 721 *error = strdup(VmService::GetErrorMessage()); |
| 722 return NULL; | 722 return NULL; |
| 723 } | 723 } |
| 724 if (has_gen_precompiled_snapshot) { | 724 if (has_compile_all) { |
| 725 result = Dart_Precompile(); | |
| 726 CHECK_RESULT(result); | |
| 727 } else if (has_compile_all) { | |
| 728 result = Dart_CompileAll(); | 725 result = Dart_CompileAll(); |
| 729 CHECK_RESULT(result); | 726 CHECK_RESULT(result); |
| 730 } | 727 } |
| 731 Dart_ExitScope(); | 728 Dart_ExitScope(); |
| 732 Dart_ExitIsolate(); | 729 Dart_ExitIsolate(); |
| 733 return isolate; | 730 return isolate; |
| 734 } | 731 } |
| 735 | 732 |
| 736 // Load the specified application script into the newly created isolate. | 733 // Load the specified application script into the newly created isolate. |
| 737 | 734 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 capture_stdio = (capture_stdout || capture_stderr); | 1032 capture_stdio = (capture_stdout || capture_stderr); |
| 1036 } | 1033 } |
| 1037 | 1034 |
| 1038 | 1035 |
| 1039 static void WriteSnapshotFile(const char* filename, | 1036 static void WriteSnapshotFile(const char* filename, |
| 1040 const uint8_t* buffer, | 1037 const uint8_t* buffer, |
| 1041 const intptr_t size) { | 1038 const intptr_t size) { |
| 1042 File* file = File::Open(filename, File::kWriteTruncate); | 1039 File* file = File::Open(filename, File::kWriteTruncate); |
| 1043 ASSERT(file != NULL); | 1040 ASSERT(file != NULL); |
| 1044 if (!file->WriteFully(buffer, size)) { | 1041 if (!file->WriteFully(buffer, size)) { |
| 1045 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 1042 ErrorExit(kErrorExitCode, |
| 1043 "Unable to open file %s for writing snapshot\n", |
| 1044 filename); |
| 1046 } | 1045 } |
| 1047 delete file; | 1046 delete file; |
| 1048 } | 1047 } |
| 1049 | 1048 |
| 1050 | 1049 |
| 1051 static void ReadSnapshotFile(const char* filename, | 1050 static void ReadSnapshotFile(const char* filename, |
| 1052 const uint8_t** buffer) { | 1051 const uint8_t** buffer) { |
| 1053 void* file = DartUtils::OpenFile(filename, false); | 1052 void* file = DartUtils::OpenFile(filename, false); |
| 1054 if (file == NULL) { | 1053 if (file == NULL) { |
| 1055 Log::PrintErr("Error: Failed to open '%s'.\n\n", filename); | 1054 ErrorExit(kErrorExitCode, |
| 1056 exit(kErrorExitCode); | 1055 "Error: Unable to open file %s for reading snapshot\n", filename); |
| 1057 } | 1056 } |
| 1058 intptr_t len = -1; | 1057 intptr_t len = -1; |
| 1059 DartUtils::ReadFile(buffer, &len, file); | 1058 DartUtils::ReadFile(buffer, &len, file); |
| 1060 if (*buffer == NULL || len == -1) { | 1059 if (*buffer == NULL || len == -1) { |
| 1061 Log::PrintErr("Error: Failed to read '%s'.\n\n", filename); | 1060 ErrorExit(kErrorExitCode, |
| 1062 exit(kErrorExitCode); | 1061 "Error: Unable to read snapshot file %s\n", filename); |
| 1063 } | 1062 } |
| 1064 DartUtils::CloseFile(file); | 1063 DartUtils::CloseFile(file); |
| 1065 } | 1064 } |
| 1066 | 1065 |
| 1067 | 1066 |
| 1068 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | 1067 static void* LoadLibrarySymbol(const char* libname, const char* symname) { |
| 1069 void* library = Extensions::LoadExtensionLibrary(libname); | 1068 void* library = Extensions::LoadExtensionLibrary(libname); |
| 1070 if (library == NULL) { | 1069 if (library == NULL) { |
| 1071 Log::PrintErr("Error: Failed to load library '%s'.\n\n", libname); | 1070 ErrorExit(kErrorExitCode, |
| 1072 exit(kErrorExitCode); | 1071 "Error: Failed to load library '%s'\n", libname); |
| 1073 } | 1072 } |
| 1074 void* symbol = Extensions::ResolveSymbol(library, symname); | 1073 void* symbol = Extensions::ResolveSymbol(library, symname); |
| 1075 if (symbol == NULL) { | 1074 if (symbol == NULL) { |
| 1076 Log::PrintErr("Failed to load symbol '%s'\n", symname); | 1075 ErrorExit(kErrorExitCode, |
| 1077 exit(kErrorExitCode); | 1076 "Error: Failed to load symbol '%s'\n", symname); |
| 1078 } | 1077 } |
| 1079 return symbol; | 1078 return symbol; |
| 1080 } | 1079 } |
| 1081 | 1080 |
| 1082 | 1081 |
| 1083 void main(int argc, char** argv) { | 1082 void main(int argc, char** argv) { |
| 1084 char* script_name; | 1083 char* script_name; |
| 1085 const int EXTRA_VM_ARGUMENTS = 2; | 1084 const int EXTRA_VM_ARGUMENTS = 2; |
| 1086 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1085 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1087 CommandLineOptions dart_options(argc); | 1086 CommandLineOptions dart_options(argc); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 DartExitOnError(result); | 1275 DartExitOnError(result); |
| 1277 WriteSnapshotFile(kPrecompiledVmIsolateName, | 1276 WriteSnapshotFile(kPrecompiledVmIsolateName, |
| 1278 vm_isolate_buffer, | 1277 vm_isolate_buffer, |
| 1279 vm_isolate_size); | 1278 vm_isolate_size); |
| 1280 WriteSnapshotFile(kPrecompiledIsolateName, | 1279 WriteSnapshotFile(kPrecompiledIsolateName, |
| 1281 isolate_buffer, | 1280 isolate_buffer, |
| 1282 isolate_size); | 1281 isolate_size); |
| 1283 WriteSnapshotFile(kPrecompiledInstructionsName, | 1282 WriteSnapshotFile(kPrecompiledInstructionsName, |
| 1284 instructions_buffer, | 1283 instructions_buffer, |
| 1285 instructions_size); | 1284 instructions_size); |
| 1286 } else if (has_compile_all) { | 1285 } else { |
| 1287 result = Dart_CompileAll(); | 1286 if (has_compile_all) { |
| 1287 result = Dart_CompileAll(); |
| 1288 DartExitOnError(result); |
| 1289 } |
| 1290 |
| 1291 if (Dart_IsNull(root_lib)) { |
| 1292 ErrorExit(kErrorExitCode, |
| 1293 "Unable to find root library for '%s'\n", |
| 1294 script_name); |
| 1295 } |
| 1296 |
| 1297 // The helper function _getMainClosure creates a closure for the main |
| 1298 // entry point which is either explicitly or implictly exported from the |
| 1299 // root library. |
| 1300 Dart_Handle main_closure = Dart_Invoke(builtin_lib, |
| 1301 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); |
| 1302 DartExitOnError(main_closure); |
| 1303 |
| 1304 // Set debug breakpoint if specified on the command line before calling |
| 1305 // the main function. |
| 1306 if (breakpoint_at != NULL) { |
| 1307 result = SetBreakpoint(breakpoint_at, root_lib); |
| 1308 if (Dart_IsError(result)) { |
| 1309 ErrorExit(kErrorExitCode, |
| 1310 "Error setting breakpoint at '%s': %s\n", |
| 1311 breakpoint_at, |
| 1312 Dart_GetError(result)); |
| 1313 } |
| 1314 } |
| 1315 |
| 1316 // Call _startIsolate in the isolate library to enable dispatching the |
| 1317 // initial startup message. |
| 1318 const intptr_t kNumIsolateArgs = 2; |
| 1319 Dart_Handle isolate_args[kNumIsolateArgs]; |
| 1320 isolate_args[0] = main_closure; // entryPoint |
| 1321 isolate_args[1] = CreateRuntimeOptions(&dart_options); // args |
| 1322 |
| 1323 Dart_Handle isolate_lib = |
| 1324 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
| 1325 result = Dart_Invoke(isolate_lib, |
| 1326 Dart_NewStringFromCString("_startMainIsolate"), |
| 1327 kNumIsolateArgs, isolate_args); |
| 1328 DartExitOnError(result); |
| 1329 |
| 1330 // Keep handling messages until the last active receive port is closed. |
| 1331 result = Dart_RunLoop(); |
| 1288 DartExitOnError(result); | 1332 DartExitOnError(result); |
| 1289 } | 1333 } |
| 1290 | |
| 1291 if (Dart_IsNull(root_lib)) { | |
| 1292 ErrorExit(kErrorExitCode, | |
| 1293 "Unable to find root library for '%s'\n", | |
| 1294 script_name); | |
| 1295 } | |
| 1296 | |
| 1297 // The helper function _getMainClosure creates a closure for the main | |
| 1298 // entry point which is either explicitly or implictly exported from the | |
| 1299 // root library. | |
| 1300 Dart_Handle main_closure = Dart_Invoke( | |
| 1301 builtin_lib, Dart_NewStringFromCString("_getMainClosure"), 0, NULL); | |
| 1302 DartExitOnError(main_closure); | |
| 1303 | |
| 1304 // Set debug breakpoint if specified on the command line before calling | |
| 1305 // the main function. | |
| 1306 if (breakpoint_at != NULL) { | |
| 1307 result = SetBreakpoint(breakpoint_at, root_lib); | |
| 1308 if (Dart_IsError(result)) { | |
| 1309 ErrorExit(kErrorExitCode, | |
| 1310 "Error setting breakpoint at '%s': %s\n", | |
| 1311 breakpoint_at, | |
| 1312 Dart_GetError(result)); | |
| 1313 } | |
| 1314 } | |
| 1315 | |
| 1316 // Call _startIsolate in the isolate library to enable dispatching the | |
| 1317 // initial startup message. | |
| 1318 const intptr_t kNumIsolateArgs = 2; | |
| 1319 Dart_Handle isolate_args[kNumIsolateArgs]; | |
| 1320 isolate_args[0] = main_closure; // entryPoint | |
| 1321 isolate_args[1] = CreateRuntimeOptions(&dart_options); // args | |
| 1322 | |
| 1323 Dart_Handle isolate_lib = Dart_LookupLibrary( | |
| 1324 Dart_NewStringFromCString("dart:isolate")); | |
| 1325 result = Dart_Invoke(isolate_lib, | |
| 1326 Dart_NewStringFromCString("_startMainIsolate"), | |
| 1327 kNumIsolateArgs, isolate_args); | |
| 1328 DartExitOnError(result); | |
| 1329 | |
| 1330 // Keep handling messages until the last active receive port is closed. | |
| 1331 result = Dart_RunLoop(); | |
| 1332 DartExitOnError(result); | |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1335 Dart_ExitScope(); | 1336 Dart_ExitScope(); |
| 1336 // Shutdown the isolate. | 1337 // Shutdown the isolate. |
| 1337 Dart_ShutdownIsolate(); | 1338 Dart_ShutdownIsolate(); |
| 1338 // Terminate process exit-code handler. | 1339 // Terminate process exit-code handler. |
| 1339 Process::TerminateExitCodeHandler(); | 1340 Process::TerminateExitCodeHandler(); |
| 1340 | 1341 |
| 1341 error = Dart_Cleanup(); | 1342 error = Dart_Cleanup(); |
| 1342 if (error != NULL) { | 1343 if (error != NULL) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1367 exit(Process::GlobalExitCode()); | 1368 exit(Process::GlobalExitCode()); |
| 1368 } | 1369 } |
| 1369 | 1370 |
| 1370 } // namespace bin | 1371 } // namespace bin |
| 1371 } // namespace dart | 1372 } // namespace dart |
| 1372 | 1373 |
| 1373 int main(int argc, char** argv) { | 1374 int main(int argc, char** argv) { |
| 1374 dart::bin::main(argc, argv); | 1375 dart::bin::main(argc, argv); |
| 1375 UNREACHABLE(); | 1376 UNREACHABLE(); |
| 1376 } | 1377 } |
| OLD | NEW |