| OLD | NEW |
| 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 'ir_nodes.dart' as ir hide Function; | 9 import 'ir_nodes.dart' as ir hide Function; |
| 10 import '../tracer.dart'; | 10 import '../tracer.dart'; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 | 188 |
| 189 visitBranch(ir.Branch node) { | 189 visitBranch(ir.Branch node) { |
| 190 String dummy = names.name(node); | 190 String dummy = names.name(node); |
| 191 String condition = visit(node.condition); | 191 String condition = visit(node.condition); |
| 192 String trueCont = formatReference(node.trueContinuation); | 192 String trueCont = formatReference(node.trueContinuation); |
| 193 String falseCont = formatReference(node.falseContinuation); | 193 String falseCont = formatReference(node.falseContinuation); |
| 194 printStmt(dummy, "Branch $condition ($trueCont, $falseCont)"); | 194 printStmt(dummy, "Branch $condition ($trueCont, $falseCont)"); |
| 195 } | 195 } |
| 196 | 196 |
| 197 visitSetClosureVariable(ir.SetClosureVariable node) { |
| 198 String dummy = names.name(node); |
| 199 String variable = node.variable.name; |
| 200 String value = formatReference(node.value); |
| 201 printStmt(dummy, 'SetClosureVariable $variable = $value'); |
| 202 visit(node.body); |
| 203 } |
| 204 |
| 205 visitDeclareFunction(ir.DeclareFunction node) { |
| 206 String dummy = names.name(node); |
| 207 String variable = node.variable.name; |
| 208 printStmt(dummy, 'DeclareFunction $variable'); |
| 209 visit(node.body); |
| 210 } |
| 211 |
| 197 String formatReference(ir.Reference ref) { | 212 String formatReference(ir.Reference ref) { |
| 198 ir.Definition target = ref.definition; | 213 ir.Definition target = ref.definition; |
| 199 if (target is ir.Continuation && target.body == null) { | 214 if (target is ir.Continuation && target.body == null) { |
| 200 return "return"; // Do not generate a name for the return continuation | 215 return "return"; // Do not generate a name for the return continuation |
| 201 } else { | 216 } else { |
| 202 return names.name(ref.definition); | 217 return names.name(ref.definition); |
| 203 } | 218 } |
| 204 } | 219 } |
| 205 | 220 |
| 206 String formatPrimitive(ir.Primitive p) => visit(p); | 221 String formatPrimitive(ir.Primitive p) => visit(p); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 219 | 234 |
| 220 visitIsTrue(ir.IsTrue node) { | 235 visitIsTrue(ir.IsTrue node) { |
| 221 return "IsTrue(${names.name(node.value.definition)})"; | 236 return "IsTrue(${names.name(node.value.definition)})"; |
| 222 } | 237 } |
| 223 | 238 |
| 224 visitThis(ir.This node) { | 239 visitThis(ir.This node) { |
| 225 return "This"; | 240 return "This"; |
| 226 } | 241 } |
| 227 | 242 |
| 228 visitReifyTypeVar(ir.ReifyTypeVar node) { | 243 visitReifyTypeVar(ir.ReifyTypeVar node) { |
| 229 return "ReifyTypeVar ${node.element.name}"; | 244 return "ReifyTypeVar ${node.typeVariable.name}"; |
| 230 } | 245 } |
| 231 | 246 |
| 247 visitCreateFunction(ir.CreateFunction node) { |
| 248 return "CreateFunction ${node.definition.element.name}"; |
| 249 } |
| 250 |
| 251 visitGetClosureVariable(ir.GetClosureVariable node) { |
| 252 String variable = node.variable.name; |
| 253 return 'GetClosureVariable $variable'; |
| 254 } |
| 255 |
| 256 |
| 232 visitCondition(ir.Condition c) {} | 257 visitCondition(ir.Condition c) {} |
| 233 visitExpression(ir.Expression e) {} | 258 visitExpression(ir.Expression e) {} |
| 234 visitPrimitive(ir.Primitive p) {} | 259 visitPrimitive(ir.Primitive p) {} |
| 235 visitDefinition(ir.Definition d) {} | 260 visitDefinition(ir.Definition d) {} |
| 236 visitNode(ir.Node n) {} | 261 visitNode(ir.Node n) {} |
| 237 } | 262 } |
| 238 | 263 |
| 239 /** | 264 /** |
| 240 * Invents (and remembers) names for Continuations, Parameters, etc. | 265 * Invents (and remembers) names for Continuations, Parameters, etc. |
| 241 * The names must match the conventions used by IR Hydra, e.g. | 266 * The names must match the conventions used by IR Hydra, e.g. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 336 |
| 312 visitLetPrim(ir.LetPrim exp) { | 337 visitLetPrim(ir.LetPrim exp) { |
| 313 visit(exp.body); | 338 visit(exp.body); |
| 314 } | 339 } |
| 315 | 340 |
| 316 visitLetCont(ir.LetCont exp) { | 341 visitLetCont(ir.LetCont exp) { |
| 317 visit(exp.continuation); | 342 visit(exp.continuation); |
| 318 visit(exp.body); | 343 visit(exp.body); |
| 319 } | 344 } |
| 320 | 345 |
| 321 visitInvokeStatic(ir.InvokeStatic exp) { | 346 void addEdgeToContinuation(ir.Reference continuation) { |
| 322 ir.Definition target = exp.continuation.definition; | 347 ir.Definition target = continuation.definition; |
| 323 if (target is ir.Continuation && target.body != null) { | 348 if (target is ir.Continuation && target.body != null) { |
| 324 current_block.addEdgeTo(getBlock(target)); | 349 current_block.addEdgeTo(getBlock(target)); |
| 325 } | 350 } |
| 326 } | 351 } |
| 327 | 352 |
| 353 visitInvokeStatic(ir.InvokeStatic exp) { |
| 354 addEdgeToContinuation(exp.continuation); |
| 355 } |
| 356 |
| 328 visitInvokeMethod(ir.InvokeMethod exp) { | 357 visitInvokeMethod(ir.InvokeMethod exp) { |
| 329 ir.Definition target = exp.continuation.definition; | 358 addEdgeToContinuation(exp.continuation); |
| 330 if (target is ir.Continuation && target.body != null) { | |
| 331 current_block.addEdgeTo(getBlock(target)); | |
| 332 } | |
| 333 } | 359 } |
| 334 | 360 |
| 335 visitInvokeConstructor(ir.InvokeConstructor exp) { | 361 visitInvokeConstructor(ir.InvokeConstructor exp) { |
| 336 ir.Definition target = exp.continuation.definition; | 362 addEdgeToContinuation(exp.continuation); |
| 337 if (target is ir.Continuation && target.body != null) { | |
| 338 current_block.addEdgeTo(getBlock(target)); | |
| 339 } | |
| 340 } | 363 } |
| 341 | 364 |
| 342 visitConcatenateStrings(ir.ConcatenateStrings exp) { | 365 visitConcatenateStrings(ir.ConcatenateStrings exp) { |
| 343 ir.Definition target = exp.continuation.definition; | 366 addEdgeToContinuation(exp.continuation); |
| 344 if (target is ir.Continuation && target.body != null) { | |
| 345 current_block.addEdgeTo(getBlock(target)); | |
| 346 } | |
| 347 } | 367 } |
| 348 | 368 |
| 349 visitInvokeContinuation(ir.InvokeContinuation exp) { | 369 visitInvokeContinuation(ir.InvokeContinuation exp) { |
| 350 ir.Definition target = exp.continuation.definition; | 370 addEdgeToContinuation(exp.continuation); |
| 351 if (target is ir.Continuation && target.body != null) { | 371 } |
| 352 current_block.addEdgeTo(getBlock(target)); | 372 |
| 353 } | 373 visitSetClosureVariable(ir.SetClosureVariable exp) { |
| 374 visit(exp.body); |
| 375 } |
| 376 |
| 377 visitDeclareFunction(ir.DeclareFunction exp) { |
| 378 visit(exp.body); |
| 354 } | 379 } |
| 355 | 380 |
| 356 visitBranch(ir.Branch exp) { | 381 visitBranch(ir.Branch exp) { |
| 357 ir.Continuation trueTarget = exp.trueContinuation.definition; | 382 ir.Continuation trueTarget = exp.trueContinuation.definition; |
| 358 if (trueTarget.body != null) { | 383 if (trueTarget.body != null) { |
| 359 current_block.addEdgeTo(getBlock(trueTarget)); | 384 current_block.addEdgeTo(getBlock(trueTarget)); |
| 360 } | 385 } |
| 361 ir.Continuation falseTarget = exp.falseContinuation.definition; | 386 ir.Continuation falseTarget = exp.falseContinuation.definition; |
| 362 if (falseTarget.body != null) { | 387 if (falseTarget.body != null) { |
| 363 current_block.addEdgeTo(getBlock(falseTarget)); | 388 current_block.addEdgeTo(getBlock(falseTarget)); |
| 364 } | 389 } |
| 365 } | 390 } |
| 366 | 391 |
| 367 visitContinuation(ir.Continuation c) { | 392 visitContinuation(ir.Continuation c) { |
| 368 var old_node = current_block; | 393 var old_node = current_block; |
| 369 current_block = getBlock(c); | 394 current_block = getBlock(c); |
| 370 visit(c.body); | 395 visit(c.body); |
| 371 current_block = old_node; | 396 current_block = old_node; |
| 372 } | 397 } |
| 373 } | 398 } |
| OLD | NEW |