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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart

Issue 800433003: First version of typr propagation in the new IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename constant_propagation.dart to type_propagation.dart. Created 6 years 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_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../util/util.dart'; 7 import '../util/util.dart';
8 import 'cps_ir_nodes.dart'; 8 import 'cps_ir_nodes.dart';
9 9
10 /// A [Decorator] is a function used by [SExpressionStringifier] to augment the 10 /// A [Decorator] is a function used by [SExpressionStringifier] to augment the
11 /// output produced for a node. It can be provided to the constructor. 11 /// output produced for a node. It can be provided to the constructor.
12 typedef String Decorator(Node node, String s); 12 typedef String Decorator(Node node, String s);
13 13
14 /// Generate a Lisp-like S-expression representation of an IR node as a string. 14 /// Generate a Lisp-like S-expression representation of an IR node as a string.
15 class SExpressionStringifier extends Visitor<String> with Indentation { 15 class SExpressionStringifier extends Visitor<String> with Indentation {
16 final _Namer namer = new _Namer(); 16 final _Namer namer = new _Namer();
17 17
18 String newValueName(Node node) => namer.defineValueName(node); 18 String newValueName(Node node) => namer.defineValueName(node);
19 String newContinuationName(Node node) => namer.defineContinuationName(node); 19 String newContinuationName(Node node) => namer.defineContinuationName(node);
20 final Decorator decorator; 20 Decorator decorator;
21 21
22 SExpressionStringifier([this.decorator]); 22 SExpressionStringifier([this.decorator]) {
23 if (this.decorator == null) {
24 this.decorator = (Node node, String s) => s;
25 }
26 }
23 27
24 String access(Reference<Definition> r) => namer.getName(r.definition); 28 String access(Reference<Definition> r) {
29 return decorator(r.definition, namer.getName(r.definition));
30 }
25 31
26 String visitParameter(Parameter node) { 32 String visitParameter(Parameter node) {
27 return namer.useElementName(node); 33 return namer.useElementName(node);
28 } 34 }
29 35
30 String visitClosureVariable(ClosureVariable node) { 36 String visitClosureVariable(ClosureVariable node) {
31 return namer.getName(node); 37 return namer.getName(node);
32 } 38 }
33 39
34 /// Main entry point for creating a [String] from a [Node]. All recursive 40 /// Main entry point for creating a [String] from a [Node]. All recursive
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 String body = visit(node.body); 74 String body = visit(node.body);
69 return '$indentation(LetPrim $name $value)\n$body'; 75 return '$indentation(LetPrim $name $value)\n$body';
70 } 76 }
71 77
72 String visitLetCont(LetCont node) { 78 String visitLetCont(LetCont node) {
73 String cont = newContinuationName(node.continuation); 79 String cont = newContinuationName(node.continuation);
74 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and 80 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and
75 // should recurse to [visit]. Currently we can't do that, because the 81 // should recurse to [visit]. Currently we can't do that, because the
76 // unstringifier_test produces [LetConts] with dummy arguments on them. 82 // unstringifier_test produces [LetConts] with dummy arguments on them.
77 String parameters = node.continuation.parameters 83 String parameters = node.continuation.parameters
78 .map((p) => ' ${newValueName(p)}') 84 .map((p) => ' ${decorator(p, newValueName(p))}')
79 .join(''); 85 .join('');
80 String contBody = indentBlock(() => visit(node.continuation.body)); 86 String contBody = indentBlock(() => visit(node.continuation.body));
81 String body = visit(node.body); 87 String body = visit(node.body);
82 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont'; 88 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont';
83 return '$indentation($op ($cont$parameters)\n' 89 return '$indentation($op ($cont$parameters)\n'
84 '$contBody)\n' 90 '$contBody)\n'
85 '$body'; 91 '$body';
86 } 92 }
87 93
88 String formatArguments(Invoke node) { 94 String formatArguments(Invoke node) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 String useReturnName(Continuation node) { 259 String useReturnName(Continuation node) {
254 assert(!_names.containsKey(node) || _names[node] == 'return'); 260 assert(!_names.containsKey(node) || _names[node] == 'return');
255 return _names[node] = 'return'; 261 return _names[node] = 'return';
256 } 262 }
257 263
258 String getName(Node node) { 264 String getName(Node node) {
259 assert(_names.containsKey(node)); 265 assert(_names.containsKey(node));
260 return _names[node]; 266 return _names[node];
261 } 267 }
262 } 268 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/constant_propagation.dart ('k') | pkg/compiler/lib/src/cps_ir/optimizers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698