Chromium Code Reviews| 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 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); |
|
siva
2015/09/14 20:32:59
This should be:
ErrorExit(kErrorExitCode,
rmacnak
2015/09/15 17:56:42
Done.
| |
| 1005 } | 1002 } |
| 1006 delete file; | 1003 delete file; |
| 1007 } | 1004 } |
| 1008 | 1005 |
| 1009 | 1006 |
| 1010 static void ReadSnapshotFile(const char* filename, | 1007 static void ReadSnapshotFile(const char* filename, |
| 1011 const uint8_t** buffer) { | 1008 const uint8_t** buffer) { |
| 1012 void* file = DartUtils::OpenFile(filename, false); | 1009 void* file = DartUtils::OpenFile(filename, false); |
| 1013 if (file == NULL) { | 1010 if (file == NULL) { |
| 1014 Log::PrintErr("Error: Failed to open '%s'.\n\n", filename); | 1011 Log::PrintErr("Error: Failed to open '%s'.\n\n", filename); |
| 1015 exit(kErrorExitCode); | 1012 exit(kErrorExitCode); |
| 1016 } | 1013 } |
| 1017 intptr_t len = -1; | 1014 intptr_t len = -1; |
| 1018 DartUtils::ReadFile(buffer, &len, file); | 1015 DartUtils::ReadFile(buffer, &len, file); |
| 1019 if (*buffer == NULL || len == -1) { | 1016 if (*buffer == NULL || len == -1) { |
| 1020 Log::PrintErr("Error: Failed to read '%s'.\n\n", filename); | 1017 Log::PrintErr("Error: Failed to read '%s'.\n\n", filename); |
| 1021 exit(kErrorExitCode); | 1018 exit(kErrorExitCode); |
|
siva
2015/09/14 20:32:59
why not ErrorExit ?
rmacnak
2015/09/15 17:56:42
Done.
| |
| 1022 } | 1019 } |
| 1023 DartUtils::CloseFile(file); | 1020 DartUtils::CloseFile(file); |
| 1024 } | 1021 } |
| 1025 | 1022 |
| 1026 | 1023 |
| 1027 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | 1024 static void* LoadLibrarySymbol(const char* libname, const char* symname) { |
| 1028 void* library = Extensions::LoadExtensionLibrary(libname); | 1025 void* library = Extensions::LoadExtensionLibrary(libname); |
| 1029 if (library == NULL) { | 1026 if (library == NULL) { |
| 1030 Log::PrintErr("Error: Failed to load library '%s'.\n\n", libname); | 1027 Log::PrintErr("Error: Failed to load library '%s'.\n\n", libname); |
| 1031 exit(kErrorExitCode); | 1028 exit(kErrorExitCode); |
|
siva
2015/09/14 20:32:59
why not ErrorExit ?
rmacnak
2015/09/15 17:56:42
Done.
| |
| 1032 } | 1029 } |
| 1033 void* symbol = Extensions::ResolveSymbol(library, symname); | 1030 void* symbol = Extensions::ResolveSymbol(library, symname); |
| 1034 if (symbol == NULL) { | 1031 if (symbol == NULL) { |
| 1035 Log::PrintErr("Failed to load symbol '%s'\n", symname); | 1032 Log::PrintErr("Failed to load symbol '%s'\n", symname); |
| 1036 exit(kErrorExitCode); | 1033 exit(kErrorExitCode); |
|
siva
2015/09/14 20:32:59
Ditto.
rmacnak
2015/09/15 17:56:42
Done.
| |
| 1037 } | 1034 } |
| 1038 return symbol; | 1035 return symbol; |
| 1039 } | 1036 } |
| 1040 | 1037 |
| 1041 | 1038 |
| 1042 void main(int argc, char** argv) { | 1039 void main(int argc, char** argv) { |
| 1043 char* script_name; | 1040 char* script_name; |
| 1044 const int EXTRA_VM_ARGUMENTS = 2; | 1041 const int EXTRA_VM_ARGUMENTS = 2; |
| 1045 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1042 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1046 CommandLineOptions dart_options(argc); | 1043 CommandLineOptions dart_options(argc); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 DartExitOnError(result); | 1221 DartExitOnError(result); |
| 1225 WriteSnapshotFile(kPrecompiledVmIsolateName, | 1222 WriteSnapshotFile(kPrecompiledVmIsolateName, |
| 1226 vm_isolate_buffer, | 1223 vm_isolate_buffer, |
| 1227 vm_isolate_size); | 1224 vm_isolate_size); |
| 1228 WriteSnapshotFile(kPrecompiledIsolateName, | 1225 WriteSnapshotFile(kPrecompiledIsolateName, |
| 1229 isolate_buffer, | 1226 isolate_buffer, |
| 1230 isolate_size); | 1227 isolate_size); |
| 1231 WriteSnapshotFile(kPrecompiledInstructionsName, | 1228 WriteSnapshotFile(kPrecompiledInstructionsName, |
| 1232 instructions_buffer, | 1229 instructions_buffer, |
| 1233 instructions_size); | 1230 instructions_size); |
| 1234 } else if (has_compile_all) { | 1231 } else { |
| 1235 result = Dart_CompileAll(); | 1232 if (has_compile_all) { |
| 1233 result = Dart_CompileAll(); | |
| 1234 DartExitOnError(result); | |
| 1235 } | |
| 1236 | |
| 1237 if (Dart_IsNull(root_lib)) { | |
| 1238 ErrorExit(kErrorExitCode, | |
| 1239 "Unable to find root library for '%s'\n", | |
| 1240 script_name); | |
| 1241 } | |
| 1242 | |
| 1243 // The helper function _getMainClosure creates a closure for the main | |
| 1244 // entry point which is either explicitly or implictly exported from the | |
| 1245 // root library. | |
| 1246 Dart_Handle main_closure = Dart_Invoke(builtin_lib, | |
| 1247 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); | |
| 1248 DartExitOnError(main_closure); | |
| 1249 | |
| 1250 // Set debug breakpoint if specified on the command line before calling | |
| 1251 // the main function. | |
| 1252 if (breakpoint_at != NULL) { | |
| 1253 result = SetBreakpoint(breakpoint_at, root_lib); | |
| 1254 if (Dart_IsError(result)) { | |
| 1255 ErrorExit(kErrorExitCode, | |
| 1256 "Error setting breakpoint at '%s': %s\n", | |
| 1257 breakpoint_at, | |
| 1258 Dart_GetError(result)); | |
| 1259 } | |
| 1260 } | |
| 1261 | |
| 1262 // Call _startIsolate in the isolate library to enable dispatching the | |
| 1263 // initial startup message. | |
| 1264 const intptr_t kNumIsolateArgs = 2; | |
| 1265 Dart_Handle isolate_args[kNumIsolateArgs]; | |
| 1266 isolate_args[0] = main_closure; // entryPoint | |
| 1267 isolate_args[1] = CreateRuntimeOptions(&dart_options); // args | |
| 1268 | |
| 1269 Dart_Handle isolate_lib = | |
| 1270 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); | |
| 1271 result = Dart_Invoke(isolate_lib, | |
| 1272 Dart_NewStringFromCString("_startMainIsolate"), | |
| 1273 kNumIsolateArgs, isolate_args); | |
| 1274 DartExitOnError(result); | |
| 1275 | |
| 1276 // Keep handling messages until the last active receive port is closed. | |
| 1277 result = Dart_RunLoop(); | |
| 1236 DartExitOnError(result); | 1278 DartExitOnError(result); |
| 1237 } | 1279 } |
| 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 } | 1280 } |
| 1282 | 1281 |
| 1283 Dart_ExitScope(); | 1282 Dart_ExitScope(); |
| 1284 // Shutdown the isolate. | 1283 // Shutdown the isolate. |
| 1285 Dart_ShutdownIsolate(); | 1284 Dart_ShutdownIsolate(); |
| 1286 // Terminate process exit-code handler. | 1285 // Terminate process exit-code handler. |
| 1287 Process::TerminateExitCodeHandler(); | 1286 Process::TerminateExitCodeHandler(); |
| 1288 | 1287 |
| 1289 Dart_Cleanup(); | 1288 Dart_Cleanup(); |
| 1290 | 1289 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1311 exit(Process::GlobalExitCode()); | 1310 exit(Process::GlobalExitCode()); |
| 1312 } | 1311 } |
| 1313 | 1312 |
| 1314 } // namespace bin | 1313 } // namespace bin |
| 1315 } // namespace dart | 1314 } // namespace dart |
| 1316 | 1315 |
| 1317 int main(int argc, char** argv) { | 1316 int main(int argc, char** argv) { |
| 1318 dart::bin::main(argc, argv); | 1317 dart::bin::main(argc, argv); |
| 1319 UNREACHABLE(); | 1318 UNREACHABLE(); |
| 1320 } | 1319 } |
| OLD | NEW |