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