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" |
11 | 11 |
12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
| 14 #include "bin/dfe.h" |
14 #include "bin/directory.h" | 15 #include "bin/directory.h" |
15 #include "bin/embedded_dart_io.h" | 16 #include "bin/embedded_dart_io.h" |
16 #include "bin/error_exit.h" | 17 #include "bin/error_exit.h" |
17 #include "bin/eventhandler.h" | 18 #include "bin/eventhandler.h" |
18 #include "bin/extensions.h" | 19 #include "bin/extensions.h" |
19 #include "bin/file.h" | 20 #include "bin/file.h" |
20 #include "bin/isolate_data.h" | 21 #include "bin/isolate_data.h" |
21 #include "bin/loader.h" | 22 #include "bin/loader.h" |
22 #include "bin/log.h" | 23 #include "bin/log.h" |
23 #include "bin/platform.h" | 24 #include "bin/platform.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static bool vm_run_app_snapshot = false; | 72 static bool vm_run_app_snapshot = false; |
72 static const char* snapshot_filename = NULL; | 73 static const char* snapshot_filename = NULL; |
73 enum SnapshotKind { | 74 enum SnapshotKind { |
74 kNone, | 75 kNone, |
75 kScript, | 76 kScript, |
76 kAppAOT, | 77 kAppAOT, |
77 kAppJIT, | 78 kAppJIT, |
78 }; | 79 }; |
79 static SnapshotKind gen_snapshot_kind = kNone; | 80 static SnapshotKind gen_snapshot_kind = kNone; |
80 static const char* snapshot_deps_filename = NULL; | 81 static const char* snapshot_deps_filename = NULL; |
81 | 82 #if !defined(DART_PRECOMPILED_RUNTIME) |
82 static bool use_dart_frontend = false; | 83 DFE dfe; |
83 | 84 #endif |
84 static const char* frontend_filename = NULL; | |
85 | |
86 // True if the VM should boostrap the SDK from a binary (.dill) file. The | |
87 // filename points into an argv buffer and does not need to be freed. | |
88 static bool use_platform_binary = false; | |
89 static const char* platform_binary_filename = NULL; | |
90 | 85 |
91 // Value of the --save-feedback flag. | 86 // Value of the --save-feedback flag. |
92 // (This pointer points into an argv buffer and does not need to be | 87 // (This pointer points into an argv buffer and does not need to be |
93 // free'd.) | 88 // free'd.) |
94 static const char* save_feedback_filename = NULL; | 89 static const char* save_feedback_filename = NULL; |
95 | 90 |
96 // Value of the --load-feedback flag. | 91 // Value of the --load-feedback flag. |
97 // (This pointer points into an argv buffer and does not need to be | 92 // (This pointer points into an argv buffer and does not need to be |
98 // free'd.) | 93 // free'd.) |
99 static const char* load_feedback_filename = NULL; | 94 static const char* load_feedback_filename = NULL; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 CommandLineOptions* vm_options) { | 328 CommandLineOptions* vm_options) { |
334 ASSERT(arg != NULL); | 329 ASSERT(arg != NULL); |
335 if (*arg != '\0') { | 330 if (*arg != '\0') { |
336 return false; | 331 return false; |
337 } | 332 } |
338 parse_all = true; | 333 parse_all = true; |
339 return true; | 334 return true; |
340 } | 335 } |
341 | 336 |
342 | 337 |
| 338 #if !defined(DART_PRECOMPILED_RUNTIME) |
343 static bool ProcessFrontendOption(const char* filename, | 339 static bool ProcessFrontendOption(const char* filename, |
344 CommandLineOptions* vm_options) { | 340 CommandLineOptions* vm_options) { |
345 ASSERT(filename != NULL); | 341 ASSERT(filename != NULL); |
346 if (filename[0] == '\0') { | 342 if (filename[0] == '\0') { |
347 return false; | 343 return false; |
348 } | 344 } |
349 use_dart_frontend = true; | 345 dfe.set_frontend_filename(filename); |
350 frontend_filename = filename; | |
351 vm_options->AddArgument("--use-dart-frontend"); | 346 vm_options->AddArgument("--use-dart-frontend"); |
352 return true; | 347 return true; |
353 } | 348 } |
354 | 349 |
355 | 350 |
356 static bool ProcessPlatformOption(const char* filename, | 351 static bool ProcessPlatformOption(const char* filename, |
357 CommandLineOptions* vm_options) { | 352 CommandLineOptions* vm_options) { |
358 ASSERT(filename != NULL); | 353 ASSERT(filename != NULL); |
359 if (filename[0] == '\0') { | 354 if (filename[0] == '\0') { |
360 return false; | 355 return false; |
361 } | 356 } |
362 use_platform_binary = true; | 357 dfe.set_platform_binary_filename(filename); |
363 platform_binary_filename = filename; | |
364 return true; | 358 return true; |
365 } | 359 } |
| 360 #endif |
366 | 361 |
367 | 362 |
368 static bool ProcessUseBlobsOption(const char* arg, | 363 static bool ProcessUseBlobsOption(const char* arg, |
369 CommandLineOptions* vm_options) { | 364 CommandLineOptions* vm_options) { |
370 ASSERT(arg != NULL); | 365 ASSERT(arg != NULL); |
371 if (*arg != '\0') { | 366 if (*arg != '\0') { |
372 return false; | 367 return false; |
373 } | 368 } |
374 use_blobs = true; | 369 use_blobs = true; |
375 return true; | 370 return true; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 {"--help", ProcessHelpOption}, | 576 {"--help", ProcessHelpOption}, |
582 {"--packages=", ProcessPackagesOption}, | 577 {"--packages=", ProcessPackagesOption}, |
583 {"--package-root=", ProcessPackageRootOption}, | 578 {"--package-root=", ProcessPackageRootOption}, |
584 {"-v", ProcessVerboseOption}, | 579 {"-v", ProcessVerboseOption}, |
585 {"--verbose", ProcessVerboseOption}, | 580 {"--verbose", ProcessVerboseOption}, |
586 {"--version", ProcessVersionOption}, | 581 {"--version", ProcessVersionOption}, |
587 | 582 |
588 // VM specific options to the standalone dart program. | 583 // VM specific options to the standalone dart program. |
589 {"--compile_all", ProcessCompileAllOption}, | 584 {"--compile_all", ProcessCompileAllOption}, |
590 {"--parse_all", ProcessParseAllOption}, | 585 {"--parse_all", ProcessParseAllOption}, |
| 586 #if !defined(DART_PRECOMPILED_RUNTIME) |
591 {"--dfe=", ProcessFrontendOption}, | 587 {"--dfe=", ProcessFrontendOption}, |
592 {"--platform=", ProcessPlatformOption}, | 588 {"--platform=", ProcessPlatformOption}, |
| 589 #endif |
593 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 590 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
594 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 591 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
595 {"--observe", ProcessObserveOption}, | 592 {"--observe", ProcessObserveOption}, |
596 {"--snapshot=", ProcessSnapshotFilenameOption}, | 593 {"--snapshot=", ProcessSnapshotFilenameOption}, |
597 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 594 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
598 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, | 595 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, |
599 {"--use-blobs", ProcessUseBlobsOption}, | 596 {"--use-blobs", ProcessUseBlobsOption}, |
600 {"--save-feedback=", ProcessSaveFeedbackOption}, | 597 {"--save-feedback=", ProcessSaveFeedbackOption}, |
601 {"--load-feedback=", ProcessLoadFeedbackOption}, | 598 {"--load-feedback=", ProcessLoadFeedbackOption}, |
602 {"--trace-loading", ProcessTraceLoadingOption}, | 599 {"--trace-loading", ProcessTraceLoadingOption}, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 // Returns newly created Isolate on success, NULL on failure. | 827 // Returns newly created Isolate on success, NULL on failure. |
831 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, | 828 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
832 const char* script_uri, | 829 const char* script_uri, |
833 const char* main, | 830 const char* main, |
834 const char* package_root, | 831 const char* package_root, |
835 const char* packages_config, | 832 const char* packages_config, |
836 Dart_IsolateFlags* flags, | 833 Dart_IsolateFlags* flags, |
837 char** error, | 834 char** error, |
838 int* exit_code) { | 835 int* exit_code) { |
839 ASSERT(script_uri != NULL); | 836 ASSERT(script_uri != NULL); |
840 const bool is_kernel_isolate = | |
841 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; | |
842 if (is_kernel_isolate) { | |
843 if (!use_dart_frontend) { | |
844 *error = strdup("Kernel isolate not supported."); | |
845 return NULL; | |
846 } | |
847 script_uri = frontend_filename; | |
848 if (packages_config == NULL) { | |
849 packages_config = commandline_packages_file; | |
850 } | |
851 } | |
852 | |
853 void* kernel_platform = NULL; | 837 void* kernel_platform = NULL; |
854 void* kernel_program = NULL; | 838 void* kernel_program = NULL; |
855 AppSnapshot* app_snapshot = NULL; | 839 AppSnapshot* app_snapshot = NULL; |
856 | 840 |
857 #if defined(DART_PRECOMPILED_RUNTIME) | 841 #if defined(DART_PRECOMPILED_RUNTIME) |
858 // AOT: All isolates start from the app snapshot. | 842 // AOT: All isolates start from the app snapshot. |
859 bool isolate_run_app_snapshot = true; | 843 bool isolate_run_app_snapshot = true; |
860 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; | 844 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
861 const uint8_t* isolate_snapshot_instructions = | 845 const uint8_t* isolate_snapshot_instructions = |
862 app_isolate_snapshot_instructions; | 846 app_isolate_snapshot_instructions; |
863 #else | 847 #else |
864 // JIT: Main isolate starts from the app snapshot, if any. Other isolates | 848 // JIT: Main isolate starts from the app snapshot, if any. Other isolates |
865 // use the core libraries snapshot. | 849 // use the core libraries snapshot. |
866 bool isolate_run_app_snapshot = false; | 850 bool isolate_run_app_snapshot = false; |
867 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; | 851 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
868 const uint8_t* isolate_snapshot_instructions = | 852 const uint8_t* isolate_snapshot_instructions = |
869 core_isolate_snapshot_instructions; | 853 core_isolate_snapshot_instructions; |
| 854 const bool is_kernel_isolate = |
| 855 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; |
| 856 if (is_kernel_isolate) { |
| 857 if (!dfe.UseDartFrontend()) { |
| 858 *error = strdup("Kernel isolate not supported."); |
| 859 return NULL; |
| 860 } |
| 861 script_uri = dfe.frontend_filename(); |
| 862 if (packages_config == NULL) { |
| 863 packages_config = commandline_packages_file; |
| 864 } |
| 865 } |
870 if ((app_isolate_snapshot_data != NULL) && | 866 if ((app_isolate_snapshot_data != NULL) && |
871 (is_main_isolate || ((app_script_uri != NULL) && | 867 (is_main_isolate || ((app_script_uri != NULL) && |
872 (strcmp(script_uri, app_script_uri) == 0)))) { | 868 (strcmp(script_uri, app_script_uri) == 0)))) { |
873 isolate_run_app_snapshot = true; | 869 isolate_run_app_snapshot = true; |
874 isolate_snapshot_data = app_isolate_snapshot_data; | 870 isolate_snapshot_data = app_isolate_snapshot_data; |
875 isolate_snapshot_instructions = app_isolate_snapshot_instructions; | 871 isolate_snapshot_instructions = app_isolate_snapshot_instructions; |
876 } else if (!is_main_isolate) { | 872 } else if (!is_main_isolate) { |
877 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); | 873 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); |
878 if (app_snapshot != NULL) { | 874 if (app_snapshot != NULL) { |
879 isolate_run_app_snapshot = true; | 875 isolate_run_app_snapshot = true; |
880 const uint8_t* ignore_vm_snapshot_data; | 876 const uint8_t* ignore_vm_snapshot_data; |
881 const uint8_t* ignore_vm_snapshot_instructions; | 877 const uint8_t* ignore_vm_snapshot_instructions; |
882 app_snapshot->SetBuffers( | 878 app_snapshot->SetBuffers( |
883 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | 879 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
884 &isolate_snapshot_data, &isolate_snapshot_instructions); | 880 &isolate_snapshot_data, &isolate_snapshot_instructions); |
885 } | 881 } |
886 } | 882 } |
887 const bool is_service_isolate = | 883 const bool is_service_isolate = |
888 strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; | 884 strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; |
889 if (!is_kernel_isolate && !is_service_isolate) { | 885 if (!is_kernel_isolate && !is_service_isolate) { |
890 const uint8_t* platform_file = NULL; | 886 const uint8_t* platform_file = NULL; |
891 if (use_platform_binary) { | 887 if (dfe.UsePlatformBinary()) { |
892 intptr_t platform_length = -1; | 888 intptr_t platform_length = -1; |
893 bool success = TryReadKernel(platform_binary_filename, &platform_file, | 889 bool success = dfe.TryReadKernelFile(dfe.platform_binary_filename(), |
894 &platform_length); | 890 &platform_file, &platform_length); |
895 if (!success) { | 891 if (!success) { |
896 *error = strdup("The platform binary is not a valid Dart Kernel file."); | 892 *error = strdup("The platform binary is not a valid Dart Kernel file."); |
897 *exit_code = kErrorExitCode; | 893 *exit_code = kErrorExitCode; |
898 return NULL; | 894 return NULL; |
899 } | 895 } |
900 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); | 896 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); |
901 } | 897 } |
902 | 898 |
903 bool is_kernel = false; | 899 bool is_kernel = false; |
904 const uint8_t* kernel_file = NULL; | 900 const uint8_t* kernel_file = NULL; |
905 intptr_t kernel_length = -1; | 901 intptr_t kernel_length = -1; |
906 if (use_dart_frontend) { | 902 if (dfe.UseDartFrontend()) { |
907 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | 903 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); |
908 *error = result.error; // Copy error message (if any). | 904 *error = result.error; // Copy error message (if any). |
909 switch (result.status) { | 905 switch (result.status) { |
910 case Dart_KernelCompilationStatus_Ok: | 906 case Dart_KernelCompilationStatus_Ok: |
911 is_kernel = true; | 907 is_kernel = true; |
912 kernel_file = result.kernel; | 908 kernel_file = result.kernel; |
913 kernel_length = result.kernel_size; | 909 kernel_length = result.kernel_size; |
914 break; | 910 break; |
915 case Dart_KernelCompilationStatus_Error: | 911 case Dart_KernelCompilationStatus_Error: |
916 *exit_code = kCompilationErrorExitCode; | 912 *exit_code = kCompilationErrorExitCode; |
917 break; | 913 break; |
918 case Dart_KernelCompilationStatus_Crash: | 914 case Dart_KernelCompilationStatus_Crash: |
919 *exit_code = kDartFrontendErrorExitCode; | 915 *exit_code = kDartFrontendErrorExitCode; |
920 break; | 916 break; |
921 case Dart_KernelCompilationStatus_Unknown: | 917 case Dart_KernelCompilationStatus_Unknown: |
922 *exit_code = kErrorExitCode; | 918 *exit_code = kErrorExitCode; |
923 break; | 919 break; |
924 } | 920 } |
925 if (!is_kernel) { | 921 if (!is_kernel) { |
926 free(const_cast<uint8_t*>(platform_file)); | 922 free(const_cast<uint8_t*>(platform_file)); |
927 delete reinterpret_cast<kernel::Program*>(kernel_platform); | 923 delete reinterpret_cast<kernel::Program*>(kernel_platform); |
928 return NULL; | 924 return NULL; |
929 } | 925 } |
930 } else if (!isolate_run_app_snapshot) { | 926 } else if (!isolate_run_app_snapshot) { |
931 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); | 927 is_kernel = |
| 928 dfe.TryReadKernelFile(script_uri, &kernel_file, &kernel_length); |
932 } | 929 } |
933 | 930 |
934 if (is_kernel) { | 931 if (is_kernel) { |
935 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | 932 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
936 } | 933 } |
937 } | 934 } |
938 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 935 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
939 | 936 |
940 IsolateData* isolate_data = | 937 IsolateData* isolate_data = |
941 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | 938 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 Platform::Exit(Process::GlobalExitCode()); | 1769 Platform::Exit(Process::GlobalExitCode()); |
1773 } | 1770 } |
1774 | 1771 |
1775 } // namespace bin | 1772 } // namespace bin |
1776 } // namespace dart | 1773 } // namespace dart |
1777 | 1774 |
1778 int main(int argc, char** argv) { | 1775 int main(int argc, char** argv) { |
1779 dart::bin::main(argc, argv); | 1776 dart::bin::main(argc, argv); |
1780 UNREACHABLE(); | 1777 UNREACHABLE(); |
1781 } | 1778 } |
OLD | NEW |