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