Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: pkg/compiler/lib/src/tree_ir/tree_ir_tracer.dart

Issue 1068243002: Overhaul tree IR visitor and rename IR classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 import 'optimization/optimization.dart'; 10 import 'optimization/optimization.dart';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void _addGotoStatement(Block target) { 51 void _addGotoStatement(Block target) {
52 blocks.last.statements.add(target); 52 blocks.last.statements.add(target);
53 } 53 }
54 54
55 void _addBlock(Block block) { 55 void _addBlock(Block block) {
56 block.index = blocks.length; 56 block.index = blocks.length;
57 block.catcher = catcher; 57 block.catcher = catcher;
58 blocks.add(block); 58 blocks.add(block);
59 } 59 }
60 60
61 void collect(ExecutableDefinition node) { 61 void collect(RootNode node) {
62 if (node.body != null) { 62 node.forEachBody(visitStatement);
63 if (node is ConstructorDefinition) {
64 for (Initializer initializer in node.initializers) {
65 if (initializer is FieldInitializer) {
66 visitStatement(initializer.body);
67 }
68 }
69 }
70 visitStatement(node.body);
71 }
72 } 63 }
73 64
74 visitLabeledStatement(LabeledStatement node) { 65 visitLabeledStatement(LabeledStatement node) {
75 Block target = new Block(node.label); 66 Block target = new Block(node.label);
76 breakTargets[node.label] = target; 67 breakTargets[node.label] = target;
77 visitStatement(node.body); 68 visitStatement(node.body);
78 _addBlock(target); 69 _addBlock(target);
79 visitStatement(node.next); 70 visitStatement(node.next);
80 } 71 }
81 72
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 visitStatement(node.next); 167 visitStatement(node.next);
177 } 168 }
178 169
179 visitSetField(SetField node) { 170 visitSetField(SetField node) {
180 _addStatement(node); 171 _addStatement(node);
181 visitStatement(node.next); 172 visitStatement(node.next);
182 } 173 }
183 174
184 } 175 }
185 176
186 class TreeTracer extends TracerUtil with StatementVisitor, PassMixin { 177 class TreeTracer extends TracerUtil with StatementVisitor {
187 // TODO(asgerf): Fix visitors so we don't have to use PassMixin here. 178 // TODO(asgerf): Fix visitors so we don't have to use PassMixin here.
Kevin Millikin (Google) 2015/04/08 15:10:16 I think you can remove this TODO.
asgerf 2015/04/09 09:58:23 Done.
188 String get passName => null; 179 String get passName => null;
189 180
190 final EventSink<String> output; 181 final EventSink<String> output;
191 182
192 TreeTracer(this.output); 183 TreeTracer(this.output);
193 184
194 Names names; 185 Names names;
195 BlockCollector collector; 186 BlockCollector collector;
196 int statementCounter; 187 int statementCounter;
197 188
198 void traceGraph(String name, ExecutableDefinition node) { 189 void traceGraph(String name, RootNode node) {
199 if (node is FunctionDefinition && node.isAbstract) return; 190 if (node.isEmpty) return;
200 if (node is FieldDefinition && node.body == null) return;
201 tag("cfg", () { 191 tag("cfg", () {
202 printProperty("name", name); 192 printProperty("name", name);
203 rewrite(node); 193 printRootNode(node);
204 collector.blocks.forEach(printBlock); 194 collector.blocks.forEach(printBlock);
205 }); 195 });
206 } 196 }
207 197
208 @override 198 void printRootNode(RootNode node) {
209 void rewriteExecutableDefinition(ExecutableDefinition node) {
210 collector = new BlockCollector(); 199 collector = new BlockCollector();
211 names = new Names(); 200 names = new Names();
212 statementCounter = 0; 201 statementCounter = 0;
213 collector = new BlockCollector(); 202 collector = new BlockCollector();
214 collector.collect(node); 203 collector.collect(node);
215 collector.blocks.forEach(printBlock); 204 collector.blocks.forEach(printBlock);
216 } 205 }
217 206
218 void printBlock(Block block) { 207 void printBlock(Block block) {
219 tag("block", () { 208 tag("block", () {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 String prefix = v.element == null ? 'v' : '${v.element.name}_'; 517 String prefix = v.element == null ? 'v' : '${v.element.name}_';
529 while (name == null || _usedNames.contains(name)) { 518 while (name == null || _usedNames.contains(name)) {
530 name = "$prefix${_counter++}"; 519 name = "$prefix${_counter++}";
531 } 520 }
532 _names[v] = name; 521 _names[v] = name;
533 _usedNames.add(name); 522 _usedNames.add(name);
534 } 523 }
535 return name; 524 return name;
536 } 525 }
537 } 526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698