Skip to content

Commit 3ab0b4a

Browse files
Updated witness generator to produce function sequence
1 parent d538f7a commit 3ab0b4a

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

genWitness/genWitness

124 KB
Binary file not shown.

genWitness/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int argc, char** argv)
2929
if (ifs) {
3030
string s;
3131
vector<Node> nodes; // Store all the nodes
32+
vector<tuple<int, bool, string>> funcSeq; // XXX Store the function sequence
33+
// XXX bool = 0 : entry, 1: return
3234
map<string, pair<int, int>> functions; // Store all the functions
3335
vector<string> ext; // Store external function names
3436
int sink_id = 0; // same as violation
@@ -137,7 +139,7 @@ int main(int argc, char** argv)
137139
}
138140
}
139141
// Set the scope of each called functions
140-
traverse(nodes, functions, entry_id, nodes.size()-1, "main", -1);
142+
traverse(nodes, funcSeq, functions, entry_id, nodes.size()-1, "main", -1);
141143

142144
#ifdef DEBUG
143145
for (auto i = nodes.begin(); i != nodes.end(); i++) {
@@ -149,9 +151,16 @@ int main(int argc, char** argv)
149151
}
150152
cout << "\n\n\n============= HUMAN READABLE ============\n";
151153
printGraph(nodes, functions, entry_id, nodes.size()-1);
154+
for (auto i = funcSeq.begin(); i != funcSeq.end(); i++) {
155+
cout << get<0>(*i) << " ";
156+
if (get<1>(*i)) cout << "return";
157+
else cout << "entrance";
158+
cout << " " << get<2>(*i) << endl;
159+
}
152160
#else
153161
printMisc(filename);
154-
printGraph(nodes, functions, entry_id, nodes.size()-1);
162+
// printGraph(nodes, functions, entry_id, nodes.size()-1);
163+
printFuncSeq(funcSeq);
155164
cout << "</graph>\n</graphml>";
156165
#endif
157166
}

genWitness/utils.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,53 @@ void printGraph(vector<Node>& nodes, map<string, pair<int, int>>& f, int b, int
7070
}
7171
}
7272

73-
void traverse(vector<Node>& nodes, map<string, pair<int, int>>& f, int b, int e, string s, int p) {
73+
void printFuncSeq(vector<tuple<int, bool, string>>& funcSeq) {
74+
vector<string> funcName;
75+
cout << "<node id=\"ENTRY\">\n"
76+
<< "<data key=\"entry\">true</data>\n"
77+
<< "</node>\n";
78+
cout << "<edge source=\"ENTRY\" target=\"" << get<0>(funcSeq[0]) << "\"/>\n";
79+
for (size_t i = 0; i < funcSeq.size()-1; i++) {
80+
cout << "<node id=\"" << get<0>(funcSeq[i]) << "\"/>\n";
81+
cout << "<edge source=\"" << get<0>(funcSeq[i]) << "\" target=\"" << get<0>(funcSeq[i+1]) << "\">\n";
82+
if (get<1>(funcSeq[i]) == 0) {
83+
cout << "<data key=\"enterFunction\">" << get<2>(funcSeq[i]) << "</data>\n"
84+
<< "</edge>\n";
85+
funcName.push_back(get<2>(funcSeq[i]));
86+
}
87+
else {
88+
cout << "<data key=\"returnFrom\">" << funcName.back() << "</data>\n"
89+
<< "</edge>\n";
90+
funcName.pop_back();
91+
}
92+
}
93+
cout << "<node id=\"" << get<0>(funcSeq.back()) << "\"/>\n";
94+
cout << "<edge source=\"" << get<0>(funcSeq.back()) << "\" target=\"ERROR\">\n";
95+
cout << "<data key=\"returnFrom\">" << funcName.back() << "</data>\n"
96+
<< "</edge>\n";
97+
funcName.pop_back();
98+
cout << "<node id=\"ERROR\">\n"
99+
<< "<data key=\"violation\">true</data>\n"
100+
<< "</node>\n";
101+
}
102+
103+
void traverse(vector<Node>& nodes, vector<tuple<int, bool, string>>& funcSeq, map<string, pair<int, int>>& f, int b, int e, string s, int p) {
74104
for (int i = b; i <= e; i++) {
75105
if (!nodes[i].isExtern()) {
76106
nodes[i].setScope(s);
77107
if (nodes[i].isFuncCall()) {
78108
string n = nodes[i].getFunc();
79109
int bn = f[n].first, en = f[n].second;
80110
if (n.find("VERIFIER") == string::npos) {
111+
funcSeq.push_back(make_tuple(nodes[i].getId(), 0, n));
81112
nodes[i].setNext(bn);
82-
traverse(nodes, f, bn, en, n, i);
113+
traverse(nodes, funcSeq, f, bn, en, n, i);
83114
}
84115
}
85116
else if (nodes[i].isFuncReturn()) {
86117
nodes[i].setNext(p+1);
118+
string n = nodes[i].getFunc();
119+
funcSeq.push_back(make_tuple(nodes[i].getId(),1, n));
87120
}
88121
}
89122
}

genWitness/utils.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
#include <vector>
55
#include <map>
66
#include <string>
7+
#include <tuple>
78
#include "nodes.h"
89

910
bool checkTrivial(const std::string&);
1011
bool checkFunctionEntrance(const std::string &);
1112
bool checkFunctionReturn(const std::string &);
1213
void printGraph(std::vector<Node>&, std::map<std::string, std::pair<int, int>>&, int, int) ;
14+
void printFuncSeq(std::vector<std::tuple<int, bool, std::string>>&);
1315
void printMisc(std::string);
14-
void traverse(std::vector<Node>&, std::map<std::string, std::pair<int, int>>&, int, int, std::string, int ) ;
16+
void traverse(std::vector<Node>&,
17+
std::vector<std::tuple<int, bool, std::string>>&,
18+
std::map<std::string, std::pair<int, int>>&, int, int, std::string, int ) ;
1519
void changeOperator(std::string&);
1620
#endif// __UTILS_H__

scripts/gen_witness.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ if [ -d output ]; then
99
rm -rf output
1010
fi
1111
mkdir output
12-
cp template.graphml output/witness.graphml
12+
#cp template.graphml output/witness.graphml
13+
genWitness/genWitness $1 > witness.graphml
14+
sed -i 's/_call[0-9]//g' witness.graphml
15+
mv witness.graphml output
1316
date2=$(date +"%s")
1417
diff=$(($date2-$date1))
1518
echo -e "\n*** Witness Generation: $(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed."

0 commit comments

Comments
 (0)