forked from simshi/function-fanout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONFormatter.cpp
More file actions
67 lines (50 loc) · 1.31 KB
/
JSONFormatter.cpp
File metadata and controls
67 lines (50 loc) · 1.31 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
#include "llvm/Support/raw_ostream.h"
#include "JSONFormatter.h"
namespace FunctionFanout {
JSONFormatter::JSONFormatter(llvm::raw_ostream* ost) :
ost_(*ost), num_of_definitions_(0), num_of_callees_(0)
{
}
JSONFormatter::~JSONFormatter()
{
}
void JSONFormatter::BeginSourceFile()
{
ost_ << "{\n";
}
void JSONFormatter::EndSourceFile()
{
ost_ << "}\n";
ost_.flush();
}
void JSONFormatter::FormatFunction(const std::string name, const std::string type, const params_t& params)
{
ost_ << "\"" << type << " " << name << "(";
std::vector<std::string>::const_iterator it = params.begin();
if (it != params.end()) {
ost_ << *it;
for (++it; it != params.end(); ++it) {
ost_ << ", " << *it;
}
}
ost_ << ")\"";
}
void JSONFormatter::AddDefinition(const std::string name, const std::string type, const params_t& params)
{
if (num_of_definitions_ > 0) ost_ << ",\n";
FormatFunction(name, type, params);
ost_ << ":[";
++num_of_definitions_;
}
void JSONFormatter::EndDefinition()
{
ost_ << "]";
num_of_callees_ = 0;
}
void JSONFormatter::AddCallee(const std::string name, const std::string type, const params_t& params)
{
if (num_of_callees_ > 0) ost_ << ", ";
FormatFunction(name, type, params);
++num_of_callees_;
}
} /* namespace FunctionFanout */