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 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
8 : this.backend = backend, | 8 : this.backend = backend, |
9 super(backend.compiler); | 9 super(backend.compiler); |
10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 indent++; | 626 indent++; |
627 generateStatements(elseGraph); | 627 generateStatements(elseGraph); |
628 indent--; | 628 indent--; |
629 addIndented("}"); | 629 addIndented("}"); |
630 } | 630 } |
631 buffer.add("\n"); | 631 buffer.add("\n"); |
632 } | 632 } |
633 return true; | 633 return true; |
634 } | 634 } |
635 | 635 |
636 bool visitSwitchInfo(HSwitchBlockInformation info) { | |
637 bool isExpression = isJSExpression(info.expression); | |
638 if (!isExpression) { | |
639 generateStatements(info.expression); | |
640 } | |
641 addIndentation(); | |
642 for (LabelElement label in info.labels) { | |
643 if (label.isTarget) { | |
644 writeLabel(label); | |
645 buffer.add(":"); | |
646 } | |
647 } | |
648 addIndented("switch ("); | |
649 if (isExpression) { | |
650 generateExpression(info.expression); | |
651 } else { | |
652 use(info.expression.conditionExpression, JSPrecedence.EXPRESSION_PRECEDENC E); | |
floitsch
2012/06/06 11:50:26
80chars.
Lasse Reichstein Nielsen
2012/06/06 13:01:21
Done.
| |
653 } | |
654 buffer.add(") {\n"); | |
655 indent++; | |
656 for (int i = 0; i < info.matchExpressions.length; i++) { | |
657 for (Constant constant in info.matchExpressions[i]) { | |
658 addIndented("case "); | |
659 generateConstant(constant); | |
660 buffer.add(":\n"); | |
661 } | |
662 if (i == info.matchExpressions.length - 1 && info.hasDefault) { | |
663 addIndented("default:\n"); | |
664 } | |
665 indent++; | |
666 generateStatements(info.statements[i]); | |
667 indent--; | |
668 } | |
669 indent--; | |
670 addIndented("}\n"); | |
671 return true; | |
672 } | |
673 | |
636 bool visitSequenceInfo(HStatementSequenceInformation info) { | 674 bool visitSequenceInfo(HStatementSequenceInformation info) { |
637 return false; | 675 return false; |
638 } | 676 } |
639 | 677 |
640 bool visitSubGraphInfo(HSubGraphBlockInformation info) { | 678 bool visitSubGraphInfo(HSubGraphBlockInformation info) { |
641 visitSubGraph(info.subGraph); | 679 visitSubGraph(info.subGraph); |
642 return true; | 680 return true; |
643 } | 681 } |
644 | 682 |
645 bool visitSubExpressionInfo(HSubExpressionBlockInformation info) { | 683 bool visitSubExpressionInfo(HSubExpressionBlockInformation info) { |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1560 // We can't use 'visitArguments', since our arguments start at input[0]. | 1598 // We can't use 'visitArguments', since our arguments start at input[0]. |
1561 List<HInstruction> inputs = node.inputs; | 1599 List<HInstruction> inputs = node.inputs; |
1562 for (int i = 0; i < inputs.length; i++) { | 1600 for (int i = 0; i < inputs.length; i++) { |
1563 if (i != 0) buffer.add(', '); | 1601 if (i != 0) buffer.add(', '); |
1564 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); | 1602 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); |
1565 } | 1603 } |
1566 buffer.add(')'); | 1604 buffer.add(')'); |
1567 endExpression(JSPrecedence.MEMBER_PRECEDENCE); | 1605 endExpression(JSPrecedence.MEMBER_PRECEDENCE); |
1568 } | 1606 } |
1569 | 1607 |
1570 visitConstant(HConstant node) { | 1608 void generateConstant(Constant constant) { |
1571 assert(isGenerateAtUseSite(node)); | |
1572 // TODO(floitsch): the compile-time constant handler and the codegen | 1609 // TODO(floitsch): the compile-time constant handler and the codegen |
1573 // need to work together to avoid the parenthesis. See r4928 for an | 1610 // need to work together to avoid the parenthesis. See r4928 for an |
1574 // implementation that still dealt with precedence. | 1611 // implementation that still dealt with precedence. |
1575 ConstantHandler handler = compiler.constantHandler; | 1612 ConstantHandler handler = compiler.constantHandler; |
1576 String name = handler.getNameForConstant(node.constant); | 1613 String name = handler.getNameForConstant(constant); |
1577 if (name === null) { | 1614 if (name === null) { |
1578 assert(!node.constant.isObject()); | 1615 assert(!constant.isObject()); |
1579 if (node.constant.isNum() | 1616 if (constant.isNum() |
1580 && expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) { | 1617 && expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) { |
1581 buffer.add('('); | 1618 buffer.add('('); |
1582 handler.writeConstant(buffer, node.constant); | 1619 handler.writeConstant(buffer, constant); |
1583 buffer.add(')'); | 1620 buffer.add(')'); |
1584 } else { | 1621 } else { |
1585 handler.writeConstant(buffer, node.constant); | 1622 handler.writeConstant(buffer, constant); |
1586 } | 1623 } |
1587 } else { | 1624 } else { |
1588 buffer.add(compiler.namer.CURRENT_ISOLATE); | 1625 buffer.add(compiler.namer.CURRENT_ISOLATE); |
1589 buffer.add("."); | 1626 buffer.add("."); |
1590 buffer.add(name); | 1627 buffer.add(name); |
1591 } | 1628 } |
1629 | |
1630 } | |
1631 | |
1632 visitConstant(HConstant node) { | |
1633 assert(isGenerateAtUseSite(node)); | |
1634 generateConstant(node.constant); | |
1592 } | 1635 } |
1593 | 1636 |
1594 visitLoopBranch(HLoopBranch node) { | 1637 visitLoopBranch(HLoopBranch node) { |
1595 if (subGraph !== null && node.block === subGraph.end) { | 1638 if (subGraph !== null && node.block === subGraph.end) { |
1596 // We are generating code for a loop condition. | 1639 // We are generating code for a loop condition. |
1597 // If doing this as part of a SubGraph traversal, the | 1640 // If doing this as part of a SubGraph traversal, the |
1598 // calling code will handle the control flow logic. | 1641 // calling code will handle the control flow logic. |
1599 | 1642 |
1600 // If we are generating the subgraph as an expression, the | 1643 // If we are generating the subgraph as an expression, the |
1601 // condition will be generated as the expression. | 1644 // condition will be generated as the expression. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1789 for (int i = 0; i < indent; i++) { | 1832 for (int i = 0; i < indent; i++) { |
1790 buffer.add(' '); | 1833 buffer.add(' '); |
1791 } | 1834 } |
1792 } | 1835 } |
1793 | 1836 |
1794 void addIndented(String text) { | 1837 void addIndented(String text) { |
1795 addIndentation(); | 1838 addIndentation(); |
1796 buffer.add(text); | 1839 buffer.add(text); |
1797 } | 1840 } |
1798 | 1841 |
1842 void visitSwitch(HSwitch node) { | |
1843 // Switches are handled using [visitSwitchInfo]. | |
1844 } | |
1845 | |
1799 void visitStatic(HStatic node) { | 1846 void visitStatic(HStatic node) { |
1800 world.registerStaticUse(node.element); | 1847 world.registerStaticUse(node.element); |
1801 buffer.add(compiler.namer.isolateAccess(node.element)); | 1848 buffer.add(compiler.namer.isolateAccess(node.element)); |
1802 } | 1849 } |
1803 | 1850 |
1804 void visitStaticStore(HStaticStore node) { | 1851 void visitStaticStore(HStaticStore node) { |
1805 world.registerStaticUse(node.element); | 1852 world.registerStaticUse(node.element); |
1806 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); | 1853 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); |
1807 buffer.add(compiler.namer.isolateAccess(node.element)); | 1854 buffer.add(compiler.namer.isolateAccess(node.element)); |
1808 buffer.add(' = '); | 1855 buffer.add(' = '); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2573 startBailoutSwitch(); | 2620 startBailoutSwitch(); |
2574 } | 2621 } |
2575 } | 2622 } |
2576 | 2623 |
2577 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2624 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
2578 if (labeledBlockInfo.body.start.hasGuards()) { | 2625 if (labeledBlockInfo.body.start.hasGuards()) { |
2579 endBailoutSwitch(); | 2626 endBailoutSwitch(); |
2580 } | 2627 } |
2581 } | 2628 } |
2582 } | 2629 } |
OLD | NEW |