Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 11446018: Fix for issue 6768 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 // Get the script name. 130 // Get the script name.
131 if (i < argc) { 131 if (i < argc) {
132 *script_name = argv[i]; 132 *script_name = argv[i];
133 i += 1; 133 i += 1;
134 } else { 134 } else {
135 *script_name = NULL; 135 *script_name = NULL;
136 } 136 }
137 137
138 if (snapshot_filename == NULL) {
139 Log::PrintErr("No snapshot output file specified.\n\n");
140 return -1;
141 }
142
138 return 0; 143 return 0;
139 } 144 }
140 145
141 146
142 static void WriteSnapshotFile(const uint8_t* buffer, const intptr_t size) { 147 static void WriteSnapshotFile(const uint8_t* buffer, const intptr_t size) {
143 File* file = File::Open(snapshot_filename, File::kWriteTruncate); 148 File* file = File::Open(snapshot_filename, File::kWriteTruncate);
144 ASSERT(file != NULL); 149 ASSERT(file != NULL);
145 for (intptr_t i = 0; i < size; i++) { 150 for (intptr_t i = 0; i < size; i++) {
146 file->WriteByte(buffer[i]); 151 file->WriteByte(buffer[i]);
147 } 152 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 Dart_Handle lib; 356 Dart_Handle lib;
352 // Load the builtin library to make it available in the snapshot 357 // Load the builtin library to make it available in the snapshot
353 // for importing. 358 // for importing.
354 lib = Builtin::LoadAndCheckLibrary(id); 359 lib = Builtin::LoadAndCheckLibrary(id);
355 ASSERT(!Dart_IsError(lib)); 360 ASSERT(!Dart_IsError(lib));
356 return lib; 361 return lib;
357 } 362 }
358 363
359 364
360 static void PrintUsage() { 365 static void PrintUsage() {
361 Log::PrintErr("dart [<vm-flags>] [<dart-script-file>]\n"); 366 Log::PrintErr(
367 "Usage:\n"
368 "\n"
369 " gen_snapshot [<vm-flags>] [<options>] \\\n"
370 " {--script_snapshot=<out-file> | --snapshot=<out-file>} \\\n"
371 " [<dart-script-file>]\n"
372 "\n"
373 " Writes a snapshot of <dart-script-file> to <out-file>. If no\n"
374 " <dart-script-file> is passed, a generic snapshot of all the corelibs is\n"
375 " created. One of the following is required:\n"
376 "\n"
377 " --script_snapshot=<file> Generates a script snapshot.\n"
378 " --snapshot=<file> Generates a complete snapshot. Uses the url\n"
379 " mapping specified on the command line to load\n"
380 " the libraries.\n"
381 "Supported options:\n"
382 "\n"
383 "--package_root=<path>\n"
384 " Where to find packages, that is, \"package:...\" imports.\n"
385 "\n"
386 "--url_mapping=<mapping>\n"
387 " Uses the URL mapping(s) specified on the command line to load the\n"
388 " libraries. For use only with --snapshot=.\n");
362 } 389 }
363 390
364 391
365 static void VerifyLoaded(Dart_Handle library) { 392 static void VerifyLoaded(Dart_Handle library) {
366 if (Dart_IsError(library)) { 393 if (Dart_IsError(library)) {
367 const char* err_msg = Dart_GetError(library); 394 const char* err_msg = Dart_GetError(library);
368 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); 395 Log::PrintErr("Errors encountered while loading: %s\n", err_msg);
369 Dart_ExitScope(); 396 Dart_ExitScope();
370 Dart_ShutdownIsolate(); 397 Dart_ShutdownIsolate();
371 exit(255); 398 exit(255);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 467
441 // Parse command line arguments. 468 // Parse command line arguments.
442 if (ParseArguments(argc, 469 if (ParseArguments(argc,
443 argv, 470 argv,
444 &vm_options, 471 &vm_options,
445 &app_script_name) < 0) { 472 &app_script_name) < 0) {
446 PrintUsage(); 473 PrintUsage();
447 return 255; 474 return 255;
448 } 475 }
449 476
450 if (snapshot_filename == NULL) {
451 Log::PrintErr("No snapshot output file specified\n");
452 return 255;
453 }
454
455 DartUtils::SetOriginalWorkingDirectory(); 477 DartUtils::SetOriginalWorkingDirectory();
456 478
457 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 479 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
458 480
459 // Initialize the Dart VM. 481 // Initialize the Dart VM.
460 // Note: We don't expect isolates to be created from dart code during 482 // Note: We don't expect isolates to be created from dart code during
461 // snapshot generation. 483 // snapshot generation.
462 if (!Dart_Initialize(NULL, NULL, NULL, NULL)) { 484 if (!Dart_Initialize(NULL, NULL, NULL, NULL)) {
463 Log::PrintErr("VM initialization failed\n"); 485 Log::PrintErr("VM initialization failed\n");
464 return 255; 486 return 255;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 CreateAndWriteSnapshot(true); 594 CreateAndWriteSnapshot(true);
573 595
574 free(snapshot_buffer); 596 free(snapshot_buffer);
575 } 597 }
576 } else { 598 } else {
577 SetupForGenericSnapshotCreation(); 599 SetupForGenericSnapshotCreation();
578 CreateAndWriteSnapshot(false); 600 CreateAndWriteSnapshot(false);
579 } 601 }
580 return 0; 602 return 0;
581 } 603 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698