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

Side by Side Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10386161: Start compiler refactoring to support more than a single backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months 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
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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 Element getGetRuntimeTypeInfo() { 133 Element getGetRuntimeTypeInfo() {
134 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); 134 return compiler.findHelper(const SourceString('getRuntimeTypeInfo'));
135 } 135 }
136 } 136 }
137 137
138 class SsaBuilderTask extends CompilerTask { 138 class SsaBuilderTask extends CompilerTask {
139 final Interceptors interceptors; 139 final Interceptors interceptors;
140 final Map<Node, ClosureData> closureDataCache; 140 final Map<Node, ClosureData> closureDataCache;
141 final CodeEmitterTask emitter;
141 142
142 String get name() => 'SSA builder'; 143 String get name() => 'SSA builder';
143 144
144 SsaBuilderTask(Compiler compiler) 145 SsaBuilderTask(JavaScriptBackend backend)
145 : interceptors = new Interceptors(compiler), 146 : interceptors = new Interceptors(backend.compiler),
146 closureDataCache = new HashMap<Node, ClosureData>(), 147 closureDataCache = new HashMap<Node, ClosureData>(),
147 super(compiler); 148 emitter = backend.emitter,
149 super(backend.compiler);
148 150
149 HGraph build(WorkItem work) { 151 HGraph build(WorkItem work) {
150 return measure(() { 152 return measure(() {
151 FunctionElement element = work.element; 153 FunctionElement element = work.element;
152 HInstruction.idCounter = 0; 154 HInstruction.idCounter = 0;
153 SsaBuilder builder = new SsaBuilder(compiler, work); 155 SsaBuilder builder = new SsaBuilder(this, work);
154 HGraph graph; 156 HGraph graph;
155 switch (element.kind) { 157 switch (element.kind) {
156 case ElementKind.GENERATIVE_CONSTRUCTOR: 158 case ElementKind.GENERATIVE_CONSTRUCTOR:
157 graph = compileConstructor(builder, work); 159 graph = compileConstructor(builder, work);
158 break; 160 break;
159 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY: 161 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY:
160 case ElementKind.FUNCTION: 162 case ElementKind.FUNCTION:
161 case ElementKind.GETTER: 163 case ElementKind.GETTER:
162 case ElementKind.SETTER: 164 case ElementKind.SETTER:
163 graph = builder.buildMethod(work.element); 165 graph = builder.buildMethod(work.element);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 HInstruction oldValue = readLocal(boxedVariable); 294 HInstruction oldValue = readLocal(boxedVariable);
293 updateLocal(boxElement, newBox); 295 updateLocal(boxElement, newBox);
294 updateLocal(boxedVariable, oldValue); 296 updateLocal(boxedVariable, oldValue);
295 } 297 }
296 updateLocal(boxElement, newBox); 298 updateLocal(boxElement, newBox);
297 } 299 }
298 300
299 void startFunction(FunctionElement function, 301 void startFunction(FunctionElement function,
300 FunctionExpression node) { 302 FunctionExpression node) {
301 303
302 ClosureTranslator translator = 304 ClosureTranslator translator = new ClosureTranslator(builder);
303 new ClosureTranslator(builder.compiler, builder.elements);
304 closureData = translator.translate(node); 305 closureData = translator.translate(node);
305 306
306 FunctionSignature params = function.computeSignature(builder.compiler); 307 FunctionSignature params = function.computeSignature(builder.compiler);
307 params.forEachParameter((Element element) { 308 params.forEachParameter((Element element) {
308 HInstruction parameter = new HParameterValue(element); 309 HInstruction parameter = new HParameterValue(element);
309 builder.add(parameter); 310 builder.add(parameter);
310 parameter = builder.potentiallyCheckType(parameter, element); 311 parameter = builder.potentiallyCheckType(parameter, element);
311 directLocals[element] = parameter; 312 directLocals[element] = parameter;
312 }); 313 });
313 314
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 List<LabelElement> result = null; 761 List<LabelElement> result = null;
761 for (LabelElement element in target.labels) { 762 for (LabelElement element in target.labels) {
762 if (result === null) result = <LabelElement>[]; 763 if (result === null) result = <LabelElement>[];
763 result.add(element); 764 result.add(element);
764 } 765 }
765 return (result === null) ? const <LabelElement>[] : result; 766 return (result === null) ? const <LabelElement>[] : result;
766 } 767 }
767 } 768 }
768 769
769 class SsaBuilder implements Visitor { 770 class SsaBuilder implements Visitor {
770 final Compiler compiler; 771 final SsaBuilderTask builder;
771 TreeElements elements; 772 TreeElements elements;
772 final Interceptors interceptors; 773 final Interceptors interceptors;
773 final WorkItem work; 774 final WorkItem work;
774 bool methodInterceptionEnabled; 775 bool methodInterceptionEnabled;
775 HGraph graph; 776 HGraph graph;
776 LocalsHandler localsHandler; 777 LocalsHandler localsHandler;
777 HInstruction rethrowableException; 778 HInstruction rethrowableException;
778 779
779 Map<TargetElement, JumpHandler> jumpTargets; 780 Map<TargetElement, JumpHandler> jumpTargets;
780 781
781 // We build the Ssa graph by simulating a stack machine. 782 // We build the Ssa graph by simulating a stack machine.
782 List<HInstruction> stack; 783 List<HInstruction> stack;
783 784
784 // The current block to add instructions to. Might be null, if we are 785 // The current block to add instructions to. Might be null, if we are
785 // visiting dead code. 786 // visiting dead code.
786 HBasicBlock current; 787 HBasicBlock current;
787 // The most recently opened block. Has the same value as [current] while 788 // The most recently opened block. Has the same value as [current] while
788 // the block is open, but unlike [current], it isn't cleared when the current 789 // the block is open, but unlike [current], it isn't cleared when the current
789 // block is closed. 790 // block is closed.
790 HBasicBlock lastOpenedBlock; 791 HBasicBlock lastOpenedBlock;
791 792
792 LibraryElement get currentLibrary() => work.element.getLibrary(); 793 LibraryElement get currentLibrary() => work.element.getLibrary();
794 Compiler get compiler() => builder.compiler;
795 CodeEmitterTask get emitter() => builder.emitter;
793 796
794 SsaBuilder(Compiler compiler, WorkItem work) 797 SsaBuilder(SsaBuilderTask builder, WorkItem work)
795 : this.compiler = compiler, 798 : this.builder = builder,
796 this.work = work, 799 this.work = work,
797 interceptors = compiler.builder.interceptors, 800 interceptors = builder.interceptors,
798 methodInterceptionEnabled = true, 801 methodInterceptionEnabled = true,
799 elements = work.resolutionTree, 802 elements = work.resolutionTree,
800 graph = new HGraph(), 803 graph = new HGraph(),
801 stack = new List<HInstruction>(), 804 stack = new List<HInstruction>(),
802 jumpTargets = new Map<TargetElement, JumpHandler>() { 805 jumpTargets = new Map<TargetElement, JumpHandler>() {
803 localsHandler = new LocalsHandler(this); 806 localsHandler = new LocalsHandler(this);
804 } 807 }
805 808
806 void disableMethodInterception() { 809 void disableMethodInterception() {
807 assert(methodInterceptionEnabled); 810 assert(methodInterceptionEnabled);
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 wrapExpressionGraph(conditionExpression), 1469 wrapExpressionGraph(conditionExpression),
1467 wrapStatementGraph(bodyGraph), 1470 wrapStatementGraph(bodyGraph),
1468 null, 1471 null,
1469 loopEntryBlock.loopInformation.target, 1472 loopEntryBlock.loopInformation.target,
1470 loopEntryBlock.loopInformation.labels); 1473 loopEntryBlock.loopInformation.labels);
1471 loopEntryBlock.setBlockFlow(loopBlockInfo, current); 1474 loopEntryBlock.setBlockFlow(loopBlockInfo, current);
1472 loopInfo.loopBlockInformation = loopBlockInfo; 1475 loopInfo.loopBlockInformation = loopBlockInfo;
1473 } 1476 }
1474 1477
1475 visitFunctionExpression(FunctionExpression node) { 1478 visitFunctionExpression(FunctionExpression node) {
1476 ClosureData nestedClosureData = compiler.builder.closureDataCache[node]; 1479 ClosureData nestedClosureData = builder.closureDataCache[node];
1477 if (nestedClosureData === null) { 1480 if (nestedClosureData === null) {
1478 // TODO(floitsch): we can only assume that the reason for not having a 1481 // TODO(floitsch): we can only assume that the reason for not having a
1479 // closure data here is, because the function is inside an initializer. 1482 // closure data here is, because the function is inside an initializer.
1480 compiler.unimplemented("Closures inside initializers", node: node); 1483 compiler.unimplemented("Closures inside initializers", node: node);
1481 } 1484 }
1482 assert(nestedClosureData !== null); 1485 assert(nestedClosureData !== null);
1483 assert(nestedClosureData.closureClassElement !== null); 1486 assert(nestedClosureData.closureClassElement !== null);
1484 ClassElement closureClassElement = 1487 ClassElement closureClassElement =
1485 nestedClosureData.closureClassElement; 1488 nestedClosureData.closureClassElement;
1486 FunctionElement callElement = nestedClosureData.callElement; 1489 FunctionElement callElement = nestedClosureData.callElement;
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 <HInstruction>[target, input], 3376 <HInstruction>[target, input],
3374 HType.STRING)); 3377 HType.STRING));
3375 return builder.pop(); 3378 return builder.pop();
3376 } 3379 }
3377 3380
3378 HInstruction result(Node node) { 3381 HInstruction result(Node node) {
3379 flushLiterals(node); 3382 flushLiterals(node);
3380 return prefix; 3383 return prefix;
3381 } 3384 }
3382 } 3385 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/native_handler.dart ('k') | lib/compiler/implementation/ssa/closure.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698