forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumper.h
More file actions
98 lines (77 loc) · 2.46 KB
/
Dumper.h
File metadata and controls
98 lines (77 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_UTILS_DUMPER_H
#define HERMES_UTILS_DUMPER_H
#include <map>
#include "hermes/IR/IRVisitor.h"
namespace llvh {
class raw_ostream;
} // namespace llvh
namespace hermes {
class Value;
class Argument;
class Instruction;
class BasicBlock;
class Function;
class Module;
class CondBranchInst;
class AllocaInst;
class ReturnInst;
class Parameter;
class BranchInst;
/// Display a nice dotty graph that depicts the function.
void viewGraph(Function *F);
/// A utility class for naming instructions. This should only be used for
/// pretty-printing instructions.
struct InstructionNamer {
InstructionNamer() = default;
std::map<Value *, unsigned> InstrMap;
unsigned Counter{0};
void clear();
unsigned getNumber(Value *);
};
using llvh::raw_ostream;
struct IRPrinter : public IRVisitor<IRPrinter, void> {
/// Indentation level.
unsigned Indent;
SourceErrorManager &sm_;
/// Output stream.
llvh::raw_ostream &os;
/// If set to true then we need to escape the quote mark because the output of
/// this printer may be printed as a quoted label.
bool needEscape;
InstructionNamer InstNamer;
InstructionNamer BBNamer;
explicit IRPrinter(Context &ctx, llvh::raw_ostream &ost, bool escape = false)
: Indent(0),
sm_(ctx.getSourceErrorManager()),
os(ost),
needEscape(escape) {}
virtual ~IRPrinter() = default;
virtual void printFunctionHeader(Function *F);
virtual void printFunctionVariables(Function *F);
virtual void printValueLabel(Instruction *I, Value *V, unsigned opIndex);
virtual void printTypeLabel(Type T);
virtual void printInstruction(Instruction *I);
virtual void printInstructionDestination(Instruction *I);
virtual void printSourceLocation(SMLoc loc);
virtual void printSourceLocation(SMRange rng);
std::string getQuoteSign() {
return needEscape ? R"(\")" : R"(")";
}
/// Quote the string if it has spaces.
std::string quoteStr(StringRef name);
/// Escapes the string if it has non-printable characters.
std::string escapeStr(StringRef name);
/// Declare the functions we are going to reimplement.
void visitInstruction(const Instruction &I);
void visitBasicBlock(const BasicBlock &BB);
void visitFunction(const Function &F);
void visitModule(const Module &M);
};
} // namespace hermes
#endif