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 const bool REPORT_EXCESS_RESOLUTION = false; | 10 const bool REPORT_EXCESS_RESOLUTION = false; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Contains backend-specific data that is used throughout the compilation of | 34 * Contains backend-specific data that is used throughout the compilation of |
| 35 * one work item. | 35 * one work item. |
| 36 */ | 36 */ |
| 37 class ItemCompilationContext { | 37 class ItemCompilationContext { |
| 38 } | 38 } |
| 39 | 39 |
| 40 class WorkItem { | 40 class WorkItem { |
| 41 final ItemCompilationContext compilationContext; | 41 final ItemCompilationContext compilationContext; |
| 42 /** | |
| 43 * Invariant: [element] must be the declaration element. | |
|
ahe
2012/09/18 11:25:54
This is not a documentation comment.
Johnni Winther
2012/09/20 08:12:23
Done.
| |
| 44 */ | |
| 42 final Element element; | 45 final Element element; |
| 43 TreeElements resolutionTree; | 46 TreeElements resolutionTree; |
| 44 bool allowSpeculativeOptimization = true; | 47 bool allowSpeculativeOptimization = true; |
| 45 List<HTypeGuard> guards = const <HTypeGuard>[]; | 48 List<HTypeGuard> guards = const <HTypeGuard>[]; |
| 46 | 49 |
| 47 WorkItem(this.element, this.resolutionTree, this.compilationContext); | 50 WorkItem(this.element, this.resolutionTree, this.compilationContext) { |
| 51 assert(element.isDeclaration); | |
| 52 } | |
| 48 | 53 |
| 49 bool isAnalyzed() => resolutionTree !== null; | 54 bool isAnalyzed() => resolutionTree !== null; |
| 50 | 55 |
| 51 void run(Compiler compiler, Enqueuer world) { | 56 void run(Compiler compiler, Enqueuer world) { |
| 52 CodeBuffer codeBuffer = world.universe.generatedCode[element]; | 57 CodeBuffer codeBuffer = world.universe.generatedCode[element]; |
| 53 if (codeBuffer !== null) return; | 58 if (codeBuffer !== null) return; |
| 54 resolutionTree = compiler.analyze(this, world); | 59 resolutionTree = compiler.analyze(this, world); |
| 55 compiler.codegen(this, world); | 60 compiler.codegen(this, world); |
| 56 } | 61 } |
| 57 } | 62 } |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 print("Inferred return types:"); | 607 print("Inferred return types:"); |
| 603 print("----------------------"); | 608 print("----------------------"); |
| 604 backend.dumpReturnTypes(); | 609 backend.dumpReturnTypes(); |
| 605 } | 610 } |
| 606 } | 611 } |
| 607 | 612 |
| 608 void processRecompilationQueue(Enqueuer world) { | 613 void processRecompilationQueue(Enqueuer world) { |
| 609 assert(phase == PHASE_RECOMPILING); | 614 assert(phase == PHASE_RECOMPILING); |
| 610 while (!world.recompilationCandidates.isEmpty()) { | 615 while (!world.recompilationCandidates.isEmpty()) { |
| 611 WorkItem work = world.recompilationCandidates.next(); | 616 WorkItem work = world.recompilationCandidates.next(); |
| 612 CodeBuffer oldCode = world.universe.generatedCode[work.element]; | 617 Element element = work.element; |
| 613 world.universe.generatedCode.remove(work.element); | 618 CodeBuffer oldCode = world.universe.generatedCode[element]; |
| 614 world.universe.generatedBailoutCode.remove(work.element); | 619 world.universe.generatedCode.remove(element); |
| 615 withCurrentElement(work.element, () => work.run(this, world)); | 620 world.universe.generatedBailoutCode.remove(element); |
| 616 CodeBuffer newCode = world.universe.generatedCode[work.element]; | 621 withCurrentElement(element, () => work.run(this, world)); |
| 622 CodeBuffer newCode = world.universe.generatedCode[element]; | |
| 617 if (REPORT_PASS2_OPTIMIZATIONS && newCode != oldCode) { | 623 if (REPORT_PASS2_OPTIMIZATIONS && newCode != oldCode) { |
| 618 log("Pass 2 optimization:"); | 624 log("Pass 2 optimization:"); |
| 619 log("Before:\n$oldCode"); | 625 log("Before:\n$oldCode"); |
| 620 log("After:\n$newCode"); | 626 log("After:\n$newCode"); |
| 621 } | 627 } |
| 622 } | 628 } |
| 623 } | 629 } |
| 624 | 630 |
| 625 /** | 631 /** |
| 626 * Perform various checks of the queues. This includes checking that | 632 * Perform various checks of the queues. This includes checking that |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 log('Excess resolution work: ${resolved.length}.'); | 670 log('Excess resolution work: ${resolved.length}.'); |
| 665 if (!REPORT_EXCESS_RESOLUTION) return; | 671 if (!REPORT_EXCESS_RESOLUTION) return; |
| 666 for (Element e in resolved) { | 672 for (Element e in resolved) { |
| 667 SourceSpan span = spanFromElement(e); | 673 SourceSpan span = spanFromElement(e); |
| 668 reportDiagnostic(span, 'Warning: $e resolved but not compiled.', | 674 reportDiagnostic(span, 'Warning: $e resolved but not compiled.', |
| 669 api.Diagnostic.WARNING); | 675 api.Diagnostic.WARNING); |
| 670 } | 676 } |
| 671 } | 677 } |
| 672 | 678 |
| 673 TreeElements analyzeElement(Element element) { | 679 TreeElements analyzeElement(Element element) { |
| 680 assert(element.isDeclaration); | |
| 674 TreeElements elements = enqueuer.resolution.getCachedElements(element); | 681 TreeElements elements = enqueuer.resolution.getCachedElements(element); |
| 675 if (elements !== null) return elements; | 682 if (elements !== null) return elements; |
| 676 final int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION | 683 final int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION |
| 677 | ElementCategory.FACTORY; | 684 | ElementCategory.FACTORY; |
| 678 ElementKind kind = element.kind; | 685 ElementKind kind = element.kind; |
| 679 if (!element.isAccessor() && | 686 if (!element.isAccessor() && |
| 680 ((kind === ElementKind.ABSTRACT_FIELD) || | 687 ((kind === ElementKind.ABSTRACT_FIELD) || |
| 681 (kind.category & allowed) == 0)) { | 688 (kind.category & allowed) == 0)) { |
| 682 return null; | 689 return null; |
| 683 } | 690 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 707 } | 714 } |
| 708 } | 715 } |
| 709 Element element = work.element; | 716 Element element = work.element; |
| 710 TreeElements result = world.getCachedElements(element); | 717 TreeElements result = world.getCachedElements(element); |
| 711 if (result !== null) return result; | 718 if (result !== null) return result; |
| 712 if (world !== enqueuer.resolution) { | 719 if (world !== enqueuer.resolution) { |
| 713 internalErrorOnElement(element, | 720 internalErrorOnElement(element, |
| 714 'Internal error: unresolved element: $element.'); | 721 'Internal error: unresolved element: $element.'); |
| 715 } | 722 } |
| 716 result = analyzeElement(element); | 723 result = analyzeElement(element); |
| 724 assert(element.isDeclaration); | |
| 717 enqueuer.resolution.resolvedElements[element] = result; | 725 enqueuer.resolution.resolvedElements[element] = result; |
| 718 return result; | 726 return result; |
| 719 } | 727 } |
| 720 | 728 |
| 721 void codegen(WorkItem work, Enqueuer world) { | 729 void codegen(WorkItem work, Enqueuer world) { |
| 722 if (world !== enqueuer.codegen) return null; | 730 if (world !== enqueuer.codegen) return null; |
| 723 if (progress.elapsedInMs() > 500) { | 731 if (progress.elapsedInMs() > 500) { |
| 724 // TODO(ahe): Add structured diagnostics to the compiler API and | 732 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 725 // use it to separate this from the --verbose option. | 733 // use it to separate this from the --verbose option. |
| 726 if (phase == PHASE_COMPILING) { | 734 if (phase == PHASE_COMPILING) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 final endOffset = end.charOffset + end.slowCharCount; | 946 final endOffset = end.charOffset + end.slowCharCount; |
| 939 | 947 |
| 940 // [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 |
| 941 // happens for instance when scanning '$$'. | 949 // happens for instance when scanning '$$'. |
| 942 assert(endOffset >= beginOffset); | 950 assert(endOffset >= beginOffset); |
| 943 return f(beginOffset, endOffset); | 951 return f(beginOffset, endOffset); |
| 944 } | 952 } |
| 945 | 953 |
| 946 String toString() => 'SourceSpan($uri, $begin, $end)'; | 954 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 947 } | 955 } |
| OLD | NEW |