| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 exit_code); | 815 exit_code); |
| 816 Platform::Exit(kErrorExitCode); | 816 Platform::Exit(kErrorExitCode); |
| 817 } | 817 } |
| 818 if (exit_code == 0) { | 818 if (exit_code == 0) { |
| 819 Snapshot::GenerateAppJIT(snapshot_filename); | 819 Snapshot::GenerateAppJIT(snapshot_filename); |
| 820 } | 820 } |
| 821 } | 821 } |
| 822 | 822 |
| 823 static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, | 823 static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, |
| 824 bool is_main_isolate, | 824 bool is_main_isolate, |
| 825 bool kernel_file_specified, |
| 825 const char* script_uri, | 826 const char* script_uri, |
| 826 const char* package_root, | 827 const char* package_root, |
| 827 const char* packages_config, | 828 const char* packages_config, |
| 828 bool set_native_resolvers, | 829 bool set_native_resolvers, |
| 829 bool isolate_run_app_snapshot, | 830 bool isolate_run_app_snapshot, |
| 830 char** error, | 831 char** error, |
| 831 int* exit_code) { | 832 int* exit_code) { |
| 832 Dart_EnterScope(); | 833 Dart_EnterScope(); |
| 833 IsolateData* isolate_data = | 834 IsolateData* isolate_data = |
| 834 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 835 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 835 void* kernel_program = isolate_data->kernel_program; | 836 void* kernel_program = isolate_data->kernel_program; |
| 836 | 837 |
| 837 // Set up the library tag handler for this isolate. | 838 // Set up the library tag handler for this isolate. |
| 838 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 839 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 839 CHECK_RESULT(result); | 840 CHECK_RESULT(result); |
| 840 | 841 |
| 841 // Prepare builtin and other core libraries for use to resolve URIs. | 842 // Prepare builtin and other core libraries for use to resolve URIs. |
| 842 // Set up various closures, e.g: printing, timers etc. | 843 // Set up various closures, e.g: printing, timers etc. |
| 843 // Set up 'package root' for URI resolution. | 844 // Set up 'package root' for URI resolution. |
| 844 result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 845 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
| 845 CHECK_RESULT(result); | 846 CHECK_RESULT(result); |
| 846 | 847 |
| 847 if (kernel_program != NULL) { | 848 if (kernel_file_specified) { |
| 848 Dart_Handle uri = Dart_NewStringFromCString(script_uri); | 849 ASSERT(kernel_program != NULL); |
| 849 CHECK_RESULT(uri); | 850 result = Dart_LoadKernel(kernel_program); |
| 850 Dart_Handle resolved_script_uri = DartUtils::ResolveScript(uri); | 851 } else { |
| 851 CHECK_RESULT(resolved_script_uri); | 852 if (kernel_program != NULL) { |
| 852 result = | 853 Dart_Handle uri = Dart_NewStringFromCString(script_uri); |
| 853 Dart_LoadScript(uri, resolved_script_uri, | 854 CHECK_RESULT(uri); |
| 854 reinterpret_cast<Dart_Handle>(kernel_program), 0, 0); | 855 Dart_Handle resolved_script_uri = DartUtils::ResolveScript(uri); |
| 855 CHECK_RESULT(result); | 856 CHECK_RESULT(resolved_script_uri); |
| 857 result = |
| 858 Dart_LoadScript(uri, resolved_script_uri, |
| 859 reinterpret_cast<Dart_Handle>(kernel_program), 0, 0); |
| 860 CHECK_RESULT(result); |
| 861 } |
| 856 } | 862 } |
| 857 if (set_native_resolvers) { | 863 if (set_native_resolvers) { |
| 858 // Setup the native resolver as the snapshot does not carry it. | 864 // Setup the native resolver as the snapshot does not carry it. |
| 859 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 865 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 860 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 866 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 861 } | 867 } |
| 862 if (isolate_run_app_snapshot) { | 868 if (isolate_run_app_snapshot) { |
| 863 Dart_Handle result = Loader::ReloadNativeExtensions(); | 869 Dart_Handle result = Loader::ReloadNativeExtensions(); |
| 864 CHECK_RESULT(result); | 870 CHECK_RESULT(result); |
| 865 } | 871 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 IsolateData* isolate_data = | 975 IsolateData* isolate_data = |
| 970 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | 976 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
| 971 Dart_Isolate isolate = Dart_CreateIsolate( | 977 Dart_Isolate isolate = Dart_CreateIsolate( |
| 972 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, | 978 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, |
| 973 flags, isolate_data, error); | 979 flags, isolate_data, error); |
| 974 if (isolate == NULL) { | 980 if (isolate == NULL) { |
| 975 delete isolate_data; | 981 delete isolate_data; |
| 976 return NULL; | 982 return NULL; |
| 977 } | 983 } |
| 978 | 984 |
| 979 return IsolateSetupHelper(isolate, false, script_uri, package_root, | 985 return IsolateSetupHelper(isolate, false, false, script_uri, package_root, |
| 980 packages_config, isolate_snapshot_data, | 986 packages_config, isolate_snapshot_data, |
| 981 isolate_run_app_snapshot, error, exit_code); | 987 isolate_run_app_snapshot, error, exit_code); |
| 982 } | 988 } |
| 983 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 989 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 984 | 990 |
| 985 // Returns newly created Service Isolate on success, NULL on failure. | 991 // Returns newly created Service Isolate on success, NULL on failure. |
| 986 // For now we only support the service isolate coming up from sources | 992 // For now we only support the service isolate coming up from sources |
| 987 // which are compiled by the VM parser. | 993 // which are compiled by the VM parser. |
| 988 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, | 994 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, |
| 989 const char* main, | 995 const char* main, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 const char* main, | 1073 const char* main, |
| 1068 const char* package_root, | 1074 const char* package_root, |
| 1069 const char* packages_config, | 1075 const char* packages_config, |
| 1070 Dart_IsolateFlags* flags, | 1076 Dart_IsolateFlags* flags, |
| 1071 char** error, | 1077 char** error, |
| 1072 int* exit_code) { | 1078 int* exit_code) { |
| 1073 ASSERT(script_uri != NULL); | 1079 ASSERT(script_uri != NULL); |
| 1074 void* kernel_platform = NULL; | 1080 void* kernel_platform = NULL; |
| 1075 void* kernel_program = NULL; | 1081 void* kernel_program = NULL; |
| 1076 AppSnapshot* app_snapshot = NULL; | 1082 AppSnapshot* app_snapshot = NULL; |
| 1083 bool kernel_file_specified = false; |
| 1077 | 1084 |
| 1078 IsolateData* isolate_data = | 1085 IsolateData* isolate_data = |
| 1079 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | 1086 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
| 1080 if (is_main_isolate && (snapshot_deps_filename != NULL)) { | 1087 if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
| 1081 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | 1088 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
| 1082 } | 1089 } |
| 1083 | 1090 |
| 1084 #if defined(DART_PRECOMPILED_RUNTIME) | 1091 #if defined(DART_PRECOMPILED_RUNTIME) |
| 1085 // AOT: All isolates start from the app snapshot. | 1092 // AOT: All isolates start from the app snapshot. |
| 1086 bool isolate_run_app_snapshot = true; | 1093 bool isolate_run_app_snapshot = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1107 const uint8_t* ignore_vm_snapshot_data; | 1114 const uint8_t* ignore_vm_snapshot_data; |
| 1108 const uint8_t* ignore_vm_snapshot_instructions; | 1115 const uint8_t* ignore_vm_snapshot_instructions; |
| 1109 app_snapshot->SetBuffers( | 1116 app_snapshot->SetBuffers( |
| 1110 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | 1117 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
| 1111 &isolate_snapshot_data, &isolate_snapshot_instructions); | 1118 &isolate_snapshot_data, &isolate_snapshot_instructions); |
| 1112 } | 1119 } |
| 1113 } | 1120 } |
| 1114 if (!isolate_run_app_snapshot) { | 1121 if (!isolate_run_app_snapshot) { |
| 1115 kernel_platform = dfe.kernel_platform(); | 1122 kernel_platform = dfe.kernel_platform(); |
| 1116 kernel_program = dfe.ReadScript(script_uri); | 1123 kernel_program = dfe.ReadScript(script_uri); |
| 1117 if (kernel_program == NULL && dfe.UseDartFrontend()) { | 1124 if (kernel_program != NULL) { |
| 1125 // A kernel file was specified on the command line instead of a source |
| 1126 // file. Load that kernel file directly. |
| 1127 kernel_file_specified = true; |
| 1128 } else if (dfe.UseDartFrontend()) { |
| 1118 kernel_program = dfe.CompileAndReadScript(script_uri, error, exit_code); | 1129 kernel_program = dfe.CompileAndReadScript(script_uri, error, exit_code); |
| 1119 if (kernel_program == NULL) { | 1130 if (kernel_program == NULL) { |
| 1120 return NULL; | 1131 return NULL; |
| 1121 } | 1132 } |
| 1122 } | 1133 } |
| 1123 isolate_data->kernel_program = kernel_program; | 1134 isolate_data->kernel_program = kernel_program; |
| 1124 } | 1135 } |
| 1125 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1136 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1126 | 1137 |
| 1127 Dart_Isolate isolate = NULL; | 1138 Dart_Isolate isolate = NULL; |
| 1128 if (kernel_platform != NULL) { | 1139 if (kernel_platform != NULL) { |
| 1129 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, | 1140 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
| 1130 flags, isolate_data, error); | 1141 flags, isolate_data, error); |
| 1131 } else if (kernel_program != NULL) { | 1142 } else if (kernel_program != NULL) { |
| 1132 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, | 1143 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, |
| 1133 flags, isolate_data, error); | 1144 flags, isolate_data, error); |
| 1134 } else { | 1145 } else { |
| 1135 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | 1146 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
| 1136 isolate_snapshot_instructions, flags, | 1147 isolate_snapshot_instructions, flags, |
| 1137 isolate_data, error); | 1148 isolate_data, error); |
| 1138 } | 1149 } |
| 1139 if (isolate == NULL) { | 1150 if (isolate == NULL) { |
| 1140 delete isolate_data; | 1151 delete isolate_data; |
| 1141 return NULL; | 1152 return NULL; |
| 1142 } | 1153 } |
| 1143 | 1154 |
| 1144 bool set_native_resolvers = (kernel_program || isolate_snapshot_data); | 1155 bool set_native_resolvers = (kernel_program || isolate_snapshot_data); |
| 1145 return IsolateSetupHelper(isolate, is_main_isolate, script_uri, package_root, | 1156 return IsolateSetupHelper(isolate, is_main_isolate, kernel_file_specified, |
| 1146 packages_config, set_native_resolvers, | 1157 script_uri, package_root, packages_config, |
| 1147 isolate_run_app_snapshot, error, exit_code); | 1158 set_native_resolvers, isolate_run_app_snapshot, |
| 1159 error, exit_code); |
| 1148 } | 1160 } |
| 1149 | 1161 |
| 1150 #undef CHECK_RESULT | 1162 #undef CHECK_RESULT |
| 1151 | 1163 |
| 1152 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 1164 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| 1153 const char* main, | 1165 const char* main, |
| 1154 const char* package_root, | 1166 const char* package_root, |
| 1155 const char* package_config, | 1167 const char* package_config, |
| 1156 Dart_IsolateFlags* flags, | 1168 Dart_IsolateFlags* flags, |
| 1157 void* data, | 1169 void* data, |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 Platform::Exit(Process::GlobalExitCode()); | 1904 Platform::Exit(Process::GlobalExitCode()); |
| 1893 } | 1905 } |
| 1894 | 1906 |
| 1895 } // namespace bin | 1907 } // namespace bin |
| 1896 } // namespace dart | 1908 } // namespace dart |
| 1897 | 1909 |
| 1898 int main(int argc, char** argv) { | 1910 int main(int argc, char** argv) { |
| 1899 dart::bin::main(argc, argv); | 1911 dart::bin::main(argc, argv); |
| 1900 UNREACHABLE(); | 1912 UNREACHABLE(); |
| 1901 } | 1913 } |
| OLD | NEW |