-
Notifications
You must be signed in to change notification settings - Fork 2
/
Config.cpp
106 lines (87 loc) · 2.11 KB
/
Config.cpp
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
99
100
101
102
103
104
105
106
#include "Config.h"
#include <fstream>
#include <vector>
#include <nlohmann/json.hpp>
using namespace std;
using json = nlohmann::json;
CallTraceItem::CallTraceItem(string func, string file, uint32_t line) : func(func), file(file), line(line)
{
}
InitMemErr::InitMemErr()
{
}
vector<string> parseInput(string input)
{
vector<string> inputFiles;
ifstream s(input);
string line;
while (getline(s, line))
{
inputFiles.push_back(line);
}
return inputFiles;
}
void parseConfigFile(
string filename,
vector<string> &entryFunctionNames,
vector<InitMemErr> &initMemErrs,
vector<string> &inputFilenames,
uint32_t &maxCallDepth,
string &callGraph,
bool &doPrint)
{
ifstream configFile(filename);
assert(configFile.is_open());
json j = nlohmann::json::parse(configFile, nullptr, true, true); // allow json comments
// entry functions
for (json &entry : j["entries"])
{
entryFunctionNames.push_back(entry);
}
// init memory errors
for (json &jInitMemErr : j["initMemErrs"])
{
InitMemErr initMemErr;
// call trace
for (json &item : jInitMemErr["callTrace"])
{
initMemErr.callTrace.push_back(CallTraceItem(item["func"], item["file"], item["line"]));
}
// bug type
initMemErr.isRead = jInitMemErr["isRead"];
// memory access size
initMemErr.memAccessSize = jInitMemErr["memAccessSize"];
initMemErrs.push_back(initMemErr);
}
// file that contains all input files
string input;
if (j.contains("input"))
{
input = j["input"];
}
else
{
input = "input";
}
inputFilenames = parseInput(input); // all input files
// max call depth
maxCallDepth = j["maxCallDepth"];
// call graph file
if (j.contains("callGraph"))
{
callGraph = j["callGraph"];
}
else
{
callGraph = "cg";
}
// whether to print the graph and related information
if (j.contains("doPrint"))
{
doPrint = j["doPrint"];
}
else
{
doPrint = false;
}
}