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

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

Issue 10855146: Make the closure-to-class translator more accessible. It can now be (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return compiler.findHelper(const SourceString('setRuntimeTypeInfo')); 126 return compiler.findHelper(const SourceString('setRuntimeTypeInfo'));
127 } 127 }
128 128
129 Element getGetRuntimeTypeInfo() { 129 Element getGetRuntimeTypeInfo() {
130 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); 130 return compiler.findHelper(const SourceString('getRuntimeTypeInfo'));
131 } 131 }
132 } 132 }
133 133
134 class SsaBuilderTask extends CompilerTask { 134 class SsaBuilderTask extends CompilerTask {
135 final Interceptors interceptors; 135 final Interceptors interceptors;
136 final Map<Node, ClosureData> closureDataCache;
137 final CodeEmitterTask emitter; 136 final CodeEmitterTask emitter;
138 // Loop tracking information. 137 // Loop tracking information.
139 final Set<FunctionElement> functionsCalledInLoop; 138 final Set<FunctionElement> functionsCalledInLoop;
140 final Map<SourceString, Selector> selectorsCalledInLoop; 139 final Map<SourceString, Selector> selectorsCalledInLoop;
141 final JavaScriptBackend backend; 140 final JavaScriptBackend backend;
142 141
143 String get name() => 'SSA builder'; 142 String get name() => 'SSA builder';
144 143
145 SsaBuilderTask(JavaScriptBackend backend) 144 SsaBuilderTask(JavaScriptBackend backend)
146 : interceptors = new Interceptors(backend.compiler), 145 : interceptors = new Interceptors(backend.compiler),
147 closureDataCache = new HashMap<Node, ClosureData>(),
148 emitter = backend.emitter, 146 emitter = backend.emitter,
149 functionsCalledInLoop = new Set<FunctionElement>(), 147 functionsCalledInLoop = new Set<FunctionElement>(),
150 selectorsCalledInLoop = new Map<SourceString, Selector>(), 148 selectorsCalledInLoop = new Map<SourceString, Selector>(),
151 backend = backend, 149 backend = backend,
152 super(backend.compiler); 150 super(backend.compiler);
153 151
154 HGraph build(WorkItem work) { 152 HGraph build(WorkItem work) {
155 return measure(() { 153 return measure(() {
156 FunctionElement element = work.element; 154 FunctionElement element = work.element;
157 HInstruction.idCounter = 0; 155 HInstruction.idCounter = 0;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 * too. 217 * too.
220 */ 218 */
221 class LocalsHandler { 219 class LocalsHandler {
222 /** 220 /**
223 * The values of locals that can be directly accessed (without redirections 221 * The values of locals that can be directly accessed (without redirections
224 * to boxes or closure-fields). 222 * to boxes or closure-fields).
225 */ 223 */
226 Map<Element, HInstruction> directLocals; 224 Map<Element, HInstruction> directLocals;
227 Map<Element, Element> redirectionMapping; 225 Map<Element, Element> redirectionMapping;
228 SsaBuilder builder; 226 SsaBuilder builder;
229 ClosureData closureData; 227 ClosureToClassMapping closureData;
230 228
231 LocalsHandler(this.builder) 229 LocalsHandler(this.builder)
232 : directLocals = new Map<Element, HInstruction>(), 230 : directLocals = new Map<Element, HInstruction>(),
233 redirectionMapping = new Map<Element, Element>(); 231 redirectionMapping = new Map<Element, Element>();
234 232
235 get typesTask() => builder.compiler.typesTask; 233 get typesTask() => builder.compiler.typesTask;
236 234
237 /** 235 /**
238 * Creates a new [LocalsHandler] based on [other]. We only need to 236 * Creates a new [LocalsHandler] based on [other]. We only need to
239 * copy the [directLocals], since the other fields can be shared 237 * copy the [directLocals], since the other fields can be shared
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 updateLocal(boxElement, oldBox); 313 updateLocal(boxElement, oldBox);
316 HInstruction oldValue = readLocal(boxedVariable); 314 HInstruction oldValue = readLocal(boxedVariable);
317 updateLocal(boxElement, newBox); 315 updateLocal(boxElement, newBox);
318 updateLocal(boxedVariable, oldValue); 316 updateLocal(boxedVariable, oldValue);
319 } 317 }
320 updateLocal(boxElement, newBox); 318 updateLocal(boxElement, newBox);
321 } 319 }
322 320
323 void startFunction(FunctionElement function, 321 void startFunction(FunctionElement function,
324 FunctionExpression node) { 322 FunctionExpression node) {
323 Compiler compiler = builder.compiler;
324 closureData = compiler.closureToClassMapper.computeClosureToClassMapping(
325 node, builder.elements);
325 326
326 ClosureTranslator translator = new ClosureTranslator(builder); 327 FunctionSignature signature = function.computeSignature(compiler);
327 closureData = translator.translate(node);
328
329 FunctionSignature signature = function.computeSignature(builder.compiler);
330 signature.forEachParameter((Element element) { 328 signature.forEachParameter((Element element) {
331 HInstruction parameter = new HParameterValue(element); 329 HInstruction parameter = new HParameterValue(element);
332 builder.add(parameter); 330 builder.add(parameter);
333 builder.parameters[element] = parameter; 331 builder.parameters[element] = parameter;
334 directLocals[element] = parameter; 332 directLocals[element] = parameter;
335 parameter.guaranteedType = 333 parameter.guaranteedType =
336 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); 334 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element));
337 }); 335 });
338 336
339 enterScope(node); 337 enterScope(node);
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 wrapStatementGraph(bodyGraph), 1539 wrapStatementGraph(bodyGraph),
1542 null, 1540 null,
1543 loopEntryBlock.loopInformation.target, 1541 loopEntryBlock.loopInformation.target,
1544 loopEntryBlock.loopInformation.labels, 1542 loopEntryBlock.loopInformation.labels,
1545 node); 1543 node);
1546 loopEntryBlock.setBlockFlow(loopBlockInfo, current); 1544 loopEntryBlock.setBlockFlow(loopBlockInfo, current);
1547 loopInfo.loopBlockInformation = loopBlockInfo; 1545 loopInfo.loopBlockInformation = loopBlockInfo;
1548 } 1546 }
1549 1547
1550 visitFunctionExpression(FunctionExpression node) { 1548 visitFunctionExpression(FunctionExpression node) {
1551 ClosureData nestedClosureData = builder.closureDataCache[node]; 1549 ClosureToClassMapping nestedClosureData =
1552 if (nestedClosureData === null) { 1550 compiler.closureToClassMapper.getMappingForNestedFunction(node);
1553 // TODO(floitsch): we can only assume that the reason for not having a
1554 // closure data here is, because the function is inside an initializer.
1555 compiler.unimplemented("Closures inside initializers", node: node);
1556 }
1557 assert(nestedClosureData !== null); 1551 assert(nestedClosureData !== null);
1558 assert(nestedClosureData.closureClassElement !== null); 1552 assert(nestedClosureData.closureClassElement !== null);
1559 ClassElement closureClassElement = 1553 ClassElement closureClassElement =
1560 nestedClosureData.closureClassElement; 1554 nestedClosureData.closureClassElement;
1561 FunctionElement callElement = nestedClosureData.callElement; 1555 FunctionElement callElement = nestedClosureData.callElement;
1562 // TODO(ahe): This should be registered in codegen, not here. 1556 // TODO(ahe): This should be registered in codegen, not here.
1563 compiler.enqueuer.codegen.addToWorkList(callElement, elements); 1557 compiler.enqueuer.codegen.addToWorkList(callElement, elements);
1564 // TODO(ahe): This should be registered in codegen, not here. 1558 // TODO(ahe): This should be registered in codegen, not here.
1565 compiler.enqueuer.codegen.registerInstantiatedClass(closureClassElement); 1559 compiler.enqueuer.codegen.registerInstantiatedClass(closureClassElement);
1566 assert(closureClassElement.members.isEmpty()); 1560 assert(closureClassElement.members.isEmpty());
(...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 new HSubGraphBlockInformation(elseBranch.graph)); 3608 new HSubGraphBlockInformation(elseBranch.graph));
3615 3609
3616 HBasicBlock conditionStartBlock = conditionBranch.block; 3610 HBasicBlock conditionStartBlock = conditionBranch.block;
3617 conditionStartBlock.setBlockFlow(info, joinBlock); 3611 conditionStartBlock.setBlockFlow(info, joinBlock);
3618 SubGraph conditionGraph = conditionBranch.graph; 3612 SubGraph conditionGraph = conditionBranch.graph;
3619 HIf branch = conditionGraph.end.last; 3613 HIf branch = conditionGraph.end.last;
3620 assert(branch is HIf); 3614 assert(branch is HIf);
3621 branch.blockInformation = conditionStartBlock.blockFlow; 3615 branch.blockInformation = conditionStartBlock.blockFlow;
3622 } 3616 }
3623 } 3617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698