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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_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 dart2js.ir_tracer; 5 library dart2js.ir_tracer;
6 6
7 import 'dart:async' show EventSink; 7 import 'dart:async' show EventSink;
8 8
9 import 'cps_ir_nodes.dart' as cps_ir hide Function; 9 import 'cps_ir_nodes.dart' as cps_ir hide Function;
10 import '../tracer.dart'; 10 import '../tracer.dart';
11 11
12 /** 12 /**
13 * If true, show LetCont expressions in output. 13 * If true, show LetCont expressions in output.
14 */ 14 */
15 const bool IR_TRACE_LET_CONT = false; 15 const bool IR_TRACE_LET_CONT = false;
16 16
17 class IRTracer extends TracerUtil implements cps_ir.Visitor { 17 class IRTracer extends TracerUtil implements cps_ir.Visitor {
18 EventSink<String> output; 18 EventSink<String> output;
19 19
20 IRTracer(this.output); 20 IRTracer(this.output);
21 21
22 visit(cps_ir.Node node) => node.accept(this); 22 visit(cps_ir.Node node) => node.accept(this);
23 23
24 void traceGraph(String name, cps_ir.ExecutableDefinition graph) { 24 void traceGraph(String name, cps_ir.RootNode graph) {
25 tag("cfg", () { 25 tag("cfg", () {
26 printProperty("name", name); 26 printProperty("name", name);
27 if (graph.isEmpty) return;
27 visit(graph); 28 visit(graph);
Kevin Millikin (Google) 2015/04/08 15:10:15 Maybe this can be disentangled a bit after this ch
asgerf 2015/04/09 09:58:23 I agree, this code has stagnated quite a bit. I u
28 }); 29 });
29 } 30 }
30 31
31 // Temporary field used during tree walk 32 // Temporary field used during tree walk
32 Names names; 33 Names names;
33 34
34 printDefinition(cps_ir.ExecutableDefinition node) { 35 printDefinition(cps_ir.RootNode node) {
35 names = new Names(); 36 names = new Names();
36 BlockCollector builder = new BlockCollector(names); 37 BlockCollector builder = new BlockCollector(names);
37 builder.visit(node); 38 builder.visit(node);
38 39
39 for (Block block in builder.entries) { 40 for (Block block in builder.entries) {
40 printBlock(block); 41 printBlock(block);
41 } 42 }
42 for (Block block in builder.cont2block.values) { 43 for (Block block in builder.cont2block.values) {
43 printBlock(block); 44 printBlock(block);
44 } 45 }
45 names = null; 46 names = null;
46 } 47 }
47 48
48 visitFieldDefinition(cps_ir.FieldDefinition node) { 49 visitFieldDefinition(cps_ir.FieldDefinition node) {
49 if (node.hasInitializer) { 50 printDefinition(node);
50 printDefinition(node);
51 }
52 } 51 }
53 52
54 visitFunctionDefinition(cps_ir.FunctionDefinition node) { 53 visitFunctionDefinition(cps_ir.FunctionDefinition node) {
55 if (node.isAbstract) return;
56 printDefinition(node); 54 printDefinition(node);
57 } 55 }
58 56
59 visitConstructorDefinition(cps_ir.ConstructorDefinition node) { 57 visitConstructorDefinition(cps_ir.ConstructorDefinition node) {
60 if (node.isAbstract) return;
61 printDefinition(node); 58 printDefinition(node);
62 } 59 }
63 60
64 // Bodies and initializers are not visited. They contain continuations which 61 // Bodies and initializers are not visited. They contain continuations which
65 // are found by a BlockCollector, then those continuations are processed by 62 // are found by a BlockCollector, then those continuations are processed by
66 // this visitor. 63 // this visitor.
67 unexpectedNode(cps_ir.Node node) { 64 unexpectedNode(cps_ir.Node node) {
68 throw 'The IR tracer reached an unexpected IR instruction: $node'; 65 throw 'The IR tracer reached an unexpected IR instruction: $node';
69 } 66 }
70 67
71 visitRunnableBody(cps_ir.RunnableBody node) { 68 visitBody(cps_ir.Body node) {
72 unexpectedNode(node); 69 unexpectedNode(node);
73 } 70 }
74 visitFieldInitializer(cps_ir.FieldInitializer node) { 71 visitFieldInitializer(cps_ir.FieldInitializer node) {
75 unexpectedNode(node); 72 unexpectedNode(node);
76 } 73 }
77 visitSuperInitializer(cps_ir.SuperInitializer node) { 74 visitSuperInitializer(cps_ir.SuperInitializer node) {
78 unexpectedNode(node); 75 unexpectedNode(node);
79 } 76 }
80 77
81 int countUses(cps_ir.Definition definition) { 78 int countUses(cps_ir.Definition definition) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (block == null) { 419 if (block == null) {
423 block = new Block(names.name(c), c.parameters, c.body); 420 block = new Block(names.name(c), c.parameters, c.body);
424 cont2block[c] = block; 421 cont2block[c] = block;
425 } 422 }
426 return block; 423 return block;
427 } 424 }
428 425
429 visit(cps_ir.Node node) => node.accept(this); 426 visit(cps_ir.Node node) => node.accept(this);
430 427
431 visitFieldDefinition(cps_ir.FieldDefinition node) { 428 visitFieldDefinition(cps_ir.FieldDefinition node) {
432 if (node.hasInitializer) { 429 visit(node.body);
433 visit(node.body);
434 }
435 } 430 }
436 431
437 visitFunctionDefinition(cps_ir.FunctionDefinition node) { 432 visitFunctionDefinition(cps_ir.FunctionDefinition node) {
438 visit(node.body); 433 visit(node.body);
439 } 434 }
440 435
441 visitConstructorDefinition(cps_ir.ConstructorDefinition node) { 436 visitConstructorDefinition(cps_ir.ConstructorDefinition node) {
442 visit(node.body); 437 visit(node.body);
443 } 438 }
444 439
445 visitRunnableBody(cps_ir.RunnableBody node) { 440 visitBody(cps_ir.Body node) {
446 current_block = new Block(names.name(node), [], node.body); 441 current_block = new Block(names.name(node), [], node.body);
447 entries.add(current_block); 442 entries.add(current_block);
448 visit(node.body); 443 visit(node.body);
449 } 444 }
450 445
451 visitFieldInitializer(cps_ir.FieldInitializer node) { 446 visitFieldInitializer(cps_ir.FieldInitializer node) {
452 visit(node.body); 447 visit(node.body);
453 } 448 }
454 449
455 visitSuperInitializer(cps_ir.SuperInitializer node) { 450 visitSuperInitializer(cps_ir.SuperInitializer node) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 @override 591 @override
597 visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { 592 visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) {
598 unexpectedNode(node); 593 unexpectedNode(node);
599 } 594 }
600 595
601 @override 596 @override
602 visitTypeExpression(cps_ir.TypeExpression node) { 597 visitTypeExpression(cps_ir.TypeExpression node) {
603 unexpectedNode(node); 598 unexpectedNode(node);
604 } 599 }
605 } 600 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698