| 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 Emitter 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 Loading... |
| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 List<LabelElement> result = null; | 748 List<LabelElement> result = null; |
| 748 for (LabelElement element in target.labels) { | 749 for (LabelElement element in target.labels) { |
| 749 if (result === null) result = <LabelElement>[]; | 750 if (result === null) result = <LabelElement>[]; |
| 750 result.add(element); | 751 result.add(element); |
| 751 } | 752 } |
| 752 return (result === null) ? const <LabelElement>[] : result; | 753 return (result === null) ? const <LabelElement>[] : result; |
| 753 } | 754 } |
| 754 } | 755 } |
| 755 | 756 |
| 756 class SsaBuilder implements Visitor { | 757 class SsaBuilder implements Visitor { |
| 757 final Compiler compiler; | 758 final SsaBuilderTask builder; |
| 758 TreeElements elements; | 759 TreeElements elements; |
| 759 final Interceptors interceptors; | 760 final Interceptors interceptors; |
| 760 final WorkItem work; | 761 final WorkItem work; |
| 761 bool methodInterceptionEnabled; | 762 bool methodInterceptionEnabled; |
| 762 HGraph graph; | 763 HGraph graph; |
| 763 LocalsHandler localsHandler; | 764 LocalsHandler localsHandler; |
| 764 HInstruction rethrowableException; | 765 HInstruction rethrowableException; |
| 765 | 766 |
| 766 Map<TargetElement, JumpHandler> jumpTargets; | 767 Map<TargetElement, JumpHandler> jumpTargets; |
| 767 | 768 |
| 768 // We build the Ssa graph by simulating a stack machine. | 769 // We build the Ssa graph by simulating a stack machine. |
| 769 List<HInstruction> stack; | 770 List<HInstruction> stack; |
| 770 | 771 |
| 771 // The current block to add instructions to. Might be null, if we are | 772 // The current block to add instructions to. Might be null, if we are |
| 772 // visiting dead code. | 773 // visiting dead code. |
| 773 HBasicBlock current; | 774 HBasicBlock current; |
| 774 // The most recently opened block. Has the same value as [current] while | 775 // The most recently opened block. Has the same value as [current] while |
| 775 // the block is open, but unlike [current], it isn't cleared when the current | 776 // the block is open, but unlike [current], it isn't cleared when the current |
| 776 // block is closed. | 777 // block is closed. |
| 777 HBasicBlock lastOpenedBlock; | 778 HBasicBlock lastOpenedBlock; |
| 778 | 779 |
| 779 LibraryElement get currentLibrary() => work.element.getLibrary(); | 780 LibraryElement get currentLibrary() => work.element.getLibrary(); |
| 781 Compiler get compiler() => builder.compiler; |
| 782 Emitter get emitter() => builder.emitter; |
| 780 | 783 |
| 781 SsaBuilder(Compiler compiler, WorkItem work) | 784 SsaBuilder(SsaBuilderTask builder, WorkItem work) |
| 782 : this.compiler = compiler, | 785 : this.builder = builder, |
| 783 this.work = work, | 786 this.work = work, |
| 784 interceptors = compiler.builder.interceptors, | 787 interceptors = builder.interceptors, |
| 785 methodInterceptionEnabled = true, | 788 methodInterceptionEnabled = true, |
| 786 elements = work.resolutionTree, | 789 elements = work.resolutionTree, |
| 787 graph = new HGraph(), | 790 graph = new HGraph(), |
| 788 stack = new List<HInstruction>(), | 791 stack = new List<HInstruction>(), |
| 789 jumpTargets = new Map<TargetElement, JumpHandler>() { | 792 jumpTargets = new Map<TargetElement, JumpHandler>() { |
| 790 localsHandler = new LocalsHandler(this); | 793 localsHandler = new LocalsHandler(this); |
| 791 } | 794 } |
| 792 | 795 |
| 793 void disableMethodInterception() { | 796 void disableMethodInterception() { |
| 794 assert(methodInterceptionEnabled); | 797 assert(methodInterceptionEnabled); |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 wrapExpressionGraph(conditionExpression), | 1456 wrapExpressionGraph(conditionExpression), |
| 1454 wrapStatementGraph(bodyGraph), | 1457 wrapStatementGraph(bodyGraph), |
| 1455 null, | 1458 null, |
| 1456 loopEntryBlock.loopInformation.target, | 1459 loopEntryBlock.loopInformation.target, |
| 1457 loopEntryBlock.loopInformation.labels); | 1460 loopEntryBlock.loopInformation.labels); |
| 1458 loopEntryBlock.setBlockFlow(loopBlockInfo, current); | 1461 loopEntryBlock.setBlockFlow(loopBlockInfo, current); |
| 1459 loopInfo.loopBlockInformation = loopBlockInfo; | 1462 loopInfo.loopBlockInformation = loopBlockInfo; |
| 1460 } | 1463 } |
| 1461 | 1464 |
| 1462 visitFunctionExpression(FunctionExpression node) { | 1465 visitFunctionExpression(FunctionExpression node) { |
| 1463 ClosureData nestedClosureData = compiler.builder.closureDataCache[node]; | 1466 ClosureData nestedClosureData = builder.closureDataCache[node]; |
| 1464 if (nestedClosureData === null) { | 1467 if (nestedClosureData === null) { |
| 1465 // TODO(floitsch): we can only assume that the reason for not having a | 1468 // TODO(floitsch): we can only assume that the reason for not having a |
| 1466 // closure data here is, because the function is inside an initializer. | 1469 // closure data here is, because the function is inside an initializer. |
| 1467 compiler.unimplemented("Closures inside initializers", node: node); | 1470 compiler.unimplemented("Closures inside initializers", node: node); |
| 1468 } | 1471 } |
| 1469 assert(nestedClosureData !== null); | 1472 assert(nestedClosureData !== null); |
| 1470 assert(nestedClosureData.closureClassElement !== null); | 1473 assert(nestedClosureData.closureClassElement !== null); |
| 1471 ClassElement closureClassElement = | 1474 ClassElement closureClassElement = |
| 1472 nestedClosureData.closureClassElement; | 1475 nestedClosureData.closureClassElement; |
| 1473 FunctionElement callElement = nestedClosureData.callElement; | 1476 FunctionElement callElement = nestedClosureData.callElement; |
| (...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3312 <HInstruction>[target, input], | 3315 <HInstruction>[target, input], |
| 3313 HType.STRING)); | 3316 HType.STRING)); |
| 3314 return builder.pop(); | 3317 return builder.pop(); |
| 3315 } | 3318 } |
| 3316 | 3319 |
| 3317 HInstruction result() { | 3320 HInstruction result() { |
| 3318 flushLiterals(); | 3321 flushLiterals(); |
| 3319 return prefix; | 3322 return prefix; |
| 3320 } | 3323 } |
| 3321 } | 3324 } |
| OLD | NEW |