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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
8 final SsaCodeGeneratorTask generator; | 8 final SsaCodeGeneratorTask generator; |
9 final SsaBuilderTask builder; | 9 final SsaBuilderTask builder; |
10 final SsaOptimizerTask optimizer; | 10 final SsaOptimizerTask optimizer; |
(...skipping 2571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2582 void visit(ast.Node node) { | 2582 void visit(ast.Node node) { |
2583 if (node != null) node.accept(this); | 2583 if (node != null) node.accept(this); |
2584 } | 2584 } |
2585 | 2585 |
2586 /// Visit [node] and pop the resulting [HInstruction]. | 2586 /// Visit [node] and pop the resulting [HInstruction]. |
2587 HInstruction visitAndPop(ast.Node node) { | 2587 HInstruction visitAndPop(ast.Node node) { |
2588 node.accept(this); | 2588 node.accept(this); |
2589 return pop(); | 2589 return pop(); |
2590 } | 2590 } |
2591 | 2591 |
2592 visitAssert(ast.Assert node) { | |
2593 if (!compiler.enableUserAssertions) return; | |
2594 | |
2595 void buildCondition() { | |
2596 visit(node.condition); | |
2597 var arguments = [pop()]; | |
2598 pushInvokeStatic(node, backend.assertConditionHelperMethod, arguments); | |
2599 } | |
2600 void fail() { | |
2601 var arguments = new List(); | |
2602 if (node.message != null) { | |
2603 visit(node.message); | |
2604 arguments.add(pop()); | |
2605 } else { | |
2606 arguments.add(graph.addConstantNull(compiler)); | |
2607 } | |
2608 pushInvokeStatic(node, backend.assertThrowMethod, arguments); | |
2609 pop(); | |
2610 } | |
2611 handleIf(node, | |
Siggi Cherem (dart-lang)
2015/09/03 16:13:24
What does the final output endup looking like?
In
Lasse Reichstein Nielsen
2015/09/09 12:02:46
Ack, it's the latter, only uglier: if (....helper(
| |
2612 visitCondition: buildCondition, | |
2613 visitThen: () {}, | |
2614 visitElse: fail); | |
2615 } | |
2616 | |
2592 visitBlock(ast.Block node) { | 2617 visitBlock(ast.Block node) { |
2593 assert(!isAborted()); | 2618 assert(!isAborted()); |
2594 if (!isReachable) return; // This can only happen when inlining. | 2619 if (!isReachable) return; // This can only happen when inlining. |
2595 for (Link<ast.Node> link = node.statements.nodes; | 2620 for (Link<ast.Node> link = node.statements.nodes; |
2596 !link.isEmpty; | 2621 !link.isEmpty; |
2597 link = link.tail) { | 2622 link = link.tail) { |
2598 visit(link.head); | 2623 visit(link.head); |
2599 if (!isReachable) { | 2624 if (!isReachable) { |
2600 // The block has been aborted by a return or a throw. | 2625 // The block has been aborted by a return or a throw. |
2601 if (!stack.isEmpty) { | 2626 if (!stack.isEmpty) { |
(...skipping 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5155 DartType instance = type.asInstanceOf(supertype.element); | 5180 DartType instance = type.asInstanceOf(supertype.element); |
5156 compiler.types.checkTypeVariableBounds(instance, | 5181 compiler.types.checkTypeVariableBounds(instance, |
5157 addTypeVariableBoundCheck); | 5182 addTypeVariableBoundCheck); |
5158 if (definitelyFails) { | 5183 if (definitelyFails) { |
5159 return true; | 5184 return true; |
5160 } | 5185 } |
5161 } | 5186 } |
5162 return false; | 5187 return false; |
5163 } | 5188 } |
5164 | 5189 |
5165 @override | |
5166 visitAssert(ast.Send node, ast.Node expression, _) { | |
5167 if (!compiler.enableUserAssertions) { | |
5168 stack.add(graph.addConstantNull(compiler)); | |
5169 return; | |
5170 } | |
5171 assert(invariant(node, node.arguments.tail.isEmpty, | |
5172 message: "Invalid assertion: $node")); | |
5173 generateStaticFunctionInvoke( | |
5174 node, backend.assertMethod, CallStructure.ONE_ARG); | |
5175 } | |
5176 | |
5177 visitStaticSend(ast.Send node) { | 5190 visitStaticSend(ast.Send node) { |
5178 internalError(node, "Unexpected visitStaticSend"); | 5191 internalError(node, "Unexpected visitStaticSend"); |
5179 } | 5192 } |
5180 | 5193 |
5181 /// Generate an invocation to the static or top level [function]. | 5194 /// Generate an invocation to the static or top level [function]. |
5182 void generateStaticFunctionInvoke( | 5195 void generateStaticFunctionInvoke( |
5183 ast.Send node, | 5196 ast.Send node, |
5184 FunctionElement function, | 5197 FunctionElement function, |
5185 CallStructure callStructure) { | 5198 CallStructure callStructure) { |
5186 List<HInstruction> inputs = makeStaticArgumentList( | 5199 List<HInstruction> inputs = makeStaticArgumentList( |
(...skipping 3037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8224 void visitConstantInvoke( | 8237 void visitConstantInvoke( |
8225 ast.Send node, | 8238 ast.Send node, |
8226 ConstantExpression constant, | 8239 ConstantExpression constant, |
8227 ast.NodeList arguments, | 8240 ast.NodeList arguments, |
8228 CallStructure callStreucture, | 8241 CallStructure callStreucture, |
8229 _) { | 8242 _) { |
8230 visitNode(node); | 8243 visitNode(node); |
8231 } | 8244 } |
8232 | 8245 |
8233 @override | 8246 @override |
8234 void errorInvalidAssert( | |
8235 ast.Send node, | |
8236 ast.NodeList arguments, | |
8237 _) { | |
8238 visitNode(node); | |
8239 } | |
8240 | |
8241 @override | |
8242 void errorUndefinedBinaryExpression( | 8247 void errorUndefinedBinaryExpression( |
8243 ast.Send node, | 8248 ast.Send node, |
8244 ast.Node left, | 8249 ast.Node left, |
8245 ast.Operator operator, | 8250 ast.Operator operator, |
8246 ast.Node right, | 8251 ast.Node right, |
8247 _) { | 8252 _) { |
8248 visitNode(node); | 8253 visitNode(node); |
8249 } | 8254 } |
8250 | 8255 |
8251 @override | 8256 @override |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8863 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8868 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
8864 unaliased.accept(this, builder); | 8869 unaliased.accept(this, builder); |
8865 } | 8870 } |
8866 | 8871 |
8867 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8872 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
8868 JavaScriptBackend backend = builder.compiler.backend; | 8873 JavaScriptBackend backend = builder.compiler.backend; |
8869 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8874 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
8870 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8875 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
8871 } | 8876 } |
8872 } | 8877 } |
OLD | NEW |