blob: d4b61651dcbe2f32e4897c0c2674933508ab625c [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(" ");
30 PrintString(instruction->DebugName());
31 PrintNewLine();
32 }
33
34 virtual void VisitBasicBlock(HBasicBlock* block) {
35 PrintString("BasicBlock ");
36 PrintInt(block->block_id());
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000037 const GrowableArray<HBasicBlock*>* blocks = block->predecessors();
38 if (!blocks->IsEmpty()) {
39 PrintString(", pred: ");
40 for (size_t i = 0; i < blocks->Size() -1; i++) {
41 PrintInt(blocks->Get(i)->block_id());
42 PrintString(", ");
43 }
44 PrintInt(blocks->Peek()->block_id());
45 }
46 blocks = block->successors();
47 if (!blocks->IsEmpty()) {
48 PrintString(", succ: ");
49 for (size_t i = 0; i < blocks->Size() - 1; i++) {
50 PrintInt(blocks->Get(i)->block_id());
51 PrintString(", ");
52 }
53 PrintInt(blocks->Peek()->block_id());
54 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +000055 PrintNewLine();
56 HGraphVisitor::VisitBasicBlock(block);
57 }
58
59 virtual void PrintNewLine() = 0;
60 virtual void PrintInt(int value) = 0;
61 virtual void PrintString(const char* value) = 0;
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(HPrettyPrinter);
65};
66
67} // namespace art
68
69#endif // ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_