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 16 matching lines...) Expand all Loading... |
27 #include "bin/utils.h" | 27 #include "bin/utils.h" |
28 #include "bin/vmservice_impl.h" | 28 #include "bin/vmservice_impl.h" |
29 #include "platform/globals.h" | 29 #include "platform/globals.h" |
30 #include "platform/growable_array.h" | 30 #include "platform/growable_array.h" |
31 #include "platform/hashmap.h" | 31 #include "platform/hashmap.h" |
32 #include "platform/text_buffer.h" | 32 #include "platform/text_buffer.h" |
33 #if !defined(DART_PRECOMPILER) | 33 #if !defined(DART_PRECOMPILER) |
34 #include "zlib/zlib.h" | 34 #include "zlib/zlib.h" |
35 #endif | 35 #endif |
36 | 36 |
| 37 #include "vm/kernel.h" |
| 38 |
37 namespace dart { | 39 namespace dart { |
38 namespace bin { | 40 namespace bin { |
39 | 41 |
40 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. | 42 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. |
41 extern const uint8_t* vm_snapshot_data; | 43 extern const uint8_t* vm_snapshot_data; |
42 extern const uint8_t* vm_snapshot_instructions; | 44 extern const uint8_t* vm_snapshot_instructions; |
43 extern const uint8_t* core_isolate_snapshot_data; | 45 extern const uint8_t* core_isolate_snapshot_data; |
44 extern const uint8_t* core_isolate_snapshot_instructions; | 46 extern const uint8_t* core_isolate_snapshot_instructions; |
45 | 47 |
46 /** | 48 /** |
(...skipping 13 matching lines...) Expand all Loading... |
60 kAppAOT, | 62 kAppAOT, |
61 kAppJIT, | 63 kAppJIT, |
62 }; | 64 }; |
63 static SnapshotKind gen_snapshot_kind = kNone; | 65 static SnapshotKind gen_snapshot_kind = kNone; |
64 static const char* snapshot_deps_filename = NULL; | 66 static const char* snapshot_deps_filename = NULL; |
65 | 67 |
66 static bool use_dart_frontend = false; | 68 static bool use_dart_frontend = false; |
67 | 69 |
68 static const char* frontend_filename = NULL; | 70 static const char* frontend_filename = NULL; |
69 | 71 |
| 72 // True if the VM should boostrap the SDK from a binary (.dill) file. The |
| 73 // filename points into an argv buffer and does not need to be freed. |
| 74 static bool use_platform_binary = false; |
| 75 static const char* platform_binary_filename = NULL; |
| 76 |
70 // Value of the --save-feedback flag. | 77 // Value of the --save-feedback flag. |
71 // (This pointer points into an argv buffer and does not need to be | 78 // (This pointer points into an argv buffer and does not need to be |
72 // free'd.) | 79 // free'd.) |
73 static const char* save_feedback_filename = NULL; | 80 static const char* save_feedback_filename = NULL; |
74 | 81 |
75 // Value of the --load-feedback flag. | 82 // Value of the --load-feedback flag. |
76 // (This pointer points into an argv buffer and does not need to be | 83 // (This pointer points into an argv buffer and does not need to be |
77 // free'd.) | 84 // free'd.) |
78 static const char* load_feedback_filename = NULL; | 85 static const char* load_feedback_filename = NULL; |
79 | 86 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (filename[0] == '\0') { | 333 if (filename[0] == '\0') { |
327 return false; | 334 return false; |
328 } | 335 } |
329 use_dart_frontend = true; | 336 use_dart_frontend = true; |
330 frontend_filename = filename; | 337 frontend_filename = filename; |
331 vm_options->AddArgument("--use-dart-frontend"); | 338 vm_options->AddArgument("--use-dart-frontend"); |
332 return true; | 339 return true; |
333 } | 340 } |
334 | 341 |
335 | 342 |
| 343 static bool ProcessPlatformOption(const char* filename, |
| 344 CommandLineOptions* vm_options) { |
| 345 ASSERT(filename != NULL); |
| 346 if (filename[0] == '\0') { |
| 347 return false; |
| 348 } |
| 349 use_platform_binary = true; |
| 350 platform_binary_filename = filename; |
| 351 return true; |
| 352 } |
| 353 |
| 354 |
336 static bool ProcessUseBlobsOption(const char* arg, | 355 static bool ProcessUseBlobsOption(const char* arg, |
337 CommandLineOptions* vm_options) { | 356 CommandLineOptions* vm_options) { |
338 ASSERT(arg != NULL); | 357 ASSERT(arg != NULL); |
339 if (*arg != '\0') { | 358 if (*arg != '\0') { |
340 return false; | 359 return false; |
341 } | 360 } |
342 use_blobs = true; | 361 use_blobs = true; |
343 return true; | 362 return true; |
344 } | 363 } |
345 | 364 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 {"--packages=", ProcessPackagesOption}, | 569 {"--packages=", ProcessPackagesOption}, |
551 {"--package-root=", ProcessPackageRootOption}, | 570 {"--package-root=", ProcessPackageRootOption}, |
552 {"-v", ProcessVerboseOption}, | 571 {"-v", ProcessVerboseOption}, |
553 {"--verbose", ProcessVerboseOption}, | 572 {"--verbose", ProcessVerboseOption}, |
554 {"--version", ProcessVersionOption}, | 573 {"--version", ProcessVersionOption}, |
555 | 574 |
556 // VM specific options to the standalone dart program. | 575 // VM specific options to the standalone dart program. |
557 {"--compile_all", ProcessCompileAllOption}, | 576 {"--compile_all", ProcessCompileAllOption}, |
558 {"--parse_all", ProcessParseAllOption}, | 577 {"--parse_all", ProcessParseAllOption}, |
559 {"--dfe=", ProcessFrontendOption}, | 578 {"--dfe=", ProcessFrontendOption}, |
| 579 {"--platform=", ProcessPlatformOption}, |
560 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 580 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
561 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 581 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
562 {"--observe", ProcessObserveOption}, | 582 {"--observe", ProcessObserveOption}, |
563 {"--snapshot=", ProcessSnapshotFilenameOption}, | 583 {"--snapshot=", ProcessSnapshotFilenameOption}, |
564 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 584 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
565 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, | 585 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, |
566 {"--use-blobs", ProcessUseBlobsOption}, | 586 {"--use-blobs", ProcessUseBlobsOption}, |
567 {"--save-feedback=", ProcessSaveFeedbackOption}, | 587 {"--save-feedback=", ProcessSaveFeedbackOption}, |
568 {"--load-feedback=", ProcessLoadFeedbackOption}, | 588 {"--load-feedback=", ProcessLoadFeedbackOption}, |
569 {"--trace-loading", ProcessTraceLoadingOption}, | 589 {"--trace-loading", ProcessTraceLoadingOption}, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 isolate_run_app_snapshot = true; | 866 isolate_run_app_snapshot = true; |
847 const uint8_t* ignore_vm_snapshot_data; | 867 const uint8_t* ignore_vm_snapshot_data; |
848 const uint8_t* ignore_vm_snapshot_instructions; | 868 const uint8_t* ignore_vm_snapshot_instructions; |
849 app_snapshot->SetBuffers( | 869 app_snapshot->SetBuffers( |
850 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | 870 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
851 &isolate_snapshot_data, &isolate_snapshot_instructions); | 871 &isolate_snapshot_data, &isolate_snapshot_instructions); |
852 } | 872 } |
853 } | 873 } |
854 #endif | 874 #endif |
855 | 875 |
856 const uint8_t* kernel_file = NULL; | 876 void* kernel_platform = NULL; |
857 intptr_t kernel_length = -1; | 877 void* kernel_program = NULL; |
858 bool is_kernel = false; | 878 if (!is_kernel_isolate && !is_service_isolate) { |
| 879 const uint8_t* platform_file = NULL; |
| 880 if (use_platform_binary) { |
| 881 intptr_t platform_length = -1; |
| 882 bool success = TryReadKernel(platform_binary_filename, &platform_file, |
| 883 &platform_length); |
| 884 if (!success) { |
| 885 *error = strdup("The platform binary is not a valid Dart Kernel file."); |
| 886 *exit_code = kErrorExitCode; |
| 887 return NULL; |
| 888 } |
| 889 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); |
| 890 } |
859 | 891 |
860 if (!is_kernel_isolate && !is_service_isolate) { | 892 bool is_kernel = false; |
| 893 const uint8_t* kernel_file = NULL; |
| 894 intptr_t kernel_length = -1; |
861 if (use_dart_frontend) { | 895 if (use_dart_frontend) { |
862 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | 896 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); |
863 *error = result.error; // Copy error message (if any). | 897 *error = result.error; // Copy error message (if any). |
864 switch (result.status) { | 898 switch (result.status) { |
865 case Dart_KernelCompilationStatus_Ok: | 899 case Dart_KernelCompilationStatus_Ok: |
866 is_kernel = true; | 900 is_kernel = true; |
867 kernel_file = result.kernel; | 901 kernel_file = result.kernel; |
868 kernel_length = result.kernel_size; | 902 kernel_length = result.kernel_size; |
869 break; | 903 break; |
870 case Dart_KernelCompilationStatus_Error: | 904 case Dart_KernelCompilationStatus_Error: |
871 *exit_code = kCompilationErrorExitCode; | 905 *exit_code = kCompilationErrorExitCode; |
872 return NULL; | 906 break; |
873 case Dart_KernelCompilationStatus_Crash: | 907 case Dart_KernelCompilationStatus_Crash: |
874 *exit_code = kDartFrontendErrorExitCode; | 908 *exit_code = kDartFrontendErrorExitCode; |
875 return NULL; | 909 break; |
876 case Dart_KernelCompilationStatus_Unknown: | 910 case Dart_KernelCompilationStatus_Unknown: |
877 *exit_code = kErrorExitCode; | 911 *exit_code = kErrorExitCode; |
878 return NULL; | 912 break; |
| 913 } |
| 914 if (!is_kernel) { |
| 915 free(const_cast<uint8_t*>(platform_file)); |
| 916 delete reinterpret_cast<kernel::Program*>(kernel_platform); |
| 917 return NULL; |
879 } | 918 } |
880 } else if (!isolate_run_app_snapshot) { | 919 } else if (!isolate_run_app_snapshot) { |
881 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); | 920 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); |
882 } | 921 } |
883 } | |
884 | 922 |
885 void* kernel_program = NULL; | 923 if (is_kernel) { |
886 if (is_kernel) { | 924 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
887 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | 925 } |
888 } | 926 } |
889 | 927 |
890 IsolateData* isolate_data = | 928 IsolateData* isolate_data = |
891 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | 929 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
892 if (is_main_isolate && (snapshot_deps_filename != NULL)) { | 930 if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
893 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | 931 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
894 } | 932 } |
895 // If the script is a Kernel binary, then we will try to bootstrap from the | |
896 // script. | |
897 Dart_Isolate isolate = | 933 Dart_Isolate isolate = |
898 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, | 934 kernel_platform != NULL |
899 flags, isolate_data, error) | 935 ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
900 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | 936 flags, isolate_data, error) |
901 isolate_snapshot_instructions, flags, | 937 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
902 isolate_data, error); | 938 isolate_snapshot_instructions, flags, |
| 939 isolate_data, error); |
903 if (isolate == NULL) { | 940 if (isolate == NULL) { |
904 delete isolate_data; | 941 delete isolate_data; |
905 return NULL; | 942 return NULL; |
906 } | 943 } |
907 | 944 |
908 Dart_EnterScope(); | 945 Dart_EnterScope(); |
909 | 946 |
910 // Set up the library tag handler for this isolate. | 947 // Set up the library tag handler for this isolate. |
911 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 948 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
912 CHECK_RESULT(result); | 949 CHECK_RESULT(result); |
913 | 950 |
914 if (is_kernel) { | 951 if (kernel_program != NULL) { |
915 Dart_Handle result = Dart_LoadKernel(kernel_program); | 952 Dart_Handle result = Dart_LoadKernel(kernel_program); |
916 CHECK_RESULT(result); | 953 CHECK_RESULT(result); |
917 } | 954 } |
918 if (is_kernel || (isolate_snapshot_data != NULL)) { | 955 if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) { |
919 // Setup the native resolver as the snapshot does not carry it. | 956 // Setup the native resolver as the snapshot does not carry it. |
920 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 957 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
921 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 958 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
922 } | 959 } |
923 if (isolate_run_app_snapshot) { | 960 if (isolate_run_app_snapshot) { |
924 Dart_Handle result = Loader::ReloadNativeExtensions(); | 961 Dart_Handle result = Loader::ReloadNativeExtensions(); |
925 CHECK_RESULT(result); | 962 CHECK_RESULT(result); |
926 } | 963 } |
927 | 964 |
928 if (Dart_IsServiceIsolate(isolate)) { | 965 if (Dart_IsServiceIsolate(isolate)) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 CHECK_RESULT(result); | 1015 CHECK_RESULT(result); |
979 ASSERT(app_script_uri == NULL); | 1016 ASSERT(app_script_uri == NULL); |
980 app_script_uri = strdup(resolved_script_uri); | 1017 app_script_uri = strdup(resolved_script_uri); |
981 } | 1018 } |
982 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1019 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
983 } else { | 1020 } else { |
984 // Load the specified application script into the newly created isolate. | 1021 // Load the specified application script into the newly created isolate. |
985 Dart_Handle uri = | 1022 Dart_Handle uri = |
986 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 1023 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
987 CHECK_RESULT(uri); | 1024 CHECK_RESULT(uri); |
988 if (!is_kernel) { | 1025 if (kernel_platform == NULL) { |
989 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); | 1026 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
990 CHECK_RESULT(result); | 1027 CHECK_RESULT(result); |
991 } else { | 1028 } else { |
992 // Various core-library parts will send requests to the Loader to resolve | 1029 // Various core-library parts will send requests to the Loader to resolve |
993 // relative URIs and perform other related tasks. We need Loader to be | 1030 // relative URIs and perform other related tasks. We need Loader to be |
994 // initialized for this to work because loading from Kernel binary | 1031 // initialized for this to work because loading from Kernel binary |
995 // bypasses normal source code loading paths that initialize it. | 1032 // bypasses normal source code loading paths that initialize it. |
996 Loader::InitForSnapshot(script_uri); | 1033 Loader::InitForSnapshot(script_uri); |
997 } | 1034 } |
998 | 1035 |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 Platform::Exit(Process::GlobalExitCode()); | 1754 Platform::Exit(Process::GlobalExitCode()); |
1718 } | 1755 } |
1719 | 1756 |
1720 } // namespace bin | 1757 } // namespace bin |
1721 } // namespace dart | 1758 } // namespace dart |
1722 | 1759 |
1723 int main(int argc, char** argv) { | 1760 int main(int argc, char** argv) { |
1724 dart::bin::main(argc, argv); | 1761 dart::bin::main(argc, argv); |
1725 UNREACHABLE(); | 1762 UNREACHABLE(); |
1726 } | 1763 } |
OLD | NEW |