| 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 #include "vm/parser.h" |
| 9 | 10 |
| 10 namespace dart { | 11 namespace dart { |
| 11 | 12 |
| 12 DEFINE_FLAG(bool, print_environments, false, "Print SSA environments."); | 13 DEFINE_FLAG(bool, print_environments, false, "Print SSA environments."); |
| 13 | 14 |
| 14 | 15 |
| 15 void BufferFormatter::Print(const char* format, ...) { | 16 void BufferFormatter::Print(const char* format, ...) { |
| 16 va_list args; | 17 va_list args; |
| 17 va_start(args, format); | 18 va_start(args, format); |
| 18 VPrint(format, args); | 19 VPrint(format, args); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 | 77 |
| 77 void FlowGraphPrinter::PrintComputation(Computation* comp) { | 78 void FlowGraphPrinter::PrintComputation(Computation* comp) { |
| 78 char str[1000]; | 79 char str[1000]; |
| 79 BufferFormatter f(str, sizeof(str)); | 80 BufferFormatter f(str, sizeof(str)); |
| 80 comp->PrintTo(&f); | 81 comp->PrintTo(&f); |
| 81 OS::Print("%s", str); | 82 OS::Print("%s", str); |
| 82 } | 83 } |
| 83 | 84 |
| 84 | 85 |
| 86 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, |
| 87 intptr_t token_pos, |
| 88 Value* value, |
| 89 const AbstractType& dst_type, |
| 90 const String& dst_name, |
| 91 bool eliminated) { |
| 92 const Class& cls = Class::Handle(parsed_function.function().owner()); |
| 93 const Script& script = Script::Handle(cls.script()); |
| 94 const char* static_type_name = "unknown"; |
| 95 if (value != NULL) { |
| 96 const AbstractType& type = AbstractType::Handle(value->StaticType()); |
| 97 static_type_name = String::Handle(type.UserVisibleName()).ToCString(); |
| 98 } |
| 99 Parser::PrintMessage(script, token_pos, "", |
| 100 "%s type check: static type '%s' is %s specific than " |
| 101 "type '%s' of '%s'.", |
| 102 eliminated ? "Eliminated" : "Generated", |
| 103 static_type_name, |
| 104 eliminated ? "more" : "not more", |
| 105 String::Handle(dst_type.UserVisibleName()).ToCString(), |
| 106 dst_name.ToCString()); |
| 107 } |
| 108 |
| 109 |
| 85 static void PrintICData(BufferFormatter* f, const ICData& ic_data) { | 110 static void PrintICData(BufferFormatter* f, const ICData& ic_data) { |
| 86 f->Print(" IC[%d: ", ic_data.NumberOfChecks()); | 111 f->Print(" IC[%d: ", ic_data.NumberOfChecks()); |
| 87 Function& target = Function::Handle(); | 112 Function& target = Function::Handle(); |
| 88 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { | 113 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { |
| 89 GrowableArray<intptr_t> class_ids; | 114 GrowableArray<intptr_t> class_ids; |
| 90 ic_data.GetCheckAt(i, &class_ids, &target); | 115 ic_data.GetCheckAt(i, &class_ids, &target); |
| 91 if (i > 0) { | 116 if (i > 0) { |
| 92 f->Print(" | "); | 117 f->Print(" | "); |
| 93 } | 118 } |
| 94 for (intptr_t k = 0; k < class_ids.length(); k++) { | 119 for (intptr_t k = 0; k < class_ids.length(); k++) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 f->Print(")"); | 171 f->Print(")"); |
| 147 f->Print(" instantiator_type_arguments("); | 172 f->Print(" instantiator_type_arguments("); |
| 148 instantiator_type_arguments()->PrintTo(f); | 173 instantiator_type_arguments()->PrintTo(f); |
| 149 f->Print(")"); | 174 f->Print(")"); |
| 150 } | 175 } |
| 151 | 176 |
| 152 | 177 |
| 153 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { | 178 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { |
| 154 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 179 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
| 155 if (i > 0) f->Print(", "); | 180 if (i > 0) f->Print(", "); |
| 156 f->Print("cid%d", ArgumentAt(i)->cid()); | 181 ArgumentAt(i)->value()->PrintTo(f); |
| 157 } | 182 } |
| 158 } | 183 } |
| 159 | 184 |
| 160 | 185 |
| 161 void InstanceCallComp::PrintOperandsTo(BufferFormatter* f) const { | 186 void InstanceCallComp::PrintOperandsTo(BufferFormatter* f) const { |
| 162 f->Print("%s", function_name().ToCString()); | 187 f->Print("%s", function_name().ToCString()); |
| 163 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 188 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
| 164 f->Print(", "); | 189 if (i > 0) f->Print(", "); |
| 165 f->Print("cid%d", ArgumentAt(i)->cid()); | 190 ArgumentAt(i)->value()->PrintTo(f); |
| 166 } | 191 } |
| 167 } | 192 } |
| 168 | 193 |
| 169 | 194 |
| 170 void PolymorphicInstanceCallComp::PrintTo(BufferFormatter* f) const { | 195 void PolymorphicInstanceCallComp::PrintTo(BufferFormatter* f) const { |
| 171 f->Print("%s(", DebugName()); | 196 f->Print("%s(", DebugName()); |
| 172 instance_call()->PrintOperandsTo(f); | 197 instance_call()->PrintOperandsTo(f); |
| 173 f->Print(") "); | 198 f->Print(") "); |
| 174 if (HasICData()) { | 199 if (HasICData()) { |
| 175 PrintICData(f, *ic_data()); | 200 PrintICData(f, *ic_data()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 void EqualityCompareComp::PrintOperandsTo(BufferFormatter* f) const { | 212 void EqualityCompareComp::PrintOperandsTo(BufferFormatter* f) const { |
| 188 left()->PrintTo(f); | 213 left()->PrintTo(f); |
| 189 f->Print(" %s ", Token::Str(kind())); | 214 f->Print(" %s ", Token::Str(kind())); |
| 190 right()->PrintTo(f); | 215 right()->PrintTo(f); |
| 191 } | 216 } |
| 192 | 217 |
| 193 | 218 |
| 194 void StaticCallComp::PrintOperandsTo(BufferFormatter* f) const { | 219 void StaticCallComp::PrintOperandsTo(BufferFormatter* f) const { |
| 195 f->Print("%s", String::Handle(function().name()).ToCString()); | 220 f->Print("%s", String::Handle(function().name()).ToCString()); |
| 196 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 221 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
| 197 f->Print(", "); | 222 if (i > 0) f->Print(", "); |
| 198 f->Print("cid%d", ArgumentAt(i)->cid()); | 223 ArgumentAt(i)->value()->PrintTo(f); |
| 199 } | 224 } |
| 200 } | 225 } |
| 201 | 226 |
| 202 | 227 |
| 203 void LoadLocalComp::PrintOperandsTo(BufferFormatter* f) const { | 228 void LoadLocalComp::PrintOperandsTo(BufferFormatter* f) const { |
| 204 f->Print("%s lvl:%d", local().name().ToCString(), context_level()); | 229 f->Print("%s lvl:%d", local().name().ToCString(), context_level()); |
| 205 } | 230 } |
| 206 | 231 |
| 207 | 232 |
| 208 void StoreLocalComp::PrintOperandsTo(BufferFormatter* f) const { | 233 void StoreLocalComp::PrintOperandsTo(BufferFormatter* f) const { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ElementAt(i)->PrintTo(f); | 314 ElementAt(i)->PrintTo(f); |
| 290 } | 315 } |
| 291 if (ElementCount() > 0) f->Print(", "); | 316 if (ElementCount() > 0) f->Print(", "); |
| 292 element_type()->PrintTo(f); | 317 element_type()->PrintTo(f); |
| 293 } | 318 } |
| 294 | 319 |
| 295 | 320 |
| 296 void CreateClosureComp::PrintOperandsTo(BufferFormatter* f) const { | 321 void CreateClosureComp::PrintOperandsTo(BufferFormatter* f) const { |
| 297 f->Print("%s", function().ToCString()); | 322 f->Print("%s", function().ToCString()); |
| 298 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 323 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
| 299 f->Print(", "); | 324 if (i > 0) f->Print(", "); |
| 300 f->Print("cid%d", ArgumentAt(i)->cid()); | 325 ArgumentAt(i)->value()->PrintTo(f); |
| 301 } | 326 } |
| 302 } | 327 } |
| 303 | 328 |
| 304 | 329 |
| 305 void LoadVMFieldComp::PrintOperandsTo(BufferFormatter* f) const { | 330 void LoadVMFieldComp::PrintOperandsTo(BufferFormatter* f) const { |
| 306 value()->PrintTo(f); | 331 value()->PrintTo(f); |
| 307 f->Print(", %d", offset_in_bytes()); | 332 f->Print(", %d", offset_in_bytes()); |
| 308 } | 333 } |
| 309 | 334 |
| 310 | 335 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } else if (HasSSATemp()) { | 449 } else if (HasSSATemp()) { |
| 425 f->Print(" v%d <- ", ssa_temp_index()); | 450 f->Print(" v%d <- ", ssa_temp_index()); |
| 426 } else { | 451 } else { |
| 427 f->Print(" t%d <- ", temp_index()); | 452 f->Print(" t%d <- ", temp_index()); |
| 428 } | 453 } |
| 429 computation()->PrintTo(f); | 454 computation()->PrintTo(f); |
| 430 } | 455 } |
| 431 | 456 |
| 432 | 457 |
| 433 void PushArgumentInstr::PrintTo(BufferFormatter* f) const { | 458 void PushArgumentInstr::PrintTo(BufferFormatter* f) const { |
| 459 f->Print(" %s ", DebugName()); |
| 460 value()->PrintTo(f); |
| 461 } |
| 462 |
| 463 |
| 464 void ReturnInstr::PrintTo(BufferFormatter* f) const { |
| 434 f->Print(" %s:%d ", DebugName(), cid()); | 465 f->Print(" %s:%d ", DebugName(), cid()); |
| 435 value()->PrintTo(f); | 466 value()->PrintTo(f); |
| 436 } | 467 } |
| 437 | 468 |
| 438 | 469 |
| 439 void ReturnInstr::PrintTo(BufferFormatter* f) const { | |
| 440 f->Print(" %s ", DebugName()); | |
| 441 value()->PrintTo(f); | |
| 442 } | |
| 443 | |
| 444 | |
| 445 void ThrowInstr::PrintTo(BufferFormatter* f) const { | 470 void ThrowInstr::PrintTo(BufferFormatter* f) const { |
| 446 f->Print(" %s ", DebugName()); | 471 f->Print(" %s:%d ", DebugName(), cid()); |
| 447 exception()->PrintTo(f); | 472 exception()->PrintTo(f); |
| 448 } | 473 } |
| 449 | 474 |
| 450 | 475 |
| 451 void ReThrowInstr::PrintTo(BufferFormatter* f) const { | 476 void ReThrowInstr::PrintTo(BufferFormatter* f) const { |
| 452 f->Print(" %s ", DebugName()); | 477 f->Print(" %s:%d ", DebugName(), cid()); |
| 453 exception()->PrintTo(f); | 478 exception()->PrintTo(f); |
| 454 f->Print(", "); | 479 f->Print(", "); |
| 455 stack_trace()->PrintTo(f); | 480 stack_trace()->PrintTo(f); |
| 456 } | 481 } |
| 457 | 482 |
| 458 | 483 |
| 459 void GotoInstr::PrintTo(BufferFormatter* f) const { | 484 void GotoInstr::PrintTo(BufferFormatter* f) const { |
| 460 if (HasParallelMove()) { | 485 if (HasParallelMove()) { |
| 461 parallel_move()->PrintTo(f); | 486 parallel_move()->PrintTo(f); |
| 462 } else { | 487 } else { |
| 463 f->Print(" "); | 488 f->Print(" "); |
| 464 } | 489 } |
| 465 f->Print(" goto %d", successor()->block_id()); | 490 f->Print(" goto %d", successor()->block_id()); |
| 466 } | 491 } |
| 467 | 492 |
| 468 | 493 |
| 469 void BranchInstr::PrintTo(BufferFormatter* f) const { | 494 void BranchInstr::PrintTo(BufferFormatter* f) const { |
| 470 f->Print(" %s ", DebugName()); | 495 f->Print(" %s:%d ", DebugName(), cid()); |
| 471 f->Print("if "); | 496 f->Print("if "); |
| 472 left()->PrintTo(f); | 497 left()->PrintTo(f); |
| 473 f-> Print(" %s ", Token::Str(kind())); | 498 f-> Print(" %s ", Token::Str(kind())); |
| 474 right()->PrintTo(f); | 499 right()->PrintTo(f); |
| 475 | 500 |
| 476 f->Print(" goto (%d, %d)", | 501 f->Print(" goto (%d, %d)", |
| 477 true_successor()->block_id(), | 502 true_successor()->block_id(), |
| 478 false_successor()->block_id()); | 503 false_successor()->block_id()); |
| 479 if (HasICData()) { | 504 if (HasICData()) { |
| 480 PrintICData(f, *ic_data()); | 505 PrintICData(f, *ic_data()); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } else if (HasSSATemp()) { | 718 } else if (HasSSATemp()) { |
| 694 f->Print("v%d ", ssa_temp_index()); | 719 f->Print("v%d ", ssa_temp_index()); |
| 695 } else { | 720 } else { |
| 696 f->Print("t%d ", temp_index()); | 721 f->Print("t%d ", temp_index()); |
| 697 } | 722 } |
| 698 computation()->PrintTo(f); | 723 computation()->PrintTo(f); |
| 699 } | 724 } |
| 700 | 725 |
| 701 | 726 |
| 702 void PushArgumentInstr::PrintToVisualizer(BufferFormatter* f) const { | 727 void PushArgumentInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 728 f->Print("_ %s ", DebugName()); |
| 729 value()->PrintTo(f); |
| 730 } |
| 731 |
| 732 |
| 733 void ReturnInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 703 f->Print("_ %s:%d ", DebugName(), cid()); | 734 f->Print("_ %s:%d ", DebugName(), cid()); |
| 704 value()->PrintTo(f); | 735 value()->PrintTo(f); |
| 705 } | 736 } |
| 706 | 737 |
| 707 | 738 |
| 708 void ReturnInstr::PrintToVisualizer(BufferFormatter* f) const { | |
| 709 f->Print("_ %s ", DebugName()); | |
| 710 value()->PrintTo(f); | |
| 711 } | |
| 712 | |
| 713 | |
| 714 void ThrowInstr::PrintToVisualizer(BufferFormatter* f) const { | 739 void ThrowInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 715 f->Print("_ %s ", DebugName()); | 740 f->Print("_ %s:%d ", DebugName(), cid()); |
| 716 exception()->PrintTo(f); | 741 exception()->PrintTo(f); |
| 717 } | 742 } |
| 718 | 743 |
| 719 | 744 |
| 720 void ReThrowInstr::PrintToVisualizer(BufferFormatter* f) const { | 745 void ReThrowInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 721 f->Print("_ %s ", DebugName()); | 746 f->Print("_ %s:%d ", DebugName(), cid()); |
| 722 exception()->PrintTo(f); | 747 exception()->PrintTo(f); |
| 723 f->Print(", "); | 748 f->Print(", "); |
| 724 stack_trace()->PrintTo(f); | 749 stack_trace()->PrintTo(f); |
| 725 } | 750 } |
| 726 | 751 |
| 727 | 752 |
| 728 void GotoInstr::PrintToVisualizer(BufferFormatter* f) const { | 753 void GotoInstr::PrintToVisualizer(BufferFormatter* f) const { |
| 729 f->Print("_ goto B%d", successor()->block_id()); | 754 f->Print("_ goto B%d", successor()->block_id()); |
| 730 } | 755 } |
| 731 | 756 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 755 if ((i < locations_.length()) && !locations_[i].IsInvalid()) { | 780 if ((i < locations_.length()) && !locations_[i].IsInvalid()) { |
| 756 f->Print(" ["); | 781 f->Print(" ["); |
| 757 locations_[i].PrintTo(f); | 782 locations_[i].PrintTo(f); |
| 758 f->Print("]"); | 783 f->Print("]"); |
| 759 } | 784 } |
| 760 } | 785 } |
| 761 f->Print(" }"); | 786 f->Print(" }"); |
| 762 } | 787 } |
| 763 | 788 |
| 764 } // namespace dart | 789 } // namespace dart |
| OLD | NEW |