| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/il_printer.h" | 5 #include "vm/il_printer.h" |
| 6 | 6 |
| 7 #include "vm/intermediate_language.h" | 7 #include "vm/intermediate_language.h" |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 (current == NULL) ? NULL : current->AsBlockEntry(); | 50 (current == NULL) ? NULL : current->AsBlockEntry(); |
| 51 if (successor != NULL) { | 51 if (successor != NULL) { |
| 52 OS::Print(" goto %d", successor->block_id()); | 52 OS::Print(" goto %d", successor->block_id()); |
| 53 } | 53 } |
| 54 OS::Print("\n"); | 54 OS::Print("\n"); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 void FlowGraphPrinter::PrintInstruction(Instruction* instr) { | 59 void FlowGraphPrinter::PrintInstruction(Instruction* instr) { |
| 60 char str[120]; | 60 char str[1000]; |
| 61 BufferFormatter f(str, sizeof(str)); | 61 BufferFormatter f(str, sizeof(str)); |
| 62 instr->PrintTo(&f); | 62 instr->PrintTo(&f); |
| 63 if (FLAG_print_environments && (instr->env() != NULL)) { | 63 if (FLAG_print_environments && (instr->env() != NULL)) { |
| 64 instr->env()->PrintTo(&f); | 64 instr->env()->PrintTo(&f); |
| 65 } | 65 } |
| 66 OS::Print("%s", str); | 66 OS::Print("%s", str); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 void FlowGraphPrinter::PrintComputation(Computation* comp) { | 70 void FlowGraphPrinter::PrintComputation(Computation* comp) { |
| 71 char str[120]; | 71 char str[1000]; |
| 72 BufferFormatter f(str, sizeof(str)); | 72 BufferFormatter f(str, sizeof(str)); |
| 73 comp->PrintTo(&f); | 73 comp->PrintTo(&f); |
| 74 OS::Print("%s", str); | 74 OS::Print("%s", str); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 void Computation::PrintTo(BufferFormatter* f) const { | 78 void Computation::PrintTo(BufferFormatter* f) const { |
| 79 f->Print("%s(", DebugName()); | 79 f->Print("%s(", DebugName()); |
| 80 PrintOperandsTo(f); | 80 PrintOperandsTo(f); |
| 81 f->Print(")"); | 81 f->Print(")"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 102 void ConstantVal::PrintTo(BufferFormatter* f) const { | 102 void ConstantVal::PrintTo(BufferFormatter* f) const { |
| 103 f->Print("#%s", value().ToCString()); | 103 f->Print("#%s", value().ToCString()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 void AssertAssignableComp::PrintOperandsTo(BufferFormatter* f) const { | 107 void AssertAssignableComp::PrintOperandsTo(BufferFormatter* f) const { |
| 108 value()->PrintTo(f); | 108 value()->PrintTo(f); |
| 109 f->Print(", %s, '%s'", | 109 f->Print(", %s, '%s'", |
| 110 String::Handle(dst_type().Name()).ToCString(), | 110 String::Handle(dst_type().Name()).ToCString(), |
| 111 dst_name().ToCString()); | 111 dst_name().ToCString()); |
| 112 f->Print(" (instantiator:"); | 112 f->Print(" instantiator("); |
| 113 instantiator()->PrintTo(f); | 113 instantiator()->PrintTo(f); |
| 114 f->Print(")"); | 114 f->Print(")"); |
| 115 f->Print(" (instantiator_type_arguments:"); | 115 f->Print(" instantiator_type_arguments("); |
| 116 instantiator_type_arguments()->PrintTo(f); | 116 instantiator_type_arguments()->PrintTo(f); |
| 117 f->Print(")"); | 117 f->Print(")"); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { | 121 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { |
| 122 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 122 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
| 123 if (i == 0) f->Print(", "); | 123 if (i == 0) f->Print(", "); |
| 124 ArgumentAt(i)->PrintTo(f); | 124 ArgumentAt(i)->PrintTo(f); |
| 125 } | 125 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 f->Print("%s, ", String::Handle(field().name()).ToCString()); | 199 f->Print("%s, ", String::Handle(field().name()).ToCString()); |
| 200 value()->PrintTo(f); | 200 value()->PrintTo(f); |
| 201 } | 201 } |
| 202 | 202 |
| 203 | 203 |
| 204 void InstanceOfComp::PrintOperandsTo(BufferFormatter* f) const { | 204 void InstanceOfComp::PrintOperandsTo(BufferFormatter* f) const { |
| 205 value()->PrintTo(f); | 205 value()->PrintTo(f); |
| 206 f->Print(" %s %s", | 206 f->Print(" %s %s", |
| 207 negate_result() ? "ISNOT" : "IS", | 207 negate_result() ? "ISNOT" : "IS", |
| 208 String::Handle(type().Name()).ToCString()); | 208 String::Handle(type().Name()).ToCString()); |
| 209 f->Print(" (instantiator:"); | 209 f->Print(" instantiator("); |
| 210 instantiator()->PrintTo(f); | 210 instantiator()->PrintTo(f); |
| 211 f->Print(")"); | 211 f->Print(")"); |
| 212 f->Print(" (type-arg:"); | 212 f->Print(" type-arg("); |
| 213 instantiator_type_arguments()->PrintTo(f); | 213 instantiator_type_arguments()->PrintTo(f); |
| 214 f->Print(")"); | 214 f->Print(")"); |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 void RelationalOpComp::PrintOperandsTo(BufferFormatter* f) const { | 218 void RelationalOpComp::PrintOperandsTo(BufferFormatter* f) const { |
| 219 f->Print("%s, ", Token::Str(kind())); | 219 f->Print("%s, ", Token::Str(kind())); |
| 220 left()->PrintTo(f); | 220 left()->PrintTo(f); |
| 221 f->Print(", "); | 221 f->Print(", "); |
| 222 right()->PrintTo(f); | 222 right()->PrintTo(f); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 void ToDoubleComp::PrintOperandsTo(BufferFormatter* f) const { | 318 void ToDoubleComp::PrintOperandsTo(BufferFormatter* f) const { |
| 319 ASSERT(from() == kDouble || from() == kSmi); | 319 ASSERT(from() == kDouble || from() == kSmi); |
| 320 f->Print("%s ", from() == kDouble ? "double2double" : "smi2double"); | 320 f->Print("%s ", from() == kDouble ? "double2double" : "smi2double"); |
| 321 value()->PrintTo(f); | 321 value()->PrintTo(f); |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { | 325 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { |
| 326 f->Print("%2d: [graph]", block_id()); | 326 f->Print("%2d: [graph]", block_id()); |
| 327 if (start_env_ != NULL) { | 327 if (start_env_ != NULL) { |
| 328 for (intptr_t i = 0; i < start_env_->length(); ++i) { | 328 start_env_->PrintTo(f); |
| 329 f->Print("\n "); | |
| 330 (*start_env_)[i]->PrintTo(f); | |
| 331 } | |
| 332 } | 329 } |
| 333 } | 330 } |
| 334 | 331 |
| 335 | 332 |
| 336 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { | 333 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { |
| 337 f->Print("%2d: [join]", block_id()); | 334 f->Print("%2d: [join]", block_id()); |
| 338 if (phis_ != NULL) { | 335 if (phis_ != NULL) { |
| 339 for (intptr_t i = 0; i < phis_->length(); ++i) { | 336 for (intptr_t i = 0; i < phis_->length(); ++i) { |
| 340 if ((*phis_)[i] == NULL) continue; | 337 if ((*phis_)[i] == NULL) continue; |
| 341 f->Print("\n"); | 338 f->Print("\n"); |
| 342 (*phis_)[i]->PrintTo(f); | 339 (*phis_)[i]->PrintTo(f); |
| 343 } | 340 } |
| 344 } | 341 } |
| 345 } | 342 } |
| 346 | 343 |
| 347 | 344 |
| 348 void PhiInstr::PrintTo(BufferFormatter* f) const { | 345 void PhiInstr::PrintTo(BufferFormatter* f) const { |
| 349 f->Print(" v%d <- phi(", ssa_temp_index()); | 346 f->Print(" v%d <- phi(", ssa_temp_index()); |
| 350 for (intptr_t i = 0; i < inputs_.length(); ++i) { | 347 for (intptr_t i = 0; i < inputs_.length(); ++i) { |
| 351 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); | 348 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); |
| 352 if (i < inputs_.length() - 1) f->Print(","); | 349 if (i < inputs_.length() - 1) f->Print(","); |
| 353 } | 350 } |
| 354 f->Print(")"); | 351 f->Print(")"); |
| 355 } | 352 } |
| 356 | 353 |
| 357 | 354 |
| 355 void ParameterInstr::PrintTo(BufferFormatter* f) const { |
| 356 f->Print(" v%d <- parameter(%d)", index()); |
| 357 } |
| 358 |
| 359 |
| 358 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { | 360 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { |
| 359 f->Print("%2d: [target", block_id()); | 361 f->Print("%2d: [target", block_id()); |
| 360 if (HasTryIndex()) { | 362 if (HasTryIndex()) { |
| 361 f->Print(" catch %d]", try_index()); | 363 f->Print(" catch %d]", try_index()); |
| 362 } else { | 364 } else { |
| 363 f->Print("]"); | 365 f->Print("]"); |
| 364 } | 366 } |
| 365 } | 367 } |
| 366 | 368 |
| 367 | 369 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 false_successor()->block_id()); | 418 false_successor()->block_id()); |
| 417 } | 419 } |
| 418 | 420 |
| 419 | 421 |
| 420 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { | 422 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { |
| 421 UNIMPLEMENTED(); | 423 UNIMPLEMENTED(); |
| 422 } | 424 } |
| 423 | 425 |
| 424 | 426 |
| 425 void FlowGraphVisualizer::Print(const char* format, ...) { | 427 void FlowGraphVisualizer::Print(const char* format, ...) { |
| 426 char str[120]; | 428 char str[1000]; |
| 427 BufferFormatter f(str, sizeof(str)); | 429 BufferFormatter f(str, sizeof(str)); |
| 428 f.Print("%*s", 2 * indent_, ""); | 430 f.Print("%*s", 2 * indent_, ""); |
| 429 va_list args; | 431 va_list args; |
| 430 va_start(args, format); | 432 va_start(args, format); |
| 431 f.VPrint(format, args); | 433 f.VPrint(format, args); |
| 432 va_end(args); | 434 va_end(args); |
| 433 (*Dart::flow_graph_writer())(str, strlen(str)); | 435 (*Dart::flow_graph_writer())(str, strlen(str)); |
| 434 } | 436 } |
| 435 | 437 |
| 436 | 438 |
| 437 void FlowGraphVisualizer::PrintInstruction(Instruction* instr) { | 439 void FlowGraphVisualizer::PrintInstruction(Instruction* instr) { |
| 438 char str[120]; | 440 char str[1000]; |
| 439 BufferFormatter f(str, sizeof(str)); | 441 BufferFormatter f(str, sizeof(str)); |
| 440 instr->PrintToVisualizer(&f); | 442 instr->PrintToVisualizer(&f); |
| 441 if (FLAG_print_environments && (instr->env() != NULL)) { | 443 if (FLAG_print_environments && (instr->env() != NULL)) { |
| 442 instr->env()->PrintTo(&f); | 444 instr->env()->PrintTo(&f); |
| 443 } | 445 } |
| 444 f.Print(" <|@\n"); | 446 f.Print(" <|@\n"); |
| 445 (*Dart::flow_graph_writer())(str, strlen(str)); | 447 (*Dart::flow_graph_writer())(str, strlen(str)); |
| 446 } | 448 } |
| 447 | 449 |
| 448 | 450 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 #undef BEGIN | 555 #undef BEGIN |
| 554 #undef END | 556 #undef END |
| 555 } | 557 } |
| 556 | 558 |
| 557 | 559 |
| 558 // === Printing instructions in a visualizer-understandable format: | 560 // === Printing instructions in a visualizer-understandable format: |
| 559 // "result instruction(op1, op2)" where result is a temporary name | 561 // "result instruction(op1, op2)" where result is a temporary name |
| 560 // or _ for instruction without result. | 562 // or _ for instruction without result. |
| 561 void GraphEntryInstr::PrintToVisualizer(BufferFormatter* f) const { | 563 void GraphEntryInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 562 f->Print("_ [graph]"); | 564 f->Print("_ [graph]"); |
| 565 if (start_env_ != NULL) { |
| 566 start_env_->PrintTo(f); |
| 567 } |
| 563 } | 568 } |
| 564 | 569 |
| 565 | 570 |
| 566 void JoinEntryInstr::PrintToVisualizer(BufferFormatter* f) const { | 571 void JoinEntryInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 567 f->Print("_ [join]"); | 572 f->Print("_ [join]"); |
| 568 } | 573 } |
| 569 | 574 |
| 570 | 575 |
| 571 void PhiInstr::PrintToVisualizer(BufferFormatter* f) const { | 576 void PhiInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 572 f->Print("v%d [", ssa_temp_index()); | 577 f->Print("v%d [", ssa_temp_index()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 589 if (i > 0) f->Print(" "); | 594 if (i > 0) f->Print(" "); |
| 590 if (InputAt(i)->IsConstant()) { | 595 if (InputAt(i)->IsConstant()) { |
| 591 InputAt(i)->PrintTo(f); | 596 InputAt(i)->PrintTo(f); |
| 592 } | 597 } |
| 593 } | 598 } |
| 594 f->Print("\""); | 599 f->Print("\""); |
| 595 } | 600 } |
| 596 } | 601 } |
| 597 | 602 |
| 598 | 603 |
| 604 void ParameterInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 605 ASSERT(ssa_temp_index() != -1); |
| 606 ASSERT(temp_index() == -1); |
| 607 f->Print("v%d Parameter(%d)", ssa_temp_index(), index()); |
| 608 } |
| 609 |
| 610 |
| 599 void TargetEntryInstr::PrintToVisualizer(BufferFormatter* f) const { | 611 void TargetEntryInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 600 f->Print("_ [target"); | 612 f->Print("_ [target"); |
| 601 if (HasTryIndex()) { | 613 if (HasTryIndex()) { |
| 602 f->Print(" catch %d]", try_index()); | 614 f->Print(" catch %d]", try_index()); |
| 603 } else { | 615 } else { |
| 604 f->Print("]"); | 616 f->Print("]"); |
| 605 } | 617 } |
| 606 } | 618 } |
| 607 | 619 |
| 608 | 620 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 void Environment::PrintTo(BufferFormatter* f) const { | 672 void Environment::PrintTo(BufferFormatter* f) const { |
| 661 f->Print(" env={ "); | 673 f->Print(" env={ "); |
| 662 for (intptr_t i = 0; i < values_.length(); ++i) { | 674 for (intptr_t i = 0; i < values_.length(); ++i) { |
| 663 if (i > 0) f->Print(", "); | 675 if (i > 0) f->Print(", "); |
| 664 values_[i]->PrintTo(f); | 676 values_[i]->PrintTo(f); |
| 665 } | 677 } |
| 666 f->Print(" }"); | 678 f->Print(" }"); |
| 667 } | 679 } |
| 668 | 680 |
| 669 } // namespace dart | 681 } // namespace dart |
| OLD | NEW |