| 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 /** The one true [World]. */ | 5 /** The one true [World]. */ |
| 6 World world; | 6 World world; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Experimental phase to enable await, only set when using the | 9 * Experimental phase to enable await, only set when using the |
| 10 * await/awaitc.dart entrypoint. | 10 * await/awaitc.dart entrypoint. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 typedef void MessageHandler(String prefix, String message, SourceSpan span); | 21 typedef void MessageHandler(String prefix, String message, SourceSpan span); |
| 22 | 22 |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Should be called exactly once to setup singleton world. | 25 * Should be called exactly once to setup singleton world. |
| 26 * Can use world.reset() to reinitialize. | 26 * Can use world.reset() to reinitialize. |
| 27 */ | 27 */ |
| 28 void initializeWorld(FileSystem files) { | 28 void initializeWorld(FileSystem files) { |
| 29 assert(world == null); | 29 assert(world == null); |
| 30 world = new World(files); | 30 world = new World(files); |
| 31 world.init(); | 31 if (!options.legOnly) world.init(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Compiles the [target] dart file using the given [corelib]. | 35 * Compiles the [target] dart file using the given [corelib]. |
| 36 */ | 36 */ |
| 37 bool compile(String homedir, List<String> args, FileSystem files) { | 37 bool compile(String homedir, List<String> args, FileSystem files) { |
| 38 parseOptions(homedir, args, files); | 38 parseOptions(homedir, args, files); |
| 39 initializeWorld(files); | 39 initializeWorld(files); |
| 40 return world.compileAndSave(); | 40 return world.compileAndSave(); |
| 41 } | 41 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 /** Counters that track statistics about the generated code. */ | 60 /** Counters that track statistics about the generated code. */ |
| 61 class CounterLog { | 61 class CounterLog { |
| 62 int dynamicMethodCalls = 0; | 62 int dynamicMethodCalls = 0; |
| 63 int typeAsserts = 0; | 63 int typeAsserts = 0; |
| 64 int objectProtoMembers = 0; | 64 int objectProtoMembers = 0; |
| 65 int invokeCalls = 0; | 65 int invokeCalls = 0; |
| 66 int msetN = 0; | 66 int msetN = 0; |
| 67 | 67 |
| 68 info() { | 68 info() { |
| 69 if (options.legOnly) return; |
| 69 world.info('Dynamically typed method calls: $dynamicMethodCalls'); | 70 world.info('Dynamically typed method calls: $dynamicMethodCalls'); |
| 70 world.info('Generated type assertions: $typeAsserts'); | 71 world.info('Generated type assertions: $typeAsserts'); |
| 71 world.info('Members on Object.prototype: $objectProtoMembers'); | 72 world.info('Members on Object.prototype: $objectProtoMembers'); |
| 72 world.info('Invoke calls: $invokeCalls'); | 73 world.info('Invoke calls: $invokeCalls'); |
| 73 world.info('msetN calls: $msetN'); | 74 world.info('msetN calls: $msetN'); |
| 74 } | 75 } |
| 75 | 76 |
| 76 // We need to push a new counter when we are abstract interpreting, so we | 77 // We need to push a new counter when we are abstract interpreting, so we |
| 77 // can discard it if we discard the code. | 78 // can discard it if we discard the code. |
| 78 // TODO(jmesserly): this is ugly but I'm not sure how to make it cleaner, | 79 // TODO(jmesserly): this is ugly but I'm not sure how to make it cleaner, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 373 } |
| 373 | 374 |
| 374 bool compile() { | 375 bool compile() { |
| 375 // TODO(jimhug): Must have called setOptions - better errors. | 376 // TODO(jimhug): Must have called setOptions - better errors. |
| 376 if (options.dartScript == null) { | 377 if (options.dartScript == null) { |
| 377 fatal('no script provided to compile'); | 378 fatal('no script provided to compile'); |
| 378 return false; | 379 return false; |
| 379 } | 380 } |
| 380 | 381 |
| 381 try { | 382 try { |
| 382 info('compiling ${options.dartScript} with corelib $corelib'); | 383 if (options.legOnly) { |
| 384 info('[leg] compiling ${options.dartScript}'); |
| 385 } else { |
| 386 info('compiling ${options.dartScript} with corelib $corelib'); |
| 387 } |
| 383 if (!runLeg()) runCompilationPhases(); | 388 if (!runLeg()) runCompilationPhases(); |
| 384 } catch (var exc) { | 389 } catch (var exc) { |
| 385 if (hasErrors && !options.throwOnErrors) { | 390 if (hasErrors && !options.throwOnErrors) { |
| 386 // TODO(jimhug): If dev mode then throw. | 391 // TODO(jimhug): If dev mode then throw. |
| 387 } else { | 392 } else { |
| 388 // TODO(jimhug): Handle these in world or in callers? | 393 // TODO(jimhug): Handle these in world or in callers? |
| 389 throw; | 394 throw; |
| 390 } | 395 } |
| 391 } | 396 } |
| 392 printStatus(); | 397 printStatus(); |
| 393 return !hasErrors; | 398 return !hasErrors; |
| 394 } | 399 } |
| 395 | 400 |
| 396 /** Returns true if Leg handled the compilation job. */ | 401 /** Returns true if Leg handled the compilation job. */ |
| 397 bool runLeg() { | 402 bool runLeg() { |
| 398 if (!options.enableLeg) return false; | 403 if (!options.legOnly) return false; |
| 399 if (legCompile == null) { | 404 if (legCompile == null) { |
| 400 fatal('requested leg enabled, but no leg compiler available'); | 405 fatal('requested leg enabled, but no leg compiler available'); |
| 401 } | 406 } |
| 402 bool res = withTiming('try leg compile', () => legCompile(this)); | 407 bool res = withTiming('[leg] compile', () => legCompile(this)); |
| 403 if (!res && options.legOnly) { | 408 if (!res && options.legOnly) { |
| 404 fatal("Leg could not compile ${options.dartScript}"); | 409 fatal("Leg could not compile ${options.dartScript}"); |
| 405 return true; // In --leg_only, always "handle" the compilation. | 410 return true; // In --leg_only, always "handle" the compilation. |
| 406 } | 411 } |
| 407 return res; | 412 return res; |
| 408 } | 413 } |
| 409 | 414 |
| 410 void runCompilationPhases() { | 415 void runCompilationPhases() { |
| 411 final lib = withTiming('first pass', () => processDartScript()); | 416 final lib = withTiming('first pass', () => processDartScript()); |
| 412 withTiming('resolve top level', resolveAll); | 417 withTiming('resolve top level', resolveAll); |
| 413 if (experimentalAwaitPhase != null) { | 418 if (experimentalAwaitPhase != null) { |
| 414 withTiming('await translation', experimentalAwaitPhase); | 419 withTiming('await translation', experimentalAwaitPhase); |
| 415 } | 420 } |
| 416 withTiming('analyze pass', () { analyzeCode(lib); }); | 421 withTiming('analyze pass', () { analyzeCode(lib); }); |
| 417 if (options.checkOnly) return; | 422 if (options.checkOnly) return; |
| 418 | 423 |
| 419 withTiming('generate code', () { generateCode(lib); }); | 424 withTiming('generate code', () { generateCode(lib); }); |
| 420 } | 425 } |
| 421 | 426 |
| 422 String getGeneratedCode() { | 427 String getGeneratedCode() { |
| 423 // TODO(jimhug): Assert compilation is all done here. | 428 // TODO(jimhug): Assert compilation is all done here. |
| 424 if (legCode != null) { | 429 if (legCode != null) { |
| 425 assert(options.enableLeg); | 430 assert(options.legOnly); |
| 426 return legCode; | 431 return legCode; |
| 427 } else { | 432 } else { |
| 428 return frogCode; | 433 return frogCode; |
| 429 } | 434 } |
| 430 } | 435 } |
| 431 | 436 |
| 432 SourceFile readFile(String filename) { | 437 SourceFile readFile(String filename) { |
| 433 try { | 438 try { |
| 434 final sourceFile = reader.readFile(filename); | 439 final sourceFile = reader.readFile(filename); |
| 435 dartBytesRead += sourceFile.text.length; | 440 dartBytesRead += sourceFile.text.length; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 | 631 |
| 627 withTiming(String name, f()) { | 632 withTiming(String name, f()) { |
| 628 final sw = new Stopwatch(); | 633 final sw = new Stopwatch(); |
| 629 sw.start(); | 634 sw.start(); |
| 630 var result = f(); | 635 var result = f(); |
| 631 sw.stop(); | 636 sw.stop(); |
| 632 info('$name in ${sw.elapsedInMs()}msec'); | 637 info('$name in ${sw.elapsedInMs()}msec'); |
| 633 return result; | 638 return result; |
| 634 } | 639 } |
| 635 } | 640 } |
| OLD | NEW |