| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/il_printer.h" |
| 6 |
| 7 #include "vm/intermediate_language.h" |
| 8 #include "vm/os.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 |
| 13 void FlowGraphPrinter::VisitBlocks() { |
| 14 OS::Print("==== %s\n", function_.ToFullyQualifiedCString()); |
| 15 |
| 16 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 17 // Print the block entry. |
| 18 Instruction* current = block_order_[i]->Accept(this); |
| 19 // And all the successors until an exit, branch, or a block entry. |
| 20 while ((current != NULL) && !current->IsBlockEntry()) { |
| 21 OS::Print("\n"); |
| 22 current = current->Accept(this); |
| 23 } |
| 24 BlockEntryInstr* successor = |
| 25 (current == NULL) ? NULL : current->AsBlockEntry(); |
| 26 if (successor != NULL) { |
| 27 // For readability label blocks with their reverse postorder index, |
| 28 // not their postorder block number, so the first block is 0 (not |
| 29 // n-1). |
| 30 OS::Print(" goto %d", reverse_index(successor->postorder_number())); |
| 31 } |
| 32 OS::Print("\n"); |
| 33 } |
| 34 } |
| 35 |
| 36 |
| 37 void FlowGraphPrinter::VisitUse(UseVal* val) { |
| 38 OS::Print("t%d", val->definition()->temp_index()); |
| 39 } |
| 40 |
| 41 |
| 42 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { |
| 43 OS::Print("#%s", val->value().ToCString()); |
| 44 } |
| 45 |
| 46 |
| 47 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { |
| 48 OS::Print("AssertAssignable("); |
| 49 comp->value()->Accept(this); |
| 50 OS::Print(", %s, '%s'", |
| 51 String::Handle(comp->dst_type().Name()).ToCString(), |
| 52 comp->dst_name().ToCString()); |
| 53 if (comp->instantiator_type_arguments() != NULL) { |
| 54 OS::Print(" (instantiator:"); |
| 55 comp->instantiator_type_arguments()->Accept(this); |
| 56 } |
| 57 OS::Print(")"); |
| 58 } |
| 59 |
| 60 |
| 61 void FlowGraphPrinter::VisitAssertBoolean(AssertBooleanComp* comp) { |
| 62 OS::Print("AssertBoolean("); |
| 63 comp->value()->Accept(this); |
| 64 OS::Print(")"); |
| 65 } |
| 66 |
| 67 |
| 68 void FlowGraphPrinter::VisitCurrentContext(CurrentContextComp* comp) { |
| 69 OS::Print("CurrentContext"); |
| 70 } |
| 71 |
| 72 |
| 73 void FlowGraphPrinter::VisitClosureCall(ClosureCallComp* comp) { |
| 74 OS::Print("ClosureCall("); |
| 75 comp->context()->Accept(this); |
| 76 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { |
| 77 OS::Print(", "); |
| 78 comp->ArgumentAt(i)->Accept(this); |
| 79 } |
| 80 OS::Print(")"); |
| 81 } |
| 82 |
| 83 |
| 84 void FlowGraphPrinter::VisitInstanceCall(InstanceCallComp* comp) { |
| 85 OS::Print("InstanceCall(%s", comp->function_name().ToCString()); |
| 86 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { |
| 87 OS::Print(", "); |
| 88 comp->ArgumentAt(i)->Accept(this); |
| 89 } |
| 90 OS::Print(")"); |
| 91 } |
| 92 |
| 93 |
| 94 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) { |
| 95 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind())); |
| 96 comp->left()->Accept(this); |
| 97 OS::Print(", "); |
| 98 comp->right()->Accept(this); |
| 99 OS::Print(")"); |
| 100 } |
| 101 |
| 102 |
| 103 void FlowGraphPrinter::VisitEqualityCompare(EqualityCompareComp* comp) { |
| 104 comp->left()->Accept(this); |
| 105 OS::Print(" == "); |
| 106 comp->right()->Accept(this); |
| 107 } |
| 108 |
| 109 |
| 110 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) { |
| 111 OS::Print("StaticCall(%s", |
| 112 String::Handle(comp->function().name()).ToCString()); |
| 113 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { |
| 114 OS::Print(", "); |
| 115 comp->ArgumentAt(i)->Accept(this); |
| 116 } |
| 117 OS::Print(")"); |
| 118 } |
| 119 |
| 120 |
| 121 void FlowGraphPrinter::VisitLoadLocal(LoadLocalComp* comp) { |
| 122 OS::Print("LoadLocal(%s lvl:%d)", |
| 123 comp->local().name().ToCString(), comp->context_level()); |
| 124 } |
| 125 |
| 126 |
| 127 void FlowGraphPrinter::VisitStoreLocal(StoreLocalComp* comp) { |
| 128 OS::Print("StoreLocal(%s, ", comp->local().name().ToCString()); |
| 129 comp->value()->Accept(this); |
| 130 OS::Print(", lvl: %d)", comp->context_level()); |
| 131 } |
| 132 |
| 133 |
| 134 void FlowGraphPrinter::VisitNativeCall(NativeCallComp* comp) { |
| 135 OS::Print("NativeCall(%s)", comp->native_name().ToCString()); |
| 136 } |
| 137 |
| 138 |
| 139 void FlowGraphPrinter::VisitLoadInstanceField(LoadInstanceFieldComp* comp) { |
| 140 OS::Print("LoadInstanceField(%s, ", |
| 141 String::Handle(comp->field().name()).ToCString()); |
| 142 comp->instance()->Accept(this); |
| 143 OS::Print(")"); |
| 144 } |
| 145 |
| 146 |
| 147 void FlowGraphPrinter::VisitStoreInstanceField(StoreInstanceFieldComp* comp) { |
| 148 OS::Print("StoreInstanceField(%s, ", |
| 149 String::Handle(comp->field().name()).ToCString()); |
| 150 comp->instance()->Accept(this); |
| 151 OS::Print(", "); |
| 152 comp->value()->Accept(this); |
| 153 OS::Print(")"); |
| 154 } |
| 155 |
| 156 |
| 157 void FlowGraphPrinter::VisitLoadStaticField(LoadStaticFieldComp* comp) { |
| 158 OS::Print("LoadStaticField(%s)", |
| 159 String::Handle(comp->field().name()).ToCString()); |
| 160 } |
| 161 |
| 162 |
| 163 void FlowGraphPrinter::VisitStoreStaticField(StoreStaticFieldComp* comp) { |
| 164 OS::Print("StoreStaticField(%s, ", |
| 165 String::Handle(comp->field().name()).ToCString()); |
| 166 comp->value()->Accept(this); |
| 167 OS::Print(")"); |
| 168 } |
| 169 |
| 170 |
| 171 void FlowGraphPrinter::VisitStoreIndexed(StoreIndexedComp* comp) { |
| 172 OS::Print("StoreIndexed("); |
| 173 comp->array()->Accept(this); |
| 174 OS::Print(", "); |
| 175 comp->index()->Accept(this); |
| 176 OS::Print(", "); |
| 177 comp->value()->Accept(this); |
| 178 OS::Print(")"); |
| 179 } |
| 180 |
| 181 |
| 182 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) { |
| 183 OS::Print("InstanceSetter("); |
| 184 comp->receiver()->Accept(this); |
| 185 OS::Print(", "); |
| 186 comp->value()->Accept(this); |
| 187 OS::Print(")"); |
| 188 } |
| 189 |
| 190 |
| 191 void FlowGraphPrinter::VisitStaticSetter(StaticSetterComp* comp) { |
| 192 OS::Print("StaticSetter("); |
| 193 comp->value()->Accept(this); |
| 194 OS::Print(")"); |
| 195 } |
| 196 |
| 197 |
| 198 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) { |
| 199 OS::Print("! "); |
| 200 comp->value()->Accept(this); |
| 201 } |
| 202 |
| 203 |
| 204 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { |
| 205 comp->value()->Accept(this); |
| 206 OS::Print(" %s %s", |
| 207 comp->negate_result() ? "ISNOT" : "IS", |
| 208 String::Handle(comp->type().Name()).ToCString()); |
| 209 if (comp->type_arguments() != NULL) { |
| 210 OS::Print(" (type-arg:"); |
| 211 comp->type_arguments()->Accept(this); |
| 212 } |
| 213 OS::Print(")"); |
| 214 } |
| 215 |
| 216 |
| 217 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) { |
| 218 OS::Print("AllocateObject(%s", |
| 219 Class::Handle(comp->constructor().owner()).ToCString()); |
| 220 for (intptr_t i = 0; i < comp->arguments().length(); i++) { |
| 221 OS::Print(", "); |
| 222 comp->arguments()[i]->Accept(this); |
| 223 } |
| 224 OS::Print(")"); |
| 225 } |
| 226 |
| 227 |
| 228 void FlowGraphPrinter::VisitAllocateObjectWithBoundsCheck( |
| 229 AllocateObjectWithBoundsCheckComp* comp) { |
| 230 OS::Print("AllocateObjectWithBoundsCheck(%s", |
| 231 Class::Handle(comp->constructor().owner()).ToCString()); |
| 232 for (intptr_t i = 0; i < comp->arguments().length(); i++) { |
| 233 OS::Print(", "); |
| 234 comp->arguments()[i]->Accept(this); |
| 235 } |
| 236 OS::Print(")"); |
| 237 } |
| 238 |
| 239 |
| 240 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { |
| 241 OS::Print("CreateArray("); |
| 242 for (int i = 0; i < comp->ElementCount(); ++i) { |
| 243 if (i != 0) OS::Print(", "); |
| 244 comp->ElementAt(i)->Accept(this); |
| 245 } |
| 246 if (comp->ElementCount() > 0) OS::Print(", "); |
| 247 comp->element_type()->Accept(this); |
| 248 OS::Print(")"); |
| 249 } |
| 250 |
| 251 |
| 252 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) { |
| 253 OS::Print("CreateClosure(%s", comp->function().ToCString()); |
| 254 if (comp->type_arguments() != NULL) { |
| 255 OS::Print(", "); |
| 256 comp->type_arguments()->Accept(this); |
| 257 } |
| 258 OS::Print(")"); |
| 259 } |
| 260 |
| 261 |
| 262 void FlowGraphPrinter::VisitNativeLoadField(NativeLoadFieldComp* comp) { |
| 263 OS::Print("NativeLoadField("); |
| 264 comp->value()->Accept(this); |
| 265 OS::Print(", %d)", comp->offset_in_bytes()); |
| 266 } |
| 267 |
| 268 |
| 269 void FlowGraphPrinter::VisitInstantiateTypeArguments( |
| 270 InstantiateTypeArgumentsComp* comp) { |
| 271 const String& type_args = String::Handle(comp->type_arguments().Name()); |
| 272 OS::Print("InstantiateTypeArguments(%s, ", type_args.ToCString()); |
| 273 comp->instantiator()->Accept(this); |
| 274 OS::Print(")"); |
| 275 } |
| 276 |
| 277 |
| 278 void FlowGraphPrinter::VisitExtractConstructorTypeArguments( |
| 279 ExtractConstructorTypeArgumentsComp* comp) { |
| 280 const String& type_args = String::Handle(comp->type_arguments().Name()); |
| 281 OS::Print("ExtractConstructorTypeArguments(%s, ", type_args.ToCString()); |
| 282 comp->instantiator()->Accept(this); |
| 283 OS::Print(")"); |
| 284 } |
| 285 |
| 286 |
| 287 void FlowGraphPrinter::VisitExtractConstructorInstantiator( |
| 288 ExtractConstructorInstantiatorComp* comp) { |
| 289 OS::Print("ExtractConstructorInstantiator("); |
| 290 comp->instantiator()->Accept(this); |
| 291 OS::Print(", "); |
| 292 comp->discard_value()->Accept(this); |
| 293 OS::Print(")"); |
| 294 } |
| 295 |
| 296 |
| 297 void FlowGraphPrinter::VisitAllocateContext(AllocateContextComp* comp) { |
| 298 OS::Print("AllocateContext(%d)", comp->num_context_variables()); |
| 299 } |
| 300 |
| 301 |
| 302 void FlowGraphPrinter::VisitChainContext(ChainContextComp* comp) { |
| 303 OS::Print("ChainContext("); |
| 304 comp->context_value()->Accept(this); |
| 305 OS::Print(")"); |
| 306 } |
| 307 |
| 308 |
| 309 void FlowGraphPrinter::VisitCloneContext(CloneContextComp* comp) { |
| 310 OS::Print("CloneContext("); |
| 311 comp->context_value()->Accept(this); |
| 312 OS::Print(")"); |
| 313 } |
| 314 |
| 315 |
| 316 void FlowGraphPrinter::VisitCatchEntry(CatchEntryComp* comp) { |
| 317 OS::Print("CatchEntry(%s, %s)", |
| 318 comp->exception_var().name().ToCString(), |
| 319 comp->stacktrace_var().name().ToCString()); |
| 320 } |
| 321 |
| 322 |
| 323 void FlowGraphPrinter::VisitStoreContext(StoreContextComp* comp) { |
| 324 OS::Print("StoreContext("); |
| 325 comp->value()->Accept(this); |
| 326 OS::Print(")"); |
| 327 } |
| 328 |
| 329 |
| 330 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { |
| 331 OS::Print("%2d: [join]", reverse_index(instr->postorder_number())); |
| 332 } |
| 333 |
| 334 |
| 335 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { |
| 336 OS::Print("%2d: [target", reverse_index(instr->postorder_number())); |
| 337 if (instr->HasTryIndex()) { |
| 338 OS::Print(" catch %d]", instr->try_index()); |
| 339 } else { |
| 340 OS::Print("]"); |
| 341 } |
| 342 } |
| 343 |
| 344 |
| 345 void FlowGraphPrinter::VisitDo(DoInstr* instr) { |
| 346 OS::Print(" "); |
| 347 instr->computation()->Accept(this); |
| 348 } |
| 349 |
| 350 |
| 351 void FlowGraphPrinter::VisitBind(BindInstr* instr) { |
| 352 OS::Print(" t%d <- ", instr->temp_index()); |
| 353 instr->computation()->Accept(this); |
| 354 } |
| 355 |
| 356 |
| 357 void FlowGraphPrinter::VisitPickTemp(PickTempInstr* instr) { |
| 358 OS::Print(" t%d <- Pick(t%d)", instr->temp_index(), instr->source()); |
| 359 } |
| 360 |
| 361 |
| 362 void FlowGraphPrinter::VisitTuckTemp(TuckTempInstr* instr) { |
| 363 OS::Print(" t%d := t%d", instr->destination(), instr->source()); |
| 364 } |
| 365 |
| 366 |
| 367 void FlowGraphPrinter::VisitReturn(ReturnInstr* instr) { |
| 368 OS::Print(" return "); |
| 369 instr->value()->Accept(this); |
| 370 } |
| 371 |
| 372 |
| 373 void FlowGraphPrinter::VisitThrow(ThrowInstr* instr) { |
| 374 OS::Print("Throw("); |
| 375 instr->exception()->Accept(this); |
| 376 OS::Print(")"); |
| 377 } |
| 378 |
| 379 |
| 380 void FlowGraphPrinter::VisitReThrow(ReThrowInstr* instr) { |
| 381 OS::Print("ReThrow("); |
| 382 instr->exception()->Accept(this); |
| 383 OS::Print(", "); |
| 384 instr->stack_trace()->Accept(this); |
| 385 OS::Print(")"); |
| 386 } |
| 387 |
| 388 |
| 389 void FlowGraphPrinter::VisitBranch(BranchInstr* instr) { |
| 390 OS::Print(" if "); |
| 391 instr->value()->Accept(this); |
| 392 OS::Print(" goto(%d, %d)", |
| 393 reverse_index(instr->true_successor()->postorder_number()), |
| 394 reverse_index(instr->false_successor()->postorder_number())); |
| 395 } |
| 396 |
| 397 } // namespace dart |
| OLD | NEW |