| 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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 // Set up the library tag handler for this isolate. | 674 // Set up the library tag handler for this isolate. |
| 675 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 675 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 676 CHECK_RESULT(result); | 676 CHECK_RESULT(result); |
| 677 | 677 |
| 678 if (Dart_IsServiceIsolate(isolate)) { | 678 if (Dart_IsServiceIsolate(isolate)) { |
| 679 // If this is the service isolate, load embedder specific bits and return. | 679 // If this is the service isolate, load embedder specific bits and return. |
| 680 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) { | 680 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) { |
| 681 *error = strdup(VmService::GetErrorMessage()); | 681 *error = strdup(VmService::GetErrorMessage()); |
| 682 return NULL; | 682 return NULL; |
| 683 } | 683 } |
| 684 if (has_gen_precompiled_snapshot) { | 684 if (has_compile_all) { |
| 685 result = Dart_Precompile(); | |
| 686 CHECK_RESULT(result); | |
| 687 } else if (has_compile_all) { | |
| 688 result = Dart_CompileAll(); | 685 result = Dart_CompileAll(); |
| 689 CHECK_RESULT(result); | 686 CHECK_RESULT(result); |
| 690 } | 687 } |
| 691 Dart_ExitScope(); | 688 Dart_ExitScope(); |
| 692 Dart_ExitIsolate(); | 689 Dart_ExitIsolate(); |
| 693 return isolate; | 690 return isolate; |
| 694 } | 691 } |
| 695 | 692 |
| 696 // Load the specified application script into the newly created isolate. | 693 // Load the specified application script into the newly created isolate. |
| 697 | 694 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 capture_stdio = (capture_stdout || capture_stderr); | 991 capture_stdio = (capture_stdout || capture_stderr); |
| 995 } | 992 } |
| 996 | 993 |
| 997 | 994 |
| 998 static void WriteSnapshotFile(const char* filename, | 995 static void WriteSnapshotFile(const char* filename, |
| 999 const uint8_t* buffer, | 996 const uint8_t* buffer, |
| 1000 const intptr_t size) { | 997 const intptr_t size) { |
| 1001 File* file = File::Open(filename, File::kWriteTruncate); | 998 File* file = File::Open(filename, File::kWriteTruncate); |
| 1002 ASSERT(file != NULL); | 999 ASSERT(file != NULL); |
| 1003 if (!file->WriteFully(buffer, size)) { | 1000 if (!file->WriteFully(buffer, size)) { |
| 1004 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 1001 ErrorExit(kErrorExitCode, |
| 1002 "Unable to open file %s for writing snapshot\n", |
| 1003 filename); |
| 1005 } | 1004 } |
| 1006 delete file; | 1005 delete file; |
| 1007 } | 1006 } |
| 1008 | 1007 |
| 1009 | 1008 |
| 1010 static void ReadSnapshotFile(const char* filename, | 1009 static void ReadSnapshotFile(const char* filename, |
| 1011 const uint8_t** buffer) { | 1010 const uint8_t** buffer) { |
| 1012 void* file = DartUtils::OpenFile(filename, false); | 1011 void* file = DartUtils::OpenFile(filename, false); |
| 1013 if (file == NULL) { | 1012 if (file == NULL) { |
| 1014 Log::PrintErr("Error: Failed to open '%s'.\n\n", filename); | 1013 ErrorExit(kErrorExitCode, |
| 1015 exit(kErrorExitCode); | 1014 "Error: Unable to open file %s for reading snapshot\n", filename); |
| 1016 } | 1015 } |
| 1017 intptr_t len = -1; | 1016 intptr_t len = -1; |
| 1018 DartUtils::ReadFile(buffer, &len, file); | 1017 DartUtils::ReadFile(buffer, &len, file); |
| 1019 if (*buffer == NULL || len == -1) { | 1018 if (*buffer == NULL || len == -1) { |
| 1020 Log::PrintErr("Error: Failed to read '%s'.\n\n", filename); | 1019 ErrorExit(kErrorExitCode, |
| 1021 exit(kErrorExitCode); | 1020 "Error: Unable to read snapshot file %s\n", filename); |
| 1022 } | 1021 } |
| 1023 DartUtils::CloseFile(file); | 1022 DartUtils::CloseFile(file); |
| 1024 } | 1023 } |
| 1025 | 1024 |
| 1026 | 1025 |
| 1027 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | 1026 static void* LoadLibrarySymbol(const char* libname, const char* symname) { |
| 1028 void* library = Extensions::LoadExtensionLibrary(libname); | 1027 void* library = Extensions::LoadExtensionLibrary(libname); |
| 1029 if (library == NULL) { | 1028 if (library == NULL) { |
| 1030 Log::PrintErr("Error: Failed to load library '%s'.\n\n", libname); | 1029 ErrorExit(kErrorExitCode, |
| 1031 exit(kErrorExitCode); | 1030 "Error: Failed to load library '%s'\n", libname); |
| 1032 } | 1031 } |
| 1033 void* symbol = Extensions::ResolveSymbol(library, symname); | 1032 void* symbol = Extensions::ResolveSymbol(library, symname); |
| 1034 if (symbol == NULL) { | 1033 if (symbol == NULL) { |
| 1035 Log::PrintErr("Failed to load symbol '%s'\n", symname); | 1034 ErrorExit(kErrorExitCode, |
| 1036 exit(kErrorExitCode); | 1035 "Error: Failed to load symbol '%s'\n", symname); |
| 1037 } | 1036 } |
| 1038 return symbol; | 1037 return symbol; |
| 1039 } | 1038 } |
| 1040 | 1039 |
| 1041 | 1040 |
| 1042 void main(int argc, char** argv) { | 1041 void main(int argc, char** argv) { |
| 1043 char* script_name; | 1042 char* script_name; |
| 1044 const int EXTRA_VM_ARGUMENTS = 2; | 1043 const int EXTRA_VM_ARGUMENTS = 2; |
| 1045 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1044 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1046 CommandLineOptions dart_options(argc); | 1045 CommandLineOptions dart_options(argc); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 DartExitOnError(result); | 1223 DartExitOnError(result); |
| 1225 WriteSnapshotFile(kPrecompiledVmIsolateName, | 1224 WriteSnapshotFile(kPrecompiledVmIsolateName, |
| 1226 vm_isolate_buffer, | 1225 vm_isolate_buffer, |
| 1227 vm_isolate_size); | 1226 vm_isolate_size); |
| 1228 WriteSnapshotFile(kPrecompiledIsolateName, | 1227 WriteSnapshotFile(kPrecompiledIsolateName, |
| 1229 isolate_buffer, | 1228 isolate_buffer, |
| 1230 isolate_size); | 1229 isolate_size); |
| 1231 WriteSnapshotFile(kPrecompiledInstructionsName, | 1230 WriteSnapshotFile(kPrecompiledInstructionsName, |
| 1232 instructions_buffer, | 1231 instructions_buffer, |
| 1233 instructions_size); | 1232 instructions_size); |
| 1234 } else if (has_compile_all) { | 1233 } else { |
| 1235 result = Dart_CompileAll(); | 1234 if (has_compile_all) { |
| 1235 result = Dart_CompileAll(); |
| 1236 DartExitOnError(result); |
| 1237 } |
| 1238 |
| 1239 if (Dart_IsNull(root_lib)) { |
| 1240 ErrorExit(kErrorExitCode, |
| 1241 "Unable to find root library for '%s'\n", |
| 1242 script_name); |
| 1243 } |
| 1244 |
| 1245 // The helper function _getMainClosure creates a closure for the main |
| 1246 // entry point which is either explicitly or implictly exported from the |
| 1247 // root library. |
| 1248 Dart_Handle main_closure = Dart_Invoke(builtin_lib, |
| 1249 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); |
| 1250 DartExitOnError(main_closure); |
| 1251 |
| 1252 // Set debug breakpoint if specified on the command line before calling |
| 1253 // the main function. |
| 1254 if (breakpoint_at != NULL) { |
| 1255 result = SetBreakpoint(breakpoint_at, root_lib); |
| 1256 if (Dart_IsError(result)) { |
| 1257 ErrorExit(kErrorExitCode, |
| 1258 "Error setting breakpoint at '%s': %s\n", |
| 1259 breakpoint_at, |
| 1260 Dart_GetError(result)); |
| 1261 } |
| 1262 } |
| 1263 |
| 1264 // Call _startIsolate in the isolate library to enable dispatching the |
| 1265 // initial startup message. |
| 1266 const intptr_t kNumIsolateArgs = 2; |
| 1267 Dart_Handle isolate_args[kNumIsolateArgs]; |
| 1268 isolate_args[0] = main_closure; // entryPoint |
| 1269 isolate_args[1] = CreateRuntimeOptions(&dart_options); // args |
| 1270 |
| 1271 Dart_Handle isolate_lib = |
| 1272 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
| 1273 result = Dart_Invoke(isolate_lib, |
| 1274 Dart_NewStringFromCString("_startMainIsolate"), |
| 1275 kNumIsolateArgs, isolate_args); |
| 1276 DartExitOnError(result); |
| 1277 |
| 1278 // Keep handling messages until the last active receive port is closed. |
| 1279 result = Dart_RunLoop(); |
| 1236 DartExitOnError(result); | 1280 DartExitOnError(result); |
| 1237 } | 1281 } |
| 1238 | |
| 1239 if (Dart_IsNull(root_lib)) { | |
| 1240 ErrorExit(kErrorExitCode, | |
| 1241 "Unable to find root library for '%s'\n", | |
| 1242 script_name); | |
| 1243 } | |
| 1244 | |
| 1245 // The helper function _getMainClosure creates a closure for the main | |
| 1246 // entry point which is either explicitly or implictly exported from the | |
| 1247 // root library. | |
| 1248 Dart_Handle main_closure = Dart_Invoke( | |
| 1249 builtin_lib, Dart_NewStringFromCString("_getMainClosure"), 0, NULL); | |
| 1250 DartExitOnError(main_closure); | |
| 1251 | |
| 1252 // Set debug breakpoint if specified on the command line before calling | |
| 1253 // the main function. | |
| 1254 if (breakpoint_at != NULL) { | |
| 1255 result = SetBreakpoint(breakpoint_at, root_lib); | |
| 1256 if (Dart_IsError(result)) { | |
| 1257 ErrorExit(kErrorExitCode, | |
| 1258 "Error setting breakpoint at '%s': %s\n", | |
| 1259 breakpoint_at, | |
| 1260 Dart_GetError(result)); | |
| 1261 } | |
| 1262 } | |
| 1263 | |
| 1264 // Call _startIsolate in the isolate library to enable dispatching the | |
| 1265 // initial startup message. | |
| 1266 const intptr_t kNumIsolateArgs = 2; | |
| 1267 Dart_Handle isolate_args[kNumIsolateArgs]; | |
| 1268 isolate_args[0] = main_closure; // entryPoint | |
| 1269 isolate_args[1] = CreateRuntimeOptions(&dart_options); // args | |
| 1270 | |
| 1271 Dart_Handle isolate_lib = Dart_LookupLibrary( | |
| 1272 Dart_NewStringFromCString("dart:isolate")); | |
| 1273 result = Dart_Invoke(isolate_lib, | |
| 1274 Dart_NewStringFromCString("_startMainIsolate"), | |
| 1275 kNumIsolateArgs, isolate_args); | |
| 1276 DartExitOnError(result); | |
| 1277 | |
| 1278 // Keep handling messages until the last active receive port is closed. | |
| 1279 result = Dart_RunLoop(); | |
| 1280 DartExitOnError(result); | |
| 1281 } | 1282 } |
| 1282 | 1283 |
| 1283 Dart_ExitScope(); | 1284 Dart_ExitScope(); |
| 1284 // Shutdown the isolate. | 1285 // Shutdown the isolate. |
| 1285 Dart_ShutdownIsolate(); | 1286 Dart_ShutdownIsolate(); |
| 1286 // Terminate process exit-code handler. | 1287 // Terminate process exit-code handler. |
| 1287 Process::TerminateExitCodeHandler(); | 1288 Process::TerminateExitCodeHandler(); |
| 1288 | 1289 |
| 1289 Dart_Cleanup(); | 1290 Dart_Cleanup(); |
| 1290 | 1291 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1311 exit(Process::GlobalExitCode()); | 1312 exit(Process::GlobalExitCode()); |
| 1312 } | 1313 } |
| 1313 | 1314 |
| 1314 } // namespace bin | 1315 } // namespace bin |
| 1315 } // namespace dart | 1316 } // namespace dart |
| 1316 | 1317 |
| 1317 int main(int argc, char** argv) { | 1318 int main(int argc, char** argv) { |
| 1318 dart::bin::main(argc, argv); | 1319 dart::bin::main(argc, argv); |
| 1319 UNREACHABLE(); | 1320 UNREACHABLE(); |
| 1320 } | 1321 } |
| OLD | NEW |