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

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

Issue 787603003: Generative constructors in the new dart backend. (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 18 matching lines...) Expand all
29 } 29 }
30 30
31 // Temporary field used during tree walk 31 // Temporary field used during tree walk
32 Names names; 32 Names names;
33 33
34 visitExecutableDefinition(cps_ir.ExecutableDefinition node) { 34 visitExecutableDefinition(cps_ir.ExecutableDefinition node) {
35 names = new Names(); 35 names = new Names();
36 BlockCollector builder = new BlockCollector(names); 36 BlockCollector builder = new BlockCollector(names);
37 builder.visit(node); 37 builder.visit(node);
38 38
39 printNode(builder.entry); 39 for (Block block in builder.entries) {
40 printNode(block);
41 }
40 for (Block block in builder.cont2block.values) { 42 for (Block block in builder.cont2block.values) {
41 printNode(block); 43 printNode(block);
42 } 44 }
43 names = null; 45 names = null;
44 } 46 }
45 47
46 visitFieldDefinition(cps_ir.FieldDefinition node) { 48 visitFieldDefinition(cps_ir.FieldDefinition node) {
47 if (node.hasInitializer) { 49 if (node.hasInitializer) {
48 visitExecutableDefinition(node); 50 visitExecutableDefinition(node);
49 } 51 }
50 } 52 }
51 53
52 visitFunctionDefinition(cps_ir.FunctionDefinition node) { 54 visitFunctionDefinition(cps_ir.FunctionDefinition node) {
55 if (node.isAbstract) return;
53 visitExecutableDefinition(node); 56 visitExecutableDefinition(node);
54 } 57 }
55 58
59 visitConstructorDefinition(cps_ir.ConstructorDefinition node) {
60 if (node.isAbstract) return;
61 visitExecutableDefinition(node);
62 }
63
56 int countUses(cps_ir.Definition definition) { 64 int countUses(cps_ir.Definition definition) {
57 int count = 0; 65 int count = 0;
58 cps_ir.Reference ref = definition.firstRef; 66 cps_ir.Reference ref = definition.firstRef;
59 while (ref != null) { 67 while (ref != null) {
60 ++count; 68 ++count;
61 ref = ref.next; 69 ref = ref.next;
62 } 70 }
63 return count; 71 return count;
64 } 72 }
65 73
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 267
260 visitCreateFunction(cps_ir.CreateFunction node) { 268 visitCreateFunction(cps_ir.CreateFunction node) {
261 return "CreateFunction ${node.definition.element.name}"; 269 return "CreateFunction ${node.definition.element.name}";
262 } 270 }
263 271
264 visitGetClosureVariable(cps_ir.GetClosureVariable node) { 272 visitGetClosureVariable(cps_ir.GetClosureVariable node) {
265 String variable = names.name(node.variable.definition); 273 String variable = names.name(node.variable.definition);
266 return 'GetClosureVariable $variable'; 274 return 'GetClosureVariable $variable';
267 } 275 }
268 276
269 277 visitRunnableBody(cps_ir.RunnableBody node) {}
278 visitFieldInitializer(cps_ir.FieldInitializer node) {}
279 visitSuperInitializer(cps_ir.SuperInitializer node) {}
270 visitCondition(cps_ir.Condition c) {} 280 visitCondition(cps_ir.Condition c) {}
271 visitExpression(cps_ir.Expression e) {} 281 visitExpression(cps_ir.Expression e) {}
272 visitPrimitive(cps_ir.Primitive p) {} 282 visitPrimitive(cps_ir.Primitive p) {}
273 visitDefinition(cps_ir.Definition d) {} 283 visitDefinition(cps_ir.Definition d) {}
284 visitInitializer(cps_ir.Initializer i) {}
274 visitNode(cps_ir.Node n) {} 285 visitNode(cps_ir.Node n) {}
275 } 286 }
276 287
277 /** 288 /**
278 * Invents (and remembers) names for Continuations, Parameters, etc. 289 * Invents (and remembers) names for Continuations, Parameters, etc.
279 * The names must match the conventions used by IR Hydra, e.g. 290 * The names must match the conventions used by IR Hydra, e.g.
280 * Continuations and Functions must have names of form B### since they 291 * Continuations and Functions must have names of form B### since they
281 * are visualized as basic blocks. 292 * are visualized as basic blocks.
282 */ 293 */
283 class Names { 294 class Names {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 332
322 Block(this.name, this.parameters, this.body); 333 Block(this.name, this.parameters, this.body);
323 334
324 void addEdgeTo(Block successor) { 335 void addEdgeTo(Block successor) {
325 succ.add(successor); 336 succ.add(successor);
326 successor.pred.add(this); 337 successor.pred.add(this);
327 } 338 }
328 } 339 }
329 340
330 class BlockCollector extends cps_ir.Visitor { 341 class BlockCollector extends cps_ir.Visitor {
331 Block entry;
332 final Map<cps_ir.Continuation, Block> cont2block = 342 final Map<cps_ir.Continuation, Block> cont2block =
333 <cps_ir.Continuation, Block>{}; 343 <cps_ir.Continuation, Block>{};
344 final Set<Block> entries = new Set<Block>();
334 Block current_block; 345 Block current_block;
335 346
336 Names names; 347 Names names;
337 BlockCollector(this.names); 348 BlockCollector(this.names);
338 349
339 Block getBlock(cps_ir.Continuation c) { 350 Block getBlock(cps_ir.Continuation c) {
340 Block block = cont2block[c]; 351 Block block = cont2block[c];
341 if (block == null) { 352 if (block == null) {
342 block = new Block(names.name(c), c.parameters, c.body); 353 block = new Block(names.name(c), c.parameters, c.body);
343 cont2block[c] = block; 354 cont2block[c] = block;
344 } 355 }
345 return block; 356 return block;
346 } 357 }
347 358
348 visitExecutableDefinition(cps_ir.ExecutableDefinition node) { 359 visitRunnableBody(cps_ir.RunnableBody node) {
349 entry = current_block = new Block(names.name(node), [], node.body); 360 current_block = new Block(names.name(node), [], node.body);
361 entries.add(current_block);
350 visit(node.body); 362 visit(node.body);
351 } 363 }
352 364
365 visitFieldInitializer(cps_ir.FieldInitializer node) {
366 visit(node.body);
367 }
368
369 visitSuperInitializer(cps_ir.SuperInitializer node) {
370 node.arguments.forEach(visit);
371 }
372
373 visitExecutableDefinition(cps_ir.ExecutableDefinition node) {
374 visit(node.body);
375 }
376
353 visitFieldDefinition(cps_ir.FieldDefinition node) { 377 visitFieldDefinition(cps_ir.FieldDefinition node) {
354 if (node.hasInitializer) { 378 if (node.hasInitializer) {
355 visitExecutableDefinition(node); 379 visitExecutableDefinition(node);
356 } 380 }
357 } 381 }
358 382
359 visitFunctionDefinition(cps_ir.FunctionDefinition node) { 383 visitFunctionDefinition(cps_ir.FunctionDefinition node) {
360 visitExecutableDefinition(node); 384 visitExecutableDefinition(node);
361 } 385 }
362 386
387 visitConstructorDefinition(cps_ir.ConstructorDefinition node) {
388 visitExecutableDefinition(node);
389 }
390
363 visitLetPrim(cps_ir.LetPrim exp) { 391 visitLetPrim(cps_ir.LetPrim exp) {
364 visit(exp.body); 392 visit(exp.body);
365 } 393 }
366 394
367 visitLetCont(cps_ir.LetCont exp) { 395 visitLetCont(cps_ir.LetCont exp) {
368 visit(exp.continuation); 396 visit(exp.continuation);
369 visit(exp.body); 397 visit(exp.body);
370 } 398 }
371 399
372 void addEdgeToContinuation(cps_ir.Reference continuation) { 400 void addEdgeToContinuation(cps_ir.Reference continuation) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 443 }
416 } 444 }
417 445
418 visitContinuation(cps_ir.Continuation c) { 446 visitContinuation(cps_ir.Continuation c) {
419 var old_node = current_block; 447 var old_node = current_block;
420 current_block = getBlock(c); 448 current_block = getBlock(c);
421 visit(c.body); 449 visit(c.body);
422 current_block = old_node; 450 current_block = old_node;
423 } 451 }
424 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698