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 | 5 |
| 6 /** | 6 /** |
| 7 * If true, print a warning for each method that was resolved, but not | 7 * If true, print a warning for each method that was resolved, but not |
| 8 * compiled. | 8 * compiled. |
| 9 */ | 9 */ |
| 10 final bool REPORT_EXCESS_RESOLUTION = false; | 10 final bool REPORT_EXCESS_RESOLUTION = false; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * If true, trace information on pass2 optimizations. | 13 * If true, trace information on pass2 optimizations. |
| 14 */ | 14 */ |
| 15 final bool REPORT_PASS2_OPTIMIZATIONS = false; | 15 final bool REPORT_PASS2_OPTIMIZATIONS = false; |
| 16 | 16 |
| 17 class WorkItem { | 17 class WorkItem { |
| 18 final Element element; | 18 final Element element; |
| 19 TreeElements resolutionTree; | 19 TreeElements resolutionTree; |
| 20 bool allowSpeculativeOptimization = true; | 20 bool allowSpeculativeOptimization = true; |
| 21 List<HTypeGuard> guards = const <HTypeGuard>[]; | 21 List<HTypeGuard> guards = const <HTypeGuard>[]; |
| 22 | 22 |
| 23 WorkItem(this.element, this.resolutionTree); | 23 WorkItem(this.element, this.resolutionTree); |
| 24 | 24 |
| 25 bool isAnalyzed() => resolutionTree !== null; | 25 bool isAnalyzed() => resolutionTree !== null; |
| 26 | 26 |
| 27 String run(Compiler compiler, Enqueuer world) { | 27 void run(Compiler compiler, Enqueuer world) { |
| 28 CodeBuffer codeBuffer = world.universe.generatedCode[element]; | 28 CodeBuffer codeBuffer = world.universe.generatedCode[element]; |
| 29 if (codeBuffer !== null) return codeBuffer.toString(); | 29 if (codeBuffer !== null) return; |
| 30 resolutionTree = compiler.analyze(this, world); | 30 resolutionTree = compiler.analyze(this, world); |
| 31 return compiler.codegen(this, world); | 31 compiler.codegen(this, world); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 class Backend { | 35 class Backend { |
| 36 final Compiler compiler; | 36 final Compiler compiler; |
| 37 | 37 |
| 38 Backend(this.compiler); | 38 Backend(this.compiler); |
| 39 | 39 |
| 40 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { | 40 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { |
| 41 lib.forEachExport((Element e) { | 41 lib.forEachExport((Element e) { |
| 42 if (e.isFunction()) world.addToWorkList(e); | 42 if (e.isFunction()) world.addToWorkList(e); |
| 43 }); | 43 }); |
| 44 } | 44 } |
| 45 | 45 |
| 46 abstract void enqueueHelpers(Enqueuer world); | 46 abstract void enqueueHelpers(Enqueuer world); |
| 47 abstract CodeBuffer codegen(WorkItem work); | 47 abstract void codegen(WorkItem work); |
| 48 abstract void processNativeClasses(Enqueuer world, | 48 abstract void processNativeClasses(Enqueuer world, |
| 49 Collection<LibraryElement> libraries); | 49 Collection<LibraryElement> libraries); |
| 50 abstract void assembleProgram(); | 50 abstract void assembleProgram(); |
| 51 abstract List<CompilerTask> get tasks(); | 51 abstract List<CompilerTask> get tasks(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 class Compiler implements DiagnosticListener { | 54 class Compiler implements DiagnosticListener { |
| 55 final Map<String, LibraryElement> libraries; | 55 final Map<String, LibraryElement> libraries; |
| 56 int nextFreeClassId = 0; | 56 int nextFreeClassId = 0; |
| 57 World world; | 57 World world; |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 if (result !== null) return result; | 736 if (result !== null) return result; |
| 737 if (world !== enqueuer.resolution) { | 737 if (world !== enqueuer.resolution) { |
| 738 internalErrorOnElement(element, | 738 internalErrorOnElement(element, |
| 739 'Internal error: unresolved element: $element.'); | 739 'Internal error: unresolved element: $element.'); |
| 740 } | 740 } |
| 741 result = analyzeElement(element); | 741 result = analyzeElement(element); |
| 742 enqueuer.resolution.resolvedElements[element] = result; | 742 enqueuer.resolution.resolvedElements[element] = result; |
| 743 return result; | 743 return result; |
| 744 } | 744 } |
| 745 | 745 |
| 746 String codegen(WorkItem work, Enqueuer world) { | 746 void codegen(WorkItem work, Enqueuer world) { |
| 747 if (world !== enqueuer.codegen) return null; | 747 if (world !== enqueuer.codegen) return null; |
| 748 if (progress.elapsedInMs() > 500) { | 748 if (progress.elapsedInMs() > 500) { |
| 749 // TODO(ahe): Add structured diagnostics to the compiler API and | 749 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 750 // use it to separate this from the --verbose option. | 750 // use it to separate this from the --verbose option. |
| 751 if (phase == PHASE_COMPILING) { | 751 if (phase == PHASE_COMPILING) { |
| 752 log('Compiled ${codegenWorld.generatedCode.length} methods.'); | 752 log('Compiled ${codegenWorld.generatedCode.length} methods.'); |
| 753 } else { | 753 } else { |
| 754 log('Recompiled ${world.recompilationCandidates.processed} methods.'); | 754 log('Recompiled ${world.recompilationCandidates.processed} methods.'); |
| 755 } | 755 } |
| 756 progress.reset(); | 756 progress.reset(); |
| 757 } | 757 } |
| 758 if (work.element.kind.category == ElementCategory.VARIABLE) { | 758 if (work.element.kind.category == ElementCategory.VARIABLE) { |
| 759 constantHandler.compileWorkItem(work); | 759 constantHandler.compileWorkItem(work); |
| 760 return null; | |
| 761 } else { | 760 } else { |
| 762 CodeBuffer codeBuffer = backend.codegen(work); | 761 CodeBuffer codeBuffer = backend.codegen(work); |
|
ahe
2012/08/14 07:57:56
codeBuffer is never used.
Søren Gjesse
2012/08/14 08:26:30
Removed.
| |
| 763 codegenWorld.addGeneratedCode(work, codeBuffer); | |
| 764 return codeBuffer.toString(); | |
| 765 } | 762 } |
| 766 } | 763 } |
| 767 | 764 |
| 768 void registerInstantiatedClass(ClassElement cls) { | 765 void registerInstantiatedClass(ClassElement cls) { |
| 769 enqueuer.resolution.registerInstantiatedClass(cls); | 766 enqueuer.resolution.registerInstantiatedClass(cls); |
| 770 enqueuer.codegen.registerInstantiatedClass(cls); | 767 enqueuer.codegen.registerInstantiatedClass(cls); |
| 771 } | 768 } |
| 772 | 769 |
| 773 Type resolveTypeAnnotation(Element element, TypeAnnotation annotation) { | 770 Type resolveTypeAnnotation(Element element, TypeAnnotation annotation) { |
| 774 return resolver.resolveTypeAnnotation(element, annotation); | 771 return resolver.resolveTypeAnnotation(element, annotation); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 final endOffset = end.charOffset + end.slowCharCount; | 946 final endOffset = end.charOffset + end.slowCharCount; |
| 950 | 947 |
| 951 // [begin] and [end] might be the same for the same empty token. This | 948 // [begin] and [end] might be the same for the same empty token. This |
| 952 // happens for instance when scanning '$$'. | 949 // happens for instance when scanning '$$'. |
| 953 assert(endOffset >= beginOffset); | 950 assert(endOffset >= beginOffset); |
| 954 return f(beginOffset, endOffset); | 951 return f(beginOffset, endOffset); |
| 955 } | 952 } |
| 956 | 953 |
| 957 String toString() => 'SourceSpan($uri, $begin, $end)'; | 954 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 958 } | 955 } |
| OLD | NEW |