blob: 606c91519e814f7f83c12a2afbd1674493944334 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_
18#define ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_
19
20#include "nodes.h"
21
22namespace art {
23
24class HPrettyPrinter : public HGraphVisitor {
25 public:
26 explicit HPrettyPrinter(HGraph* graph) : HGraphVisitor(graph) { }
27
28 virtual void VisitInstruction(HInstruction* instruction) {
29 PrintString(" ");
Nicolas Geoffray787c3072014-03-17 10:20:19 +000030 PrintInt(instruction->GetId());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000031 PrintString(": ");
Nicolas Geoffray818f2102014-02-18 16:43:35 +000032 PrintString(instruction->DebugName());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000033 if (instruction->InputCount() != 0) {
34 PrintString("(");
35 bool first = true;
36 for (HInputIterator it(instruction); !it.Done(); it.Advance()) {
37 if (first) {
38 first = false;
39 } else {
40 PrintString(", ");
41 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000042 PrintInt(it.Current()->GetId());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000043 }
44 PrintString(")");
45 }
46 if (instruction->HasUses()) {
47 PrintString(" [");
48 bool first = true;
49 for (HUseIterator it(instruction); !it.Done(); it.Advance()) {
50 if (first) {
51 first = false;
52 } else {
53 PrintString(", ");
54 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000055 PrintInt(it.Current()->GetId());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000056 }
57 PrintString("]");
58 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +000059 PrintNewLine();
60 }
61
62 virtual void VisitBasicBlock(HBasicBlock* block) {
63 PrintString("BasicBlock ");
Nicolas Geoffray787c3072014-03-17 10:20:19 +000064 PrintInt(block->GetBlockId());
65 const GrowableArray<HBasicBlock*>* blocks = block->GetPredecessors();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000066 if (!blocks->IsEmpty()) {
67 PrintString(", pred: ");
68 for (size_t i = 0; i < blocks->Size() -1; i++) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +000069 PrintInt(blocks->Get(i)->GetBlockId());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000070 PrintString(", ");
71 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000072 PrintInt(blocks->Peek()->GetBlockId());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000073 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000074 blocks = block->GetSuccessors();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000075 if (!blocks->IsEmpty()) {
76 PrintString(", succ: ");
77 for (size_t i = 0; i < blocks->Size() - 1; i++) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +000078 PrintInt(blocks->Get(i)->GetBlockId());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000079 PrintString(", ");
80 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +000081 PrintInt(blocks->Peek()->GetBlockId());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000082 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +000083 PrintNewLine();
84 HGraphVisitor::VisitBasicBlock(block);
85 }
86
87 virtual void PrintNewLine() = 0;
88 virtual void PrintInt(int value) = 0;
89 virtual void PrintString(const char* value) = 0;
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(HPrettyPrinter);
93};
94
95} // namespace art
96
97#endif // ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_