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

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

Issue 11312242: Revised CL for customisable logging (replacing printfs). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « runtime/bin/file_win.cc ('k') | runtime/bin/log.h » ('j') | 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>
11 11
12 #include "include/dart_api.h" 12 #include "include/dart_api.h"
13 13
14 #include "bin/builtin.h" 14 #include "bin/builtin.h"
15 #include "bin/dartutils.h" 15 #include "bin/dartutils.h"
16 #include "bin/file.h" 16 #include "bin/file.h"
17 #include "bin/log.h"
18
17 #include "platform/globals.h" 19 #include "platform/globals.h"
18 20
19 #define CHECK_RESULT(result) \ 21 #define CHECK_RESULT(result) \
20 if (Dart_IsError(result)) { \ 22 if (Dart_IsError(result)) { \
21 free(snapshot_buffer); \ 23 free(snapshot_buffer); \
22 fprintf(stderr, "Error: %s", Dart_GetError(result)); \ 24 Log::PrintErr("Error: %s", Dart_GetError(result)); \
23 Dart_ExitScope(); \ 25 Dart_ExitScope(); \
24 Dart_ShutdownIsolate(); \ 26 Dart_ShutdownIsolate(); \
25 exit(255); \ 27 exit(255); \
26 } \ 28 } \
27 29
28 30
29 // Global state that indicates whether a snapshot is to be created and 31 // Global state that indicates whether a snapshot is to be created and
30 // if so which file to write the snapshot into. 32 // if so which file to write the snapshot into.
31 static const char* snapshot_filename = NULL; 33 static const char* snapshot_filename = NULL;
32 static bool script_snapshot = false; 34 static bool script_snapshot = false;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 Dart_Handle lib; 200 Dart_Handle lib;
199 // Load the builtin library to make it available in the snapshot 201 // Load the builtin library to make it available in the snapshot
200 // for importing. 202 // for importing.
201 lib = Builtin::LoadAndCheckLibrary(id); 203 lib = Builtin::LoadAndCheckLibrary(id);
202 ASSERT(!Dart_IsError(lib)); 204 ASSERT(!Dart_IsError(lib));
203 return lib; 205 return lib;
204 } 206 }
205 207
206 208
207 static void PrintUsage() { 209 static void PrintUsage() {
208 fprintf(stderr, 210 Log::PrintErr("dart [<vm-flags>] [<dart-script-file>]\n");
209 "dart [<vm-flags>] "
210 "[<dart-script-file>]\n");
211 } 211 }
212 212
213 213
214 static void VerifyLoaded(Dart_Handle library) { 214 static void VerifyLoaded(Dart_Handle library) {
215 if (Dart_IsError(library)) { 215 if (Dart_IsError(library)) {
216 const char* err_msg = Dart_GetError(library); 216 const char* err_msg = Dart_GetError(library);
217 fprintf(stderr, "Errors encountered while loading: %s\n", err_msg); 217 Log::PrintErr("Errors encountered while loading: %s\n", err_msg);
218 Dart_ExitScope(); 218 Dart_ExitScope();
219 Dart_ShutdownIsolate(); 219 Dart_ShutdownIsolate();
220 exit(255); 220 exit(255);
221 } 221 }
222 ASSERT(Dart_IsLibrary(library)); 222 ASSERT(Dart_IsLibrary(library));
223 } 223 }
224 224
225 225
226 static void CreateAndWriteSnapshot(bool script_snapshot) { 226 static void CreateAndWriteSnapshot(bool script_snapshot) {
227 Dart_Handle result; 227 Dart_Handle result;
(...skipping 16 matching lines...) Expand all
244 244
245 // Shutdown the isolate. 245 // Shutdown the isolate.
246 Dart_ShutdownIsolate(); 246 Dart_ShutdownIsolate();
247 } 247 }
248 248
249 249
250 static void SetupForGenericSnapshotCreation() { 250 static void SetupForGenericSnapshotCreation() {
251 // Set up the library tag handler for this isolate. 251 // Set up the library tag handler for this isolate.
252 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 252 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
253 if (Dart_IsError(result)) { 253 if (Dart_IsError(result)) {
254 fprintf(stderr, "%s", Dart_GetError(result)); 254 Log::PrintErr("%s", Dart_GetError(result));
255 Dart_ExitScope(); 255 Dart_ExitScope();
256 Dart_ShutdownIsolate(); 256 Dart_ShutdownIsolate();
257 exit(255); 257 exit(255);
258 } 258 }
259 // This is a generic dart snapshot which needs builtin library setup. 259 // This is a generic dart snapshot which needs builtin library setup.
260 Dart_Handle library = 260 Dart_Handle library =
261 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); 261 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary);
262 VerifyLoaded(library); 262 VerifyLoaded(library);
263 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); 263 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary);
264 VerifyLoaded(library); 264 VerifyLoaded(library);
(...skipping 18 matching lines...) Expand all
283 // Parse command line arguments. 283 // Parse command line arguments.
284 if (ParseArguments(argc, 284 if (ParseArguments(argc,
285 argv, 285 argv,
286 &vm_options, 286 &vm_options,
287 &app_script_name) < 0) { 287 &app_script_name) < 0) {
288 PrintUsage(); 288 PrintUsage();
289 return 255; 289 return 255;
290 } 290 }
291 291
292 if (snapshot_filename == NULL) { 292 if (snapshot_filename == NULL) {
293 fprintf(stderr, "No snapshot output file specified\n"); 293 Log::PrintErr("No snapshot output file specified\n");
294 return 255; 294 return 255;
295 } 295 }
296 296
297 DartUtils::SetOriginalWorkingDirectory(); 297 DartUtils::SetOriginalWorkingDirectory();
298 298
299 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 299 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
300 300
301 // Initialize the Dart VM. 301 // Initialize the Dart VM.
302 // Note: We don't expect isolates to be created from dart code during 302 // Note: We don't expect isolates to be created from dart code during
303 // snapshot generation. 303 // snapshot generation.
304 if (!Dart_Initialize(NULL, NULL, NULL)) { 304 if (!Dart_Initialize(NULL, NULL, NULL)) {
305 fprintf(stderr, "VM initialization failed\n"); 305 Log::PrintErr("VM initialization failed\n");
306 return 255; 306 return 255;
307 } 307 }
308 308
309 char* error; 309 char* error;
310 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); 310 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
311 if (isolate == NULL) { 311 if (isolate == NULL) {
312 fprintf(stderr, "Error: %s", error); 312 Log::PrintErr("Error: %s", error);
313 free(error); 313 free(error);
314 exit(255); 314 exit(255);
315 } 315 }
316 316
317 Dart_Handle result; 317 Dart_Handle result;
318 Dart_Handle library; 318 Dart_Handle library;
319 Dart_EnterScope(); 319 Dart_EnterScope();
320 320
321 ASSERT(snapshot_filename != NULL); 321 ASSERT(snapshot_filename != NULL);
322 // Load up the script before a snapshot is created. 322 // Load up the script before a snapshot is created.
(...skipping 30 matching lines...) Expand all
353 Dart_ExitScope(); 353 Dart_ExitScope();
354 Dart_ShutdownIsolate(); 354 Dart_ShutdownIsolate();
355 355
356 // Now load the specified script and create a script snapshot. 356 // Now load the specified script and create a script snapshot.
357 Dart_Isolate isolate = Dart_CreateIsolate(NULL, 357 Dart_Isolate isolate = Dart_CreateIsolate(NULL,
358 NULL, 358 NULL,
359 snapshot_buffer, 359 snapshot_buffer,
360 NULL, 360 NULL,
361 &error); 361 &error);
362 if (isolate == NULL) { 362 if (isolate == NULL) {
363 fprintf(stderr, "%s", error); 363 Log::PrintErr("%s", error);
364 free(error); 364 free(error);
365 free(snapshot_buffer); 365 free(snapshot_buffer);
366 exit(255); 366 exit(255);
367 } 367 }
368 Dart_EnterScope(); 368 Dart_EnterScope();
369 369
370 // Setup generic library tag handler. 370 // Setup generic library tag handler.
371 result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 371 result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
372 CHECK_RESULT(result); 372 CHECK_RESULT(result);
373 373
(...skipping 14 matching lines...) Expand all
388 CreateAndWriteSnapshot(true); 388 CreateAndWriteSnapshot(true);
389 389
390 free(snapshot_buffer); 390 free(snapshot_buffer);
391 } 391 }
392 } else { 392 } else {
393 SetupForGenericSnapshotCreation(); 393 SetupForGenericSnapshotCreation();
394 CreateAndWriteSnapshot(false); 394 CreateAndWriteSnapshot(false);
395 } 395 }
396 return 0; 396 return 0;
397 } 397 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | runtime/bin/log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698