| 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 import 'cps_ir_nodes.dart' as cps_ir; | 8 import 'cps_ir_nodes.dart' as cps_ir; |
| 9 import '../tracer.dart'; | 9 import '../tracer.dart'; |
| 10 | 10 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 visit(node.body); | 133 visit(node.body); |
| 134 } | 134 } |
| 135 | 135 |
| 136 visitLetMutable(cps_ir.LetMutable node) { | 136 visitLetMutable(cps_ir.LetMutable node) { |
| 137 String id = names.name(node.variable); | 137 String id = names.name(node.variable); |
| 138 printStmt(id, "LetMutable $id = ${formatReference(node.value)}"); | 138 printStmt(id, "LetMutable $id = ${formatReference(node.value)}"); |
| 139 visit(node.body); | 139 visit(node.body); |
| 140 } | 140 } |
| 141 | 141 |
| 142 visitInvokeStatic(cps_ir.InvokeStatic node) { | 142 visitInvokeStatic(cps_ir.InvokeStatic node) { |
| 143 String dummy = names.name(node); | |
| 144 String callName = node.selector.name; | 143 String callName = node.selector.name; |
| 145 String args = node.arguments.map(formatReference).join(', '); | 144 String args = node.arguments.map(formatReference).join(', '); |
| 146 String kont = formatReference(node.continuation); | 145 return "InvokeStatic $callName ($args)"; |
| 147 printStmt(dummy, "InvokeStatic $callName ($args) $kont"); | |
| 148 } | 146 } |
| 149 | 147 |
| 150 visitInvokeMethod(cps_ir.InvokeMethod node) { | 148 visitInvokeMethod(cps_ir.InvokeMethod node) { |
| 151 String dummy = names.name(node); | |
| 152 String receiver = formatReference(node.receiver); | 149 String receiver = formatReference(node.receiver); |
| 153 String callName = node.selector.name; | 150 String callName = node.selector.name; |
| 154 String args = node.arguments.map(formatReference).join(', '); | 151 String args = node.arguments.map(formatReference).join(', '); |
| 155 String kont = formatReference(node.continuation); | 152 return "InvokeMethod $receiver $callName ($args)"; |
| 156 printStmt(dummy, | |
| 157 "InvokeMethod $receiver $callName ($args) $kont"); | |
| 158 } | 153 } |
| 159 | 154 |
| 160 visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { | 155 visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { |
| 161 String dummy = names.name(node); | |
| 162 String receiver = formatReference(node.receiver); | 156 String receiver = formatReference(node.receiver); |
| 163 String callName = node.selector.name; | 157 String callName = node.selector.name; |
| 164 String args = node.arguments.map(formatReference).join(', '); | 158 String args = node.arguments.map(formatReference).join(', '); |
| 165 String kont = formatReference(node.continuation); | 159 return "InvokeMethodDirectly $receiver $callName ($args)"; |
| 166 printStmt(dummy, | |
| 167 "InvokeMethodDirectly $receiver $callName ($args) $kont"); | |
| 168 } | 160 } |
| 169 | 161 |
| 170 visitInvokeConstructor(cps_ir.InvokeConstructor node) { | 162 visitInvokeConstructor(cps_ir.InvokeConstructor node) { |
| 171 String dummy = names.name(node); | |
| 172 String className = node.target.enclosingClass.name; | 163 String className = node.target.enclosingClass.name; |
| 173 String callName; | 164 String callName; |
| 174 if (node.target.name.isEmpty) { | 165 if (node.target.name.isEmpty) { |
| 175 callName = '${className}'; | 166 callName = '${className}'; |
| 176 } else { | 167 } else { |
| 177 callName = '${className}.${node.target.name}'; | 168 callName = '${className}.${node.target.name}'; |
| 178 } | 169 } |
| 179 String args = node.arguments.map(formatReference).join(', '); | 170 String args = node.arguments.map(formatReference).join(', '); |
| 180 String kont = formatReference(node.continuation); | 171 return "InvokeConstructor $callName ($args)"; |
| 181 printStmt(dummy, "InvokeConstructor $callName ($args) $kont"); | |
| 182 } | 172 } |
| 183 | 173 |
| 184 visitThrow(cps_ir.Throw node) { | 174 visitThrow(cps_ir.Throw node) { |
| 185 String dummy = names.name(node); | 175 String dummy = names.name(node); |
| 186 String value = formatReference(node.value); | 176 String value = formatReference(node.value); |
| 187 printStmt(dummy, "Throw $value"); | 177 printStmt(dummy, "Throw $value"); |
| 188 } | 178 } |
| 189 | 179 |
| 190 visitRethrow(cps_ir.Rethrow node) { | 180 visitRethrow(cps_ir.Rethrow node) { |
| 191 String dummy = names.name(node); | 181 String dummy = names.name(node); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 206 List<String> entries = new List<String>(); | 196 List<String> entries = new List<String>(); |
| 207 for (cps_ir.LiteralMapEntry entry in node.entries) { | 197 for (cps_ir.LiteralMapEntry entry in node.entries) { |
| 208 String key = formatReference(entry.key); | 198 String key = formatReference(entry.key); |
| 209 String value = formatReference(entry.value); | 199 String value = formatReference(entry.value); |
| 210 entries.add("$key: $value"); | 200 entries.add("$key: $value"); |
| 211 } | 201 } |
| 212 return "LiteralMap (${entries.join(', ')})"; | 202 return "LiteralMap (${entries.join(', ')})"; |
| 213 } | 203 } |
| 214 | 204 |
| 215 visitTypeCast(cps_ir.TypeCast node) { | 205 visitTypeCast(cps_ir.TypeCast node) { |
| 216 String dummy = names.name(node); | |
| 217 String value = formatReference(node.value); | 206 String value = formatReference(node.value); |
| 218 String args = node.typeArguments.map(formatReference).join(', '); | 207 String args = node.typeArguments.map(formatReference).join(', '); |
| 219 String kont = formatReference(node.continuation); | 208 return "TypeCast ($value ${node.dartType} ($args))"; |
| 220 printStmt(dummy, "TypeCast ($value ${node.dartType} ($args)) $kont"); | |
| 221 } | 209 } |
| 222 | 210 |
| 223 visitInvokeContinuation(cps_ir.InvokeContinuation node) { | 211 visitInvokeContinuation(cps_ir.InvokeContinuation node) { |
| 224 String dummy = names.name(node); | 212 String dummy = names.name(node); |
| 225 String kont = formatReference(node.continuation); | 213 String kont = formatReference(node.continuation); |
| 226 String args = node.arguments.map(formatReference).join(', '); | 214 String args = node.arguments.map(formatReference).join(', '); |
| 227 printStmt(dummy, "InvokeContinuation $kont ($args)"); | 215 printStmt(dummy, "InvokeContinuation $kont ($args)"); |
| 228 } | 216 } |
| 229 | 217 |
| 230 visitBranch(cps_ir.Branch node) { | 218 visitBranch(cps_ir.Branch node) { |
| 231 String dummy = names.name(node); | 219 String dummy = names.name(node); |
| 232 String condition = formatReference(node.condition); | 220 String condition = formatReference(node.condition); |
| 233 String trueCont = formatReference(node.trueContinuation); | 221 String trueCont = formatReference(node.trueContinuation); |
| 234 String falseCont = formatReference(node.falseContinuation); | 222 String falseCont = formatReference(node.falseContinuation); |
| 235 String strict = node.isStrictCheck ? "Strict" : "NonStrict"; | 223 String strict = node.isStrictCheck ? "Strict" : "NonStrict"; |
| 236 printStmt(dummy, "Branch $condition ($trueCont, $falseCont) $strict"); | 224 printStmt(dummy, "Branch $condition ($trueCont, $falseCont) $strict"); |
| 237 } | 225 } |
| 238 | 226 |
| 239 visitAwait(cps_ir.Await node) { | 227 visitAwait(cps_ir.Await node) { |
| 240 String dummy = names.name(node); | |
| 241 String value = formatReference(node.input); | 228 String value = formatReference(node.input); |
| 242 String continuation = formatReference(node.continuation); | 229 return 'Await $value'; |
| 243 printStmt(dummy, 'Await $value $continuation'); | |
| 244 } | 230 } |
| 245 | 231 |
| 246 visitYield(cps_ir.Yield node) { | 232 visitYield(cps_ir.Yield node) { |
| 247 String dummy = names.name(node); | |
| 248 String name = node.hasStar ? 'YieldStar' : 'Yield'; | 233 String name = node.hasStar ? 'YieldStar' : 'Yield'; |
| 249 String value = formatReference(node.input); | 234 String value = formatReference(node.input); |
| 250 String continuation = formatReference(node.continuation); | 235 return '$name $value'; |
| 251 printStmt(dummy, '$name $value $continuation'); | |
| 252 } | 236 } |
| 253 | 237 |
| 254 visitSetMutable(cps_ir.SetMutable node) { | 238 visitSetMutable(cps_ir.SetMutable node) { |
| 255 String variable = names.name(node.variable.definition); | 239 String variable = names.name(node.variable.definition); |
| 256 String value = formatReference(node.value); | 240 String value = formatReference(node.value); |
| 257 return 'SetMutable $variable := $value'; | 241 return 'SetMutable $variable := $value'; |
| 258 } | 242 } |
| 259 | 243 |
| 260 String formatReference(cps_ir.Reference ref) { | 244 String formatReference(cps_ir.Reference ref) { |
| 261 cps_ir.Definition target = ref.definition; | 245 cps_ir.Definition target = ref.definition; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return 'GetStatic($element)'; | 284 return 'GetStatic($element)'; |
| 301 } | 285 } |
| 302 | 286 |
| 303 visitSetStatic(cps_ir.SetStatic node) { | 287 visitSetStatic(cps_ir.SetStatic node) { |
| 304 String element = node.element.name; | 288 String element = node.element.name; |
| 305 String value = formatReference(node.value); | 289 String value = formatReference(node.value); |
| 306 return 'SetStatic $element = $value'; | 290 return 'SetStatic $element = $value'; |
| 307 } | 291 } |
| 308 | 292 |
| 309 visitGetLazyStatic(cps_ir.GetLazyStatic node) { | 293 visitGetLazyStatic(cps_ir.GetLazyStatic node) { |
| 310 String dummy = names.name(node); | 294 String element = node.element.name; |
| 311 String kont = formatReference(node.continuation); | 295 return "GetLazyStatic $element"; |
| 312 printStmt(dummy, "GetLazyStatic $kont"); | |
| 313 } | 296 } |
| 314 | 297 |
| 315 visitCreateBox(cps_ir.CreateBox node) { | 298 visitCreateBox(cps_ir.CreateBox node) { |
| 316 return 'CreateBox'; | 299 return 'CreateBox'; |
| 317 } | 300 } |
| 318 | 301 |
| 319 visitCreateInstance(cps_ir.CreateInstance node) { | 302 visitCreateInstance(cps_ir.CreateInstance node) { |
| 320 String className = node.classElement.name; | 303 String className = node.classElement.name; |
| 321 String arguments = node.arguments.map(formatReference).join(', '); | 304 String arguments = node.arguments.map(formatReference).join(', '); |
| 322 String typeInformation = | 305 String typeInformation = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 return 'ApplyBuiltinOperator $operator ($args)'; | 360 return 'ApplyBuiltinOperator $operator ($args)'; |
| 378 } | 361 } |
| 379 | 362 |
| 380 visitApplyBuiltinMethod(cps_ir.ApplyBuiltinMethod node) { | 363 visitApplyBuiltinMethod(cps_ir.ApplyBuiltinMethod node) { |
| 381 String method = node.method.toString(); | 364 String method = node.method.toString(); |
| 382 String receiver = formatReference(node.receiver); | 365 String receiver = formatReference(node.receiver); |
| 383 String args = node.arguments.map(formatReference).join(', '); | 366 String args = node.arguments.map(formatReference).join(', '); |
| 384 return 'ApplyBuiltinMethod $method $receiver ($args)'; | 367 return 'ApplyBuiltinMethod $method $receiver ($args)'; |
| 385 } | 368 } |
| 386 | 369 |
| 387 @override | |
| 388 visitForeignCode(cps_ir.ForeignCode node) { | 370 visitForeignCode(cps_ir.ForeignCode node) { |
| 389 String id = names.name(node); | 371 String id = names.name(node); |
| 390 String arguments = node.arguments.map(formatReference).join(', '); | 372 String arguments = node.arguments.map(formatReference).join(', '); |
| 391 String continuation = formatReference(node.continuation); | 373 printStmt(id, |
| 392 printStmt(id, "ForeignCode ${node.type} ${node.codeTemplate.source} " | 374 "ForeignCode ${node.type} ${node.codeTemplate.source} $arguments"); |
| 393 "$arguments $continuation"); | |
| 394 } | 375 } |
| 395 | 376 |
| 396 visitGetLength(cps_ir.GetLength node) { | 377 visitGetLength(cps_ir.GetLength node) { |
| 397 String object = formatReference(node.object); | 378 String object = formatReference(node.object); |
| 398 return 'GetLength $object'; | 379 return 'GetLength $object'; |
| 399 } | 380 } |
| 400 | 381 |
| 401 visitGetIndex(cps_ir.GetIndex node) { | 382 visitGetIndex(cps_ir.GetIndex node) { |
| 402 String object = formatReference(node.object); | 383 String object = formatReference(node.object); |
| 403 String index = formatReference(node.index); | 384 String index = formatReference(node.index); |
| 404 return 'GetIndex $object $index'; | 385 return 'GetIndex $object $index'; |
| 405 } | 386 } |
| 406 | 387 |
| 407 visitSetIndex(cps_ir.SetIndex node) { | 388 visitSetIndex(cps_ir.SetIndex node) { |
| 408 String object = formatReference(node.object); | 389 String object = formatReference(node.object); |
| 409 String index = formatReference(node.index); | 390 String index = formatReference(node.index); |
| 410 String value = formatReference(node.value); | 391 String value = formatReference(node.value); |
| 411 return 'SetIndex $object $index $value'; | 392 return 'SetIndex $object $index $value'; |
| 412 } | 393 } |
| 413 | 394 |
| 414 @override | |
| 415 visitRefinement(cps_ir.Refinement node) { | 395 visitRefinement(cps_ir.Refinement node) { |
| 416 String value = formatReference(node.value); | 396 String value = formatReference(node.value); |
| 417 return 'Refinement $value ${node.refineType}'; | 397 return 'Refinement $value ${node.refineType}'; |
| 418 } | 398 } |
| 419 } | 399 } |
| 420 | 400 |
| 421 /** | 401 /** |
| 422 * Invents (and remembers) names for Continuations, Parameters, etc. | 402 * Invents (and remembers) names for Continuations, Parameters, etc. |
| 423 * The names must match the conventions used by IR Hydra, e.g. | 403 * The names must match the conventions used by IR Hydra, e.g. |
| 424 * Continuations and Functions must have names of form B### since they | 404 * Continuations and Functions must have names of form B### since they |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 cps_ir.Definition target = continuation.definition; | 499 cps_ir.Definition target = continuation.definition; |
| 520 if (target is cps_ir.Continuation && !target.isReturnContinuation) { | 500 if (target is cps_ir.Continuation && !target.isReturnContinuation) { |
| 521 currentBlock.addEdgeTo(getBlock(target)); | 501 currentBlock.addEdgeTo(getBlock(target)); |
| 522 } | 502 } |
| 523 } | 503 } |
| 524 | 504 |
| 525 visitInvokeContinuation(cps_ir.InvokeContinuation exp) { | 505 visitInvokeContinuation(cps_ir.InvokeContinuation exp) { |
| 526 addEdgeToContinuation(exp.continuation); | 506 addEdgeToContinuation(exp.continuation); |
| 527 } | 507 } |
| 528 | 508 |
| 529 visitInvokeStatic(cps_ir.InvokeStatic exp) { | 509 visitInvokeStatic(cps_ir.InvokeStatic node) { |
| 530 addEdgeToContinuation(exp.continuation); | 510 unexpectedNode(node); |
| 531 } | 511 } |
| 532 | 512 |
| 533 visitInvokeMethod(cps_ir.InvokeMethod exp) { | 513 visitInvokeMethod(cps_ir.InvokeMethod node) { |
| 534 addEdgeToContinuation(exp.continuation); | 514 unexpectedNode(node); |
| 535 } | 515 } |
| 536 | 516 |
| 537 visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly exp) { | 517 visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { |
| 538 addEdgeToContinuation(exp.continuation); | 518 unexpectedNode(node); |
| 539 } | 519 } |
| 540 | 520 |
| 541 visitInvokeConstructor(cps_ir.InvokeConstructor exp) { | 521 visitInvokeConstructor(cps_ir.InvokeConstructor node) { |
| 542 addEdgeToContinuation(exp.continuation); | 522 unexpectedNode(node); |
| 543 } | 523 } |
| 544 | 524 |
| 545 visitThrow(cps_ir.Throw exp) { | 525 visitThrow(cps_ir.Throw exp) { |
| 546 } | 526 } |
| 547 | 527 |
| 548 visitRethrow(cps_ir.Rethrow exp) { | 528 visitRethrow(cps_ir.Rethrow exp) { |
| 549 } | 529 } |
| 550 | 530 |
| 551 visitUnreachable(cps_ir.Unreachable node) { | 531 visitUnreachable(cps_ir.Unreachable node) { |
| 552 } | 532 } |
| 553 | 533 |
| 554 visitGetLazyStatic(cps_ir.GetLazyStatic exp) { | 534 visitGetLazyStatic(cps_ir.GetLazyStatic node) { |
| 555 addEdgeToContinuation(exp.continuation); | 535 unexpectedNode(node); |
| 556 } | 536 } |
| 557 | 537 |
| 558 visitBranch(cps_ir.Branch exp) { | 538 visitBranch(cps_ir.Branch exp) { |
| 559 cps_ir.Continuation trueTarget = exp.trueContinuation.definition; | 539 cps_ir.Continuation trueTarget = exp.trueContinuation.definition; |
| 560 if (!trueTarget.isReturnContinuation) { | 540 if (!trueTarget.isReturnContinuation) { |
| 561 currentBlock.addEdgeTo(getBlock(trueTarget)); | 541 currentBlock.addEdgeTo(getBlock(trueTarget)); |
| 562 } | 542 } |
| 563 cps_ir.Continuation falseTarget = exp.falseContinuation.definition; | 543 cps_ir.Continuation falseTarget = exp.falseContinuation.definition; |
| 564 if (!falseTarget.isReturnContinuation) { | 544 if (!falseTarget.isReturnContinuation) { |
| 565 currentBlock.addEdgeTo(getBlock(falseTarget)); | 545 currentBlock.addEdgeTo(getBlock(falseTarget)); |
| 566 } | 546 } |
| 567 } | 547 } |
| 568 | 548 |
| 569 visitTypeCast(cps_ir.TypeCast exp) { | 549 visitTypeCast(cps_ir.TypeCast node) { |
| 570 addEdgeToContinuation(exp.continuation); | 550 unexpectedNode(node); |
| 571 } | 551 } |
| 572 | 552 |
| 573 visitContinuation(cps_ir.Continuation c) { | 553 visitContinuation(cps_ir.Continuation c) { |
| 574 var old_node = currentBlock; | 554 var old_node = currentBlock; |
| 575 currentBlock = getBlock(c); | 555 currentBlock = getBlock(c); |
| 576 visit(c.body); | 556 visit(c.body); |
| 577 currentBlock = old_node; | 557 currentBlock = old_node; |
| 578 } | 558 } |
| 579 | 559 |
| 580 // Primitives and conditions are not visited when searching for blocks. | 560 // Primitives and conditions are not visited when searching for blocks. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 } | 660 } |
| 681 | 661 |
| 682 visitSetField(cps_ir.SetField node) { | 662 visitSetField(cps_ir.SetField node) { |
| 683 unexpectedNode(node); | 663 unexpectedNode(node); |
| 684 } | 664 } |
| 685 | 665 |
| 686 visitSetStatic(cps_ir.SetStatic node) { | 666 visitSetStatic(cps_ir.SetStatic node) { |
| 687 unexpectedNode(node); | 667 unexpectedNode(node); |
| 688 } | 668 } |
| 689 | 669 |
| 690 @override | |
| 691 visitForeignCode(cps_ir.ForeignCode node) { | 670 visitForeignCode(cps_ir.ForeignCode node) { |
| 692 addEdgeToContinuation(node.continuation); | 671 unexpectedNode(node); |
| 693 } | 672 } |
| 694 | 673 |
| 695 @override | |
| 696 visitAwait(cps_ir.Await node) { | 674 visitAwait(cps_ir.Await node) { |
| 697 addEdgeToContinuation(node.continuation); | 675 unexpectedNode(node); |
| 698 } | 676 } |
| 699 | 677 |
| 700 @override | |
| 701 visitYield(cps_ir.Yield node) { | 678 visitYield(cps_ir.Yield node) { |
| 702 addEdgeToContinuation(node.continuation); | 679 unexpectedNode(node); |
| 703 } | 680 } |
| 704 | 681 |
| 705 @override | |
| 706 visitRefinement(cps_ir.Refinement node) { | 682 visitRefinement(cps_ir.Refinement node) { |
| 707 unexpectedNode(node); | 683 unexpectedNode(node); |
| 708 } | 684 } |
| 709 } | 685 } |
| OLD | NEW |