| Index: sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart
|
| index 134a8bd4cc21f252a52702a669d409357570be9f..7920ec74211c5c743fb22954ce178c5ed70309ea 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart
|
| @@ -10,12 +10,17 @@ import 'dart_tree.dart';
|
|
|
| class Block {
|
| int index;
|
| - final List<Statement> statements = <Statement>[];
|
| + final Label label;
|
| + /// Mixed list of [Statement] and [Block].
|
| + /// A [Block] represents a synthetic goto statement.
|
| + final List statements = [];
|
| final List<Block> predecessors = <Block>[];
|
| final List<Block> successors = <Block>[];
|
|
|
| String get name => 'B$index';
|
|
|
| + Block([this.label]);
|
| +
|
| void addEdgeTo(Block successor) {
|
| successors.add(successor);
|
| successor.predecessors.add(this);
|
| @@ -36,6 +41,9 @@ class BlockCollector extends Visitor {
|
| void _addStatement(Statement statement) {
|
| blocks.last.statements.add(statement);
|
| }
|
| + void _addGotoStatement(Block target) {
|
| + blocks.last.statements.add(target);
|
| + }
|
|
|
| void _addBlock(Block block) {
|
| block.index = blocks.length;
|
| @@ -60,7 +68,7 @@ class BlockCollector extends Visitor {
|
| visitNot(Not node) {}
|
|
|
| visitLabeledStatement(LabeledStatement node) {
|
| - Block target = new Block();
|
| + Block target = new Block(node.label);
|
| breakTargets[node.label] = target;
|
| visitStatement(node.body);
|
| _addBlock(target);
|
| @@ -100,8 +108,10 @@ class BlockCollector extends Visitor {
|
| visitStatement(node.elseStatement);
|
| }
|
|
|
| - visitWhile(While node) {
|
| + visitWhileTrue(WhileTrue node) {
|
| Block continueTarget = new Block();
|
| + _addGotoStatement(continueTarget);
|
| +
|
| continueTargets[node.label] = continueTarget;
|
| blocks.last.addEdgeTo(continueTarget);
|
| _addBlock(continueTarget);
|
| @@ -109,13 +119,38 @@ class BlockCollector extends Visitor {
|
| visitStatement(node.body);
|
| }
|
|
|
| + visitWhileCondition(WhileCondition node) {
|
| + Block whileBlock = new Block();
|
| + _addGotoStatement(whileBlock);
|
| +
|
| + _addBlock(whileBlock);
|
| + _addStatement(node);
|
| + whileBlock.statements.add(node);
|
| + blocks.last.addEdgeTo(whileBlock);
|
| +
|
| + Block bodyBlock = new Block();
|
| + Block nextBlock = new Block();
|
| + whileBlock.addEdgeTo(bodyBlock);
|
| + whileBlock.addEdgeTo(nextBlock);
|
| +
|
| + continueTargets[node.label] = bodyBlock;
|
| + _addBlock(bodyBlock);
|
| + visitStatement(node.body);
|
| +
|
| + _addBlock(nextBlock);
|
| + visitStatement(node.next);
|
| +
|
| + ifTargets[node.body] = bodyBlock;
|
| + ifTargets[node.next] = nextBlock;
|
| + }
|
| +
|
| visitExpressionStatement(ExpressionStatement node) {
|
| _addStatement(node);
|
| visitStatement(node.next);
|
| }
|
| }
|
|
|
| -class TreeTracer extends TracerUtil with Visitor {
|
| +class TreeTracer extends TracerUtil with StatementVisitor {
|
| final EventSink<String> output;
|
|
|
| TreeTracer(this.output);
|
| @@ -153,11 +188,24 @@ class TreeTracer extends TracerUtil with Visitor {
|
| });
|
| });
|
| tag("HIR", () {
|
| - block.statements.forEach(visitStatement);
|
| + if (block.label != null) {
|
| + printStatement(null,
|
| + "Label ${block.name}, useCount=${block.label.useCount}");
|
| + }
|
| + block.statements.forEach(visitBlockMember);
|
| });
|
| });
|
| }
|
|
|
| + void visitBlockMember(member) {
|
| + if (member is Block) {
|
| + printStatement(null, "goto block B${member.name}");
|
| + } else {
|
| + assert(member is Statement);
|
| + visitStatement(member);
|
| + }
|
| + }
|
| +
|
| void printStatement(String name, String contents) {
|
| int bci = 0;
|
| int uses = 0;
|
| @@ -168,18 +216,6 @@ class TreeTracer extends TracerUtil with Visitor {
|
| add("$bci $uses $name $contents <|@\n");
|
| }
|
|
|
| - visitVariable(Variable node) {
|
| - printStatement(null, "dead-use ${names.varName(node)}");
|
| - }
|
| -
|
| - visitInvokeStatic(InvokeStatic node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitConstant(Constant node) {
|
| - printStatement(null, "dead-use ${node.value}");
|
| - }
|
| -
|
| visitLabeledStatement(LabeledStatement node) {
|
| // These do not get added to a block's list of statements.
|
| }
|
| @@ -190,42 +226,6 @@ class TreeTracer extends TracerUtil with Visitor {
|
| printStatement(name, "let $name = $rhs");
|
| }
|
|
|
| - visitInvokeMethod(InvokeMethod node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitInvokeConstructor(InvokeConstructor node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitConcatenateStrings(ConcatenateStrings node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitLiteralList(LiteralList node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitLiteralMap(LiteralMap node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitInvokeConstConstructor(InvokeConstConstructor node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitConditional(Conditional node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitLogicalOperator(LogicalOperator node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| - visitNot(Not node) {
|
| - printStatement(null, expr(node));
|
| - }
|
| -
|
| visitReturn(Return node) {
|
| printStatement(null, "return ${expr(node.value)}");
|
| }
|
| @@ -246,12 +246,20 @@ class TreeTracer extends TracerUtil with Visitor {
|
| printStatement(null, "if $condition then $thenTarget else $elseTarget");
|
| }
|
|
|
| - visitWhile(While node) {
|
| + visitWhileTrue(WhileTrue node) {
|
| printStatement(null, "while true do");
|
| }
|
|
|
| + visitWhileCondition(WhileCondition node) {
|
| + String bodyTarget = collector.ifTargets[node.body].name;
|
| + String nextTarget = collector.ifTargets[node.next].name;
|
| + printStatement(null, "while ${expr(node.condition)}");
|
| + printStatement(null, "do $bodyTarget");
|
| + printStatement(null, "then $nextTarget" );
|
| + }
|
| +
|
| visitExpressionStatement(ExpressionStatement node) {
|
| - visitExpression(node.expression);
|
| + printStatement(null, expr(node.expression));
|
| }
|
|
|
| String expr(Expression e) {
|
| @@ -259,7 +267,7 @@ class TreeTracer extends TracerUtil with Visitor {
|
| }
|
| }
|
|
|
| -class SubexpressionVisitor extends Visitor<String, String> {
|
| +class SubexpressionVisitor extends ExpressionVisitor<String> {
|
| Names names;
|
|
|
| SubexpressionVisitor(this.names);
|
| @@ -372,21 +380,6 @@ class SubexpressionVisitor extends Visitor<String, String> {
|
| return '!$operand';
|
| }
|
|
|
| - // Note: There should not be statements in the context of expressions.
|
| - String visitStatement(Statement node) {
|
| - return "$node statement in expression context";
|
| - }
|
| -
|
| - String visitLabeledStatement(LabeledStatement node) => visitStatement(node);
|
| - String visitAssign(Assign node) => visitStatement(node);
|
| - String visitReturn(Return node) => visitStatement(node);
|
| - String visitBreak(Break node) => visitStatement(node);
|
| - String visitContinue(Continue node) => visitStatement(node);
|
| - String visitIf(If node) => visitStatement(node);
|
| - String visitWhile(While node) => visitStatement(node);
|
| - String visitExpressionStatement(ExpressionStatement node) {
|
| - return visitStatement(node);
|
| - }
|
| }
|
|
|
| /**
|
|
|