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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 static bool run_app_snapshot = false; | 54 static bool run_app_snapshot = false; |
55 static const char* snapshot_filename = NULL; | 55 static const char* snapshot_filename = NULL; |
56 enum SnapshotKind { | 56 enum SnapshotKind { |
57 kNone, | 57 kNone, |
58 kScript, | 58 kScript, |
59 kAppAOT, | 59 kAppAOT, |
60 kAppJIT, | 60 kAppJIT, |
61 }; | 61 }; |
62 static SnapshotKind gen_snapshot_kind = kNone; | 62 static SnapshotKind gen_snapshot_kind = kNone; |
63 | 63 |
| 64 static bool use_dart_frontend = false; |
| 65 |
| 66 static const char* frontend_filename = NULL; |
| 67 |
64 // Value of the --package-root flag. | 68 // Value of the --package-root flag. |
65 // (This pointer points into an argv buffer and does not need to be | 69 // (This pointer points into an argv buffer and does not need to be |
66 // free'd.) | 70 // free'd.) |
67 static const char* commandline_package_root = NULL; | 71 static const char* commandline_package_root = NULL; |
68 | 72 |
69 // Value of the --packages flag. | 73 // Value of the --packages flag. |
70 // (This pointer points into an argv buffer and does not need to be | 74 // (This pointer points into an argv buffer and does not need to be |
71 // free'd.) | 75 // free'd.) |
72 static const char* commandline_packages_file = NULL; | 76 static const char* commandline_packages_file = NULL; |
73 | 77 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 CommandLineOptions* vm_options) { | 321 CommandLineOptions* vm_options) { |
318 ASSERT(arg != NULL); | 322 ASSERT(arg != NULL); |
319 if (*arg != '\0') { | 323 if (*arg != '\0') { |
320 return false; | 324 return false; |
321 } | 325 } |
322 parse_all = true; | 326 parse_all = true; |
323 return true; | 327 return true; |
324 } | 328 } |
325 | 329 |
326 | 330 |
| 331 static bool ProcessFrontendOption(const char* filename, |
| 332 CommandLineOptions* vm_options) { |
| 333 ASSERT(filename != NULL); |
| 334 if (filename[0] == '\0') { |
| 335 return false; |
| 336 } |
| 337 use_dart_frontend = true; |
| 338 frontend_filename = filename; |
| 339 return true; |
| 340 } |
| 341 |
| 342 |
327 static bool ProcessUseBlobsOption(const char* arg, | 343 static bool ProcessUseBlobsOption(const char* arg, |
328 CommandLineOptions* vm_options) { | 344 CommandLineOptions* vm_options) { |
329 ASSERT(arg != NULL); | 345 ASSERT(arg != NULL); |
330 if (*arg != '\0') { | 346 if (*arg != '\0') { |
331 return false; | 347 return false; |
332 } | 348 } |
333 use_blobs = true; | 349 use_blobs = true; |
334 return true; | 350 return true; |
335 } | 351 } |
336 | 352 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 {"--help", ProcessHelpOption}, | 549 {"--help", ProcessHelpOption}, |
534 {"--packages=", ProcessPackagesOption}, | 550 {"--packages=", ProcessPackagesOption}, |
535 {"--package-root=", ProcessPackageRootOption}, | 551 {"--package-root=", ProcessPackageRootOption}, |
536 {"-v", ProcessVerboseOption}, | 552 {"-v", ProcessVerboseOption}, |
537 {"--verbose", ProcessVerboseOption}, | 553 {"--verbose", ProcessVerboseOption}, |
538 {"--version", ProcessVersionOption}, | 554 {"--version", ProcessVersionOption}, |
539 | 555 |
540 // VM specific options to the standalone dart program. | 556 // VM specific options to the standalone dart program. |
541 {"--compile_all", ProcessCompileAllOption}, | 557 {"--compile_all", ProcessCompileAllOption}, |
542 {"--parse_all", ProcessParseAllOption}, | 558 {"--parse_all", ProcessParseAllOption}, |
| 559 {"--dfe=", ProcessFrontendOption}, |
543 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 560 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
544 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 561 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
545 {"--observe", ProcessObserveOption}, | 562 {"--observe", ProcessObserveOption}, |
546 {"--snapshot=", ProcessSnapshotFilenameOption}, | 563 {"--snapshot=", ProcessSnapshotFilenameOption}, |
547 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 564 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
548 {"--use-blobs", ProcessUseBlobsOption}, | 565 {"--use-blobs", ProcessUseBlobsOption}, |
549 {"--trace-loading", ProcessTraceLoadingOption}, | 566 {"--trace-loading", ProcessTraceLoadingOption}, |
550 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, | 567 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, |
551 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, | 568 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, |
552 {"--short_socket_read", ProcessShortSocketReadOption}, | 569 {"--short_socket_read", ProcessShortSocketReadOption}, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 const bool run_service_isolate = needs_load_port; | 801 const bool run_service_isolate = needs_load_port; |
785 #else | 802 #else |
786 // Always create the service isolate in DEBUG and RELEASE modes for profiling, | 803 // Always create the service isolate in DEBUG and RELEASE modes for profiling, |
787 // even if we don't need it for loading. | 804 // even if we don't need it for loading. |
788 const bool run_service_isolate = true; | 805 const bool run_service_isolate = true; |
789 #endif // PRODUCT | 806 #endif // PRODUCT |
790 if (!run_service_isolate && | 807 if (!run_service_isolate && |
791 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { | 808 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |
792 return NULL; | 809 return NULL; |
793 } | 810 } |
| 811 if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { |
| 812 if (!use_dart_frontend) { |
| 813 *error = strdup("Kernel isolate not supported."); |
| 814 return NULL; |
| 815 } else { |
| 816 if (packages_config == NULL) { |
| 817 packages_config = commandline_packages_file; |
| 818 } |
| 819 } |
| 820 } |
794 | 821 |
795 // If the script is a Kernel binary, then we will try to bootstrap from the | 822 // If the script is a Kernel binary, then we will try to bootstrap from the |
796 // script. | 823 // script. |
797 const uint8_t* kernel_file = NULL; | 824 const uint8_t* kernel_file = NULL; |
798 intptr_t kernel_length = -1; | 825 intptr_t kernel_length = -1; |
799 const bool is_kernel = | 826 const bool is_kernel = |
800 !run_app_snapshot && | 827 !run_app_snapshot && |
801 TryReadKernel(script_uri, &kernel_file, &kernel_length); | 828 TryReadKernel(script_uri, &kernel_file, &kernel_length); |
802 | 829 |
803 void* kernel_program = NULL; | 830 void* kernel_program = NULL; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 890 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
864 CHECK_RESULT(result); | 891 CHECK_RESULT(result); |
865 | 892 |
866 if (needs_load_port) { | 893 if (needs_load_port) { |
867 // Set up the load port provided by the service isolate so that we can | 894 // Set up the load port provided by the service isolate so that we can |
868 // load scripts. | 895 // load scripts. |
869 result = DartUtils::SetupServiceLoadPort(); | 896 result = DartUtils::SetupServiceLoadPort(); |
870 CHECK_RESULT(result); | 897 CHECK_RESULT(result); |
871 } | 898 } |
872 | 899 |
| 900 if (Dart_IsKernelIsolate(isolate)) { |
| 901 script_uri = frontend_filename; |
| 902 } |
| 903 |
873 // Setup package root if specified. | 904 // Setup package root if specified. |
874 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 905 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
875 CHECK_RESULT(result); | 906 CHECK_RESULT(result); |
876 | 907 |
877 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 908 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
878 CHECK_RESULT(result); | 909 CHECK_RESULT(result); |
879 | 910 |
| 911 if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) { |
| 912 Log::PrintErr("Waiting for Kernel isolate to load.\n"); |
| 913 // This must be the main script to be loaded. Wait for Kernel isolate |
| 914 // to finish initialization. |
| 915 Dart_Port port = Dart_ServiceWaitForKernelPort(); |
| 916 if (port == ILLEGAL_PORT) { |
| 917 *error = strdup("Error while initializing Kernel isolate"); |
| 918 return NULL; |
| 919 } |
| 920 } |
| 921 |
880 if (run_app_snapshot) { | 922 if (run_app_snapshot) { |
881 result = DartUtils::SetupIOLibrary(script_uri); | 923 result = DartUtils::SetupIOLibrary(script_uri); |
882 CHECK_RESULT(result); | 924 CHECK_RESULT(result); |
883 Loader::InitForSnapshot(script_uri); | 925 Loader::InitForSnapshot(script_uri); |
884 } else { | 926 } else { |
885 // Load the specified application script into the newly created isolate. | 927 // Load the specified application script into the newly created isolate. |
886 Dart_Handle uri = | 928 Dart_Handle uri = |
887 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 929 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
888 CHECK_RESULT(uri); | 930 CHECK_RESULT(uri); |
889 if (!is_kernel) { | 931 if (!is_kernel) { |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 Platform::Exit(Process::GlobalExitCode()); | 1985 Platform::Exit(Process::GlobalExitCode()); |
1944 } | 1986 } |
1945 | 1987 |
1946 } // namespace bin | 1988 } // namespace bin |
1947 } // namespace dart | 1989 } // namespace dart |
1948 | 1990 |
1949 int main(int argc, char** argv) { | 1991 int main(int argc, char** argv) { |
1950 dart::bin::main(argc, argv); | 1992 dart::bin::main(argc, argv); |
1951 UNREACHABLE(); | 1993 UNREACHABLE(); |
1952 } | 1994 } |
OLD | NEW |