| 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // We can't use 'visitArguments', since our arguments start at input[0]. | 630 // We can't use 'visitArguments', since our arguments start at input[0]. |
| 631 List<HInstruction> inputs = node.inputs; | 631 List<HInstruction> inputs = node.inputs; |
| 632 for (int i = 0; i < inputs.length; i++) { | 632 for (int i = 0; i < inputs.length; i++) { |
| 633 if (i != 0) buffer.add(', '); | 633 if (i != 0) buffer.add(', '); |
| 634 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); | 634 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); |
| 635 } | 635 } |
| 636 buffer.add(')'); | 636 buffer.add(')'); |
| 637 endExpression(JSPrecedence.MEMBER_PRECEDENCE); | 637 endExpression(JSPrecedence.MEMBER_PRECEDENCE); |
| 638 } | 638 } |
| 639 | 639 |
| 640 visitLiteral(HLiteral node) { | 640 visitConstant(HConstant node) { |
| 641 if (node.isLiteralNull()) { | 641 // TODO(floitsch): the compile-time constant handler and the codegen |
| 642 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); | 642 // need to work together to avoid the parenthesis. See r4928 for an |
| 643 buffer.add("void 0"); | 643 // implementation that still dealt with precedence. |
| 644 endExpression(JSPrecedence.PREFIX_PRECEDENCE); | 644 ConstantHandler handler = compiler.constantHandler; |
| 645 } else if (node.value is num) { | 645 String name = handler.getNameForConstant(node.constant); |
| 646 int precedence = JSPrecedence.PRIMARY_PRECEDENCE; | 646 if (name === null) { |
| 647 if (node.value < 0 || | 647 assert(!node.constant.isObject()); |
| 648 expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) { | 648 node.constant.writeJsCode(buffer, handler); |
| 649 // Negative constants are really unary minus operator expressions. | |
| 650 // If the constant appear as a MemberExpression, it might be subject | |
| 651 // to the '.' operator, which shouldn't be put next to a number | |
| 652 // literal. It might be mistaken for a decimal point. Setting | |
| 653 // precedence to PREFIX_PRECEDENCE forces parentheses in this case. | |
| 654 precedence = JSPrecedence.PREFIX_PRECEDENCE; | |
| 655 } | |
| 656 beginExpression(precedence); | |
| 657 buffer.add(node.value); | |
| 658 endExpression(precedence); | |
| 659 } else if (node.isLiteralString()) { | |
| 660 DartString string = node.value; | |
| 661 buffer.add("'"); | |
| 662 CompileTimeConstantHandler.writeEscapedString(string, buffer, | |
| 663 (String reason) { | |
| 664 compiler.cancel(reason, instruction: node); | |
| 665 }); | |
| 666 buffer.add("'"); | |
| 667 } else { | 649 } else { |
| 668 buffer.add(node.value); | 650 buffer.add(compiler.namer.CURRENT_ISOLATE); |
| 651 buffer.add("."); |
| 652 buffer.add(name); |
| 669 } | 653 } |
| 670 } | 654 } |
| 671 | 655 |
| 672 visitLoopBranch(HLoopBranch node) { | 656 visitLoopBranch(HLoopBranch node) { |
| 673 HBasicBlock branchBlock = currentBlock; | 657 HBasicBlock branchBlock = currentBlock; |
| 674 handleLoopCondition(node); | 658 handleLoopCondition(node); |
| 675 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; | 659 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; |
| 676 // For a do while loop, the body has already been visited. | 660 // For a do while loop, the body has already been visited. |
| 677 if (!node.isDoWhile()) { | 661 if (!node.isDoWhile()) { |
| 678 visitBasicBlock(dominated[0]); | 662 visitBasicBlock(dominated[0]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 699 buffer.add(parameterNames[node.element]); | 683 buffer.add(parameterNames[node.element]); |
| 700 } | 684 } |
| 701 | 685 |
| 702 visitPhi(HPhi node) { | 686 visitPhi(HPhi node) { |
| 703 unreachable(); | 687 unreachable(); |
| 704 } | 688 } |
| 705 | 689 |
| 706 visitReturn(HReturn node) { | 690 visitReturn(HReturn node) { |
| 707 assert(node.inputs.length == 1); | 691 assert(node.inputs.length == 1); |
| 708 HInstruction input = node.inputs[0]; | 692 HInstruction input = node.inputs[0]; |
| 709 if (input.isLiteralNull()) { | 693 if (input.isConstantNull()) { |
| 710 buffer.add('return;\n'); | 694 buffer.add('return;\n'); |
| 711 } else { | 695 } else { |
| 712 buffer.add('return '); | 696 buffer.add('return '); |
| 713 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); | 697 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); |
| 714 buffer.add(';\n'); | 698 buffer.add(';\n'); |
| 715 } | 699 } |
| 716 } | 700 } |
| 717 | 701 |
| 718 visitThis(HThis node) { | 702 visitThis(HThis node) { |
| 719 buffer.add('this'); | 703 buffer.add('this'); |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 startBailoutSwitch(); | 1362 startBailoutSwitch(); |
| 1379 } | 1363 } |
| 1380 } | 1364 } |
| 1381 | 1365 |
| 1382 void endElse(HIf node) { | 1366 void endElse(HIf node) { |
| 1383 if (node.elseBlock.hasBailouts()) { | 1367 if (node.elseBlock.hasBailouts()) { |
| 1384 endBailoutSwitch(); | 1368 endBailoutSwitch(); |
| 1385 } | 1369 } |
| 1386 } | 1370 } |
| 1387 } | 1371 } |
| OLD | NEW |