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

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

Issue 756383004: Refactored treatment of closure variables in dart2js CPS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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_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';
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 visitBranch(cps_ir.Branch node) { 192 visitBranch(cps_ir.Branch node) {
193 String dummy = names.name(node); 193 String dummy = names.name(node);
194 String condition = visit(node.condition); 194 String condition = visit(node.condition);
195 String trueCont = formatReference(node.trueContinuation); 195 String trueCont = formatReference(node.trueContinuation);
196 String falseCont = formatReference(node.falseContinuation); 196 String falseCont = formatReference(node.falseContinuation);
197 printStmt(dummy, "Branch $condition ($trueCont, $falseCont)"); 197 printStmt(dummy, "Branch $condition ($trueCont, $falseCont)");
198 } 198 }
199 199
200 visitSetClosureVariable(cps_ir.SetClosureVariable node) { 200 visitSetClosureVariable(cps_ir.SetClosureVariable node) {
201 String dummy = names.name(node); 201 String dummy = names.name(node);
202 String variable = node.variable.name; 202 String variable = names.name(node.variable.definition);
203 String value = formatReference(node.value); 203 String value = formatReference(node.value);
204 printStmt(dummy, 'SetClosureVariable $variable = $value'); 204 printStmt(dummy, 'SetClosureVariable $variable = $value');
205 visit(node.body); 205 visit(node.body);
206 } 206 }
207 207
208 visitDeclareFunction(cps_ir.DeclareFunction node) { 208 visitDeclareFunction(cps_ir.DeclareFunction node) {
209 String dummy = names.name(node); 209 String dummy = names.name(node);
210 String variable = node.variable.name; 210 String variable = names.name(node.variable.definition);
211 printStmt(dummy, 'DeclareFunction $variable'); 211 printStmt(dummy, 'DeclareFunction $variable');
212 visit(node.body); 212 visit(node.body);
213 } 213 }
214 214
215 String formatReference(cps_ir.Reference ref) { 215 String formatReference(cps_ir.Reference ref) {
216 cps_ir.Definition target = ref.definition; 216 cps_ir.Definition target = ref.definition;
217 if (target is cps_ir.Continuation && target.isReturnContinuation) { 217 if (target is cps_ir.Continuation && target.isReturnContinuation) {
218 return "return"; // Do not generate a name for the return continuation 218 return "return"; // Do not generate a name for the return continuation
219 } else { 219 } else {
220 return names.name(ref.definition); 220 return names.name(ref.definition);
221 } 221 }
222 } 222 }
223 223
224 String formatPrimitive(cps_ir.Primitive p) => visit(p); 224 String formatPrimitive(cps_ir.Primitive p) => visit(p);
225 225
226 visitConstant(cps_ir.Constant node) { 226 visitConstant(cps_ir.Constant node) {
227 return "Constant ${node.expression.value.toStructuredString()}"; 227 return "Constant ${node.expression.value.toStructuredString()}";
228 } 228 }
229 229
230 visitParameter(cps_ir.Parameter node) { 230 visitParameter(cps_ir.Parameter node) {
231 return "Parameter ${names.name(node)}"; 231 return "Parameter ${names.name(node)}";
232 } 232 }
233 233
234 visitClosureVariable(cps_ir.ClosureVariable node) {
235 return "ClosureVariable ${names.name(node)}";
236 }
237
234 visitContinuation(cps_ir.Continuation node) { 238 visitContinuation(cps_ir.Continuation node) {
235 return "Continuation ${names.name(node)}"; 239 return "Continuation ${names.name(node)}";
236 } 240 }
237 241
238 visitIsTrue(cps_ir.IsTrue node) { 242 visitIsTrue(cps_ir.IsTrue node) {
239 return "IsTrue(${names.name(node.value.definition)})"; 243 return "IsTrue(${names.name(node.value.definition)})";
240 } 244 }
241 245
242 visitIdentical(cps_ir.Identical node) { 246 visitIdentical(cps_ir.Identical node) {
243 String left = formatReference(node.left); 247 String left = formatReference(node.left);
244 String right = formatReference(node.right); 248 String right = formatReference(node.right);
245 return "Identical($left, $right)"; 249 return "Identical($left, $right)";
246 } 250 }
247 251
248 visitThis(cps_ir.This node) { 252 visitThis(cps_ir.This node) {
249 return "This"; 253 return "This";
250 } 254 }
251 255
252 visitReifyTypeVar(cps_ir.ReifyTypeVar node) { 256 visitReifyTypeVar(cps_ir.ReifyTypeVar node) {
253 return "ReifyTypeVar ${node.typeVariable.name}"; 257 return "ReifyTypeVar ${node.typeVariable.name}";
254 } 258 }
255 259
256 visitCreateFunction(cps_ir.CreateFunction node) { 260 visitCreateFunction(cps_ir.CreateFunction node) {
257 return "CreateFunction ${node.definition.element.name}"; 261 return "CreateFunction ${node.definition.element.name}";
258 } 262 }
259 263
260 visitGetClosureVariable(cps_ir.GetClosureVariable node) { 264 visitGetClosureVariable(cps_ir.GetClosureVariable node) {
261 String variable = node.variable.name; 265 String variable = names.name(node.variable.definition);
262 return 'GetClosureVariable $variable'; 266 return 'GetClosureVariable $variable';
263 } 267 }
264 268
265 269
266 visitCondition(cps_ir.Condition c) {} 270 visitCondition(cps_ir.Condition c) {}
267 visitExpression(cps_ir.Expression e) {} 271 visitExpression(cps_ir.Expression e) {}
268 visitPrimitive(cps_ir.Primitive p) {} 272 visitPrimitive(cps_ir.Primitive p) {}
269 visitDefinition(cps_ir.Definition d) {} 273 visitDefinition(cps_ir.Definition d) {}
270 visitNode(cps_ir.Node n) {} 274 visitNode(cps_ir.Node n) {}
271 } 275 }
272 276
273 /** 277 /**
274 * Invents (and remembers) names for Continuations, Parameters, etc. 278 * Invents (and remembers) names for Continuations, Parameters, etc.
275 * The names must match the conventions used by IR Hydra, e.g. 279 * The names must match the conventions used by IR Hydra, e.g.
276 * Continuations and Functions must have names of form B### since they 280 * Continuations and Functions must have names of form B### since they
277 * are visualized as basic blocks. 281 * are visualized as basic blocks.
278 */ 282 */
279 class Names { 283 class Names {
280 final Map<Object, String> names = {}; 284 final Map<Object, String> names = {};
281 final Map<String, int> counters = { 285 final Map<String, int> counters = {
282 'r': 0, 286 'r': 0,
283 'B': 0, 287 'B': 0,
284 'v': 0, 288 'v': 0,
285 'x': 0 289 'x': 0,
290 'c': 0
286 }; 291 };
287 292
288 String prefix(x) { 293 String prefix(x) {
289 if (x is cps_ir.Parameter) return 'r'; 294 if (x is cps_ir.Parameter) return 'r';
290 if (x is cps_ir.Continuation || x is cps_ir.FunctionDefinition) return 'B'; 295 if (x is cps_ir.Continuation || x is cps_ir.FunctionDefinition) return 'B';
291 if (x is cps_ir.Primitive) return 'v'; 296 if (x is cps_ir.Primitive) return 'v';
297 if (x is cps_ir.ClosureVariable) return 'c';
292 return 'x'; 298 return 'x';
293 } 299 }
294 300
295 String name(x) { 301 String name(x) {
296 String nam = names[x]; 302 String nam = names[x];
297 if (nam == null) { 303 if (nam == null) {
298 String pref = prefix(x); 304 String pref = prefix(x);
299 int id = counters[pref]++; 305 int id = counters[pref]++;
300 nam = names[x] = '${pref}${id}'; 306 nam = names[x] = '${pref}${id}';
301 } 307 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 415 }
410 } 416 }
411 417
412 visitContinuation(cps_ir.Continuation c) { 418 visitContinuation(cps_ir.Continuation c) {
413 var old_node = current_block; 419 var old_node = current_block;
414 current_block = getBlock(c); 420 current_block = getBlock(c);
415 visit(c.body); 421 visit(c.body);
416 current_block = old_node; 422 current_block = old_node;
417 } 423 }
418 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698