| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void startFunction(FunctionElement function, | 312 void startFunction(FunctionElement function, |
| 313 FunctionExpression node) { | 313 FunctionExpression node) { |
| 314 | 314 |
| 315 ClosureTranslator translator = new ClosureTranslator(builder); | 315 ClosureTranslator translator = new ClosureTranslator(builder); |
| 316 closureData = translator.translate(node); | 316 closureData = translator.translate(node); |
| 317 | 317 |
| 318 FunctionSignature params = function.computeSignature(builder.compiler); | 318 FunctionSignature params = function.computeSignature(builder.compiler); |
| 319 params.forEachParameter((Element element) { | 319 params.forEachParameter((Element element) { |
| 320 HInstruction parameter = new HParameterValue(element); | 320 HInstruction parameter = new HParameterValue(element); |
| 321 builder.add(parameter); | 321 builder.add(parameter); |
| 322 builder.potentiallyCheckType(parameter, element); | 322 builder.parameters[element] = parameter; |
| 323 directLocals[element] = parameter; | 323 directLocals[element] = parameter; |
| 324 }); | 324 }); |
| 325 | 325 |
| 326 enterScope(node); | 326 enterScope(node); |
| 327 | 327 |
| 328 // If the freeVariableMapping is not empty, then this function was a | 328 // If the freeVariableMapping is not empty, then this function was a |
| 329 // nested closure that captures variables. Redirect the captured | 329 // nested closure that captures variables. Redirect the captured |
| 330 // variables to fields in the closure. | 330 // variables to fields in the closure. |
| 331 closureData.freeVariableMapping.forEach((Element from, Element to) { | 331 closureData.freeVariableMapping.forEach((Element from, Element to) { |
| 332 redirectElement(from, to); | 332 redirectElement(from, to); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 440 } |
| 441 res.guaranteedType = cachedTypeOfThis; | 441 res.guaranteedType = cachedTypeOfThis; |
| 442 } | 442 } |
| 443 return res; | 443 return res; |
| 444 } | 444 } |
| 445 | 445 |
| 446 HParameterValue getActivationParameter(Element element) { | 446 HParameterValue getActivationParameter(Element element) { |
| 447 // If the element is a parameter, we already have a | 447 // If the element is a parameter, we already have a |
| 448 // HParameterValue for it. We cannot create another one because | 448 // HParameterValue for it. We cannot create another one because |
| 449 // it could then have another name than the real parameter. And | 449 // it could then have another name than the real parameter. And |
| 450 // the other one would not not it is just a copy of the real | 450 // the other one would not know it is just a copy of the real |
| 451 // parameter. | 451 // parameter. |
| 452 if (element.isParameter()) return directLocals[element]; | 452 if (element.isParameter()) return builder.parameters[element]; |
| 453 | 453 |
| 454 return builder.activationVariables.putIfAbsent(element, () { | 454 return builder.activationVariables.putIfAbsent(element, () { |
| 455 HParameterValue parameter = new HParameterValue(element); | 455 HParameterValue parameter = new HParameterValue(element); |
| 456 builder.graph.entry.addAtExit(parameter); | 456 builder.graph.entry.addAtExit(parameter); |
| 457 return parameter; | 457 return parameter; |
| 458 }); | 458 }); |
| 459 } | 459 } |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * Sets the [element] to [value]. If the element is boxed or stored in a | 462 * Sets the [element] to [value]. If the element is boxed or stored in a |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 } | 786 } |
| 787 | 787 |
| 788 class SsaBuilder extends ResolvedVisitor implements Visitor { | 788 class SsaBuilder extends ResolvedVisitor implements Visitor { |
| 789 final SsaBuilderTask builder; | 789 final SsaBuilderTask builder; |
| 790 final Interceptors interceptors; | 790 final Interceptors interceptors; |
| 791 final WorkItem work; | 791 final WorkItem work; |
| 792 bool methodInterceptionEnabled; | 792 bool methodInterceptionEnabled; |
| 793 HGraph graph; | 793 HGraph graph; |
| 794 LocalsHandler localsHandler; | 794 LocalsHandler localsHandler; |
| 795 HInstruction rethrowableException; | 795 HInstruction rethrowableException; |
| 796 Map<Element, HParameterValue> parameters; |
| 796 | 797 |
| 797 Map<TargetElement, JumpHandler> jumpTargets; | 798 Map<TargetElement, JumpHandler> jumpTargets; |
| 798 | 799 |
| 799 /** | 800 /** |
| 800 * Variables stored in the current activation. These variables are | 801 * Variables stored in the current activation. These variables are |
| 801 * being updated in try/catch blocks, and should be | 802 * being updated in try/catch blocks, and should be |
| 802 * accessed indirectly through HFieldGet and HFieldSet. | 803 * accessed indirectly through HFieldGet and HFieldSet. |
| 803 */ | 804 */ |
| 804 Map<Element, HParameterValue> activationVariables; | 805 Map<Element, HParameterValue> activationVariables; |
| 805 | 806 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 820 | 821 |
| 821 SsaBuilder(SsaBuilderTask builder, WorkItem work) | 822 SsaBuilder(SsaBuilderTask builder, WorkItem work) |
| 822 : this.builder = builder, | 823 : this.builder = builder, |
| 823 this.work = work, | 824 this.work = work, |
| 824 interceptors = builder.interceptors, | 825 interceptors = builder.interceptors, |
| 825 methodInterceptionEnabled = true, | 826 methodInterceptionEnabled = true, |
| 826 graph = new HGraph(), | 827 graph = new HGraph(), |
| 827 stack = new List<HInstruction>(), | 828 stack = new List<HInstruction>(), |
| 828 activationVariables = new Map<Element, HParameterValue>(), | 829 activationVariables = new Map<Element, HParameterValue>(), |
| 829 jumpTargets = new Map<TargetElement, JumpHandler>(), | 830 jumpTargets = new Map<TargetElement, JumpHandler>(), |
| 831 parameters = new Map<Element, HParameterValue>(), |
| 830 super(work.resolutionTree) { | 832 super(work.resolutionTree) { |
| 831 localsHandler = new LocalsHandler(this); | 833 localsHandler = new LocalsHandler(this); |
| 832 } | 834 } |
| 833 | 835 |
| 834 void disableMethodInterception() { | 836 void disableMethodInterception() { |
| 835 assert(methodInterceptionEnabled); | 837 assert(methodInterceptionEnabled); |
| 836 methodInterceptionEnabled = false; | 838 methodInterceptionEnabled = false; |
| 837 } | 839 } |
| 838 | 840 |
| 839 void enableMethodInterception() { | 841 void enableMethodInterception() { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1071 |
| 1070 void openFunction(FunctionElement functionElement, | 1072 void openFunction(FunctionElement functionElement, |
| 1071 FunctionExpression node) { | 1073 FunctionExpression node) { |
| 1072 HBasicBlock block = graph.addNewBlock(); | 1074 HBasicBlock block = graph.addNewBlock(); |
| 1073 open(graph.entry); | 1075 open(graph.entry); |
| 1074 | 1076 |
| 1075 localsHandler.startFunction(functionElement, node); | 1077 localsHandler.startFunction(functionElement, node); |
| 1076 close(new HGoto()).addSuccessor(block); | 1078 close(new HGoto()).addSuccessor(block); |
| 1077 | 1079 |
| 1078 open(block); | 1080 open(block); |
| 1081 |
| 1082 // Put the type checks in the first successor of the entry, |
| 1083 // because that is where the type guards will also be inserted. |
| 1084 // This way we ensure that a type guard will dominate the type |
| 1085 // check. |
| 1086 FunctionSignature params = functionElement.computeSignature(compiler); |
| 1087 params.forEachParameter((Element element) { |
| 1088 HInstruction newParameter = potentiallyCheckType( |
| 1089 localsHandler.directLocals[element], element); |
| 1090 localsHandler.directLocals[element] = newParameter; |
| 1091 }); |
| 1079 } | 1092 } |
| 1080 | 1093 |
| 1081 HInstruction potentiallyCheckType(HInstruction original, | 1094 HInstruction potentiallyCheckType(HInstruction original, |
| 1082 Element sourceElement) { | 1095 Element sourceElement) { |
| 1083 if (!compiler.enableTypeAssertions) return original; | 1096 if (!compiler.enableTypeAssertions) return original; |
| 1084 | 1097 |
| 1085 Type type = sourceElement.computeType(compiler); | 1098 Type type = sourceElement.computeType(compiler); |
| 1086 if (type === null) return original; | 1099 if (type === null) return original; |
| 1087 if (type.element === compiler.dynamicClass) return original; | 1100 if (type.element === compiler.dynamicClass) return original; |
| 1088 if (type.element === compiler.objectClass) return original; | 1101 if (type.element === compiler.objectClass) return original; |
| (...skipping 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3450 void visitNodeList(NodeList node) { | 3463 void visitNodeList(NodeList node) { |
| 3451 node.visitChildren(this); | 3464 node.visitChildren(this); |
| 3452 } | 3465 } |
| 3453 | 3466 |
| 3454 HInstruction concat(HInstruction left, HInstruction right) { | 3467 HInstruction concat(HInstruction left, HInstruction right) { |
| 3455 HInstruction instruction = new HStringConcat(left, right, node); | 3468 HInstruction instruction = new HStringConcat(left, right, node); |
| 3456 builder.add(instruction); | 3469 builder.add(instruction); |
| 3457 return instruction; | 3470 return instruction; |
| 3458 } | 3471 } |
| 3459 } | 3472 } |
| OLD | NEW |