| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 OS::Print("%s", str); | 81 OS::Print("%s", str); |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 |
| 85 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, | 85 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, |
| 86 intptr_t token_pos, | 86 intptr_t token_pos, |
| 87 Value* value, | 87 Value* value, |
| 88 const AbstractType& dst_type, | 88 const AbstractType& dst_type, |
| 89 const String& dst_name, | 89 const String& dst_name, |
| 90 bool eliminated) { | 90 bool eliminated) { |
| 91 const Script& script = Script::Handle(parsed_function.function().script()); |
| 91 const char* compile_type_name = "unknown"; | 92 const char* compile_type_name = "unknown"; |
| 92 if (value != NULL) { | 93 if (value != NULL) { |
| 93 compile_type_name = value->Type()->ToCString(); | 94 const AbstractType& type = AbstractType::Handle(value->CompileType()); |
| 95 if (!type.IsNull()) { |
| 96 compile_type_name = String::Handle(type.Name()).ToCString(); |
| 97 } |
| 94 } | 98 } |
| 95 OS::Print("%s type check: compile type %s is %s specific than " | 99 Parser::PrintMessage(script, token_pos, "", |
| 96 "type '%s' of '%s'.\n", | 100 "%s type check: compile type '%s' is %s specific than " |
| 101 "type '%s' of '%s'.", |
| 97 eliminated ? "Eliminated" : "Generated", | 102 eliminated ? "Eliminated" : "Generated", |
| 98 compile_type_name, | 103 compile_type_name, |
| 99 eliminated ? "more" : "not more", | 104 eliminated ? "more" : "not more", |
| 100 String::Handle(dst_type.Name()).ToCString(), | 105 String::Handle(dst_type.Name()).ToCString(), |
| 101 dst_name.ToCString()); | 106 dst_name.ToCString()); |
| 102 } | 107 } |
| 103 | 108 |
| 104 | 109 |
| 105 void CompileType::PrintTo(BufferFormatter* f) const { | |
| 106 f->Print("T{"); | |
| 107 f->Print("%s, ", is_nullable_ ? "null" : "not-null"); | |
| 108 if (cid_ != kIllegalCid) { | |
| 109 const Class& cls = | |
| 110 Class::Handle(Isolate::Current()->class_table()->At(cid_)); | |
| 111 f->Print("%s, ", String::Handle(cls.Name()).ToCString()); | |
| 112 } else { | |
| 113 f->Print("?, "); | |
| 114 } | |
| 115 f->Print("%s}", (type_ != NULL) ? String::Handle(type_->Name()).ToCString() | |
| 116 : "?"); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 const char* CompileType::ToCString() const { | |
| 121 char buffer[1024]; | |
| 122 BufferFormatter f(buffer, sizeof(buffer)); | |
| 123 PrintTo(&f); | |
| 124 return Isolate::Current()->current_zone()->MakeCopyOfString(buffer); | |
| 125 } | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 static void PrintICData(BufferFormatter* f, const ICData& ic_data) { | 110 static void PrintICData(BufferFormatter* f, const ICData& ic_data) { |
| 131 f->Print(" IC[%"Pd": ", ic_data.NumberOfChecks()); | 111 f->Print(" IC[%"Pd": ", ic_data.NumberOfChecks()); |
| 132 Function& target = Function::Handle(); | 112 Function& target = Function::Handle(); |
| 133 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { | 113 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { |
| 134 GrowableArray<intptr_t> class_ids; | 114 GrowableArray<intptr_t> class_ids; |
| 135 ic_data.GetCheckAt(i, &class_ids, &target); | 115 ic_data.GetCheckAt(i, &class_ids, &target); |
| 136 const intptr_t count = ic_data.GetCountAt(i); | 116 const intptr_t count = ic_data.GetCountAt(i); |
| 137 if (i > 0) { | 117 if (i > 0) { |
| 138 f->Print(" | "); | 118 f->Print(" | "); |
| 139 } | 119 } |
| 140 for (intptr_t k = 0; k < class_ids.length(); k++) { | 120 for (intptr_t k = 0; k < class_ids.length(); k++) { |
| 141 if (k > 0) { | 121 if (k > 0) { |
| 142 f->Print(", "); | 122 f->Print(", "); |
| 143 } | 123 } |
| 144 const Class& cls = | 124 const Class& cls = |
| 145 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); | 125 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); |
| 146 f->Print("%s", String::Handle(cls.Name()).ToCString()); | 126 f->Print("%s", String::Handle(cls.Name()).ToCString()); |
| 147 } | 127 } |
| 148 if (count > 0) { | 128 if (count > 0) { |
| 149 f->Print(" #%"Pd, count); | 129 f->Print(" #%"Pd, count); |
| 150 } | 130 } |
| 151 f->Print(" <%p>", static_cast<void*>(target.raw())); | 131 f->Print(" <%p>", static_cast<void*>(target.raw())); |
| 152 } | 132 } |
| 153 f->Print("]"); | 133 f->Print("]"); |
| 154 } | 134 } |
| 155 | 135 |
| 156 | 136 |
| 137 static void PrintPropagatedType(BufferFormatter* f, const Definition& def) { |
| 138 if (def.HasPropagatedType()) { |
| 139 String& name = String::Handle(); |
| 140 name = AbstractType::Handle(def.PropagatedType()).Name(); |
| 141 f->Print(" {PT: %s}", name.ToCString()); |
| 142 } |
| 143 if (def.has_propagated_cid()) { |
| 144 const Class& cls = Class::Handle( |
| 145 Isolate::Current()->class_table()->At(def.propagated_cid())); |
| 146 f->Print(" {PCid: %s}", String::Handle(cls.Name()).ToCString()); |
| 147 } |
| 148 } |
| 149 |
| 150 |
| 157 static void PrintUse(BufferFormatter* f, const Definition& definition) { | 151 static void PrintUse(BufferFormatter* f, const Definition& definition) { |
| 158 if (definition.is_used()) { | 152 if (definition.is_used()) { |
| 159 if (definition.HasSSATemp()) { | 153 if (definition.HasSSATemp()) { |
| 160 f->Print("v%"Pd, definition.ssa_temp_index()); | 154 f->Print("v%"Pd, definition.ssa_temp_index()); |
| 161 } else if (definition.temp_index() != -1) { | 155 } else if (definition.temp_index() != -1) { |
| 162 f->Print("t%"Pd, definition.temp_index()); | 156 f->Print("t%"Pd, definition.temp_index()); |
| 163 } | 157 } |
| 164 } | 158 } |
| 165 } | 159 } |
| 166 | 160 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 181 | 175 |
| 182 | 176 |
| 183 void Definition::PrintTo(BufferFormatter* f) const { | 177 void Definition::PrintTo(BufferFormatter* f) const { |
| 184 PrintUse(f, *this); | 178 PrintUse(f, *this); |
| 185 if (is_used()) { | 179 if (is_used()) { |
| 186 if (HasSSATemp() || (temp_index() != -1)) f->Print(" <- "); | 180 if (HasSSATemp() || (temp_index() != -1)) f->Print(" <- "); |
| 187 } | 181 } |
| 188 f->Print("%s:%"Pd"(", DebugName(), GetDeoptId()); | 182 f->Print("%s:%"Pd"(", DebugName(), GetDeoptId()); |
| 189 PrintOperandsTo(f); | 183 PrintOperandsTo(f); |
| 190 f->Print(")"); | 184 f->Print(")"); |
| 185 PrintPropagatedType(f, *this); |
| 191 if (range_ != NULL) { | 186 if (range_ != NULL) { |
| 192 f->Print(" "); | 187 f->Print(" "); |
| 193 range_->PrintTo(f); | 188 range_->PrintTo(f); |
| 194 } | 189 } |
| 195 | |
| 196 if (type_ != NULL) { | |
| 197 f->Print(" "); | |
| 198 type_->PrintTo(f); | |
| 199 } | |
| 200 } | 190 } |
| 201 | 191 |
| 202 | 192 |
| 203 void Definition::PrintOperandsTo(BufferFormatter* f) const { | 193 void Definition::PrintOperandsTo(BufferFormatter* f) const { |
| 204 for (int i = 0; i < InputCount(); ++i) { | 194 for (int i = 0; i < InputCount(); ++i) { |
| 205 if (i > 0) f->Print(", "); | 195 if (i > 0) f->Print(", "); |
| 206 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); | 196 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); |
| 207 } | 197 } |
| 208 } | 198 } |
| 209 | 199 |
| 210 | 200 |
| 211 void Value::PrintTo(BufferFormatter* f) const { | 201 void Value::PrintTo(BufferFormatter* f) const { |
| 212 PrintUse(f, *definition()); | 202 PrintUse(f, *definition()); |
| 213 if ((reaching_type_ != NULL) && | |
| 214 (reaching_type_ != definition()->Type())) { | |
| 215 f->Print(" "); | |
| 216 reaching_type_->PrintTo(f); | |
| 217 } | |
| 218 } | 203 } |
| 219 | 204 |
| 220 | 205 |
| 221 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { | 206 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { |
| 222 const char* cstr = value().ToCString(); | 207 const char* cstr = value().ToCString(); |
| 223 const char* new_line = strchr(cstr, '\n'); | 208 const char* new_line = strchr(cstr, '\n'); |
| 224 if (new_line == NULL) { | 209 if (new_line == NULL) { |
| 225 f->Print("#%s", cstr); | 210 f->Print("#%s", cstr); |
| 226 } else { | 211 } else { |
| 227 const intptr_t pos = new_line - cstr; | 212 const intptr_t pos = new_line - cstr; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 const char* RangeBoundary::ToCString() const { | 269 const char* RangeBoundary::ToCString() const { |
| 285 char buffer[256]; | 270 char buffer[256]; |
| 286 BufferFormatter f(buffer, sizeof(buffer)); | 271 BufferFormatter f(buffer, sizeof(buffer)); |
| 287 PrintTo(&f); | 272 PrintTo(&f); |
| 288 return Isolate::Current()->current_zone()->MakeCopyOfString(buffer); | 273 return Isolate::Current()->current_zone()->MakeCopyOfString(buffer); |
| 289 } | 274 } |
| 290 | 275 |
| 291 | 276 |
| 292 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { | 277 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { |
| 293 value()->PrintTo(f); | 278 value()->PrintTo(f); |
| 294 f->Print(", %s, '%s'", | 279 f->Print(", %s, '%s'%s", |
| 295 dst_type().ToCString(), | 280 String::Handle(dst_type().Name()).ToCString(), |
| 296 dst_name().ToCString()); | 281 dst_name().ToCString(), |
| 282 is_eliminated() ? " eliminated" : ""); |
| 297 f->Print(" instantiator("); | 283 f->Print(" instantiator("); |
| 298 instantiator()->PrintTo(f); | 284 instantiator()->PrintTo(f); |
| 299 f->Print(")"); | 285 f->Print(")"); |
| 300 f->Print(" instantiator_type_arguments("); | 286 f->Print(" instantiator_type_arguments("); |
| 301 instantiator_type_arguments()->PrintTo(f); | 287 instantiator_type_arguments()->PrintTo(f); |
| 302 f->Print(")"); | 288 f->Print(")"); |
| 303 } | 289 } |
| 304 | 290 |
| 305 | 291 |
| 306 void AssertBooleanInstr::PrintOperandsTo(BufferFormatter* f) const { | 292 void AssertBooleanInstr::PrintOperandsTo(BufferFormatter* f) const { |
| 307 value()->PrintTo(f); | 293 value()->PrintTo(f); |
| 294 f->Print("%s", is_eliminated() ? " eliminated" : ""); |
| 308 } | 295 } |
| 309 | 296 |
| 310 | 297 |
| 311 void ArgumentDefinitionTestInstr::PrintOperandsTo(BufferFormatter* f) const { | 298 void ArgumentDefinitionTestInstr::PrintOperandsTo(BufferFormatter* f) const { |
| 312 saved_arguments_descriptor()->PrintTo(f); | 299 saved_arguments_descriptor()->PrintTo(f); |
| 313 f->Print(", ?%s @%"Pd"", | 300 f->Print(", ?%s @%"Pd"", |
| 314 formal_parameter_name().ToCString(), | 301 formal_parameter_name().ToCString(), |
| 315 formal_parameter_index()); | 302 formal_parameter_index()); |
| 316 } | 303 } |
| 317 | 304 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 } | 600 } |
| 614 | 601 |
| 615 | 602 |
| 616 void PhiInstr::PrintTo(BufferFormatter* f) const { | 603 void PhiInstr::PrintTo(BufferFormatter* f) const { |
| 617 f->Print("v%"Pd" <- phi(", ssa_temp_index()); | 604 f->Print("v%"Pd" <- phi(", ssa_temp_index()); |
| 618 for (intptr_t i = 0; i < inputs_.length(); ++i) { | 605 for (intptr_t i = 0; i < inputs_.length(); ++i) { |
| 619 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); | 606 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); |
| 620 if (i < inputs_.length() - 1) f->Print(", "); | 607 if (i < inputs_.length() - 1) f->Print(", "); |
| 621 } | 608 } |
| 622 f->Print(")"); | 609 f->Print(")"); |
| 610 PrintPropagatedType(f, *this); |
| 623 if (is_alive()) { | 611 if (is_alive()) { |
| 624 f->Print(" alive"); | 612 f->Print(" alive"); |
| 625 } else { | 613 } else { |
| 626 f->Print(" dead"); | 614 f->Print(" dead"); |
| 627 } | 615 } |
| 628 if (range_ != NULL) { | 616 if (range_ != NULL) { |
| 629 f->Print(" "); | 617 f->Print(" "); |
| 630 range_->PrintTo(f); | 618 range_->PrintTo(f); |
| 631 } | 619 } |
| 632 if (type_ != NULL) { | |
| 633 f->Print(" "); | |
| 634 type_->PrintTo(f); | |
| 635 } | |
| 636 } | 620 } |
| 637 | 621 |
| 638 | 622 |
| 639 void ParameterInstr::PrintOperandsTo(BufferFormatter* f) const { | 623 void ParameterInstr::PrintOperandsTo(BufferFormatter* f) const { |
| 640 f->Print("%"Pd, index()); | 624 f->Print("%"Pd, index()); |
| 641 } | 625 } |
| 642 | 626 |
| 643 | 627 |
| 644 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { | 628 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { |
| 645 f->Print("B%"Pd"[target", block_id()); | 629 f->Print("B%"Pd"[target", block_id()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 f->Print(" ["); | 689 f->Print(" ["); |
| 706 locations_[i].PrintTo(f); | 690 locations_[i].PrintTo(f); |
| 707 f->Print("]"); | 691 f->Print("]"); |
| 708 } | 692 } |
| 709 } | 693 } |
| 710 f->Print(" }"); | 694 f->Print(" }"); |
| 711 if (outer_ != NULL) outer_->PrintTo(f); | 695 if (outer_ != NULL) outer_->PrintTo(f); |
| 712 } | 696 } |
| 713 | 697 |
| 714 } // namespace dart | 698 } // namespace dart |
| OLD | NEW |