| Index: runtime/bin/main.cc
|
| diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
|
| index 9ebbcd12eb2c9fe60a2894234a536cf53852882c..8e0a59543394eceb6e686bac39fe3da2ceadd4d4 100644
|
| --- a/runtime/bin/main.cc
|
| +++ b/runtime/bin/main.cc
|
| @@ -34,6 +34,8 @@
|
| #include "zlib/zlib.h"
|
| #endif
|
|
|
| +#include "vm/kernel.h"
|
| +
|
| namespace dart {
|
| namespace bin {
|
|
|
| @@ -67,6 +69,11 @@ static bool use_dart_frontend = false;
|
|
|
| static const char* frontend_filename = NULL;
|
|
|
| +// True if the VM should boostrap the SDK from a binary (.dill) file. The
|
| +// filename points into an argv buffer and does not need to be freed.
|
| +static bool use_platform_binary = false;
|
| +static const char* platform_binary_filename = NULL;
|
| +
|
| // Value of the --save-feedback flag.
|
| // (This pointer points into an argv buffer and does not need to be
|
| // free'd.)
|
| @@ -333,6 +340,18 @@ static bool ProcessFrontendOption(const char* filename,
|
| }
|
|
|
|
|
| +static bool ProcessPlatformOption(const char* filename,
|
| + CommandLineOptions* vm_options) {
|
| + ASSERT(filename != NULL);
|
| + if (filename[0] == '\0') {
|
| + return false;
|
| + }
|
| + use_platform_binary = true;
|
| + platform_binary_filename = filename;
|
| + return true;
|
| +}
|
| +
|
| +
|
| static bool ProcessUseBlobsOption(const char* arg,
|
| CommandLineOptions* vm_options) {
|
| ASSERT(arg != NULL);
|
| @@ -557,6 +576,7 @@ static struct {
|
| {"--compile_all", ProcessCompileAllOption},
|
| {"--parse_all", ProcessParseAllOption},
|
| {"--dfe=", ProcessFrontendOption},
|
| + {"--platform=", ProcessPlatformOption},
|
| {"--enable-vm-service", ProcessEnableVmServiceOption},
|
| {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption},
|
| {"--observe", ProcessObserveOption},
|
| @@ -853,11 +873,25 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
| }
|
| #endif
|
|
|
| - const uint8_t* kernel_file = NULL;
|
| - intptr_t kernel_length = -1;
|
| - bool is_kernel = false;
|
| -
|
| + void* kernel_platform = NULL;
|
| + void* kernel_program = NULL;
|
| if (!is_kernel_isolate && !is_service_isolate) {
|
| + const uint8_t* platform_file = NULL;
|
| + if (use_platform_binary) {
|
| + intptr_t platform_length = -1;
|
| + bool success = TryReadKernel(platform_binary_filename, &platform_file,
|
| + &platform_length);
|
| + if (!success) {
|
| + *error = strdup("The platform binary is not a valid Dart Kernel file.");
|
| + *exit_code = kErrorExitCode;
|
| + return NULL;
|
| + }
|
| + kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length);
|
| + }
|
| +
|
| + bool is_kernel = false;
|
| + const uint8_t* kernel_file = NULL;
|
| + intptr_t kernel_length = -1;
|
| if (use_dart_frontend) {
|
| Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri);
|
| *error = result.error; // Copy error message (if any).
|
| @@ -869,22 +903,26 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
| break;
|
| case Dart_KernelCompilationStatus_Error:
|
| *exit_code = kCompilationErrorExitCode;
|
| - return NULL;
|
| + break;
|
| case Dart_KernelCompilationStatus_Crash:
|
| *exit_code = kDartFrontendErrorExitCode;
|
| - return NULL;
|
| + break;
|
| case Dart_KernelCompilationStatus_Unknown:
|
| *exit_code = kErrorExitCode;
|
| - return NULL;
|
| + break;
|
| + }
|
| + if (!is_kernel) {
|
| + free(const_cast<uint8_t*>(platform_file));
|
| + delete reinterpret_cast<kernel::Program*>(kernel_platform);
|
| + return NULL;
|
| }
|
| } else if (!isolate_run_app_snapshot) {
|
| is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length);
|
| }
|
| - }
|
|
|
| - void* kernel_program = NULL;
|
| - if (is_kernel) {
|
| - kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
|
| + if (is_kernel) {
|
| + kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
|
| + }
|
| }
|
|
|
| IsolateData* isolate_data =
|
| @@ -892,14 +930,13 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
| if (is_main_isolate && (snapshot_deps_filename != NULL)) {
|
| isolate_data->set_dependencies(new MallocGrowableArray<char*>());
|
| }
|
| - // If the script is a Kernel binary, then we will try to bootstrap from the
|
| - // script.
|
| Dart_Isolate isolate =
|
| - is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program,
|
| - flags, isolate_data, error)
|
| - : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
|
| - isolate_snapshot_instructions, flags,
|
| - isolate_data, error);
|
| + kernel_platform != NULL
|
| + ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform,
|
| + flags, isolate_data, error)
|
| + : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
|
| + isolate_snapshot_instructions, flags,
|
| + isolate_data, error);
|
| if (isolate == NULL) {
|
| delete isolate_data;
|
| return NULL;
|
| @@ -911,11 +948,11 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
| Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
|
| CHECK_RESULT(result);
|
|
|
| - if (is_kernel) {
|
| + if (kernel_program != NULL) {
|
| Dart_Handle result = Dart_LoadKernel(kernel_program);
|
| CHECK_RESULT(result);
|
| }
|
| - if (is_kernel || (isolate_snapshot_data != NULL)) {
|
| + if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) {
|
| // Setup the native resolver as the snapshot does not carry it.
|
| Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
|
| Builtin::SetNativeResolver(Builtin::kIOLibrary);
|
| @@ -985,7 +1022,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
| Dart_Handle uri =
|
| DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri));
|
| CHECK_RESULT(uri);
|
| - if (!is_kernel) {
|
| + if (kernel_platform == NULL) {
|
| result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri);
|
| CHECK_RESULT(result);
|
| } else {
|
|
|