Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we | 34 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we |
| 35 // link in a snapshot otherwise it is initialized to NULL. | 35 // link in a snapshot otherwise it is initialized to NULL. |
| 36 extern const uint8_t* vm_isolate_snapshot_buffer; | 36 extern const uint8_t* vm_isolate_snapshot_buffer; |
| 37 | 37 |
| 38 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a | 38 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a |
| 39 // snapshot otherwise it is initialized to NULL. | 39 // snapshot otherwise it is initialized to NULL. |
| 40 extern const uint8_t* isolate_snapshot_buffer; | 40 extern const uint8_t* isolate_snapshot_buffer; |
| 41 | 41 |
| 42 // Global state that stores a pointer to the application script snapshot. | 42 // Global state that stores a pointer to the application script snapshot. |
| 43 static bool generate_script_snapshot = false; | 43 static bool generate_script_snapshot = false; |
| 44 static bool generate_script_snapshot_after_run = false; | 44 static bool generate_full_snapshot_after_run = false; |
| 45 static bool run_full_snapshot = false; | |
| 45 static const char* snapshot_filename = NULL; | 46 static const char* snapshot_filename = NULL; |
| 46 | 47 |
| 47 | 48 |
| 48 // Value of the --package-root flag. | 49 // Value of the --package-root flag. |
| 49 // (This pointer points into an argv buffer and does not need to be | 50 // (This pointer points into an argv buffer and does not need to be |
| 50 // free'd.) | 51 // free'd.) |
| 51 static const char* commandline_package_root = NULL; | 52 static const char* commandline_package_root = NULL; |
| 52 | 53 |
| 53 // Value of the --packages flag. | 54 // Value of the --packages flag. |
| 54 // (This pointer points into an argv buffer and does not need to be | 55 // (This pointer points into an argv buffer and does not need to be |
| 55 // free'd.) | 56 // free'd.) |
| 56 static const char* commandline_packages_file = NULL; | 57 static const char* commandline_packages_file = NULL; |
| 57 | 58 |
| 58 | 59 |
| 59 // Global flag that is used to indicate that we want to compile all the | 60 // Global flag that is used to indicate that we want to compile all the |
| 60 // dart functions and not run anything. | 61 // dart functions and not run anything. |
| 61 static bool has_compile_all = false; | 62 static bool compile_all = false; |
| 62 | 63 |
| 63 | 64 |
| 64 // Global flag that is used to indicate that we want to compile all the | 65 // Global flag that is used to indicate that we want to compile all the |
| 65 // dart functions before running main and not compile anything thereafter. | 66 // dart functions before running main and not compile anything thereafter. |
| 66 static bool has_gen_precompiled_snapshot = false; | 67 static bool gen_precompiled_snapshot = false; |
| 67 | 68 |
| 68 | 69 |
| 69 // Global flag that is used to indicate that we want to run from a precompiled | 70 // Global flag that is used to indicate that we want to run from a precompiled |
| 70 // snapshot. | 71 // snapshot. |
| 71 static bool has_run_precompiled_snapshot = false; | 72 static bool run_precompiled_snapshot = false; |
| 72 | 73 |
| 73 | 74 |
| 74 // Value of the --gen/run_precompiled_snapshot flag. | 75 // Value of the --gen/run_precompiled_snapshot flag. |
| 75 // (This pointer points into an argv buffer and does not need to be | 76 // (This pointer points into an argv buffer and does not need to be |
| 76 // free'd.) | 77 // free'd.) |
| 77 static const char* precompiled_snapshot_directory = NULL; | 78 static const char* precompiled_snapshot_directory = NULL; |
| 78 | 79 |
| 79 | 80 |
| 80 // Global flag that is used to indicate that we want to compile everything in | 81 // Global flag that is used to indicate that we want to compile everything in |
| 81 // the same way as precompilation before main, then continue running in the | 82 // the same way as precompilation before main, then continue running in the |
| 82 // same process. | 83 // same process. |
| 83 static bool has_noopt = false; | 84 static bool noopt = false; |
|
srdjan
2016/02/05 17:35:02
I would add a verb to this, as done with all other
siva
2016/02/05 23:14:18
Done.
| |
| 84 | 85 |
| 85 | 86 |
| 86 extern const char* kPrecompiledLibraryName; | 87 extern const char* kPrecompiledLibraryName; |
| 87 extern const char* kPrecompiledSymbolName; | 88 extern const char* kPrecompiledSymbolName; |
| 88 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; | 89 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; |
| 89 static const char* kPrecompiledIsolateName = "precompiled.isolate"; | 90 static const char* kPrecompiledIsolateName = "precompiled.isolate"; |
| 90 static const char* kPrecompiledInstructionsName = "precompiled.S"; | 91 static const char* kPrecompiledInstructionsName = "precompiled.S"; |
| 91 | 92 static const char* kVMIsolateSuffix = "vmisolate"; |
| 93 static const char* kIsolateSuffix = "isolate"; | |
| 92 | 94 |
| 93 // Global flag that is used to indicate that we want to trace resolution of | 95 // Global flag that is used to indicate that we want to trace resolution of |
| 94 // URIs and the loading of libraries, parts and scripts. | 96 // URIs and the loading of libraries, parts and scripts. |
| 95 static bool has_trace_loading = false; | 97 static bool trace_loading = false; |
| 96 | 98 |
| 97 | 99 |
| 98 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 100 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
| 99 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 101 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 100 // VM Service options. | 102 // VM Service options. |
| 101 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 103 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
| 102 // The 0 port is a magic value which results in the first available port | 104 // The 0 port is a magic value which results in the first available port |
| 103 // being allocated. | 105 // being allocated. |
| 104 static int vm_service_server_port = -1; | 106 static int vm_service_server_port = -1; |
| 105 | 107 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 150 |
| 149 static bool IsValidFlag(const char* name, | 151 static bool IsValidFlag(const char* name, |
| 150 const char* prefix, | 152 const char* prefix, |
| 151 intptr_t prefix_length) { | 153 intptr_t prefix_length) { |
| 152 intptr_t name_length = strlen(name); | 154 intptr_t name_length = strlen(name); |
| 153 return ((name_length > prefix_length) && | 155 return ((name_length > prefix_length) && |
| 154 (strncmp(name, prefix, prefix_length) == 0)); | 156 (strncmp(name, prefix, prefix_length) == 0)); |
| 155 } | 157 } |
| 156 | 158 |
| 157 | 159 |
| 158 static bool has_version_option = false; | 160 static bool version_option = false; |
| 159 static bool ProcessVersionOption(const char* arg, | 161 static bool ProcessVersionOption(const char* arg, |
| 160 CommandLineOptions* vm_options) { | 162 CommandLineOptions* vm_options) { |
| 161 if (*arg != '\0') { | 163 if (*arg != '\0') { |
| 162 return false; | 164 return false; |
| 163 } | 165 } |
| 164 has_version_option = true; | 166 version_option = true; |
| 165 return true; | 167 return true; |
| 166 } | 168 } |
| 167 | 169 |
| 168 | 170 |
| 169 static bool has_help_option = false; | 171 static bool help_option = false; |
| 170 static bool ProcessHelpOption(const char* arg, CommandLineOptions* vm_options) { | 172 static bool ProcessHelpOption(const char* arg, CommandLineOptions* vm_options) { |
| 171 if (*arg != '\0') { | 173 if (*arg != '\0') { |
| 172 return false; | 174 return false; |
| 173 } | 175 } |
| 174 has_help_option = true; | 176 help_option = true; |
| 175 return true; | 177 return true; |
| 176 } | 178 } |
| 177 | 179 |
| 178 | 180 |
| 179 static bool has_verbose_option = false; | 181 static bool verbose_option = false; |
| 180 static bool ProcessVerboseOption(const char* arg, | 182 static bool ProcessVerboseOption(const char* arg, |
| 181 CommandLineOptions* vm_options) { | 183 CommandLineOptions* vm_options) { |
| 182 if (*arg != '\0') { | 184 if (*arg != '\0') { |
| 183 return false; | 185 return false; |
| 184 } | 186 } |
| 185 has_verbose_option = true; | 187 verbose_option = true; |
| 186 return true; | 188 return true; |
| 187 } | 189 } |
| 188 | 190 |
| 189 | 191 |
| 190 static bool ProcessPackageRootOption(const char* arg, | 192 static bool ProcessPackageRootOption(const char* arg, |
| 191 CommandLineOptions* vm_options) { | 193 CommandLineOptions* vm_options) { |
| 192 ASSERT(arg != NULL); | 194 ASSERT(arg != NULL); |
| 193 if (*arg == '\0' || *arg == '-') { | 195 if (*arg == '\0' || *arg == '-') { |
| 194 return false; | 196 return false; |
| 195 } | 197 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 return true; | 297 return true; |
| 296 } | 298 } |
| 297 | 299 |
| 298 | 300 |
| 299 static bool ProcessCompileAllOption(const char* arg, | 301 static bool ProcessCompileAllOption(const char* arg, |
| 300 CommandLineOptions* vm_options) { | 302 CommandLineOptions* vm_options) { |
| 301 ASSERT(arg != NULL); | 303 ASSERT(arg != NULL); |
| 302 if (*arg != '\0') { | 304 if (*arg != '\0') { |
| 303 return false; | 305 return false; |
| 304 } | 306 } |
| 305 has_compile_all = true; | 307 compile_all = true; |
| 306 return true; | 308 return true; |
| 307 } | 309 } |
| 308 | 310 |
| 309 | 311 |
| 310 static bool ProcessGenPrecompiledSnapshotOption( | 312 static bool ProcessGenPrecompiledSnapshotOption( |
| 311 const char* arg, | 313 const char* arg, |
| 312 CommandLineOptions* vm_options) { | 314 CommandLineOptions* vm_options) { |
| 313 // Ensure that we are not already running using a full snapshot. | 315 // Ensure that we are not already running using a full snapshot. |
| 314 if (isolate_snapshot_buffer != NULL) { | 316 if (isolate_snapshot_buffer != NULL) { |
| 315 Log::PrintErr("Precompiled snapshots must be generated with" | 317 Log::PrintErr("Precompiled snapshots must be generated with" |
| 316 " dart_no_snapshot.\n"); | 318 " dart_no_snapshot.\n"); |
| 317 return false; | 319 return false; |
| 318 } | 320 } |
| 319 ASSERT(arg != NULL); | 321 ASSERT(arg != NULL); |
| 320 if ((arg[0] == '=') || (arg[0] == ':')) { | 322 if ((arg[0] == '=') || (arg[0] == ':')) { |
| 321 precompiled_snapshot_directory = &arg[1]; | 323 precompiled_snapshot_directory = &arg[1]; |
| 322 } else { | 324 } else { |
| 323 precompiled_snapshot_directory = arg; | 325 precompiled_snapshot_directory = arg; |
| 324 } | 326 } |
| 325 has_gen_precompiled_snapshot = true; | 327 gen_precompiled_snapshot = true; |
| 326 vm_options->AddArgument("--precompilation"); | 328 vm_options->AddArgument("--precompilation"); |
| 327 return true; | 329 return true; |
| 328 } | 330 } |
| 329 | 331 |
| 330 | 332 |
| 331 static bool ProcessRunPrecompiledSnapshotOption( | 333 static bool ProcessRunPrecompiledSnapshotOption( |
| 332 const char* arg, | 334 const char* arg, |
| 333 CommandLineOptions* vm_options) { | 335 CommandLineOptions* vm_options) { |
| 334 ASSERT(arg != NULL); | 336 ASSERT(arg != NULL); |
| 335 precompiled_snapshot_directory = arg; | 337 precompiled_snapshot_directory = arg; |
| 336 if ((precompiled_snapshot_directory[0] == '=') || | 338 if ((precompiled_snapshot_directory[0] == '=') || |
| 337 (precompiled_snapshot_directory[0] == ':')) { | 339 (precompiled_snapshot_directory[0] == ':')) { |
| 338 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; | 340 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| 339 } | 341 } |
| 340 has_run_precompiled_snapshot = true; | 342 run_precompiled_snapshot = true; |
| 341 vm_options->AddArgument("--precompilation"); | 343 vm_options->AddArgument("--precompilation"); |
| 342 return true; | 344 return true; |
| 343 } | 345 } |
| 344 | 346 |
| 345 | 347 |
| 346 static bool ProcessScriptSnapshotOptionHelper(const char* filename, | 348 static bool ProcessSnapshotOptionHelper(const char* filename, |
| 347 bool* snapshot_option) { | 349 bool* snapshot_option) { |
| 348 *snapshot_option = false; | 350 ASSERT((filename != NULL) && (strlen(filename) != 0)); |
| 349 if ((filename != NULL) && (strlen(filename) != 0)) { | 351 snapshot_filename = filename; |
| 350 // Ensure that we are already running using a full snapshot. | 352 *snapshot_option = true; |
| 351 if (isolate_snapshot_buffer == NULL) { | 353 if (generate_script_snapshot && generate_full_snapshot_after_run) { |
| 352 Log::PrintErr("Script snapshots cannot be generated in this version of" | 354 Log::PrintErr("--snapshot and --snapshot-after-run options" |
| 353 " dart\n"); | 355 " cannot be specified at the same time\n"); |
| 354 return false; | 356 *snapshot_option = false; |
| 355 } | 357 return false; |
| 356 snapshot_filename = filename; | |
| 357 *snapshot_option = true; | |
| 358 if (generate_script_snapshot && generate_script_snapshot_after_run) { | |
| 359 Log::PrintErr("--snapshot and --snapshot-after-run options" | |
| 360 " cannot be specified at the same time\n"); | |
| 361 return false; | |
| 362 } | |
| 363 return true; | |
| 364 } | 358 } |
| 365 return false; | 359 return true; |
| 366 } | 360 } |
| 367 | 361 |
| 368 | 362 |
| 369 static bool ProcessScriptSnapshotOption(const char* filename, | 363 static bool ProcessScriptSnapshotOption(const char* filename, |
| 370 CommandLineOptions* vm_options) { | 364 CommandLineOptions* vm_options) { |
| 371 return ProcessScriptSnapshotOptionHelper(filename, &generate_script_snapshot); | 365 if ((filename == NULL) || (strlen(filename) == 0)) { |
| 366 return false; | |
| 367 } | |
| 368 // Ensure that we are already running using a full snapshot. | |
| 369 if (isolate_snapshot_buffer == NULL) { | |
| 370 Log::PrintErr("Script snapshots cannot be generated in this version of" | |
| 371 " dart\n"); | |
|
srdjan
2016/02/05 17:35:02
s/dart/Dart/
siva
2016/02/05 23:14:18
Done.
| |
| 372 return false; | |
| 373 } | |
| 374 return ProcessSnapshotOptionHelper(filename, &generate_script_snapshot); | |
| 372 } | 375 } |
| 373 | 376 |
| 374 | 377 |
| 375 static bool ProcessScriptSnapshotAfterRunOption( | 378 static bool ProcessFullSnapshotAfterRunOption( |
| 376 const char* filename, CommandLineOptions* vm_options) { | 379 const char* filename, CommandLineOptions* vm_options) { |
| 377 return ProcessScriptSnapshotOptionHelper(filename, | 380 if ((filename == NULL) || (strlen(filename) == 0)) { |
| 378 &generate_script_snapshot_after_run); | 381 return false; |
| 382 } | |
| 383 // Ensure that we are running 'dart_no_snapshot'. | |
| 384 if (isolate_snapshot_buffer != NULL) { | |
| 385 Log::PrintErr("Full Application snapshots must be generated with" | |
| 386 " dart_no_snapshot.\n"); | |
| 387 return false; | |
| 388 } | |
| 389 return ProcessSnapshotOptionHelper(filename, | |
| 390 &generate_full_snapshot_after_run); | |
| 379 } | 391 } |
| 380 | 392 |
| 381 | 393 |
| 394 static bool ProcessRunFullSnapshotOption( | |
| 395 const char* filename, CommandLineOptions* vm_options) { | |
| 396 // Ensure that we are not running 'dart_no_snapshot'. | |
| 397 if (isolate_snapshot_buffer == NULL) { | |
| 398 Log::PrintErr("Full Application snapshots cannot be run with" | |
| 399 " dart_no_snapshot.\n"); | |
| 400 return false; | |
| 401 } | |
| 402 return ProcessSnapshotOptionHelper(filename, &run_full_snapshot); | |
| 403 } | |
| 404 | |
| 405 | |
| 382 static bool ProcessEnableVmServiceOption(const char* option_value, | 406 static bool ProcessEnableVmServiceOption(const char* option_value, |
| 383 CommandLineOptions* vm_options) { | 407 CommandLineOptions* vm_options) { |
| 384 ASSERT(option_value != NULL); | 408 ASSERT(option_value != NULL); |
| 385 | 409 |
| 386 if (!ExtractPortAndIP(option_value, | 410 if (!ExtractPortAndIP(option_value, |
| 387 &vm_service_server_port, | 411 &vm_service_server_port, |
| 388 &vm_service_server_ip, | 412 &vm_service_server_ip, |
| 389 DEFAULT_VM_SERVICE_SERVER_PORT, | 413 DEFAULT_VM_SERVICE_SERVER_PORT, |
| 390 DEFAULT_VM_SERVICE_SERVER_IP)) { | 414 DEFAULT_VM_SERVICE_SERVER_IP)) { |
| 391 Log::PrintErr("unrecognized --enable-vm-service option syntax. " | 415 Log::PrintErr("unrecognized --enable-vm-service option syntax. " |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 416 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); | 440 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); |
| 417 return true; | 441 return true; |
| 418 } | 442 } |
| 419 | 443 |
| 420 | 444 |
| 421 static bool ProcessTraceLoadingOption(const char* arg, | 445 static bool ProcessTraceLoadingOption(const char* arg, |
| 422 CommandLineOptions* vm_options) { | 446 CommandLineOptions* vm_options) { |
| 423 if (*arg != '\0') { | 447 if (*arg != '\0') { |
| 424 return false; | 448 return false; |
| 425 } | 449 } |
| 426 has_trace_loading = true; | 450 trace_loading = true; |
| 427 return true; | 451 return true; |
| 428 } | 452 } |
| 429 | 453 |
| 430 | 454 |
| 431 | 455 |
| 432 static bool ProcessShutdownOption(const char* arg, | 456 static bool ProcessShutdownOption(const char* arg, |
| 433 CommandLineOptions* vm_options) { | 457 CommandLineOptions* vm_options) { |
| 434 ASSERT(arg != NULL); | 458 ASSERT(arg != NULL); |
| 435 if (*arg == '\0') { | 459 if (*arg == '\0') { |
| 436 do_vm_shutdown = true; | 460 do_vm_shutdown = true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 { "--version", ProcessVersionOption }, | 495 { "--version", ProcessVersionOption }, |
| 472 | 496 |
| 473 // VM specific options to the standalone dart program. | 497 // VM specific options to the standalone dart program. |
| 474 { "--compile_all", ProcessCompileAllOption }, | 498 { "--compile_all", ProcessCompileAllOption }, |
| 475 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 499 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 476 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, | 500 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, |
| 477 { "--observe", ProcessObserveOption }, | 501 { "--observe", ProcessObserveOption }, |
| 478 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, | 502 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, |
| 479 { "--shutdown", ProcessShutdownOption }, | 503 { "--shutdown", ProcessShutdownOption }, |
| 480 { "--snapshot=", ProcessScriptSnapshotOption }, | 504 { "--snapshot=", ProcessScriptSnapshotOption }, |
| 481 { "--snapshot-after-run=", ProcessScriptSnapshotAfterRunOption }, | 505 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, |
| 506 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, | |
| 482 { "--trace-loading", ProcessTraceLoadingOption }, | 507 { "--trace-loading", ProcessTraceLoadingOption }, |
| 483 { NULL, NULL } | 508 { NULL, NULL } |
| 484 }; | 509 }; |
| 485 | 510 |
| 486 | 511 |
| 487 static bool ProcessMainOptions(const char* option, | 512 static bool ProcessMainOptions(const char* option, |
| 488 CommandLineOptions* vm_options) { | 513 CommandLineOptions* vm_options) { |
| 489 int i = 0; | 514 int i = 0; |
| 490 const char* name = main_options[0].option_name; | 515 const char* name = main_options[0].option_name; |
| 491 int option_length = strlen(option); | 516 int option_length = strlen(option); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 i++; | 613 i++; |
| 589 } | 614 } |
| 590 | 615 |
| 591 // Verify consistency of arguments. | 616 // Verify consistency of arguments. |
| 592 if ((commandline_package_root != NULL) && | 617 if ((commandline_package_root != NULL) && |
| 593 (commandline_packages_file != NULL)) { | 618 (commandline_packages_file != NULL)) { |
| 594 Log::PrintErr("Specifying both a packages directory and a packages " | 619 Log::PrintErr("Specifying both a packages directory and a packages " |
| 595 "file is invalid.\n"); | 620 "file is invalid.\n"); |
| 596 return -1; | 621 return -1; |
| 597 } | 622 } |
| 598 if (has_noopt) { | 623 if (noopt) { |
| 599 if (has_gen_precompiled_snapshot) { | 624 if (gen_precompiled_snapshot) { |
| 600 Log::PrintErr("Specifying --noopt and --gen_precompiled_snapshot" | 625 Log::PrintErr("Specifying --noopt and --gen_precompiled_snapshot" |
| 601 " is invalid.\n"); | 626 " is invalid.\n"); |
| 602 return -1; | 627 return -1; |
| 603 } | 628 } |
| 604 if (has_run_precompiled_snapshot) { | 629 if (run_precompiled_snapshot) { |
| 605 Log::PrintErr("Specifying --noopt and --run_precompiled_snapshot" | 630 Log::PrintErr("Specifying --noopt and --run_precompiled_snapshot" |
| 606 " is invalid.\n"); | 631 " is invalid.\n"); |
| 607 return -1; | 632 return -1; |
| 608 } | 633 } |
| 609 } | 634 } |
| 610 if (has_gen_precompiled_snapshot && has_run_precompiled_snapshot) { | 635 if (run_full_snapshot && run_precompiled_snapshot) { |
| 611 Log::PrintErr("Specifying --gen_precompiled_snapshot and" | 636 Log::PrintErr("Specifying --run_full_snapshot and" |
| 612 " --run_precompiled_snapshot is invalid.\n"); | 637 " --run_precompiled_snapshot is invalid.\n"); |
| 613 return -1; | 638 return -1; |
| 614 } | 639 } |
| 640 if ((generate_full_snapshot_after_run || gen_precompiled_snapshot) && | |
| 641 (run_full_snapshot || run_precompiled_snapshot)) { | |
| 642 Log::PrintErr("Specifying an option to generate a snapshot and" | |
| 643 " run using a snapshot is invalid.\n"); | |
| 644 return -1; | |
| 645 } | |
| 615 | 646 |
| 616 return 0; | 647 return 0; |
| 617 } | 648 } |
| 618 | 649 |
| 619 | 650 |
| 620 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { | 651 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { |
| 621 int options_count = options->count(); | 652 int options_count = options->count(); |
| 622 Dart_Handle dart_arguments = Dart_NewList(options_count); | 653 Dart_Handle dart_arguments = Dart_NewList(options_count); |
| 623 if (Dart_IsError(dart_arguments)) { | 654 if (Dart_IsError(dart_arguments)) { |
| 624 return dart_arguments; | 655 return dart_arguments; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 | 721 |
| 691 // Returns true on success, false on failure. | 722 // Returns true on success, false on failure. |
| 692 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 723 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
| 693 const char* main, | 724 const char* main, |
| 694 const char* package_root, | 725 const char* package_root, |
| 695 const char* packages_config, | 726 const char* packages_config, |
| 696 Dart_IsolateFlags* flags, | 727 Dart_IsolateFlags* flags, |
| 697 char** error, | 728 char** error, |
| 698 int* exit_code) { | 729 int* exit_code) { |
| 699 ASSERT(script_uri != NULL); | 730 ASSERT(script_uri != NULL); |
| 731 if (run_full_snapshot && | |
| 732 !strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME)) { | |
| 733 // We do not create a service isolate when running a full application | |
| 734 // snapshot. | |
| 735 return NULL; | |
| 736 } | |
| 700 IsolateData* isolate_data = new IsolateData(script_uri, | 737 IsolateData* isolate_data = new IsolateData(script_uri, |
| 701 package_root, | 738 package_root, |
| 702 packages_config); | 739 packages_config); |
| 703 Dart_Isolate isolate = NULL; | 740 Dart_Isolate isolate = NULL; |
| 704 | 741 |
| 705 isolate = Dart_CreateIsolate(script_uri, | 742 isolate = Dart_CreateIsolate(script_uri, |
| 706 main, | 743 main, |
| 707 isolate_snapshot_buffer, | 744 isolate_snapshot_buffer, |
| 708 flags, | 745 flags, |
| 709 isolate_data, | 746 isolate_data, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 723 } | 760 } |
| 724 | 761 |
| 725 // Set up the library tag handler for this isolate. | 762 // Set up the library tag handler for this isolate. |
| 726 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 763 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 727 CHECK_RESULT(result); | 764 CHECK_RESULT(result); |
| 728 | 765 |
| 729 if (Dart_IsServiceIsolate(isolate)) { | 766 if (Dart_IsServiceIsolate(isolate)) { |
| 730 // If this is the service isolate, load embedder specific bits and return. | 767 // If this is the service isolate, load embedder specific bits and return. |
| 731 if (!VmService::Setup(vm_service_server_ip, | 768 if (!VmService::Setup(vm_service_server_ip, |
| 732 vm_service_server_port, | 769 vm_service_server_port, |
| 733 has_run_precompiled_snapshot)) { | 770 run_precompiled_snapshot)) { |
| 734 *error = strdup(VmService::GetErrorMessage()); | 771 *error = strdup(VmService::GetErrorMessage()); |
| 735 return NULL; | 772 return NULL; |
| 736 } | 773 } |
| 737 if (has_compile_all) { | 774 if (compile_all) { |
| 738 result = Dart_CompileAll(); | 775 result = Dart_CompileAll(); |
| 739 CHECK_RESULT(result); | 776 CHECK_RESULT(result); |
| 740 } | 777 } |
| 741 Dart_ExitScope(); | 778 Dart_ExitScope(); |
| 742 Dart_ExitIsolate(); | 779 Dart_ExitIsolate(); |
| 743 return isolate; | 780 return isolate; |
| 744 } | 781 } |
| 745 | 782 |
| 746 // Prepare builtin and other core libraries for use to resolve URIs. | 783 // Prepare builtin and other core libraries for use to resolve URIs. |
| 747 // Set up various closures, e.g: printing, timers etc. | 784 // Set up various closures, e.g: printing, timers etc. |
| 748 // Set up 'package root' for URI resolution. | 785 // Set up 'package root' for URI resolution. |
| 749 result = DartUtils::PrepareForScriptLoading(false, has_trace_loading); | 786 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
| 750 CHECK_RESULT(result); | 787 CHECK_RESULT(result); |
| 751 | 788 |
| 752 // Set up the load port provided by the service isolate so that we can | 789 if (!run_full_snapshot) { |
| 753 // load scripts. | 790 // Set up the load port provided by the service isolate so that we can |
| 754 result = DartUtils::SetupServiceLoadPort(); | 791 // load scripts. |
| 755 CHECK_RESULT(result); | 792 result = DartUtils::SetupServiceLoadPort(); |
| 793 CHECK_RESULT(result); | |
| 794 } | |
| 756 | 795 |
| 757 // Setup package root if specified. | 796 // Setup package root if specified. |
| 758 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 797 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
| 759 CHECK_RESULT(result); | 798 CHECK_RESULT(result); |
| 760 | 799 |
| 761 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 800 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 762 CHECK_RESULT(result); | 801 CHECK_RESULT(result); |
| 763 | 802 |
| 764 if (!has_run_precompiled_snapshot) { | 803 if (!run_precompiled_snapshot && !run_full_snapshot) { |
| 765 // Load the specified application script into the newly created isolate. | 804 // Load the specified application script into the newly created isolate. |
| 766 | |
| 767 // Load the script. | |
| 768 result = DartUtils::LoadScript(script_uri); | 805 result = DartUtils::LoadScript(script_uri); |
| 769 CHECK_RESULT(result); | 806 CHECK_RESULT(result); |
| 770 | 807 |
| 771 // Run event-loop and wait for script loading to complete. | 808 // Run event-loop and wait for script loading to complete. |
| 772 result = Dart_RunLoop(); | 809 result = Dart_RunLoop(); |
| 773 CHECK_RESULT(result); | 810 CHECK_RESULT(result); |
| 774 | 811 |
| 775 if (isolate_data->load_async_id >= 0) { | 812 if (isolate_data->load_async_id >= 0) { |
| 776 Dart_TimelineAsyncEnd("LoadScript", isolate_data->load_async_id); | 813 Dart_TimelineAsyncEnd("LoadScript", isolate_data->load_async_id); |
| 777 } | 814 } |
| 778 | 815 |
| 779 result = DartUtils::SetupIOLibrary(script_uri); | 816 result = DartUtils::SetupIOLibrary(script_uri); |
| 780 CHECK_RESULT(result); | 817 CHECK_RESULT(result); |
| 818 } else if (run_full_snapshot) { | |
| 819 result = DartUtils::SetupIOLibrary(script_uri); | |
| 820 CHECK_RESULT(result); | |
| 781 } | 821 } |
| 782 | 822 |
| 783 // Make the isolate runnable so that it is ready to handle messages. | 823 // Make the isolate runnable so that it is ready to handle messages. |
| 784 Dart_ExitScope(); | 824 Dart_ExitScope(); |
| 785 Dart_ExitIsolate(); | 825 Dart_ExitIsolate(); |
| 786 bool retval = Dart_IsolateMakeRunnable(isolate); | 826 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 787 if (!retval) { | 827 if (!retval) { |
| 788 *error = strdup("Invalid isolate state - Unable to make it runnable"); | 828 *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| 789 Dart_EnterIsolate(isolate); | 829 Dart_EnterIsolate(isolate); |
| 790 Dart_ShutdownIsolate(); | 830 Dart_ShutdownIsolate(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 867 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 828 } | 868 } |
| 829 | 869 |
| 830 | 870 |
| 831 static void PrintUsage() { | 871 static void PrintUsage() { |
| 832 Log::PrintErr( | 872 Log::PrintErr( |
| 833 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" | 873 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" |
| 834 "\n" | 874 "\n" |
| 835 "Executes the Dart script passed as <dart-script-file>.\n" | 875 "Executes the Dart script passed as <dart-script-file>.\n" |
| 836 "\n"); | 876 "\n"); |
| 837 if (!has_verbose_option) { | 877 if (!verbose_option) { |
| 838 Log::PrintErr( | 878 Log::PrintErr( |
| 839 "Common options:\n" | 879 "Common options:\n" |
| 840 "--checked or -c\n" | 880 "--checked or -c\n" |
| 841 " Insert runtime type checks and enable assertions (checked mode).\n" | 881 " Insert runtime type checks and enable assertions (checked mode).\n" |
| 842 "--help or -h\n" | 882 "--help or -h\n" |
| 843 " Display this message (add -v or --verbose for information about\n" | 883 " Display this message (add -v or --verbose for information about\n" |
| 844 " all VM options).\n" | 884 " all VM options).\n" |
| 845 "--package-root=<path> or -p<path>\n" | 885 "--package-root=<path> or -p<path>\n" |
| 846 " Where to find packages, that is, \"package:...\" imports.\n" | 886 " Where to find packages, that is, \"package:...\" imports.\n" |
| 847 "--packages=<path>\n" | 887 "--packages=<path>\n" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 | 1036 |
| 997 static void ServiceStreamCancelCallback(const char* stream_id) { | 1037 static void ServiceStreamCancelCallback(const char* stream_id) { |
| 998 if (strcmp(stream_id, kStdoutStreamId) == 0) { | 1038 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 999 SetCaptureStdout(false); | 1039 SetCaptureStdout(false); |
| 1000 } else if (strcmp(stream_id, kStderrStreamId) == 0) { | 1040 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 1001 SetCaptureStderr(false); | 1041 SetCaptureStderr(false); |
| 1002 } | 1042 } |
| 1003 } | 1043 } |
| 1004 | 1044 |
| 1005 | 1045 |
| 1006 static void WritePrecompiledSnapshotFile(const char* filename, | 1046 static void WriteSnapshotFile(const char* snapshot_directory, |
| 1007 const uint8_t* buffer, | 1047 const char* filename, |
| 1008 const intptr_t size) { | 1048 bool write_magic_number, |
| 1049 const uint8_t* buffer, | |
| 1050 const intptr_t size) { | |
| 1009 char* concat = NULL; | 1051 char* concat = NULL; |
| 1010 const char* qualified_filename; | 1052 const char* qualified_filename; |
| 1011 if (strlen(precompiled_snapshot_directory) > 0) { | 1053 if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) { |
| 1012 intptr_t len = snprintf(NULL, 0, "%s/%s", | 1054 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
| 1013 precompiled_snapshot_directory, filename); | |
| 1014 concat = new char[len + 1]; | 1055 concat = new char[len + 1]; |
| 1015 snprintf(concat, len + 1, "%s/%s", | 1056 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1016 precompiled_snapshot_directory, filename); | |
| 1017 qualified_filename = concat; | 1057 qualified_filename = concat; |
| 1018 } else { | 1058 } else { |
| 1019 qualified_filename = filename; | 1059 qualified_filename = filename; |
| 1020 } | 1060 } |
| 1021 | 1061 |
| 1022 File* file = File::Open(qualified_filename, File::kWriteTruncate); | 1062 File* file = File::Open(qualified_filename, File::kWriteTruncate); |
| 1023 ASSERT(file != NULL); | 1063 ASSERT(file != NULL); |
| 1064 | |
| 1065 if (write_magic_number) { | |
| 1066 // Write the magic number to indicate file is a script snapshot. | |
| 1067 DartUtils::WriteMagicNumber(file); | |
| 1068 } | |
| 1069 | |
| 1024 if (!file->WriteFully(buffer, size)) { | 1070 if (!file->WriteFully(buffer, size)) { |
| 1025 ErrorExit(kErrorExitCode, | 1071 ErrorExit(kErrorExitCode, |
| 1026 "Unable to open file %s for writing snapshot\n", | 1072 "Unable to open file %s for writing snapshot\n", |
| 1027 qualified_filename); | 1073 qualified_filename); |
| 1028 } | 1074 } |
| 1029 delete file; | 1075 delete file; |
| 1030 if (concat != NULL) { | 1076 if (concat != NULL) { |
| 1031 delete concat; | 1077 delete concat; |
| 1032 } | 1078 } |
| 1033 } | 1079 } |
| 1034 | 1080 |
| 1035 | 1081 |
| 1036 static void ReadPrecompiledSnapshotFile(const char* filename, | 1082 static void ReadSnapshotFile(const char* snapshot_directory, |
| 1037 const uint8_t** buffer) { | 1083 const char* filename, |
| 1084 const uint8_t** buffer) { | |
| 1038 char* concat = NULL; | 1085 char* concat = NULL; |
| 1039 const char* qualified_filename; | 1086 const char* qualified_filename; |
| 1040 if (strlen(precompiled_snapshot_directory) > 0) { | 1087 if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) { |
| 1041 intptr_t len = snprintf(NULL, 0, "%s/%s", | 1088 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
| 1042 precompiled_snapshot_directory, filename); | |
| 1043 concat = new char[len + 1]; | 1089 concat = new char[len + 1]; |
| 1044 snprintf(concat, len + 1, "%s/%s", | 1090 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1045 precompiled_snapshot_directory, filename); | |
| 1046 qualified_filename = concat; | 1091 qualified_filename = concat; |
| 1047 } else { | 1092 } else { |
| 1048 qualified_filename = filename; | 1093 qualified_filename = filename; |
| 1049 } | 1094 } |
| 1050 | 1095 |
| 1051 void* file = DartUtils::OpenFile(qualified_filename, false); | 1096 void* file = DartUtils::OpenFile(qualified_filename, false); |
| 1052 if (file == NULL) { | 1097 if (file == NULL) { |
| 1053 ErrorExit(kErrorExitCode, | 1098 ErrorExit(kErrorExitCode, |
| 1054 "Error: Unable to open file %s for reading snapshot\n", | 1099 "Error: Unable to open file %s for reading snapshot\n", |
| 1055 qualified_filename); | 1100 qualified_filename); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1084 | 1129 |
| 1085 static void GenerateScriptSnapshot() { | 1130 static void GenerateScriptSnapshot() { |
| 1086 // First create a snapshot. | 1131 // First create a snapshot. |
| 1087 uint8_t* buffer = NULL; | 1132 uint8_t* buffer = NULL; |
| 1088 intptr_t size = 0; | 1133 intptr_t size = 0; |
| 1089 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1134 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 1090 if (Dart_IsError(result)) { | 1135 if (Dart_IsError(result)) { |
| 1091 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1136 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1092 } | 1137 } |
| 1093 | 1138 |
| 1094 // Open the snapshot file. | 1139 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); |
| 1095 File* snapshot_file = File::Open(snapshot_filename, File::kWriteTruncate); | |
| 1096 if (snapshot_file == NULL) { | |
| 1097 ErrorExit(kErrorExitCode, | |
| 1098 "Unable to open file %s for writing the snapshot\n", | |
| 1099 snapshot_filename); | |
| 1100 } | |
| 1101 | |
| 1102 // Write the magic number to indicate file is a script snapshot. | |
| 1103 DartUtils::WriteMagicNumber(snapshot_file); | |
| 1104 | |
| 1105 // Now write the snapshot out to specified file. | |
| 1106 bool bytes_written = snapshot_file->WriteFully(buffer, size); | |
| 1107 ASSERT(bytes_written); | |
| 1108 delete snapshot_file; | |
| 1109 snapshot_file = NULL; | |
| 1110 } | 1140 } |
| 1111 | 1141 |
| 1112 | 1142 |
| 1143 static void ComputeSnapshotFilenames(const char* filename, | |
| 1144 char** vm_snapshot_fname, | |
| 1145 char** isolate_snapshot_fname) { | |
| 1146 intptr_t len = snprintf(NULL, 0, "%s.%s", filename, kVMIsolateSuffix); | |
| 1147 *vm_snapshot_fname = new char[len + 1]; | |
| 1148 snprintf(*vm_snapshot_fname, len + 1, "%s.%s", filename, kVMIsolateSuffix); | |
| 1149 | |
| 1150 len = snprintf(NULL, 0, "%s.%s", filename, kIsolateSuffix); | |
| 1151 *isolate_snapshot_fname = new char[len + 1]; | |
| 1152 snprintf(*isolate_snapshot_fname, len + 1, "%s.%s", filename, kIsolateSuffix); | |
| 1153 } | |
| 1154 | |
| 1155 static void GenerateFullSnapshot() { | |
| 1156 // Create a full snapshot of the script. | |
| 1157 Dart_Handle result; | |
| 1158 uint8_t* vm_isolate_buffer = NULL; | |
| 1159 intptr_t vm_isolate_size = 0; | |
| 1160 uint8_t* isolate_buffer = NULL; | |
| 1161 intptr_t isolate_size = 0; | |
| 1162 char* vm_snapshot_fname = NULL; | |
| 1163 char* isolate_snapshot_fname = NULL; | |
| 1164 | |
| 1165 result = Dart_CreateSnapshot(&vm_isolate_buffer, | |
| 1166 &vm_isolate_size, | |
| 1167 &isolate_buffer, | |
| 1168 &isolate_size); | |
| 1169 if (Dart_IsError(result)) { | |
| 1170 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | |
| 1171 } | |
| 1172 | |
| 1173 // Compute snapshot file names and write out the snapshot files. | |
| 1174 ComputeSnapshotFilenames(snapshot_filename, | |
| 1175 &vm_snapshot_fname, | |
| 1176 &isolate_snapshot_fname); | |
| 1177 WriteSnapshotFile(NULL, | |
| 1178 vm_snapshot_fname, | |
| 1179 false, | |
| 1180 vm_isolate_buffer, | |
| 1181 vm_isolate_size); | |
| 1182 WriteSnapshotFile(NULL, | |
| 1183 isolate_snapshot_fname, | |
| 1184 false, | |
| 1185 isolate_buffer, | |
| 1186 isolate_size); | |
| 1187 } | |
| 1188 | |
| 1189 | |
| 1113 #define CHECK_RESULT(result) \ | 1190 #define CHECK_RESULT(result) \ |
| 1114 if (Dart_IsError(result)) { \ | 1191 if (Dart_IsError(result)) { \ |
| 1115 if (Dart_IsVMRestartRequest(result)) { \ | 1192 if (Dart_IsVMRestartRequest(result)) { \ |
| 1116 Dart_ExitScope(); \ | 1193 Dart_ExitScope(); \ |
| 1117 Dart_ShutdownIsolate(); \ | 1194 Dart_ShutdownIsolate(); \ |
| 1118 return true; \ | 1195 return true; \ |
| 1119 } \ | 1196 } \ |
| 1120 const int exit_code = Dart_IsCompilationError(result) ? \ | 1197 const int exit_code = Dart_IsCompilationError(result) ? \ |
| 1121 kCompilationErrorExitCode : kErrorExitCode; \ | 1198 kCompilationErrorExitCode : kErrorExitCode; \ |
| 1122 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ | 1199 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 GenerateScriptSnapshot(); | 1247 GenerateScriptSnapshot(); |
| 1171 } else { | 1248 } else { |
| 1172 // Lookup the library of the root script. | 1249 // Lookup the library of the root script. |
| 1173 Dart_Handle root_lib = Dart_RootLibrary(); | 1250 Dart_Handle root_lib = Dart_RootLibrary(); |
| 1174 // Import the root library into the builtin library so that we can easily | 1251 // Import the root library into the builtin library so that we can easily |
| 1175 // lookup the main entry point exported from the root library. | 1252 // lookup the main entry point exported from the root library. |
| 1176 IsolateData* isolate_data = | 1253 IsolateData* isolate_data = |
| 1177 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1254 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 1178 result = Dart_LibraryImportLibrary( | 1255 result = Dart_LibraryImportLibrary( |
| 1179 isolate_data->builtin_lib(), root_lib, Dart_Null()); | 1256 isolate_data->builtin_lib(), root_lib, Dart_Null()); |
| 1180 if (has_gen_precompiled_snapshot) { | 1257 if (gen_precompiled_snapshot) { |
| 1181 // Load the embedder's portion of the VM service's Dart code so it will | 1258 // Load the embedder's portion of the VM service's Dart code so it will |
| 1182 // be included in the precompiled snapshot. | 1259 // be included in the precompiled snapshot. |
| 1183 if (!VmService::LoadForGenPrecompiled()) { | 1260 if (!VmService::LoadForGenPrecompiled()) { |
| 1184 fprintf(stderr, | 1261 fprintf(stderr, |
| 1185 "VM service loading failed: %s\n", | 1262 "VM service loading failed: %s\n", |
| 1186 VmService::GetErrorMessage()); | 1263 VmService::GetErrorMessage()); |
| 1187 fflush(stderr); | 1264 fflush(stderr); |
| 1188 exit(kErrorExitCode); | 1265 exit(kErrorExitCode); |
| 1189 } | 1266 } |
| 1190 } | 1267 } |
| 1191 | 1268 |
| 1192 if (has_compile_all) { | 1269 if (compile_all) { |
| 1193 result = Dart_CompileAll(); | 1270 result = Dart_CompileAll(); |
| 1194 CHECK_RESULT(result); | 1271 CHECK_RESULT(result); |
| 1195 } | 1272 } |
| 1196 | 1273 |
| 1197 if (has_noopt || has_gen_precompiled_snapshot) { | 1274 if (noopt || gen_precompiled_snapshot) { |
| 1198 Dart_QualifiedFunctionName standalone_entry_points[] = { | 1275 Dart_QualifiedFunctionName standalone_entry_points[] = { |
| 1199 { "dart:_builtin", "::", "_getMainClosure" }, | 1276 { "dart:_builtin", "::", "_getMainClosure" }, |
| 1200 { "dart:_builtin", "::", "_getPrintClosure" }, | 1277 { "dart:_builtin", "::", "_getPrintClosure" }, |
| 1201 { "dart:_builtin", "::", "_getUriBaseClosure" }, | 1278 { "dart:_builtin", "::", "_getUriBaseClosure" }, |
| 1202 { "dart:_builtin", "::", "_resolveUri" }, | 1279 { "dart:_builtin", "::", "_resolveUri" }, |
| 1203 { "dart:_builtin", "::", "_setWorkingDirectory" }, | 1280 { "dart:_builtin", "::", "_setWorkingDirectory" }, |
| 1204 { "dart:_builtin", "::", "_setPackageRoot" }, | 1281 { "dart:_builtin", "::", "_setPackageRoot" }, |
| 1205 { "dart:_builtin", "::", "_loadPackagesMap" }, | 1282 { "dart:_builtin", "::", "_loadPackagesMap" }, |
| 1206 { "dart:_builtin", "::", "_loadDataAsync" }, | 1283 { "dart:_builtin", "::", "_loadDataAsync" }, |
| 1207 { "dart:io", "::", "_makeUint8ListView" }, | 1284 { "dart:io", "::", "_makeUint8ListView" }, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1221 { "dart:io", "_Platform", "set:_nativeScript" }, | 1298 { "dart:io", "_Platform", "set:_nativeScript" }, |
| 1222 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, | 1299 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, |
| 1223 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, | 1300 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, |
| 1224 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, | 1301 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, |
| 1225 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, | 1302 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, |
| 1226 { "dart:vmservice_io", "::", "main" }, | 1303 { "dart:vmservice_io", "::", "main" }, |
| 1227 { "dart:vmservice_io", "::", "boot" }, | 1304 { "dart:vmservice_io", "::", "boot" }, |
| 1228 { NULL, NULL, NULL } // Must be terminated with NULL entries. | 1305 { NULL, NULL, NULL } // Must be terminated with NULL entries. |
| 1229 }; | 1306 }; |
| 1230 | 1307 |
| 1231 const bool reset_fields = has_gen_precompiled_snapshot; | 1308 const bool reset_fields = gen_precompiled_snapshot; |
| 1232 result = Dart_Precompile(standalone_entry_points, reset_fields); | 1309 result = Dart_Precompile(standalone_entry_points, reset_fields); |
| 1233 CHECK_RESULT(result); | 1310 CHECK_RESULT(result); |
| 1234 } | 1311 } |
| 1235 | 1312 |
| 1236 if (has_gen_precompiled_snapshot) { | 1313 if (gen_precompiled_snapshot) { |
| 1237 uint8_t* vm_isolate_buffer = NULL; | 1314 uint8_t* vm_isolate_buffer = NULL; |
| 1238 intptr_t vm_isolate_size = 0; | 1315 intptr_t vm_isolate_size = 0; |
| 1239 uint8_t* isolate_buffer = NULL; | 1316 uint8_t* isolate_buffer = NULL; |
| 1240 intptr_t isolate_size = 0; | 1317 intptr_t isolate_size = 0; |
| 1241 uint8_t* instructions_buffer = NULL; | 1318 uint8_t* instructions_buffer = NULL; |
| 1242 intptr_t instructions_size = 0; | 1319 intptr_t instructions_size = 0; |
| 1243 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, | 1320 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, |
| 1244 &vm_isolate_size, | 1321 &vm_isolate_size, |
| 1245 &isolate_buffer, | 1322 &isolate_buffer, |
| 1246 &isolate_size, | 1323 &isolate_size, |
| 1247 &instructions_buffer, | 1324 &instructions_buffer, |
| 1248 &instructions_size); | 1325 &instructions_size); |
| 1249 CHECK_RESULT(result); | 1326 CHECK_RESULT(result); |
| 1250 WritePrecompiledSnapshotFile(kPrecompiledVmIsolateName, | 1327 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1251 vm_isolate_buffer, | 1328 kPrecompiledVmIsolateName, |
| 1252 vm_isolate_size); | 1329 false, |
| 1253 WritePrecompiledSnapshotFile(kPrecompiledIsolateName, | 1330 vm_isolate_buffer, |
| 1254 isolate_buffer, | 1331 vm_isolate_size); |
| 1255 isolate_size); | 1332 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1256 WritePrecompiledSnapshotFile(kPrecompiledInstructionsName, | 1333 kPrecompiledIsolateName, |
| 1257 instructions_buffer, | 1334 false, |
| 1258 instructions_size); | 1335 isolate_buffer, |
| 1336 isolate_size); | |
| 1337 WriteSnapshotFile(precompiled_snapshot_directory, | |
| 1338 kPrecompiledInstructionsName, | |
| 1339 false, | |
| 1340 instructions_buffer, | |
| 1341 instructions_size); | |
| 1259 } else { | 1342 } else { |
| 1260 if (Dart_IsNull(root_lib)) { | 1343 if (Dart_IsNull(root_lib)) { |
| 1261 ErrorExit(kErrorExitCode, | 1344 ErrorExit(kErrorExitCode, |
| 1262 "Unable to find root library for '%s'\n", | 1345 "Unable to find root library for '%s'\n", |
| 1263 script_name); | 1346 script_name); |
| 1264 } | 1347 } |
| 1265 | 1348 |
| 1266 // The helper function _getMainClosure creates a closure for the main | 1349 // The helper function _getMainClosure creates a closure for the main |
| 1267 // entry point which is either explicitly or implictly exported from the | 1350 // entry point which is either explicitly or implictly exported from the |
| 1268 // root library. | 1351 // root library. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1281 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); | 1364 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
| 1282 result = Dart_Invoke(isolate_lib, | 1365 result = Dart_Invoke(isolate_lib, |
| 1283 Dart_NewStringFromCString("_startMainIsolate"), | 1366 Dart_NewStringFromCString("_startMainIsolate"), |
| 1284 kNumIsolateArgs, isolate_args); | 1367 kNumIsolateArgs, isolate_args); |
| 1285 CHECK_RESULT(result); | 1368 CHECK_RESULT(result); |
| 1286 | 1369 |
| 1287 // Keep handling messages until the last active receive port is closed. | 1370 // Keep handling messages until the last active receive port is closed. |
| 1288 result = Dart_RunLoop(); | 1371 result = Dart_RunLoop(); |
| 1289 CHECK_RESULT(result); | 1372 CHECK_RESULT(result); |
| 1290 | 1373 |
| 1291 // Generate a script snapshot after execution if specified. | 1374 // Generate a full snapshot after execution if specified. |
| 1292 if (generate_script_snapshot_after_run) { | 1375 if (generate_full_snapshot_after_run) { |
| 1293 GenerateScriptSnapshot(); | 1376 GenerateFullSnapshot(); |
| 1294 } | 1377 } |
| 1295 } | 1378 } |
| 1296 } | 1379 } |
| 1297 | 1380 |
| 1298 Dart_ExitScope(); | 1381 Dart_ExitScope(); |
| 1299 // Shutdown the isolate. | 1382 // Shutdown the isolate. |
| 1300 Dart_ShutdownIsolate(); | 1383 Dart_ShutdownIsolate(); |
| 1301 | 1384 |
| 1302 // No restart. | 1385 // No restart. |
| 1303 return false; | 1386 return false; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); | 1490 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); |
| 1408 | 1491 |
| 1409 // Parse command line arguments. | 1492 // Parse command line arguments. |
| 1410 if (ParseArguments(argc, | 1493 if (ParseArguments(argc, |
| 1411 argv, | 1494 argv, |
| 1412 &vm_options, | 1495 &vm_options, |
| 1413 &script_name, | 1496 &script_name, |
| 1414 &dart_options, | 1497 &dart_options, |
| 1415 &print_flags_seen, | 1498 &print_flags_seen, |
| 1416 &verbose_debug_seen) < 0) { | 1499 &verbose_debug_seen) < 0) { |
| 1417 if (has_help_option) { | 1500 if (help_option) { |
| 1418 PrintUsage(); | 1501 PrintUsage(); |
| 1419 Platform::Exit(0); | 1502 Platform::Exit(0); |
| 1420 } else if (has_version_option) { | 1503 } else if (version_option) { |
| 1421 PrintVersion(); | 1504 PrintVersion(); |
| 1422 Platform::Exit(0); | 1505 Platform::Exit(0); |
| 1423 } else if (print_flags_seen) { | 1506 } else if (print_flags_seen) { |
| 1424 // Will set the VM flags, print them out and then we exit as no | 1507 // Will set the VM flags, print them out and then we exit as no |
| 1425 // script was specified on the command line. | 1508 // script was specified on the command line. |
| 1426 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1509 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1427 Platform::Exit(0); | 1510 Platform::Exit(0); |
| 1428 } else { | 1511 } else { |
| 1429 PrintUsage(); | 1512 PrintUsage(); |
| 1430 Platform::Exit(kErrorExitCode); | 1513 Platform::Exit(kErrorExitCode); |
| 1431 } | 1514 } |
| 1432 } | 1515 } |
| 1433 | 1516 |
| 1434 Thread::InitOnce(); | 1517 Thread::InitOnce(); |
| 1435 | 1518 |
| 1436 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1519 if (!DartUtils::SetOriginalWorkingDirectory()) { |
| 1437 OSError err; | 1520 OSError err; |
| 1438 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1521 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
| 1439 fflush(stderr); | 1522 fflush(stderr); |
| 1440 Platform::Exit(kErrorExitCode); | 1523 Platform::Exit(kErrorExitCode); |
| 1441 } | 1524 } |
| 1442 | 1525 |
| 1443 if (generate_script_snapshot) { | 1526 if (generate_script_snapshot || generate_full_snapshot_after_run) { |
| 1444 vm_options.AddArgument("--load_deferred_eagerly"); | 1527 vm_options.AddArgument("--load_deferred_eagerly"); |
| 1445 } | 1528 } |
| 1446 | 1529 |
| 1447 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 1530 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
| 1448 // Always set --precompilation with dart_noopt, unless already set by these | 1531 // Always set --precompilation with dart_noopt, unless already set by these |
| 1449 // command line options. | 1532 // command line options. |
| 1450 if (!has_gen_precompiled_snapshot && | 1533 if (!gen_precompiled_snapshot && !run_precompiled_snapshot) { |
| 1451 !has_run_precompiled_snapshot) { | 1534 noopt = true; |
| 1452 has_noopt = true; | |
| 1453 vm_options.AddArgument("--precompilation"); | 1535 vm_options.AddArgument("--precompilation"); |
| 1454 } | 1536 } |
| 1455 #endif | 1537 #endif |
| 1456 | 1538 |
| 1457 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1539 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1458 | 1540 |
| 1459 // Start event handler. | 1541 // Start event handler. |
| 1460 TimerUtils::InitOnce(); | 1542 TimerUtils::InitOnce(); |
| 1461 EventHandler::Start(); | 1543 EventHandler::Start(); |
| 1462 | 1544 |
| 1463 const uint8_t* instructions_snapshot = NULL; | 1545 const uint8_t* instructions_snapshot = NULL; |
| 1464 if (has_run_precompiled_snapshot) { | 1546 if (run_precompiled_snapshot) { |
| 1465 instructions_snapshot = reinterpret_cast<const uint8_t*>( | 1547 instructions_snapshot = reinterpret_cast<const uint8_t*>( |
| 1466 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); | 1548 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); |
| 1467 ReadPrecompiledSnapshotFile(kPrecompiledVmIsolateName, | 1549 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1468 &vm_isolate_snapshot_buffer); | 1550 kPrecompiledVmIsolateName, |
| 1469 ReadPrecompiledSnapshotFile(kPrecompiledIsolateName, | 1551 &vm_isolate_snapshot_buffer); |
| 1470 &isolate_snapshot_buffer); | 1552 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1553 kPrecompiledIsolateName, | |
| 1554 &isolate_snapshot_buffer); | |
| 1555 } else if (run_full_snapshot) { | |
| 1556 char* vm_snapshot_fname; | |
| 1557 char* isolate_snapshot_fname; | |
| 1558 | |
| 1559 // Compute file names. | |
| 1560 ComputeSnapshotFilenames(snapshot_filename, | |
| 1561 &vm_snapshot_fname, | |
| 1562 &isolate_snapshot_fname); | |
| 1563 | |
| 1564 ReadSnapshotFile(NULL, vm_snapshot_fname, &vm_isolate_snapshot_buffer); | |
| 1565 ReadSnapshotFile(NULL, isolate_snapshot_fname, &isolate_snapshot_buffer); | |
| 1566 delete vm_snapshot_fname; | |
| 1567 delete isolate_snapshot_fname; | |
| 1471 } | 1568 } |
| 1472 | 1569 |
| 1473 // Initialize the Dart VM. | 1570 // Initialize the Dart VM. |
| 1474 char* error = Dart_Initialize( | 1571 char* error = Dart_Initialize( |
| 1475 vm_isolate_snapshot_buffer, instructions_snapshot, | 1572 vm_isolate_snapshot_buffer, instructions_snapshot, |
| 1476 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1573 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 1477 DartUtils::OpenFile, | 1574 DartUtils::OpenFile, |
| 1478 DartUtils::ReadFile, | 1575 DartUtils::ReadFile, |
| 1479 DartUtils::WriteFile, | 1576 DartUtils::WriteFile, |
| 1480 DartUtils::CloseFile, | 1577 DartUtils::CloseFile, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1531 Platform::Exit(Process::GlobalExitCode()); | 1628 Platform::Exit(Process::GlobalExitCode()); |
| 1532 } | 1629 } |
| 1533 | 1630 |
| 1534 } // namespace bin | 1631 } // namespace bin |
| 1535 } // namespace dart | 1632 } // namespace dart |
| 1536 | 1633 |
| 1537 int main(int argc, char** argv) { | 1634 int main(int argc, char** argv) { |
| 1538 dart::bin::main(argc, argv); | 1635 dart::bin::main(argc, argv); |
| 1539 UNREACHABLE(); | 1636 UNREACHABLE(); |
| 1540 } | 1637 } |
| OLD | NEW |