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 #include "vm/parser.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 instr->PrintTo(&f); | 70 instr->PrintTo(&f); |
71 if (FLAG_print_environments && (instr->env() != NULL)) { | 71 if (FLAG_print_environments && (instr->env() != NULL)) { |
72 instr->env()->PrintTo(&f); | 72 instr->env()->PrintTo(&f); |
73 } | 73 } |
74 if (print_locations && (instr->locs() != NULL)) { | 74 if (print_locations && (instr->locs() != NULL)) { |
75 instr->locs()->PrintTo(&f); | 75 instr->locs()->PrintTo(&f); |
76 } | 76 } |
77 if (instr->lifetime_position() != -1) { | 77 if (instr->lifetime_position() != -1) { |
78 OS::Print("%3"Pd": ", instr->lifetime_position()); | 78 OS::Print("%3"Pd": ", instr->lifetime_position()); |
79 } | 79 } |
80 if (!instr->IsBlockEntry()) OS::Print(" "); | |
81 OS::Print("%s", str); | 80 OS::Print("%s", str); |
82 } | 81 } |
83 | 82 |
84 | 83 |
85 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, | 84 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, |
86 intptr_t token_pos, | 85 intptr_t token_pos, |
87 Value* value, | 86 Value* value, |
88 const AbstractType& dst_type, | 87 const AbstractType& dst_type, |
89 const String& dst_name, | 88 const String& dst_name, |
90 bool eliminated) { | 89 bool eliminated) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 121 } |
123 const Class& cls = | 122 const Class& cls = |
124 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); | 123 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); |
125 f->Print("%s", String::Handle(cls.Name()).ToCString()); | 124 f->Print("%s", String::Handle(cls.Name()).ToCString()); |
126 } | 125 } |
127 } | 126 } |
128 f->Print("]"); | 127 f->Print("]"); |
129 } | 128 } |
130 | 129 |
131 | 130 |
132 static void PrintPropagatedType(BufferFormatter* f, const Definition& def) { | |
133 if (def.HasPropagatedType()) { | |
134 String& name = String::Handle(); | |
135 name = AbstractType::Handle(def.PropagatedType()).Name(); | |
136 f->Print(" {PT: %s}", name.ToCString()); | |
137 } | |
138 if (def.has_propagated_cid()) { | |
139 const Class& cls = Class::Handle( | |
140 Isolate::Current()->class_table()->At(def.propagated_cid())); | |
141 f->Print(" {PCid: %s}", String::Handle(cls.Name()).ToCString()); | |
142 } | |
143 } | |
144 | |
145 | |
146 static void PrintUse(BufferFormatter* f, const Definition& definition) { | |
147 if (definition.is_used()) { | |
148 if (definition.HasSSATemp()) { | |
149 f->Print("v%"Pd, definition.ssa_temp_index()); | |
150 } else if (definition.temp_index() != -1) { | |
151 f->Print("t%"Pd, definition.temp_index()); | |
152 } | |
153 } | |
154 } | |
155 | |
156 | |
157 void Definition::PrintTo(BufferFormatter* f) const { | 131 void Definition::PrintTo(BufferFormatter* f) const { |
158 PrintUse(f, *this); | 132 // Do not access 'deopt_id()' as it asserts that the computation can |
159 if (is_used()) { | 133 // deoptimize. |
160 if (HasSSATemp() || (temp_index() != -1)) f->Print(" <- "); | 134 if (HasSSATemp()) { |
| 135 f->Print("v%"Pd" <- ", ssa_temp_index()); |
161 } | 136 } |
162 f->Print("%s:%"Pd"(", DebugName(), GetDeoptId()); | 137 f->Print("%s:%"Pd"(", DebugName(), deopt_id_); |
163 PrintOperandsTo(f); | 138 PrintOperandsTo(f); |
164 f->Print(")"); | 139 f->Print(")"); |
165 PrintPropagatedType(f, *this); | |
166 } | 140 } |
167 | 141 |
168 | 142 |
169 void Definition::PrintOperandsTo(BufferFormatter* f) const { | 143 void Definition::PrintOperandsTo(BufferFormatter* f) const { |
170 for (int i = 0; i < InputCount(); ++i) { | 144 for (int i = 0; i < InputCount(); ++i) { |
171 if (i > 0) f->Print(", "); | 145 if (i > 0) f->Print(", "); |
172 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); | 146 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); |
173 } | 147 } |
174 } | 148 } |
175 | 149 |
176 | 150 |
177 void Definition::PrintToVisualizer(BufferFormatter* f) const { | 151 void Definition::PrintToVisualizer(BufferFormatter* f) const { |
178 PrintTo(f); | 152 PrintTo(f); |
179 } | 153 } |
180 | 154 |
181 | 155 |
182 void Value::PrintTo(BufferFormatter* f) const { | 156 void Value::PrintTo(BufferFormatter* f) const { |
183 PrintUse(f, *definition()); | 157 if (definition()->HasSSATemp()) { |
| 158 f->Print("v%"Pd"", definition()->ssa_temp_index()); |
| 159 } else { |
| 160 f->Print("t%"Pd"", definition()->temp_index()); |
| 161 } |
184 } | 162 } |
185 | 163 |
186 | 164 |
187 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { | 165 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { |
188 f->Print("#%s", value().ToCString()); | 166 f->Print("#%s", value().ToCString()); |
189 } | 167 } |
190 | 168 |
191 | 169 |
192 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { | 170 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { |
193 value()->PrintTo(f); | 171 value()->PrintTo(f); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 for (intptr_t i = 0; i < ArgumentCount(); ++i) { | 209 for (intptr_t i = 0; i < ArgumentCount(); ++i) { |
232 f->Print(", "); | 210 f->Print(", "); |
233 ArgumentAt(i)->value()->PrintTo(f); | 211 ArgumentAt(i)->value()->PrintTo(f); |
234 } | 212 } |
235 if (HasICData()) { | 213 if (HasICData()) { |
236 PrintICData(f, *ic_data()); | 214 PrintICData(f, *ic_data()); |
237 } | 215 } |
238 } | 216 } |
239 | 217 |
240 | 218 |
241 void PolymorphicInstanceCallInstr::PrintOperandsTo(BufferFormatter* f) const { | 219 void PolymorphicInstanceCallInstr::PrintTo(BufferFormatter* f) const { |
| 220 f->Print("%s(", DebugName()); |
242 instance_call()->PrintOperandsTo(f); | 221 instance_call()->PrintOperandsTo(f); |
| 222 f->Print(") "); |
243 PrintICData(f, ic_data()); | 223 PrintICData(f, ic_data()); |
244 } | 224 } |
245 | 225 |
246 | 226 |
247 void StrictCompareInstr::PrintOperandsTo(BufferFormatter* f) const { | 227 void StrictCompareInstr::PrintOperandsTo(BufferFormatter* f) const { |
248 f->Print("%s, ", Token::Str(kind())); | 228 f->Print("%s, ", Token::Str(kind())); |
249 left()->PrintTo(f); | 229 left()->PrintTo(f); |
250 f->Print(", "); | 230 f->Print(", "); |
251 right()->PrintTo(f); | 231 right()->PrintTo(f); |
252 } | 232 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 426 } |
447 | 427 |
448 | 428 |
449 void CheckClassInstr::PrintOperandsTo(BufferFormatter* f) const { | 429 void CheckClassInstr::PrintOperandsTo(BufferFormatter* f) const { |
450 value()->PrintTo(f); | 430 value()->PrintTo(f); |
451 PrintICData(f, unary_checks()); | 431 PrintICData(f, unary_checks()); |
452 } | 432 } |
453 | 433 |
454 | 434 |
455 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { | 435 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { |
456 f->Print("B%"Pd"[graph]", block_id()); | 436 f->Print("%2"Pd": [graph]", block_id()); |
457 if ((constant_null() != NULL) || (start_env() != NULL)) { | 437 if (start_env_ != NULL) { |
458 f->Print(" {"); | 438 f->Print("\n{\n"); |
459 if (constant_null() != NULL) { | 439 const GrowableArray<Value*>& values = start_env_->values(); |
460 f->Print("\n "); | 440 for (intptr_t i = 0; i < values.length(); i++) { |
461 constant_null()->PrintTo(f); | 441 Definition* def = values[i]->definition(); |
| 442 f->Print(" "); |
| 443 def->PrintTo(f); |
| 444 f->Print("\n"); |
462 } | 445 } |
463 if (start_env() != NULL) { | 446 f->Print("} "); |
464 for (intptr_t i = 0; i < start_env()->values().length(); ++i) { | 447 start_env_->PrintTo(f); |
465 Definition* def = start_env()->values()[i]->definition(); | |
466 if (def->IsParameter()) { | |
467 f->Print("\n "); | |
468 def->PrintTo(f); | |
469 } | |
470 } | |
471 } | |
472 f->Print("\n}"); | |
473 } | 448 } |
474 } | 449 } |
475 | 450 |
476 | 451 |
477 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { | 452 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { |
478 f->Print("B%"Pd"[join]", block_id()); | 453 f->Print("%2"Pd": [join]", block_id()); |
479 if (phis_ != NULL) { | 454 if (phis_ != NULL) { |
480 f->Print(" {"); | |
481 for (intptr_t i = 0; i < phis_->length(); ++i) { | 455 for (intptr_t i = 0; i < phis_->length(); ++i) { |
482 if ((*phis_)[i] == NULL) continue; | 456 if ((*phis_)[i] == NULL) continue; |
483 f->Print("\n "); | 457 f->Print("\n"); |
484 (*phis_)[i]->PrintTo(f); | 458 (*phis_)[i]->PrintTo(f); |
485 } | 459 } |
486 f->Print("\n}"); | |
487 } | 460 } |
488 if (HasParallelMove()) { | 461 if (HasParallelMove()) { |
489 f->Print(" "); | 462 f->Print("\n"); |
490 parallel_move()->PrintTo(f); | 463 parallel_move()->PrintTo(f); |
491 } | 464 } |
492 } | 465 } |
493 | 466 |
494 | 467 |
| 468 static void PrintPropagatedType(BufferFormatter* f, const Definition& def) { |
| 469 if (def.HasPropagatedType()) { |
| 470 String& name = String::Handle(); |
| 471 name = AbstractType::Handle(def.PropagatedType()).Name(); |
| 472 f->Print(" {PT: %s}", name.ToCString()); |
| 473 } |
| 474 if (def.has_propagated_cid()) { |
| 475 const Class& cls = Class::Handle( |
| 476 Isolate::Current()->class_table()->At(def.propagated_cid())); |
| 477 f->Print(" {PCid: %s}", String::Handle(cls.Name()).ToCString()); |
| 478 } |
| 479 } |
| 480 |
| 481 |
495 void PhiInstr::PrintTo(BufferFormatter* f) const { | 482 void PhiInstr::PrintTo(BufferFormatter* f) const { |
496 f->Print("v%"Pd" <- phi(", ssa_temp_index()); | 483 f->Print(" v%"Pd" <- phi(", ssa_temp_index()); |
497 for (intptr_t i = 0; i < inputs_.length(); ++i) { | 484 for (intptr_t i = 0; i < inputs_.length(); ++i) { |
498 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); | 485 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); |
499 if (i < inputs_.length() - 1) f->Print(", "); | 486 if (i < inputs_.length() - 1) f->Print(", "); |
500 } | 487 } |
501 f->Print(")"); | 488 f->Print(")"); |
502 PrintPropagatedType(f, *this); | 489 PrintPropagatedType(f, *this); |
503 } | 490 } |
504 | 491 |
505 | 492 |
506 void ParameterInstr::PrintOperandsTo(BufferFormatter* f) const { | 493 void ParameterInstr::PrintTo(BufferFormatter* f) const { |
507 f->Print("%"Pd, index()); | 494 f->Print(" v%"Pd" <- parameter(%"Pd")", |
| 495 HasSSATemp() ? ssa_temp_index() : temp_index(), |
| 496 index()); |
| 497 PrintPropagatedType(f, *this); |
508 } | 498 } |
509 | 499 |
510 | 500 |
511 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { | 501 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { |
512 f->Print("B%"Pd"[target", block_id()); | 502 f->Print("%2"Pd": [target", block_id()); |
513 if (IsCatchEntry()) { | 503 if (IsCatchEntry()) { |
514 f->Print(" catch %"Pd"]", catch_try_index()); | 504 f->Print(" catch %"Pd"]", catch_try_index()); |
515 } else { | 505 } else { |
516 f->Print("]"); | 506 f->Print("]"); |
517 } | 507 } |
518 if (HasParallelMove()) { | 508 if (HasParallelMove()) { |
519 f->Print(" "); | 509 f->Print("\n"); |
520 parallel_move()->PrintTo(f); | 510 parallel_move()->PrintTo(f); |
521 } | 511 } |
522 } | 512 } |
523 | 513 |
524 | 514 |
525 void PushArgumentInstr::PrintOperandsTo(BufferFormatter* f) const { | 515 void PushArgumentInstr::PrintTo(BufferFormatter* f) const { |
| 516 f->Print(" %s ", DebugName()); |
526 value()->PrintTo(f); | 517 value()->PrintTo(f); |
527 } | 518 } |
528 | 519 |
529 | 520 |
530 void ReturnInstr::PrintTo(BufferFormatter* f) const { | 521 void ReturnInstr::PrintTo(BufferFormatter* f) const { |
531 f->Print("%s ", DebugName()); | 522 f->Print(" %s ", DebugName()); |
532 value()->PrintTo(f); | 523 value()->PrintTo(f); |
533 } | 524 } |
534 | 525 |
535 | 526 |
536 void ThrowInstr::PrintTo(BufferFormatter* f) const { | 527 void ThrowInstr::PrintTo(BufferFormatter* f) const { |
537 f->Print("%s" , DebugName()); | 528 f->Print(" %s" , DebugName()); |
538 } | 529 } |
539 | 530 |
540 | 531 |
541 void ReThrowInstr::PrintTo(BufferFormatter* f) const { | 532 void ReThrowInstr::PrintTo(BufferFormatter* f) const { |
542 f->Print("%s ", DebugName()); | 533 f->Print(" %s ", DebugName()); |
543 } | 534 } |
544 | 535 |
545 | 536 |
546 void GotoInstr::PrintTo(BufferFormatter* f) const { | 537 void GotoInstr::PrintTo(BufferFormatter* f) const { |
547 if (HasParallelMove()) { | 538 if (HasParallelMove()) { |
548 parallel_move()->PrintTo(f); | 539 parallel_move()->PrintTo(f); |
549 f->Print(" "); | 540 } else { |
| 541 f->Print(" "); |
550 } | 542 } |
551 f->Print("goto:%"Pd" %"Pd"", GetDeoptId(), successor()->block_id()); | 543 f->Print(" goto:%"Pd" %"Pd"", GetDeoptId(), successor()->block_id()); |
552 } | 544 } |
553 | 545 |
554 | 546 |
555 void BranchInstr::PrintTo(BufferFormatter* f) const { | 547 void BranchInstr::PrintTo(BufferFormatter* f) const { |
556 f->Print("%s ", DebugName()); | 548 f->Print(" %s ", DebugName()); |
557 f->Print("if "); | 549 f->Print("if "); |
558 comparison()->PrintTo(f); | 550 comparison()->PrintTo(f); |
559 | 551 |
560 f->Print(" goto (%"Pd", %"Pd")", | 552 f->Print(" goto (%"Pd", %"Pd")", |
561 true_successor()->block_id(), | 553 true_successor()->block_id(), |
562 false_successor()->block_id()); | 554 false_successor()->block_id()); |
563 } | 555 } |
564 | 556 |
565 | 557 |
566 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { | 558 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { |
567 f->Print("%s ", DebugName()); | 559 f->Print(" %s ", DebugName()); |
568 for (intptr_t i = 0; i < moves_.length(); i++) { | 560 for (intptr_t i = 0; i < moves_.length(); i++) { |
569 if (i != 0) f->Print(", "); | 561 if (i != 0) f->Print(", "); |
570 moves_[i]->dest().PrintTo(f); | 562 moves_[i]->dest().PrintTo(f); |
571 f->Print(" <- "); | 563 f->Print(" <- "); |
572 moves_[i]->src().PrintTo(f); | 564 moves_[i]->src().PrintTo(f); |
573 } | 565 } |
574 } | 566 } |
575 | 567 |
576 | 568 |
577 void FlowGraphVisualizer::Print(const char* format, ...) { | 569 void FlowGraphVisualizer::Print(const char* format, ...) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 if ((locations_ != NULL) && !locations_[i].IsInvalid()) { | 792 if ((locations_ != NULL) && !locations_[i].IsInvalid()) { |
801 f->Print(" ["); | 793 f->Print(" ["); |
802 locations_[i].PrintTo(f); | 794 locations_[i].PrintTo(f); |
803 f->Print("]"); | 795 f->Print("]"); |
804 } | 796 } |
805 } | 797 } |
806 f->Print(" }"); | 798 f->Print(" }"); |
807 } | 799 } |
808 | 800 |
809 } // namespace dart | 801 } // namespace dart |
OLD | NEW |