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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 typedef void Recompile(Element element); | 7 typedef void Recompile(Element element); |
| 8 | 8 |
| 9 class ReturnInfo { | 9 class ReturnInfo { |
| 10 HType returnType; | 10 HType returnType; |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 : types = new HTypeMap(), | 639 : types = new HTypeMap(), |
| 640 boundsChecked = new Set<HInstruction>(); | 640 boundsChecked = new Set<HInstruction>(); |
| 641 } | 641 } |
| 642 | 642 |
| 643 class JavaScriptBackend extends Backend { | 643 class JavaScriptBackend extends Backend { |
| 644 SsaBuilderTask builder; | 644 SsaBuilderTask builder; |
| 645 SsaOptimizerTask optimizer; | 645 SsaOptimizerTask optimizer; |
| 646 SsaCodeGeneratorTask generator; | 646 SsaCodeGeneratorTask generator; |
| 647 CodeEmitterTask emitter; | 647 CodeEmitterTask emitter; |
| 648 | 648 |
| 649 ClassElement jsStringClass; | |
| 650 ClassElement objectInterceptorClass; | |
| 651 Element getInterceptorMethod; | |
| 652 | |
| 649 final Namer namer; | 653 final Namer namer; |
| 650 | 654 |
| 651 /** | 655 /** |
| 652 * Interface used to determine if an object has the JavaScript | 656 * Interface used to determine if an object has the JavaScript |
| 653 * indexing behavior. The interface is only visible to specific | 657 * indexing behavior. The interface is only visible to specific |
| 654 * libraries. | 658 * libraries. |
| 655 */ | 659 */ |
| 656 ClassElement jsIndexingBehaviorInterface; | 660 ClassElement jsIndexingBehaviorInterface; |
| 657 | 661 |
| 658 final Map<Element, ReturnInfo> returnInfo; | 662 final Map<Element, ReturnInfo> returnInfo; |
| 659 | 663 |
| 660 /** | 664 /** |
| 661 * Documentation wanted -- johnniwinther | 665 * Documentation wanted -- johnniwinther |
| 662 * | 666 * |
| 663 * Invariant: Elements must be declaration elements. | 667 * Invariant: Elements must be declaration elements. |
| 664 */ | 668 */ |
| 665 final List<Element> invalidateAfterCodegen; | 669 final List<Element> invalidateAfterCodegen; |
| 666 ArgumentTypesRegistry argumentTypes; | 670 ArgumentTypesRegistry argumentTypes; |
| 667 FieldTypesRegistry fieldTypes; | 671 FieldTypesRegistry fieldTypes; |
| 668 | 672 |
| 669 final Interceptors interceptors; | 673 final Interceptors interceptors; |
| 670 | 674 |
| 675 /** | |
| 676 * A collection of selectors of intercepted method calls. The | |
| 677 * emitter uses this set to generate the [:ObjectInterceptor:] class | |
| 678 * whose members just forward the call to the intercepted receiver. | |
| 679 */ | |
| 680 final Set<Selector> usedInterceptors; | |
| 681 | |
| 682 /** | |
| 683 * The members of instantiated interceptor classes. This map is used | |
| 684 * by the codegen to know whether a send must be intercepted or not. | |
| 685 */ | |
| 686 final Map<SourceString, List<Element>> interceptedElements; | |
|
ahe
2012/11/13 12:42:41
What is this mapping from and to? member names to
ngeoffray
2012/11/13 12:51:50
Done.
| |
| 687 | |
| 671 List<CompilerTask> get tasks { | 688 List<CompilerTask> get tasks { |
| 672 return <CompilerTask>[builder, optimizer, generator, emitter]; | 689 return <CompilerTask>[builder, optimizer, generator, emitter]; |
| 673 } | 690 } |
| 674 | 691 |
| 675 JavaScriptBackend(Compiler compiler, | 692 JavaScriptBackend(Compiler compiler, |
| 676 bool generateSourceMap, | 693 bool generateSourceMap, |
| 677 bool disableEval) | 694 bool disableEval) |
| 678 : namer = new Namer(compiler), | 695 : namer = new Namer(compiler), |
| 679 returnInfo = new Map<Element, ReturnInfo>(), | 696 returnInfo = new Map<Element, ReturnInfo>(), |
| 680 invalidateAfterCodegen = new List<Element>(), | 697 invalidateAfterCodegen = new List<Element>(), |
| 681 interceptors = new Interceptors(compiler), | 698 interceptors = new Interceptors(compiler), |
| 699 usedInterceptors = new Set<Selector>(), | |
| 700 interceptedElements = new Map<SourceString, List<Element>>(), | |
| 682 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { | 701 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { |
| 683 emitter = disableEval | 702 emitter = disableEval |
| 684 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) | 703 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) |
| 685 : new CodeEmitterTask(compiler, namer, generateSourceMap); | 704 : new CodeEmitterTask(compiler, namer, generateSourceMap); |
| 686 builder = new SsaBuilderTask(this); | 705 builder = new SsaBuilderTask(this); |
| 687 optimizer = new SsaOptimizerTask(this); | 706 optimizer = new SsaOptimizerTask(this); |
| 688 generator = new SsaCodeGeneratorTask(this); | 707 generator = new SsaCodeGeneratorTask(this); |
| 689 argumentTypes = new ArgumentTypesRegistry(this); | 708 argumentTypes = new ArgumentTypesRegistry(this); |
| 690 fieldTypes = new FieldTypesRegistry(this); | 709 fieldTypes = new FieldTypesRegistry(this); |
| 691 } | 710 } |
| 692 | 711 |
| 712 bool isInterceptorClass(Element element) { | |
| 713 return element == jsStringClass; | |
| 714 } | |
| 715 | |
| 716 void addInterceptedSelector(Selector selector) { | |
| 717 usedInterceptors.add(selector); | |
| 718 } | |
| 719 | |
| 720 bool shouldInterceptSelector(Selector selector) { | |
| 721 List<Element> intercepted = interceptedElements[selector.name]; | |
| 722 if (intercepted == null) return false; | |
| 723 for (Element element in intercepted) { | |
| 724 if (selector.applies(element, compiler)) return true; | |
| 725 } | |
| 726 return false; | |
| 727 } | |
| 728 | |
| 729 | |
| 730 ClassElement getBackendImplementation(ClassElement cls) { | |
| 731 ClassElement result = null; | |
| 732 if (cls == compiler.stringClass) { | |
| 733 if (jsStringClass == null) { | |
| 734 jsStringClass = | |
| 735 compiler.findInterceptor(const SourceString('JSString')); | |
| 736 objectInterceptorClass = | |
| 737 compiler.findInterceptor(const SourceString('ObjectInterceptor')); | |
| 738 getInterceptorMethod = | |
| 739 compiler.findInterceptor(const SourceString('getInterceptor')); | |
| 740 } | |
| 741 result = jsStringClass; | |
| 742 } | |
| 743 | |
| 744 if (result == null) return result; | |
| 745 | |
| 746 result.forEachMember((_, Element member) { | |
| 747 List<Element> list = interceptedElements.putIfAbsent( | |
| 748 member.name, () => new List<Element>()); | |
| 749 list.add(member); | |
| 750 }); | |
| 751 return result; | |
| 752 } | |
| 753 | |
| 693 Element get cyclicThrowHelper { | 754 Element get cyclicThrowHelper { |
| 694 return compiler.findHelper(const SourceString("throwCyclicInit")); | 755 return compiler.findHelper(const SourceString("throwCyclicInit")); |
| 695 } | 756 } |
| 696 | 757 |
| 697 JavaScriptItemCompilationContext createItemCompilationContext() { | 758 JavaScriptItemCompilationContext createItemCompilationContext() { |
| 698 return new JavaScriptItemCompilationContext(); | 759 return new JavaScriptItemCompilationContext(); |
| 699 } | 760 } |
| 700 | 761 |
| 701 Element getInterceptor(Selector selector) { | 762 Element getInterceptor(Selector selector) { |
| 702 return interceptors.getStaticInterceptor(selector); | 763 return interceptors.getStaticInterceptor(selector); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 print("Inferred return types:"); | 1013 print("Inferred return types:"); |
| 953 print("----------------------"); | 1014 print("----------------------"); |
| 954 dumpReturnTypes(); | 1015 dumpReturnTypes(); |
| 955 print(""); | 1016 print(""); |
| 956 print("Inferred field types:"); | 1017 print("Inferred field types:"); |
| 957 print("------------------------"); | 1018 print("------------------------"); |
| 958 fieldTypes.dump(); | 1019 fieldTypes.dump(); |
| 959 print(""); | 1020 print(""); |
| 960 } | 1021 } |
| 961 } | 1022 } |
| OLD | NEW |