Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: runtime/vm/il_printer.cc

Issue 10869063: Add attributions so printf like functions can have their arguments checked. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/il_printer.h ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 Instruction* current = block_order_[i]; 44 Instruction* current = block_order_[i];
45 for (ForwardInstructionIterator it(current->AsBlockEntry()); 45 for (ForwardInstructionIterator it(current->AsBlockEntry());
46 !it.Done(); 46 !it.Done();
47 it.Advance()) { 47 it.Advance()) {
48 current = it.Current(); 48 current = it.Current();
49 OS::Print("\n"); 49 OS::Print("\n");
50 PrintInstruction(current); 50 PrintInstruction(current);
51 } 51 }
52 if (current->next() != NULL) { 52 if (current->next() != NULL) {
53 ASSERT(current->next()->IsBlockEntry()); 53 ASSERT(current->next()->IsBlockEntry());
54 OS::Print(" goto %d", current->next()->AsBlockEntry()->block_id()); 54 OS::Print(" goto %"Pd"", current->next()->AsBlockEntry()->block_id());
55 } 55 }
56 OS::Print("\n"); 56 OS::Print("\n");
57 } 57 }
58 } 58 }
59 59
60 60
61 void FlowGraphPrinter::PrintInstruction(Instruction* instr) { 61 void FlowGraphPrinter::PrintInstruction(Instruction* instr) {
62 char str[1000]; 62 char str[1000];
63 BufferFormatter f(str, sizeof(str)); 63 BufferFormatter f(str, sizeof(str));
64 instr->PrintTo(&f); 64 instr->PrintTo(&f);
65 if (FLAG_print_environments && (instr->env() != NULL)) { 65 if (FLAG_print_environments && (instr->env() != NULL)) {
66 instr->env()->PrintTo(&f); 66 instr->env()->PrintTo(&f);
67 } 67 }
68 if (print_locations_ && (instr->locs() != NULL)) { 68 if (print_locations_ && (instr->locs() != NULL)) {
69 instr->locs()->PrintTo(&f); 69 instr->locs()->PrintTo(&f);
70 } 70 }
71 if (instr->lifetime_position() != -1) { 71 if (instr->lifetime_position() != -1) {
72 OS::Print("%3d: ", instr->lifetime_position()); 72 OS::Print("%3"Pd": ", instr->lifetime_position());
73 } 73 }
74 OS::Print("%s", str); 74 OS::Print("%s", str);
75 } 75 }
76 76
77 77
78 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, 78 void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function,
79 intptr_t token_pos, 79 intptr_t token_pos,
80 Value* value, 80 Value* value,
81 const AbstractType& dst_type, 81 const AbstractType& dst_type,
82 const String& dst_name, 82 const String& dst_name,
(...skipping 11 matching lines...) Expand all
94 "type '%s' of '%s'.", 94 "type '%s' of '%s'.",
95 eliminated ? "Eliminated" : "Generated", 95 eliminated ? "Eliminated" : "Generated",
96 compile_type_name, 96 compile_type_name,
97 eliminated ? "more" : "not more", 97 eliminated ? "more" : "not more",
98 String::Handle(dst_type.Name()).ToCString(), 98 String::Handle(dst_type.Name()).ToCString(),
99 dst_name.ToCString()); 99 dst_name.ToCString());
100 } 100 }
101 101
102 102
103 static void PrintICData(BufferFormatter* f, const ICData& ic_data) { 103 static void PrintICData(BufferFormatter* f, const ICData& ic_data) {
104 f->Print(" IC[%d: ", ic_data.NumberOfChecks()); 104 f->Print(" IC[%"Pd": ", ic_data.NumberOfChecks());
105 Function& target = Function::Handle(); 105 Function& target = Function::Handle();
106 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { 106 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) {
107 GrowableArray<intptr_t> class_ids; 107 GrowableArray<intptr_t> class_ids;
108 ic_data.GetCheckAt(i, &class_ids, &target); 108 ic_data.GetCheckAt(i, &class_ids, &target);
109 if (i > 0) { 109 if (i > 0) {
110 f->Print(" | "); 110 f->Print(" | ");
111 } 111 }
112 for (intptr_t k = 0; k < class_ids.length(); k++) { 112 for (intptr_t k = 0; k < class_ids.length(); k++) {
113 if (k > 0) { 113 if (k > 0) {
114 f->Print(", "); 114 f->Print(", ");
115 } 115 }
116 const Class& cls = 116 const Class& cls =
117 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); 117 Class::Handle(Isolate::Current()->class_table()->At(class_ids[k]));
118 f->Print("%s", String::Handle(cls.Name()).ToCString()); 118 f->Print("%s", String::Handle(cls.Name()).ToCString());
119 } 119 }
120 } 120 }
121 f->Print("]"); 121 f->Print("]");
122 } 122 }
123 123
124 124
125 void Definition::PrintTo(BufferFormatter* f) const { 125 void Definition::PrintTo(BufferFormatter* f) const {
126 // Do not access 'deopt_id()' as it asserts that the computation can 126 // Do not access 'deopt_id()' as it asserts that the computation can
127 // deoptimize. 127 // deoptimize.
128 f->Print("%s:%d(", DebugName(), deopt_id_); 128 f->Print("%s:%"Pd"(", DebugName(), deopt_id());
129 PrintOperandsTo(f); 129 PrintOperandsTo(f);
130 f->Print(")"); 130 f->Print(")");
131 } 131 }
132 132
133 133
134 void Definition::PrintOperandsTo(BufferFormatter* f) const { 134 void Definition::PrintOperandsTo(BufferFormatter* f) const {
135 for (int i = 0; i < InputCount(); ++i) { 135 for (int i = 0; i < InputCount(); ++i) {
136 if (i > 0) f->Print(", "); 136 if (i > 0) f->Print(", ");
137 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); 137 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f);
138 } 138 }
139 } 139 }
140 140
141 141
142 void Definition::PrintToVisualizer(BufferFormatter* f) const { 142 void Definition::PrintToVisualizer(BufferFormatter* f) const {
143 PrintTo(f); 143 PrintTo(f);
144 } 144 }
145 145
146 146
147 void Value::PrintTo(BufferFormatter* f) const { 147 void Value::PrintTo(BufferFormatter* f) const {
148 if (definition()->HasSSATemp()) { 148 if (definition()->HasSSATemp()) {
149 f->Print("v%d", definition()->ssa_temp_index()); 149 f->Print("v%"Pd"", definition()->ssa_temp_index());
150 } else { 150 } else {
151 f->Print("t%d", definition()->temp_index()); 151 f->Print("t%"Pd"", definition()->temp_index());
152 } 152 }
153 } 153 }
154 154
155 155
156 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { 156 void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const {
157 f->Print("#%s", value().ToCString()); 157 f->Print("#%s", value().ToCString());
158 } 158 }
159 159
160 160
161 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { 161 void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const {
(...skipping 12 matching lines...) Expand all
174 174
175 175
176 void AssertBooleanInstr::PrintOperandsTo(BufferFormatter* f) const { 176 void AssertBooleanInstr::PrintOperandsTo(BufferFormatter* f) const {
177 value()->PrintTo(f); 177 value()->PrintTo(f);
178 f->Print("%s", is_eliminated() ? " eliminated" : ""); 178 f->Print("%s", is_eliminated() ? " eliminated" : "");
179 } 179 }
180 180
181 181
182 void ArgumentDefinitionTestInstr::PrintOperandsTo(BufferFormatter* f) const { 182 void ArgumentDefinitionTestInstr::PrintOperandsTo(BufferFormatter* f) const {
183 saved_arguments_descriptor()->PrintTo(f); 183 saved_arguments_descriptor()->PrintTo(f);
184 f->Print(", ?%s @%d", 184 f->Print(", ?%s @%"Pd"",
185 formal_parameter_name().ToCString(), 185 formal_parameter_name().ToCString(),
186 formal_parameter_index()); 186 formal_parameter_index());
187 } 187 }
188 188
189 189
190 void ClosureCallInstr::PrintOperandsTo(BufferFormatter* f) const { 190 void ClosureCallInstr::PrintOperandsTo(BufferFormatter* f) const {
191 for (intptr_t i = 0; i < ArgumentCount(); ++i) { 191 for (intptr_t i = 0; i < ArgumentCount(); ++i) {
192 if (i > 0) f->Print(", "); 192 if (i > 0) f->Print(", ");
193 ArgumentAt(i)->value()->PrintTo(f); 193 ArgumentAt(i)->value()->PrintTo(f);
194 } 194 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 void StaticCallInstr::PrintOperandsTo(BufferFormatter* f) const { 236 void StaticCallInstr::PrintOperandsTo(BufferFormatter* f) const {
237 f->Print("%s ", String::Handle(function().name()).ToCString()); 237 f->Print("%s ", String::Handle(function().name()).ToCString());
238 for (intptr_t i = 0; i < ArgumentCount(); ++i) { 238 for (intptr_t i = 0; i < ArgumentCount(); ++i) {
239 if (i > 0) f->Print(", "); 239 if (i > 0) f->Print(", ");
240 ArgumentAt(i)->value()->PrintTo(f); 240 ArgumentAt(i)->value()->PrintTo(f);
241 } 241 }
242 } 242 }
243 243
244 244
245 void LoadLocalInstr::PrintOperandsTo(BufferFormatter* f) const { 245 void LoadLocalInstr::PrintOperandsTo(BufferFormatter* f) const {
246 f->Print("%s lvl:%d", local().name().ToCString(), context_level()); 246 f->Print("%s lvl:%"Pd"", local().name().ToCString(), context_level());
247 } 247 }
248 248
249 249
250 void StoreLocalInstr::PrintOperandsTo(BufferFormatter* f) const { 250 void StoreLocalInstr::PrintOperandsTo(BufferFormatter* f) const {
251 f->Print("%s, ", local().name().ToCString()); 251 f->Print("%s, ", local().name().ToCString());
252 value()->PrintTo(f); 252 value()->PrintTo(f);
253 f->Print(", lvl: %d", context_level()); 253 f->Print(", lvl: %"Pd"", context_level());
254 } 254 }
255 255
256 256
257 void NativeCallInstr::PrintOperandsTo(BufferFormatter* f) const { 257 void NativeCallInstr::PrintOperandsTo(BufferFormatter* f) const {
258 f->Print("%s", native_name().ToCString()); 258 f->Print("%s", native_name().ToCString());
259 } 259 }
260 260
261 261
262 void LoadInstanceFieldInstr::PrintOperandsTo(BufferFormatter* f) const { 262 void LoadInstanceFieldInstr::PrintOperandsTo(BufferFormatter* f) const {
263 f->Print("%s, ", String::Handle(field().name()).ToCString()); 263 f->Print("%s, ", String::Handle(field().name()).ToCString());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 f->Print("%s", function().ToCString()); 342 f->Print("%s", function().ToCString());
343 for (intptr_t i = 0; i < ArgumentCount(); ++i) { 343 for (intptr_t i = 0; i < ArgumentCount(); ++i) {
344 if (i > 0) f->Print(", "); 344 if (i > 0) f->Print(", ");
345 ArgumentAt(i)->value()->PrintTo(f); 345 ArgumentAt(i)->value()->PrintTo(f);
346 } 346 }
347 } 347 }
348 348
349 349
350 void LoadVMFieldInstr::PrintOperandsTo(BufferFormatter* f) const { 350 void LoadVMFieldInstr::PrintOperandsTo(BufferFormatter* f) const {
351 value()->PrintTo(f); 351 value()->PrintTo(f);
352 f->Print(", %d", offset_in_bytes()); 352 f->Print(", %"Pd"", offset_in_bytes());
353 } 353 }
354 354
355 355
356 void StoreVMFieldInstr::PrintOperandsTo(BufferFormatter* f) const { 356 void StoreVMFieldInstr::PrintOperandsTo(BufferFormatter* f) const {
357 dest()->PrintTo(f); 357 dest()->PrintTo(f);
358 f->Print(", %d, ", offset_in_bytes()); 358 f->Print(", %"Pd", ", offset_in_bytes());
359 value()->PrintTo(f); 359 value()->PrintTo(f);
360 } 360 }
361 361
362 362
363 void InstantiateTypeArgumentsInstr::PrintOperandsTo(BufferFormatter* f) const { 363 void InstantiateTypeArgumentsInstr::PrintOperandsTo(BufferFormatter* f) const {
364 const String& type_args = String::Handle(type_arguments().Name()); 364 const String& type_args = String::Handle(type_arguments().Name());
365 f->Print("%s, ", type_args.ToCString()); 365 f->Print("%s, ", type_args.ToCString());
366 instantiator()->PrintTo(f); 366 instantiator()->PrintTo(f);
367 } 367 }
368 368
369 369
370 void ExtractConstructorTypeArgumentsInstr::PrintOperandsTo( 370 void ExtractConstructorTypeArgumentsInstr::PrintOperandsTo(
371 BufferFormatter* f) const { 371 BufferFormatter* f) const {
372 const String& type_args = String::Handle(type_arguments().Name()); 372 const String& type_args = String::Handle(type_arguments().Name());
373 f->Print("%s, ", type_args.ToCString()); 373 f->Print("%s, ", type_args.ToCString());
374 instantiator()->PrintTo(f); 374 instantiator()->PrintTo(f);
375 } 375 }
376 376
377 377
378 void AllocateContextInstr::PrintOperandsTo(BufferFormatter* f) const { 378 void AllocateContextInstr::PrintOperandsTo(BufferFormatter* f) const {
379 f->Print("%d", num_context_variables()); 379 f->Print("%"Pd"", num_context_variables());
380 } 380 }
381 381
382 382
383 void CatchEntryInstr::PrintOperandsTo(BufferFormatter* f) const { 383 void CatchEntryInstr::PrintOperandsTo(BufferFormatter* f) const {
384 f->Print("%s, %s", 384 f->Print("%s, %s",
385 exception_var().name().ToCString(), 385 exception_var().name().ToCString(),
386 stacktrace_var().name().ToCString()); 386 stacktrace_var().name().ToCString());
387 } 387 }
388 388
389 389
(...skipping 27 matching lines...) Expand all
417 } 417 }
418 418
419 419
420 void CheckClassInstr::PrintOperandsTo(BufferFormatter* f) const { 420 void CheckClassInstr::PrintOperandsTo(BufferFormatter* f) const {
421 value()->PrintTo(f); 421 value()->PrintTo(f);
422 PrintICData(f, unary_checks()); 422 PrintICData(f, unary_checks());
423 } 423 }
424 424
425 425
426 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { 426 void GraphEntryInstr::PrintTo(BufferFormatter* f) const {
427 f->Print("%2d: [graph]", block_id()); 427 f->Print("%2"Pd": [graph]", block_id());
428 if (start_env_ != NULL) { 428 if (start_env_ != NULL) {
429 f->Print("\n{\n"); 429 f->Print("\n{\n");
430 const GrowableArray<Value*>& values = start_env_->values(); 430 const GrowableArray<Value*>& values = start_env_->values();
431 for (intptr_t i = 0; i < values.length(); i++) { 431 for (intptr_t i = 0; i < values.length(); i++) {
432 Definition* def = values[i]->definition(); 432 Definition* def = values[i]->definition();
433 f->Print(" ", i); 433 f->Print(" ");
434 def->PrintTo(f); 434 def->PrintTo(f);
435 f->Print("\n"); 435 f->Print("\n");
436 } 436 }
437 f->Print("} "); 437 f->Print("} ");
438 start_env_->PrintTo(f); 438 start_env_->PrintTo(f);
439 } 439 }
440 } 440 }
441 441
442 442
443 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { 443 void JoinEntryInstr::PrintTo(BufferFormatter* f) const {
444 f->Print("%2d: [join]", block_id()); 444 f->Print("%2"Pd": [join]", block_id());
445 if (phis_ != NULL) { 445 if (phis_ != NULL) {
446 for (intptr_t i = 0; i < phis_->length(); ++i) { 446 for (intptr_t i = 0; i < phis_->length(); ++i) {
447 if ((*phis_)[i] == NULL) continue; 447 if ((*phis_)[i] == NULL) continue;
448 f->Print("\n"); 448 f->Print("\n");
449 (*phis_)[i]->PrintTo(f); 449 (*phis_)[i]->PrintTo(f);
450 } 450 }
451 } 451 }
452 if (HasParallelMove()) { 452 if (HasParallelMove()) {
453 f->Print("\n"); 453 f->Print("\n");
454 parallel_move()->PrintTo(f); 454 parallel_move()->PrintTo(f);
455 } 455 }
456 } 456 }
457 457
458 458
459 static void PrintPropagatedType(BufferFormatter* f, const Definition& def) { 459 static void PrintPropagatedType(BufferFormatter* f, const Definition& def) {
460 if (def.HasPropagatedType()) { 460 if (def.HasPropagatedType()) {
461 String& name = String::Handle(); 461 String& name = String::Handle();
462 name = AbstractType::Handle(def.PropagatedType()).Name(); 462 name = AbstractType::Handle(def.PropagatedType()).Name();
463 f->Print(" {PT: %s}", name.ToCString()); 463 f->Print(" {PT: %s}", name.ToCString());
464 } 464 }
465 if (def.has_propagated_cid()) { 465 if (def.has_propagated_cid()) {
466 const Class& cls = Class::Handle( 466 const Class& cls = Class::Handle(
467 Isolate::Current()->class_table()->At(def.propagated_cid())); 467 Isolate::Current()->class_table()->At(def.propagated_cid()));
468 f->Print(" {PCid: %s}", String::Handle(cls.Name()).ToCString()); 468 f->Print(" {PCid: %s}", String::Handle(cls.Name()).ToCString());
469 } 469 }
470 } 470 }
471 471
472 472
473 void PhiInstr::PrintTo(BufferFormatter* f) const { 473 void PhiInstr::PrintTo(BufferFormatter* f) const {
474 f->Print(" v%d <- phi(", ssa_temp_index()); 474 f->Print(" v%"Pd" <- phi(", ssa_temp_index());
475 for (intptr_t i = 0; i < inputs_.length(); ++i) { 475 for (intptr_t i = 0; i < inputs_.length(); ++i) {
476 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); 476 if (inputs_[i] != NULL) inputs_[i]->PrintTo(f);
477 if (i < inputs_.length() - 1) f->Print(", "); 477 if (i < inputs_.length() - 1) f->Print(", ");
478 } 478 }
479 f->Print(")"); 479 f->Print(")");
480 PrintPropagatedType(f, *this); 480 PrintPropagatedType(f, *this);
481 } 481 }
482 482
483 483
484 void ParameterInstr::PrintTo(BufferFormatter* f) const { 484 void ParameterInstr::PrintTo(BufferFormatter* f) const {
485 f->Print(" v%d <- parameter(%d)", 485 f->Print(" v%"Pd" <- parameter(%"Pd")",
486 HasSSATemp() ? ssa_temp_index() : temp_index(), 486 HasSSATemp() ? ssa_temp_index() : temp_index(),
487 index()); 487 index());
488 PrintPropagatedType(f, *this); 488 PrintPropagatedType(f, *this);
489 } 489 }
490 490
491 491
492 void TargetEntryInstr::PrintTo(BufferFormatter* f) const { 492 void TargetEntryInstr::PrintTo(BufferFormatter* f) const {
493 f->Print("%2d: [target", block_id()); 493 f->Print("%2"Pd": [target", block_id());
494 if (IsCatchEntry()) { 494 if (IsCatchEntry()) {
495 f->Print(" catch %d]", catch_try_index()); 495 f->Print(" catch %"Pd"]", catch_try_index());
496 } else { 496 } else {
497 f->Print("]"); 497 f->Print("]");
498 } 498 }
499 if (HasParallelMove()) { 499 if (HasParallelMove()) {
500 f->Print("\n"); 500 f->Print("\n");
501 parallel_move()->PrintTo(f); 501 parallel_move()->PrintTo(f);
502 } 502 }
503 } 503 }
504 504
505 505
506 void PushArgumentInstr::PrintTo(BufferFormatter* f) const { 506 void PushArgumentInstr::PrintTo(BufferFormatter* f) const {
507 f->Print(" %s ", DebugName()); 507 f->Print(" %s ", DebugName());
508 value()->PrintTo(f); 508 value()->PrintTo(f);
509 } 509 }
510 510
511 511
512 void ReturnInstr::PrintTo(BufferFormatter* f) const { 512 void ReturnInstr::PrintTo(BufferFormatter* f) const {
513 f->Print(" %s:%d ", DebugName(), deopt_id()); 513 f->Print(" %s:%"Pd" ", DebugName(), deopt_id());
514 value()->PrintTo(f); 514 value()->PrintTo(f);
515 } 515 }
516 516
517 517
518 void ThrowInstr::PrintTo(BufferFormatter* f) const { 518 void ThrowInstr::PrintTo(BufferFormatter* f) const {
519 f->Print(" %s" , DebugName()); 519 f->Print(" %s" , DebugName());
520 } 520 }
521 521
522 522
523 void ReThrowInstr::PrintTo(BufferFormatter* f) const { 523 void ReThrowInstr::PrintTo(BufferFormatter* f) const {
524 f->Print(" %s ", DebugName()); 524 f->Print(" %s ", DebugName());
525 } 525 }
526 526
527 527
528 void GotoInstr::PrintTo(BufferFormatter* f) const { 528 void GotoInstr::PrintTo(BufferFormatter* f) const {
529 if (HasParallelMove()) { 529 if (HasParallelMove()) {
530 parallel_move()->PrintTo(f); 530 parallel_move()->PrintTo(f);
531 } else { 531 } else {
532 f->Print(" "); 532 f->Print(" ");
533 } 533 }
534 f->Print(" goto %d", successor()->block_id()); 534 f->Print(" goto %"Pd"", successor()->block_id());
535 } 535 }
536 536
537 537
538 void BranchInstr::PrintTo(BufferFormatter* f) const { 538 void BranchInstr::PrintTo(BufferFormatter* f) const {
539 f->Print(" %s ", DebugName()); 539 f->Print(" %s ", DebugName());
540 f->Print("if "); 540 f->Print("if ");
541 comparison()->PrintTo(f); 541 comparison()->PrintTo(f);
542 542
543 f->Print(" goto (%d, %d)", 543 f->Print(" goto (%"Pd", %"Pd")",
544 true_successor()->block_id(), 544 true_successor()->block_id(),
545 false_successor()->block_id()); 545 false_successor()->block_id());
546 } 546 }
547 547
548 548
549 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { 549 void ParallelMoveInstr::PrintTo(BufferFormatter* f) const {
550 f->Print(" %s ", DebugName()); 550 f->Print(" %s ", DebugName());
551 for (intptr_t i = 0; i < moves_.length(); i++) { 551 for (intptr_t i = 0; i < moves_.length(); i++) {
552 if (i != 0) f->Print(", "); 552 if (i != 0) f->Print(", ");
553 moves_[i]->dest().PrintTo(f); 553 moves_[i]->dest().PrintTo(f);
554 f->Print(" <- "); 554 f->Print(" <- ");
555 moves_[i]->src().PrintTo(f); 555 moves_[i]->src().PrintTo(f);
556 } 556 }
557 } 557 }
558 558
559 559
560 void FlowGraphVisualizer::Print(const char* format, ...) { 560 void FlowGraphVisualizer::Print(const char* format, ...) {
561 char str[1000]; 561 char str[1000];
562 BufferFormatter f(str, sizeof(str)); 562 BufferFormatter f(str, sizeof(str));
563 f.Print("%*s", 2 * indent_, ""); 563 f.Print("%*s", static_cast<int>(2 * indent_), "");
564 va_list args; 564 va_list args;
565 va_start(args, format); 565 va_start(args, format);
566 f.VPrint(format, args); 566 f.VPrint(format, args);
567 va_end(args); 567 va_end(args);
568 (*Dart::flow_graph_writer())(str, strlen(str)); 568 (*Dart::flow_graph_writer())(str, strlen(str));
569 } 569 }
570 570
571 571
572 void FlowGraphVisualizer::PrintInstruction(Instruction* instr) { 572 void FlowGraphVisualizer::PrintInstruction(Instruction* instr) {
573 char str[1000]; 573 char str[1000];
(...skipping 24 matching lines...) Expand all
598 END("compilation"); 598 END("compilation");
599 } 599 }
600 600
601 { 601 {
602 BEGIN("cfg"); 602 BEGIN("cfg");
603 Print("%s \"%s\"\n", "name", "Flow graph builder"); 603 Print("%s \"%s\"\n", "name", "Flow graph builder");
604 604
605 for (intptr_t i = 0; i < block_order_.length(); ++i) { 605 for (intptr_t i = 0; i < block_order_.length(); ++i) {
606 BEGIN("block"); 606 BEGIN("block");
607 BlockEntryInstr* entry = block_order_[i]; 607 BlockEntryInstr* entry = block_order_[i];
608 Print("%s \"B%d\"\n", "name", entry->block_id()); 608 Print("%s \"B%"Pd"\"\n", "name", entry->block_id());
609 Print("%s %d\n", "from_bci", -1); // Required field. Unused. 609 Print("%s %d\n", "from_bci", -1); // Required field. Unused.
610 Print("%s %d\n", "to_bci", -1); // Required field. Unused. 610 Print("%s %d\n", "to_bci", -1); // Required field. Unused.
611 611
612 Print("predecessors"); 612 Print("predecessors");
613 for (intptr_t j = 0; j < entry->PredecessorCount(); ++j) { 613 for (intptr_t j = 0; j < entry->PredecessorCount(); ++j) {
614 BlockEntryInstr* pred = entry->PredecessorAt(j); 614 BlockEntryInstr* pred = entry->PredecessorAt(j);
615 Print(" \"B%d\"", pred->block_id()); 615 Print(" \"B%"Pd"\"", pred->block_id());
616 } 616 }
617 Print("\n"); 617 Print("\n");
618 618
619 Print("successors"); 619 Print("successors");
620 Instruction* last = entry->last_instruction(); 620 Instruction* last = entry->last_instruction();
621 for (intptr_t j = 0; j < last->SuccessorCount(); ++j) { 621 for (intptr_t j = 0; j < last->SuccessorCount(); ++j) {
622 intptr_t next_id = last->SuccessorAt(j)->block_id(); 622 intptr_t next_id = last->SuccessorAt(j)->block_id();
623 Print(" \"B%d\"", next_id); 623 Print(" \"B%"Pd"\"", next_id);
624 } 624 }
625 Print("\n"); 625 Print("\n");
626 626
627 // TODO(fschneider): Use this for exception handlers. 627 // TODO(fschneider): Use this for exception handlers.
628 Print("xhandlers\n"); 628 Print("xhandlers\n");
629 629
630 // Can be freely used to mark blocks 630 // Can be freely used to mark blocks
631 Print("flags\n"); 631 Print("flags\n");
632 632
633 if (entry->dominator() != NULL) { 633 if (entry->dominator() != NULL) {
634 Print("%s \"B%d\"\n", "dominator", entry->dominator()->block_id()); 634 Print("%s \"B%"Pd"\"\n", "dominator", entry->dominator()->block_id());
635 } 635 }
636 636
637 // TODO(fschneider): Mark blocks with loop nesting level. 637 // TODO(fschneider): Mark blocks with loop nesting level.
638 Print("%s %d\n", "loop_depth", 0); 638 Print("%s %d\n", "loop_depth", 0);
639 639
640 { 640 {
641 BEGIN("states"); // Required section. 641 BEGIN("states"); // Required section.
642 { 642 {
643 BEGIN("locals"); // Required section. 643 BEGIN("locals"); // Required section.
644 JoinEntryInstr* join = entry->AsJoinEntry(); 644 JoinEntryInstr* join = entry->AsJoinEntry();
645 intptr_t num_phis = (join != NULL && join->phi_count()) 645 intptr_t num_phis = (join != NULL && join->phi_count())
646 ? join->phis()->length() 646 ? join->phis()->length()
647 : 0; 647 : 0;
648 Print("%s %d\n", "size", num_phis); 648 Print("%s %"Pd"\n", "size", num_phis);
649 for (intptr_t j = 0; j < num_phis; ++j) { 649 for (intptr_t j = 0; j < num_phis; ++j) {
650 PhiInstr* phi = (*join->phis())[j]; 650 PhiInstr* phi = (*join->phis())[j];
651 if (phi != NULL) { 651 if (phi != NULL) {
652 Print("%d ", j); // Print variable index. 652 Print("%"Pd" ", j); // Print variable index.
653 char buffer[120]; 653 char buffer[120];
654 BufferFormatter formatter(buffer, sizeof(buffer)); 654 BufferFormatter formatter(buffer, sizeof(buffer));
655 phi->PrintToVisualizer(&formatter); 655 phi->PrintToVisualizer(&formatter);
656 Print("%s\n", buffer); 656 Print("%s\n", buffer);
657 } 657 }
658 } 658 }
659 END("locals"); 659 END("locals");
660 } 660 }
661 END("states"); 661 END("states");
662 } 662 }
663 663
664 { 664 {
665 BEGIN("HIR"); 665 BEGIN("HIR");
666 // Print the block entry. 666 // Print the block entry.
667 Print("0 0 "); // Required fields "bci" and "use". Unused. 667 Print("0 0 "); // Required fields "bci" and "use". Unused.
668 PrintInstruction(block_order_[i]); 668 PrintInstruction(block_order_[i]);
669 // And all the successors until an exit, branch, or a block entry. 669 // And all the successors until an exit, branch, or a block entry.
670 BlockEntryInstr* entry = block_order_[i]; 670 BlockEntryInstr* entry = block_order_[i];
671 Instruction* current = entry; 671 Instruction* current = entry;
672 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { 672 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) {
673 current = it.Current(); 673 current = it.Current();
674 Print("0 0 "); 674 Print("0 0 ");
675 PrintInstruction(current); 675 PrintInstruction(current);
676 } 676 }
677 if (current->next() != NULL) { 677 if (current->next() != NULL) {
678 ASSERT(current->next()->IsBlockEntry()); 678 ASSERT(current->next()->IsBlockEntry());
679 Print("0 0 _ Goto B%d <|@\n", 679 Print("0 0 _ Goto B%"Pd" <|@\n",
680 current->next()->AsBlockEntry()->block_id()); 680 current->next()->AsBlockEntry()->block_id());
681 } 681 }
682 END("HIR"); 682 END("HIR");
683 } 683 }
684 END("block"); 684 END("block");
685 } 685 }
686 END("cfg"); 686 END("cfg");
687 } 687 }
688 #undef BEGIN 688 #undef BEGIN
689 #undef END 689 #undef END
(...skipping 10 matching lines...) Expand all
700 } 700 }
701 } 701 }
702 702
703 703
704 void JoinEntryInstr::PrintToVisualizer(BufferFormatter* f) const { 704 void JoinEntryInstr::PrintToVisualizer(BufferFormatter* f) const {
705 f->Print("_ [join]"); 705 f->Print("_ [join]");
706 } 706 }
707 707
708 708
709 void PhiInstr::PrintToVisualizer(BufferFormatter* f) const { 709 void PhiInstr::PrintToVisualizer(BufferFormatter* f) const {
710 f->Print("v%d [", ssa_temp_index()); 710 f->Print("v%"Pd" [", ssa_temp_index());
711 for (intptr_t i = 0; i < InputCount(); ++i) { 711 for (intptr_t i = 0; i < InputCount(); ++i) {
712 if (i > 0) f->Print(" "); 712 if (i > 0) f->Print(" ");
713 InputAt(i)->PrintTo(f); 713 InputAt(i)->PrintTo(f);
714 } 714 }
715 f->Print("]"); 715 f->Print("]");
716 } 716 }
717 717
718 718
719 void ParameterInstr::PrintToVisualizer(BufferFormatter* f) const { 719 void ParameterInstr::PrintToVisualizer(BufferFormatter* f) const {
720 ASSERT(HasSSATemp()); 720 ASSERT(HasSSATemp());
721 ASSERT(temp_index() == -1); 721 ASSERT(temp_index() == -1);
722 f->Print("v%d Parameter(%d)", ssa_temp_index(), index()); 722 f->Print("v%"Pd" Parameter(%"Pd")", ssa_temp_index(), index());
723 } 723 }
724 724
725 725
726 void TargetEntryInstr::PrintToVisualizer(BufferFormatter* f) const { 726 void TargetEntryInstr::PrintToVisualizer(BufferFormatter* f) const {
727 f->Print("_ [target"); 727 f->Print("_ [target");
728 if (IsCatchEntry()) { 728 if (IsCatchEntry()) {
729 f->Print(" catch %d]", catch_try_index()); 729 f->Print(" catch %"Pd"]", catch_try_index());
730 } else { 730 } else {
731 f->Print("]"); 731 f->Print("]");
732 } 732 }
733 } 733 }
734 734
735 735
736 void PushArgumentInstr::PrintToVisualizer(BufferFormatter* f) const { 736 void PushArgumentInstr::PrintToVisualizer(BufferFormatter* f) const {
737 f->Print("_ %s ", DebugName()); 737 f->Print("_ %s ", DebugName());
738 value()->PrintTo(f); 738 value()->PrintTo(f);
739 } 739 }
740 740
741 741
742 void ReturnInstr::PrintToVisualizer(BufferFormatter* f) const { 742 void ReturnInstr::PrintToVisualizer(BufferFormatter* f) const {
743 f->Print("_ %s:%d ", DebugName(), deopt_id()); 743 f->Print("_ %s:%"Pd" ", DebugName(), deopt_id());
744 value()->PrintTo(f); 744 value()->PrintTo(f);
745 } 745 }
746 746
747 747
748 void ThrowInstr::PrintToVisualizer(BufferFormatter* f) const { 748 void ThrowInstr::PrintToVisualizer(BufferFormatter* f) const {
749 f->Print("_ %s ", DebugName()); 749 f->Print("_ %s ", DebugName());
750 } 750 }
751 751
752 752
753 void ReThrowInstr::PrintToVisualizer(BufferFormatter* f) const { 753 void ReThrowInstr::PrintToVisualizer(BufferFormatter* f) const {
754 f->Print("_ %s ", DebugName()); 754 f->Print("_ %s ", DebugName());
755 } 755 }
756 756
757 757
758 void GotoInstr::PrintToVisualizer(BufferFormatter* f) const { 758 void GotoInstr::PrintToVisualizer(BufferFormatter* f) const {
759 f->Print("_ goto B%d", successor()->block_id()); 759 f->Print("_ goto B%"Pd"", successor()->block_id());
760 } 760 }
761 761
762 762
763 void BranchInstr::PrintToVisualizer(BufferFormatter* f) const { 763 void BranchInstr::PrintToVisualizer(BufferFormatter* f) const {
764 f->Print("_ %s ", DebugName()); 764 f->Print("_ %s ", DebugName());
765 f->Print("if "); 765 f->Print("if ");
766 comparison()->PrintTo(f); 766 comparison()->PrintTo(f);
767 f->Print(" goto (B%d, B%d)", 767 f->Print(" goto (B%"Pd", B%"Pd")",
768 true_successor()->block_id(), 768 true_successor()->block_id(),
769 false_successor()->block_id()); 769 false_successor()->block_id());
770 } 770 }
771 771
772 772
773 void ParallelMoveInstr::PrintToVisualizer(BufferFormatter* f) const { 773 void ParallelMoveInstr::PrintToVisualizer(BufferFormatter* f) const {
774 UNIMPLEMENTED(); 774 UNIMPLEMENTED();
775 } 775 }
776 776
777 777
778 void Environment::PrintTo(BufferFormatter* f) const { 778 void Environment::PrintTo(BufferFormatter* f) const {
779 f->Print(" env={ "); 779 f->Print(" env={ ");
780 for (intptr_t i = 0; i < values_.length(); ++i) { 780 for (intptr_t i = 0; i < values_.length(); ++i) {
781 if (i > 0) f->Print(", "); 781 if (i > 0) f->Print(", ");
782 values_[i]->PrintTo(f); 782 values_[i]->PrintTo(f);
783 if ((locations_ != NULL) && !locations_[i].IsInvalid()) { 783 if ((locations_ != NULL) && !locations_[i].IsInvalid()) {
784 f->Print(" ["); 784 f->Print(" [");
785 locations_[i].PrintTo(f); 785 locations_[i].PrintTo(f);
786 f->Print("]"); 786 f->Print("]");
787 } 787 }
788 } 788 }
789 f->Print(" }"); 789 f->Print(" }");
790 } 790 }
791 791
792 } // namespace dart 792 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/il_printer.h ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698