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 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 void visit(ast.Node node) { | 2601 void visit(ast.Node node) { |
2602 if (node != null) node.accept(this); | 2602 if (node != null) node.accept(this); |
2603 } | 2603 } |
2604 | 2604 |
2605 /// Visit [node] and pop the resulting [HInstruction]. | 2605 /// Visit [node] and pop the resulting [HInstruction]. |
2606 HInstruction visitAndPop(ast.Node node) { | 2606 HInstruction visitAndPop(ast.Node node) { |
2607 node.accept(this); | 2607 node.accept(this); |
2608 return pop(); | 2608 return pop(); |
2609 } | 2609 } |
2610 | 2610 |
| 2611 visitAssert(ast.Assert node) { |
| 2612 if (!compiler.enableUserAssertions) return; |
| 2613 |
| 2614 if (!node.hasMessage) { |
| 2615 // Generate: |
| 2616 // |
| 2617 // assertHelper(condition); |
| 2618 // |
| 2619 visit(node.condition); |
| 2620 pushInvokeStatic(node, backend.assertHelperMethod, [pop()]); |
| 2621 pop(); |
| 2622 return; |
| 2623 } |
| 2624 // Assert has message. Generate: |
| 2625 // |
| 2626 // if (assertTest(condition)) assertThrow(message); |
| 2627 // |
| 2628 void buildCondition() { |
| 2629 visit(node.condition); |
| 2630 pushInvokeStatic(node, backend.assertTestMethod, [pop()]); |
| 2631 } |
| 2632 void fail() { |
| 2633 visit(node.message); |
| 2634 pushInvokeStatic(node, backend.assertThrowMethod, [pop()]); |
| 2635 pop(); |
| 2636 } |
| 2637 handleIf(node, |
| 2638 visitCondition: buildCondition, |
| 2639 visitThen: fail); |
| 2640 } |
| 2641 |
2611 visitBlock(ast.Block node) { | 2642 visitBlock(ast.Block node) { |
2612 assert(!isAborted()); | 2643 assert(!isAborted()); |
2613 if (!isReachable) return; // This can only happen when inlining. | 2644 if (!isReachable) return; // This can only happen when inlining. |
2614 for (Link<ast.Node> link = node.statements.nodes; | 2645 for (Link<ast.Node> link = node.statements.nodes; |
2615 !link.isEmpty; | 2646 !link.isEmpty; |
2616 link = link.tail) { | 2647 link = link.tail) { |
2617 visit(link.head); | 2648 visit(link.head); |
2618 if (!isReachable) { | 2649 if (!isReachable) { |
2619 // The block has been aborted by a return or a throw. | 2650 // The block has been aborted by a return or a throw. |
2620 if (!stack.isEmpty) { | 2651 if (!stack.isEmpty) { |
(...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5176 DartType instance = type.asInstanceOf(supertype.element); | 5207 DartType instance = type.asInstanceOf(supertype.element); |
5177 compiler.types.checkTypeVariableBounds(instance, | 5208 compiler.types.checkTypeVariableBounds(instance, |
5178 addTypeVariableBoundCheck); | 5209 addTypeVariableBoundCheck); |
5179 if (definitelyFails) { | 5210 if (definitelyFails) { |
5180 return true; | 5211 return true; |
5181 } | 5212 } |
5182 } | 5213 } |
5183 return false; | 5214 return false; |
5184 } | 5215 } |
5185 | 5216 |
5186 @override | |
5187 visitAssert(ast.Send node, ast.Node expression, _) { | |
5188 if (!compiler.enableUserAssertions) { | |
5189 stack.add(graph.addConstantNull(compiler)); | |
5190 return; | |
5191 } | |
5192 assert(invariant(node, node.arguments.tail.isEmpty, | |
5193 message: "Invalid assertion: $node")); | |
5194 generateStaticFunctionInvoke( | |
5195 node, backend.assertMethod, CallStructure.ONE_ARG); | |
5196 } | |
5197 | |
5198 visitStaticSend(ast.Send node) { | 5217 visitStaticSend(ast.Send node) { |
5199 internalError(node, "Unexpected visitStaticSend"); | 5218 internalError(node, "Unexpected visitStaticSend"); |
5200 } | 5219 } |
5201 | 5220 |
5202 /// Generate an invocation to the static or top level [function]. | 5221 /// Generate an invocation to the static or top level [function]. |
5203 void generateStaticFunctionInvoke( | 5222 void generateStaticFunctionInvoke( |
5204 ast.Send node, | 5223 ast.Send node, |
5205 FunctionElement function, | 5224 FunctionElement function, |
5206 CallStructure callStructure) { | 5225 CallStructure callStructure) { |
5207 List<HInstruction> inputs = makeStaticArgumentList( | 5226 List<HInstruction> inputs = makeStaticArgumentList( |
(...skipping 3096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8304 void visitConstantInvoke( | 8323 void visitConstantInvoke( |
8305 ast.Send node, | 8324 ast.Send node, |
8306 ConstantExpression constant, | 8325 ConstantExpression constant, |
8307 ast.NodeList arguments, | 8326 ast.NodeList arguments, |
8308 CallStructure callStreucture, | 8327 CallStructure callStreucture, |
8309 _) { | 8328 _) { |
8310 visitNode(node); | 8329 visitNode(node); |
8311 } | 8330 } |
8312 | 8331 |
8313 @override | 8332 @override |
8314 void errorInvalidAssert( | |
8315 ast.Send node, | |
8316 ast.NodeList arguments, | |
8317 _) { | |
8318 visitNode(node); | |
8319 } | |
8320 | |
8321 @override | |
8322 void errorUndefinedBinaryExpression( | 8333 void errorUndefinedBinaryExpression( |
8323 ast.Send node, | 8334 ast.Send node, |
8324 ast.Node left, | 8335 ast.Node left, |
8325 ast.Operator operator, | 8336 ast.Operator operator, |
8326 ast.Node right, | 8337 ast.Node right, |
8327 _) { | 8338 _) { |
8328 visitNode(node); | 8339 visitNode(node); |
8329 } | 8340 } |
8330 | 8341 |
8331 @override | 8342 @override |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8940 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8951 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
8941 unaliased.accept(this, builder); | 8952 unaliased.accept(this, builder); |
8942 } | 8953 } |
8943 | 8954 |
8944 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8955 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
8945 JavaScriptBackend backend = builder.compiler.backend; | 8956 JavaScriptBackend backend = builder.compiler.backend; |
8946 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8957 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
8947 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8958 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
8948 } | 8959 } |
8949 } | 8960 } |
OLD | NEW |