| 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 SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); | 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA code generator'; | 7 String get name() => 'SSA code generator'; |
| 8 | 8 |
| 9 String generate(WorkItem work, HGraph graph) { | 9 String generate(WorkItem work, HGraph graph) { |
| 10 return measure(() { | 10 return measure(() { |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // We can't use 'visitArguments', since our arguments start at input[0]. | 653 // We can't use 'visitArguments', since our arguments start at input[0]. |
| 654 List<HInstruction> inputs = node.inputs; | 654 List<HInstruction> inputs = node.inputs; |
| 655 for (int i = 0; i < inputs.length; i++) { | 655 for (int i = 0; i < inputs.length; i++) { |
| 656 if (i != 0) buffer.add(', '); | 656 if (i != 0) buffer.add(', '); |
| 657 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); | 657 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); |
| 658 } | 658 } |
| 659 buffer.add(')'); | 659 buffer.add(')'); |
| 660 endExpression(JSPrecedence.MEMBER_PRECEDENCE); | 660 endExpression(JSPrecedence.MEMBER_PRECEDENCE); |
| 661 } | 661 } |
| 662 | 662 |
| 663 visitLiteral(HLiteral node) { | 663 visitConstant(HConstant node) { |
| 664 if (node.isLiteralNull()) { | 664 // TODO(floitsch): the compile-time constant handler and the codegen |
| 665 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); | 665 // need to work together to avoid the parenthesis. See r4928 for an |
| 666 buffer.add("void 0"); | 666 // implementation that still dealt with precedence. |
| 667 endExpression(JSPrecedence.PREFIX_PRECEDENCE); | 667 ConstantHandler handler = compiler.constantHandler; |
| 668 } else if (node.value is num) { | 668 String name = handler.getNameForConstant(node.constant); |
| 669 int precedence = JSPrecedence.PRIMARY_PRECEDENCE; | 669 if (name === null) { |
| 670 if (node.value < 0 || | 670 assert(!node.constant.isObject()); |
| 671 expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) { | 671 node.constant.writeJsCode(buffer, handler); |
| 672 // Negative constants are really unary minus operator expressions. | |
| 673 // If the constant appear as a MemberExpression, it might be subject | |
| 674 // to the '.' operator, which shouldn't be put next to a number | |
| 675 // literal. It might be mistaken for a decimal point. Setting | |
| 676 // precedence to PREFIX_PRECEDENCE forces parentheses in this case. | |
| 677 precedence = JSPrecedence.PREFIX_PRECEDENCE; | |
| 678 } | |
| 679 beginExpression(precedence); | |
| 680 buffer.add(node.value); | |
| 681 endExpression(precedence); | |
| 682 } else if (node.isLiteralString()) { | |
| 683 DartString string = node.value; | |
| 684 buffer.add("'"); | |
| 685 CompileTimeConstantHandler.writeEscapedString(string, buffer, | |
| 686 (String reason) { | |
| 687 compiler.cancel(reason, instruction: node); | |
| 688 }); | |
| 689 buffer.add("'"); | |
| 690 } else { | 672 } else { |
| 691 buffer.add(node.value); | 673 buffer.add(compiler.namer.CURRENT_ISOLATE); |
| 674 buffer.add("."); |
| 675 buffer.add(name); |
| 692 } | 676 } |
| 693 } | 677 } |
| 694 | 678 |
| 695 visitLoopBranch(HLoopBranch node) { | 679 visitLoopBranch(HLoopBranch node) { |
| 696 HBasicBlock branchBlock = currentBlock; | 680 HBasicBlock branchBlock = currentBlock; |
| 697 handleLoopCondition(node); | 681 handleLoopCondition(node); |
| 698 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; | 682 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; |
| 699 // For a do while loop, the body has already been visited. | 683 // For a do while loop, the body has already been visited. |
| 700 if (!node.isDoWhile()) { | 684 if (!node.isDoWhile()) { |
| 701 visitBasicBlock(dominated[0]); | 685 visitBasicBlock(dominated[0]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 722 buffer.add(parameterNames[node.element]); | 706 buffer.add(parameterNames[node.element]); |
| 723 } | 707 } |
| 724 | 708 |
| 725 visitPhi(HPhi node) { | 709 visitPhi(HPhi node) { |
| 726 unreachable(); | 710 unreachable(); |
| 727 } | 711 } |
| 728 | 712 |
| 729 visitReturn(HReturn node) { | 713 visitReturn(HReturn node) { |
| 730 assert(node.inputs.length == 1); | 714 assert(node.inputs.length == 1); |
| 731 HInstruction input = node.inputs[0]; | 715 HInstruction input = node.inputs[0]; |
| 732 if (input.isLiteralNull()) { | 716 if (input.isConstantNull()) { |
| 733 buffer.add('return;\n'); | 717 buffer.add('return;\n'); |
| 734 } else { | 718 } else { |
| 735 buffer.add('return '); | 719 buffer.add('return '); |
| 736 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); | 720 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); |
| 737 buffer.add(';\n'); | 721 buffer.add(';\n'); |
| 738 } | 722 } |
| 739 } | 723 } |
| 740 | 724 |
| 741 visitThis(HThis node) { | 725 visitThis(HThis node) { |
| 742 buffer.add('this'); | 726 buffer.add('this'); |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 startBailoutSwitch(); | 1392 startBailoutSwitch(); |
| 1409 } | 1393 } |
| 1410 } | 1394 } |
| 1411 | 1395 |
| 1412 void endElse(HIf node) { | 1396 void endElse(HIf node) { |
| 1413 if (node.elseBlock.hasBailouts()) { | 1397 if (node.elseBlock.hasBailouts()) { |
| 1414 endBailoutSwitch(); | 1398 endBailoutSwitch(); |
| 1415 } | 1399 } |
| 1416 } | 1400 } |
| 1417 } | 1401 } |
| OLD | NEW |