OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library tree_ir_tracer; | 5 library tree_ir_tracer; |
6 | 6 |
7 import 'dart:async' show EventSink; | 7 import 'dart:async' show EventSink; |
8 import '../tracer.dart'; | 8 import '../tracer.dart'; |
9 import 'tree_ir_nodes.dart'; | 9 import 'tree_ir_nodes.dart'; |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 void _addGotoStatement(Block target) { | 44 void _addGotoStatement(Block target) { |
45 blocks.last.statements.add(target); | 45 blocks.last.statements.add(target); |
46 } | 46 } |
47 | 47 |
48 void _addBlock(Block block) { | 48 void _addBlock(Block block) { |
49 block.index = blocks.length; | 49 block.index = blocks.length; |
50 blocks.add(block); | 50 blocks.add(block); |
51 } | 51 } |
52 | 52 |
53 void collect(FunctionDefinition function) { | 53 void collect(ExecutableDefinition node) { |
54 visitStatement(function.body); | 54 visitStatement(node.body); |
55 } | 55 } |
56 | 56 |
57 visitLabeledStatement(LabeledStatement node) { | 57 visitLabeledStatement(LabeledStatement node) { |
58 Block target = new Block(node.label); | 58 Block target = new Block(node.label); |
59 breakTargets[node.label] = target; | 59 breakTargets[node.label] = target; |
60 visitStatement(node.body); | 60 visitStatement(node.body); |
61 _addBlock(target); | 61 _addBlock(target); |
62 visitStatement(node.next); | 62 visitStatement(node.next); |
63 } | 63 } |
64 | 64 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 class TreeTracer extends TracerUtil with StatementVisitor { | 145 class TreeTracer extends TracerUtil with StatementVisitor { |
146 final EventSink<String> output; | 146 final EventSink<String> output; |
147 | 147 |
148 TreeTracer(this.output); | 148 TreeTracer(this.output); |
149 | 149 |
150 Names names; | 150 Names names; |
151 BlockCollector collector; | 151 BlockCollector collector; |
152 int statementCounter; | 152 int statementCounter; |
153 | 153 |
154 void traceGraph(String name, FunctionDefinition function) { | 154 void traceGraph(String name, ExecutableDefinition node) { |
155 names = new Names(); | 155 names = new Names(); |
156 statementCounter = 0; | 156 statementCounter = 0; |
157 collector = new BlockCollector(); | 157 collector = new BlockCollector(); |
158 collector.collect(function); | 158 collector.collect(node); |
159 tag("cfg", () { | 159 tag("cfg", () { |
160 printProperty("name", name); | 160 printProperty("name", name); |
161 int blockCounter = 0; | 161 int blockCounter = 0; |
162 collector.blocks.forEach(printBlock); | 162 collector.blocks.forEach(printBlock); |
163 }); | 163 }); |
164 names = null; | 164 names = null; |
165 } | 165 } |
166 | 166 |
167 void printBlock(Block block) { | 167 void printBlock(Block block) { |
168 tag("block", () { | 168 tag("block", () { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 String prefix = v.element == null ? 'v' : '${v.element.name}_'; | 411 String prefix = v.element == null ? 'v' : '${v.element.name}_'; |
412 while (name == null || _usedNames.contains(name)) { | 412 while (name == null || _usedNames.contains(name)) { |
413 name = "$prefix${_counter++}"; | 413 name = "$prefix${_counter++}"; |
414 } | 414 } |
415 _names[v] = name; | 415 _names[v] = name; |
416 _usedNames.add(name); | 416 _usedNames.add(name); |
417 } | 417 } |
418 return name; | 418 return name; |
419 } | 419 } |
420 } | 420 } |
OLD | NEW |