blob: 0c0f70224b031e57e02c19beb990b82e92c4590f [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 Geoffray3ff386a2014-03-04 14:46:47 +000030 PrintInt(instruction->id());
31 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 }
42 PrintInt(it.Current()->id());
43 }
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 }
55 PrintInt(it.Current()->id());
56 }
57 PrintString("]");
58 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +000059 PrintNewLine();
60 }
61
62 virtual void VisitBasicBlock(HBasicBlock* block) {
63 PrintString("BasicBlock ");
64 PrintInt(block->block_id());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000065 const GrowableArray<HBasicBlock*>* blocks = block->predecessors();
66 if (!blocks->IsEmpty()) {
67 PrintString(", pred: ");
68 for (size_t i = 0; i < blocks->Size() -1; i++) {
69 PrintInt(blocks->Get(i)->block_id());
70 PrintString(", ");
71 }
72 PrintInt(blocks->Peek()->block_id());
73 }
74 blocks = block->successors();
75 if (!blocks->IsEmpty()) {
76 PrintString(", succ: ");
77 for (size_t i = 0; i < blocks->Size() - 1; i++) {
78 PrintInt(blocks->Get(i)->block_id());
79 PrintString(", ");
80 }
81 PrintInt(blocks->Peek()->block_id());
82 }
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_