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 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 | 12 |
13 void BufferFormatter::Print(const char* format, ...) { | 13 void BufferFormatter::Print(const char* format, ...) { |
14 intptr_t available = size_ - position_; | 14 intptr_t available = size_ - position_; |
15 if (available <= 0) return; | 15 if (available <= 0) return; |
16 va_list args; | 16 va_list args; |
17 va_start(args, format); | 17 va_start(args, format); |
18 intptr_t written = | 18 intptr_t written = |
19 OS::VSNPrint(buffer_ + position_, available, format, args); | 19 OS::VSNPrint(buffer_ + position_, available, format, args); |
20 if (written >= 0) { | 20 if (written >= 0) { |
21 position_ += (available <= written) ? available : written; | 21 position_ += (available <= written) ? available : written; |
22 } | 22 } |
23 va_end(args); | 23 va_end(args); |
24 } | 24 } |
25 | 25 |
26 | 26 |
27 void FlowGraphPrinter::PrintBlocks() { | 27 void FlowGraphPrinter::PrintBlocks() { |
28 OS::Print("==== %s\n", function_.ToFullyQualifiedCString()); | 28 if (!function_.IsNull()) { |
29 OS::Print("==== %s\n", function_.ToFullyQualifiedCString()); | |
30 } | |
29 | 31 |
30 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 32 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
31 // Print the block entry. | 33 // Print the block entry. |
32 Print(block_order_[i]); | 34 PrintInstruction(block_order_[i]); |
33 Instruction* current = block_order_[i]->StraightLineSuccessor(); | 35 Instruction* current = block_order_[i]->StraightLineSuccessor(); |
34 // And all the successors until an exit, branch, or a block entry. | 36 // And all the successors until an exit, branch, or a block entry. |
35 while ((current != NULL) && !current->IsBlockEntry()) { | 37 while ((current != NULL) && !current->IsBlockEntry()) { |
36 OS::Print("\n"); | 38 OS::Print("\n"); |
37 Print(current); | 39 PrintInstruction(current); |
38 current = current->StraightLineSuccessor(); | 40 current = current->StraightLineSuccessor(); |
39 } | 41 } |
40 BlockEntryInstr* successor = | 42 BlockEntryInstr* successor = |
41 (current == NULL) ? NULL : current->AsBlockEntry(); | 43 (current == NULL) ? NULL : current->AsBlockEntry(); |
42 if (successor != NULL) { | 44 if (successor != NULL) { |
43 OS::Print(" goto %d", successor->block_id()); | 45 OS::Print(" goto %d", successor->block_id()); |
44 } | 46 } |
45 OS::Print("\n"); | 47 OS::Print("\n"); |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 | 51 |
50 void FlowGraphPrinter::Print(Instruction* instr) { | 52 void FlowGraphPrinter::PrintInstruction(Instruction* instr) { |
51 char str[80]; | 53 char str[80]; |
52 BufferFormatter f(str, sizeof(str)); | 54 BufferFormatter f(str, sizeof(str)); |
53 instr->PrintTo(&f); | 55 instr->PrintTo(&f); |
54 OS::Print("%s", str); | 56 OS::Print("%s", str); |
55 } | 57 } |
56 | 58 |
57 | 59 |
60 void FlowGraphPrinter::PrintComputation(Computation* comp) { | |
61 char str[80]; | |
62 BufferFormatter f(str, sizeof(str)); | |
63 comp->PrintTo(&f); | |
64 OS::Print("%s", str); | |
65 } | |
66 | |
67 | |
68 | |
58 void Computation::PrintTo(BufferFormatter* f) const { | 69 void Computation::PrintTo(BufferFormatter* f) const { |
59 f->Print("%s(", DebugName()); | 70 f->Print("%s(", DebugName()); |
60 PrintOperandsTo(f); | 71 PrintOperandsTo(f); |
61 f->Print(")"); | 72 f->Print(")"); |
62 } | 73 } |
63 | 74 |
64 | 75 |
65 void Computation::PrintOperandsTo(BufferFormatter* f) const { | 76 void Computation::PrintOperandsTo(BufferFormatter* f) const { |
66 for (int i = 0; i < InputCount(); ++i) { | 77 for (int i = 0; i < InputCount(); ++i) { |
67 if (i > 0) f->Print(", "); | 78 if (i > 0) f->Print(", "); |
68 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); | 79 if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); |
69 OS::Print(")"); | 80 f->Print(")"); |
70 } | 81 } |
71 } | 82 } |
72 | 83 |
73 | 84 |
74 void UseVal::PrintTo(BufferFormatter* f) const { | 85 void UseVal::PrintTo(BufferFormatter* f) const { |
75 f->Print("t%d", definition()->temp_index()); | 86 f->Print("t%d", definition()->temp_index()); |
76 } | 87 } |
77 | 88 |
78 | 89 |
79 void ConstantVal::PrintTo(BufferFormatter* f) const { | 90 void ConstantVal::PrintTo(BufferFormatter* f) const { |
80 f->Print("#%s", value().ToCString()); | 91 f->Print("#%s", value().ToCString()); |
81 } | 92 } |
82 | 93 |
83 | 94 |
84 void AssertAssignableComp::PrintOperandsTo(BufferFormatter* f) const { | 95 void AssertAssignableComp::PrintOperandsTo(BufferFormatter* f) const { |
85 value()->PrintTo(f); | 96 value()->PrintTo(f); |
86 f->Print(", %s, '%s'", | 97 f->Print(", %s, '%s'", |
87 String::Handle(dst_type().Name()).ToCString(), | 98 String::Handle(dst_type().Name()).ToCString(), |
88 dst_name().ToCString()); | 99 dst_name().ToCString()); |
89 if (instantiator() != NULL) { | 100 if (instantiator() != NULL) { |
90 OS::Print(" (instantiator:"); | 101 f->Print(" (instantiator:"); |
91 instantiator()->PrintTo(f); | 102 instantiator()->PrintTo(f); |
92 OS::Print(")"); | 103 f->Print(")"); |
Florian Schneider
2012/05/24 00:20:39
Thanks for catching these!
| |
93 } | 104 } |
94 if (instantiator_type_arguments() != NULL) { | 105 if (instantiator_type_arguments() != NULL) { |
95 f->Print(" (instantiator:"); | 106 f->Print(" (instantiator:"); |
96 instantiator_type_arguments()->PrintTo(f); | 107 instantiator_type_arguments()->PrintTo(f); |
97 f->Print(")"); | 108 f->Print(")"); |
98 } | 109 } |
99 } | 110 } |
100 | 111 |
101 | 112 |
102 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { | 113 void ClosureCallComp::PrintOperandsTo(BufferFormatter* f) const { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 value()->PrintTo(f); | 192 value()->PrintTo(f); |
182 } | 193 } |
183 | 194 |
184 | 195 |
185 void InstanceOfComp::PrintOperandsTo(BufferFormatter* f) const { | 196 void InstanceOfComp::PrintOperandsTo(BufferFormatter* f) const { |
186 value()->PrintTo(f); | 197 value()->PrintTo(f); |
187 f->Print(" %s %s", | 198 f->Print(" %s %s", |
188 negate_result() ? "ISNOT" : "IS", | 199 negate_result() ? "ISNOT" : "IS", |
189 String::Handle(type().Name()).ToCString()); | 200 String::Handle(type().Name()).ToCString()); |
190 if (instantiator() != NULL) { | 201 if (instantiator() != NULL) { |
191 OS::Print(" (instantiator:"); | 202 f->Print(" (instantiator:"); |
192 instantiator()->PrintTo(f); | 203 instantiator()->PrintTo(f); |
193 OS::Print(")"); | 204 f->Print(")"); |
194 } | 205 } |
195 if (type_arguments() != NULL) { | 206 if (type_arguments() != NULL) { |
196 f->Print(" (type-arg:"); | 207 f->Print(" (type-arg:"); |
197 type_arguments()->PrintTo(f); | 208 type_arguments()->PrintTo(f); |
198 } | 209 } |
199 } | 210 } |
200 | 211 |
201 | 212 |
202 void AllocateObjectComp::PrintOperandsTo(BufferFormatter* f) const { | 213 void AllocateObjectComp::PrintOperandsTo(BufferFormatter* f) const { |
203 f->Print("%s", Class::Handle(constructor().owner()).ToCString()); | 214 f->Print("%s", Class::Handle(constructor().owner()).ToCString()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 } | 281 } |
271 | 282 |
272 | 283 |
273 void CatchEntryComp::PrintOperandsTo(BufferFormatter* f) const { | 284 void CatchEntryComp::PrintOperandsTo(BufferFormatter* f) const { |
274 f->Print("%s, %s", | 285 f->Print("%s, %s", |
275 exception_var().name().ToCString(), | 286 exception_var().name().ToCString(), |
276 stacktrace_var().name().ToCString()); | 287 stacktrace_var().name().ToCString()); |
277 } | 288 } |
278 | 289 |
279 | 290 |
291 void BinaryOpComp::PrintOperandsTo(BufferFormatter* f) const { | |
292 f->Print("%s, ", Token::Str(op_kind())); | |
293 left()->PrintTo(f); | |
294 f->Print(", "); | |
295 right()->PrintTo(f); | |
296 } | |
297 | |
298 | |
280 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { | 299 void GraphEntryInstr::PrintTo(BufferFormatter* f) const { |
281 f->Print("%2d: [graph]", block_id()); | 300 f->Print("%2d: [graph]", block_id()); |
282 } | 301 } |
283 | 302 |
284 | 303 |
285 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { | 304 void JoinEntryInstr::PrintTo(BufferFormatter* f) const { |
286 f->Print("%2d: [join]", block_id()); | 305 f->Print("%2d: [join]", block_id()); |
287 } | 306 } |
288 | 307 |
289 | 308 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 f->Print(" %s ", DebugName()); | 352 f->Print(" %s ", DebugName()); |
334 f->Print("if "); | 353 f->Print("if "); |
335 value()->PrintTo(f); | 354 value()->PrintTo(f); |
336 f->Print(" goto (%d, %d)", | 355 f->Print(" goto (%d, %d)", |
337 true_successor()->block_id(), | 356 true_successor()->block_id(), |
338 false_successor()->block_id()); | 357 false_successor()->block_id()); |
339 } | 358 } |
340 | 359 |
341 | 360 |
342 } // namespace dart | 361 } // namespace dart |
OLD | NEW |