Skip to content

Commit 4f95f12

Browse files
authored
Merge pull request #86 from secure-software-engineering/f-printMethod-to-printFunction-Refactoring
printMethod() to printFunction() Transformation
2 parents 4b47343 + e531af0 commit 4f95f12

99 files changed

Lines changed: 795 additions & 794 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/phasar/PhasarLLVM/ControlFlow/BiDiICFG.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@
2323

2424
namespace psr {
2525

26-
template <typename N, typename M> class BiDiICFG : public ICFG<N, M> {
26+
template <typename N, typename F> class BiDiICFG : public ICFG<N, F> {
2727
public:
2828
virtual ~BiDiICFG() = default;
2929

3030
virtual std::vector<N> getPredsOf(N u) = 0;
3131

32-
virtual std::set<N> getEndPointsOf(M m) = 0;
32+
virtual std::set<N> getEndPointsOf(F f) = 0;
3333

3434
virtual std::vector<N> getPredsOfCallAt(N u) = 0;
3535

3636
virtual std::set<N> allNonCallEndNodes() = 0;
3737

3838
// also exposed to some clients who need it
39-
// virtual DirectedGraph<N> getOrCreateUnitGraph(M body) = 0;
39+
// virtual DirectedGraph<N> getOrCreateUnitGraph(F body) = 0;
4040

41-
virtual std::vector<N> getParameterRefs(M m) = 0;
41+
virtual std::vector<N> getParameterRefs(F f) = 0;
4242

4343
/**
4444
* Gets whether the given statement is a return site of at least one call

include/phasar/PhasarLLVM/ControlFlow/CFG.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525

2626
namespace psr {
2727

28-
template <typename N, typename M> class CFG {
28+
template <typename N, typename F> class CFG {
2929
public:
3030
virtual ~CFG() = default;
3131

32-
virtual M getFunctionOf(N stmt) const = 0;
32+
virtual F getFunctionOf(N stmt) const = 0;
3333

3434
virtual std::vector<N> getPredsOf(N stmt) const = 0;
3535

3636
virtual std::vector<N> getSuccsOf(N stmt) const = 0;
3737

38-
virtual std::vector<std::pair<N, N>> getAllControlFlowEdges(M fun) const = 0;
38+
virtual std::vector<std::pair<N, N>> getAllControlFlowEdges(F fun) const = 0;
3939

40-
virtual std::vector<N> getAllInstructionsOf(M fun) const = 0;
40+
virtual std::vector<N> getAllInstructionsOf(F fun) const = 0;
4141

4242
virtual bool isExitStmt(N stmt) const = 0;
4343

@@ -53,11 +53,11 @@ template <typename N, typename M> class CFG {
5353

5454
virtual std::string getStatementId(N stmt) const = 0;
5555

56-
virtual std::string getFunctionName(M fun) const = 0;
56+
virtual std::string getFunctionName(F fun) const = 0;
5757

58-
virtual void print(M fun, std::ostream &OS) const = 0;
58+
virtual void print(F fun, std::ostream &OS) const = 0;
5959

60-
virtual nlohmann::json getAsJson(M fun) const = 0;
60+
virtual nlohmann::json getAsJson(F fun) const = 0;
6161
};
6262

6363
} // namespace psr

include/phasar/PhasarLLVM/ControlFlow/ICFG.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ CallGraphAnalysisType to_CallGraphAnalysisType(const std::string &S);
4040

4141
std::ostream &operator<<(std::ostream &os, const CallGraphAnalysisType &CGA);
4242

43-
template <typename N, typename M> class ICFG : public virtual CFG<N, M> {
43+
template <typename N, typename F> class ICFG : public virtual CFG<N, F> {
4444
public:
4545
~ICFG() override = default;
4646

47-
virtual std::set<M> getAllFunctions() const = 0;
47+
virtual std::set<F> getAllFunctions() const = 0;
4848

49-
virtual M getFunction(const std::string &fun) const = 0;
49+
virtual F getFunction(const std::string &fun) const = 0;
5050

5151
virtual bool isCallStmt(N stmt) const = 0;
5252

@@ -56,22 +56,22 @@ template <typename N, typename M> class ICFG : public virtual CFG<N, M> {
5656

5757
virtual std::set<N> allNonCallStartNodes() const = 0;
5858

59-
virtual std::set<M> getCalleesOfCallAt(N stmt) const = 0;
59+
virtual std::set<F> getCalleesOfCallAt(N stmt) const = 0;
6060

61-
virtual std::set<N> getCallersOf(M fun) const = 0;
61+
virtual std::set<N> getCallersOf(F fun) const = 0;
6262

63-
virtual std::set<N> getCallsFromWithin(M fun) const = 0;
63+
virtual std::set<N> getCallsFromWithin(F fun) const = 0;
6464

65-
virtual std::set<N> getStartPointsOf(M fun) const = 0;
65+
virtual std::set<N> getStartPointsOf(F fun) const = 0;
6666

67-
virtual std::set<N> getExitPointsOf(M fun) const = 0;
67+
virtual std::set<N> getExitPointsOf(F fun) const = 0;
6868

6969
virtual std::set<N> getReturnSitesOfCallAt(N stmt) const = 0;
7070

71-
using CFG<N, M>::print; // tell the compiler we wish to have both prints
71+
using CFG<N, F>::print; // tell the compiler we wish to have both prints
7272
virtual void print(std::ostream &OS = std::cout) const = 0;
7373

74-
using CFG<N, M>::getAsJson; // tell the compiler we wish to have both prints
74+
using CFG<N, F>::getAsJson; // tell the compiler we wish to have both prints
7575
virtual nlohmann::json getAsJson() const = 0;
7676
};
7777

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323

2424
namespace psr {
2525

26-
template <typename N, typename D, typename M, typename V> class EdgeFunctions {
26+
template <typename N, typename D, typename F, typename V> class EdgeFunctions {
2727
public:
2828
virtual ~EdgeFunctions() = default;
2929
virtual std::shared_ptr<EdgeFunction<V>>
3030
getNormalEdgeFunction(N curr, D currNode, N succ, D succNode) = 0;
3131
virtual std::shared_ptr<EdgeFunction<V>>
32-
getCallEdgeFunction(N callStmt, D srcNode, M destinationMethod,
32+
getCallEdgeFunction(N callStmt, D srcNode, F destinationFunction,
3333
D destNode) = 0;
3434
virtual std::shared_ptr<EdgeFunction<V>>
35-
getReturnEdgeFunction(N callSite, M calleeMethod, N exitStmt, D exitNode,
35+
getReturnEdgeFunction(N callSite, F calleeFunction, N exitStmt, D exitNode,
3636
N reSite, D retNode) = 0;
3737
virtual std::shared_ptr<EdgeFunction<V>>
3838
getCallToRetEdgeFunction(N callSite, D callNode, N retSite, D retSiteNode,
39-
std::set<M> callees) = 0;
39+
std::set<F> callees) = 0;
4040
virtual std::shared_ptr<EdgeFunction<V>>
4141
getSummaryEdgeFunction(N curr, D currNode, N succ, D succNode) = 0;
4242
};

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowEdgeFunctionCache.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ namespace psr {
3030
* version is used if existend, otherwise a new one is created and inserted
3131
* into the cache.
3232
*/
33-
template <typename N, typename D, typename M, typename T, typename V,
33+
template <typename N, typename D, typename F, typename T, typename V,
3434
typename L, typename I>
3535
class FlowEdgeFunctionCache {
3636
private:
37-
IDETabulationProblem<N, D, M, T, V, L, I> &problem;
37+
IDETabulationProblem<N, D, F, T, V, L, I> &problem;
3838
// Auto add zero
3939
bool autoAddZero;
4040
D zeroValue;
4141
// Caches for the flow functions
4242
std::map<std::tuple<N, N>, std::shared_ptr<FlowFunction<D>>>
4343
NormalFlowFunctionCache;
44-
std::map<std::tuple<N, M>, std::shared_ptr<FlowFunction<D>>>
44+
std::map<std::tuple<N, F>, std::shared_ptr<FlowFunction<D>>>
4545
CallFlowFunctionCache;
46-
std::map<std::tuple<N, M, N, N>, std::shared_ptr<FlowFunction<D>>>
46+
std::map<std::tuple<N, F, N, N>, std::shared_ptr<FlowFunction<D>>>
4747
ReturnFlowFunctionCache;
48-
std::map<std::tuple<N, N, std::set<M>>, std::shared_ptr<FlowFunction<D>>>
48+
std::map<std::tuple<N, N, std::set<F>>, std::shared_ptr<FlowFunction<D>>>
4949
CallToRetFlowFunctionCache;
5050
// Caches for the edge functions
5151
std::map<std::tuple<N, D, N, D>, std::shared_ptr<EdgeFunction<L>>>
5252
NormalEdgeFunctionCache;
53-
std::map<std::tuple<N, D, M, D>, std::shared_ptr<EdgeFunction<L>>>
53+
std::map<std::tuple<N, D, F, D>, std::shared_ptr<EdgeFunction<L>>>
5454
CallEdgeFunctionCache;
55-
std::map<std::tuple<N, M, N, D, N, D>, std::shared_ptr<EdgeFunction<L>>>
55+
std::map<std::tuple<N, F, N, D, N, D>, std::shared_ptr<EdgeFunction<L>>>
5656
ReturnEdgeFunctionCache;
5757
std::map<std::tuple<N, D, N, D>, std::shared_ptr<EdgeFunction<L>>>
5858
CallToRetEdgeFunctionCache;
@@ -62,7 +62,7 @@ class FlowEdgeFunctionCache {
6262
public:
6363
// Ctor allows access to the IDEProblem in order to get access to flow and
6464
// edge function factory functions.
65-
FlowEdgeFunctionCache(IDETabulationProblem<N, D, M, T, V, L, I> &problem)
65+
FlowEdgeFunctionCache(IDETabulationProblem<N, D, F, T, V, L, I> &problem)
6666
: problem(problem),
6767
autoAddZero(problem.getIFDSIDESolverConfig().autoAddZero),
6868
zeroValue(problem.getZeroValue()) {
@@ -133,16 +133,16 @@ class FlowEdgeFunctionCache {
133133
}
134134
}
135135

136-
std::shared_ptr<FlowFunction<D>> getCallFlowFunction(N callStmt, M destMthd) {
136+
std::shared_ptr<FlowFunction<D>> getCallFlowFunction(N callStmt, F destFun) {
137137
PAMM_GET_INSTANCE;
138138
auto &lg = lg::get();
139139
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
140140
<< "Call flow function factory call");
141141
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
142142
<< "(N) Call Stmt : " << problem.NtoString(callStmt));
143143
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
144-
<< "(M) Dest Mthd : " << problem.FtoString(destMthd));
145-
auto key = std::tie(callStmt, destMthd);
144+
<< "(F) Dest Fun : " << problem.FtoString(destFun));
145+
auto key = std::tie(callStmt, destFun);
146146
if (CallFlowFunctionCache.count(key)) {
147147
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
148148
<< "Flow function fetched from cache");
@@ -154,16 +154,16 @@ class FlowEdgeFunctionCache {
154154
auto ff =
155155
(autoAddZero)
156156
? std::make_shared<ZeroedFlowFunction<D>>(
157-
problem.getCallFlowFunction(callStmt, destMthd), zeroValue)
158-
: problem.getCallFlowFunction(callStmt, destMthd);
157+
problem.getCallFlowFunction(callStmt, destFun), zeroValue)
158+
: problem.getCallFlowFunction(callStmt, destFun);
159159
CallFlowFunctionCache.insert(std::make_pair(key, ff));
160160
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "Flow function constructed");
161161
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << ' ');
162162
return ff;
163163
}
164164
}
165165

166-
std::shared_ptr<FlowFunction<D>> getRetFlowFunction(N callSite, M calleeMthd,
166+
std::shared_ptr<FlowFunction<D>> getRetFlowFunction(N callSite, F calleeFun,
167167
N exitStmt, N retSite) {
168168
PAMM_GET_INSTANCE;
169169
auto &lg = lg::get();
@@ -172,12 +172,12 @@ class FlowEdgeFunctionCache {
172172
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
173173
<< "(N) Call Site : " << problem.NtoString(callSite));
174174
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
175-
<< "(M) Callee : " << problem.FtoString(calleeMthd));
175+
<< "(F) Callee : " << problem.FtoString(calleeFun));
176176
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
177177
<< "(N) Exit Stmt : " << problem.NtoString(exitStmt));
178178
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
179179
<< "(N) Ret Site : " << problem.NtoString(retSite));
180-
auto key = std::tie(callSite, calleeMthd, exitStmt, retSite);
180+
auto key = std::tie(callSite, calleeFun, exitStmt, retSite);
181181
if (ReturnFlowFunctionCache.count(key)) {
182182
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
183183
<< "Flow function fetched from cache");
@@ -188,10 +188,10 @@ class FlowEdgeFunctionCache {
188188
INC_COUNTER("Return-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full);
189189
auto ff = (autoAddZero)
190190
? std::make_shared<ZeroedFlowFunction<D>>(
191-
problem.getRetFlowFunction(callSite, calleeMthd,
191+
problem.getRetFlowFunction(callSite, calleeFun,
192192
exitStmt, retSite),
193193
zeroValue)
194-
: problem.getRetFlowFunction(callSite, calleeMthd, exitStmt,
194+
: problem.getRetFlowFunction(callSite, calleeFun, exitStmt,
195195
retSite);
196196
ReturnFlowFunctionCache.insert(std::make_pair(key, ff));
197197
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "Flow function constructed");
@@ -201,7 +201,7 @@ class FlowEdgeFunctionCache {
201201
}
202202

203203
std::shared_ptr<FlowFunction<D>>
204-
getCallToRetFlowFunction(N callSite, N retSite, std::set<M> callees) {
204+
getCallToRetFlowFunction(N callSite, N retSite, std::set<F> callees) {
205205
PAMM_GET_INSTANCE;
206206
auto &lg = lg::get();
207207
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -210,7 +210,7 @@ class FlowEdgeFunctionCache {
210210
<< "(N) Call Site : " << problem.NtoString(callSite));
211211
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
212212
<< "(N) Ret Site : " << problem.NtoString(retSite));
213-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "(M) Callee's : ");
213+
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "(F) Callee's : ");
214214
for (auto callee : callees) {
215215
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
216216
<< " " << problem.FtoString(callee));
@@ -239,7 +239,7 @@ class FlowEdgeFunctionCache {
239239
}
240240

241241
std::shared_ptr<FlowFunction<D>> getSummaryFlowFunction(N callStmt,
242-
M destMthd) {
242+
F destFun) {
243243
// PAMM_GET_INSTANCE;
244244
// INC_COUNTER("Summary-FF Construction", 1, PAMM_SEVERITY_LEVEL::Full);
245245
auto &lg = lg::get();
@@ -248,9 +248,9 @@ class FlowEdgeFunctionCache {
248248
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
249249
<< "(N) Call Stmt : " << problem.NtoString(callStmt));
250250
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
251-
<< "(M) Dest Mthd : " << problem.FtoString(destMthd));
251+
<< "(F) Dest Mthd : " << problem.FtoString(destFun));
252252
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << ' ');
253-
auto ff = problem.getSummaryFlowFunction(callStmt, destMthd);
253+
auto ff = problem.getSummaryFlowFunction(callStmt, destFun);
254254
return ff;
255255
}
256256

@@ -286,7 +286,7 @@ class FlowEdgeFunctionCache {
286286
}
287287

288288
std::shared_ptr<EdgeFunction<L>>
289-
getCallEdgeFunction(N callStmt, D srcNode, M destinationMethod, D destNode) {
289+
getCallEdgeFunction(N callStmt, D srcNode, F destinationFunction, D destNode) {
290290
PAMM_GET_INSTANCE;
291291
auto &lg = lg::get();
292292
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -296,11 +296,11 @@ class FlowEdgeFunctionCache {
296296
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
297297
<< "(D) Src Node : " << problem.DtoString(srcNode));
298298
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
299-
<< "(M) Dest Mthd : "
300-
<< problem.FtoString(destinationMethod));
299+
<< "(F) Dest Fun : "
300+
<< problem.FtoString(destinationFunction));
301301
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
302302
<< "(D) Dest Node : " << problem.DtoString(destNode));
303-
auto key = std::tie(callStmt, srcNode, destinationMethod, destNode);
303+
auto key = std::tie(callStmt, srcNode, destinationFunction, destNode);
304304
if (CallEdgeFunctionCache.count(key)) {
305305
INC_COUNTER("Call-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full);
306306
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -310,7 +310,7 @@ class FlowEdgeFunctionCache {
310310
} else {
311311
INC_COUNTER("Call-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full);
312312
auto ef = problem.getCallEdgeFunction(callStmt, srcNode,
313-
destinationMethod, destNode);
313+
destinationFunction, destNode);
314314
CallEdgeFunctionCache.insert(std::make_pair(key, ef));
315315
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "Edge function constructed");
316316
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << ' ');
@@ -319,7 +319,7 @@ class FlowEdgeFunctionCache {
319319
}
320320

321321
std::shared_ptr<EdgeFunction<L>> getReturnEdgeFunction(N callSite,
322-
M calleeMethod,
322+
F calleeFunction,
323323
N exitStmt, D exitNode,
324324
N reSite, D retNode) {
325325
PAMM_GET_INSTANCE;
@@ -329,7 +329,7 @@ class FlowEdgeFunctionCache {
329329
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
330330
<< "(N) Call Site : " << problem.NtoString(callSite));
331331
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
332-
<< "(M) Callee : " << problem.FtoString(calleeMethod));
332+
<< "(F) Callee : " << problem.FtoString(calleeFunction));
333333
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
334334
<< "(N) Exit Stmt : " << problem.NtoString(exitStmt));
335335
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -339,7 +339,7 @@ class FlowEdgeFunctionCache {
339339
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
340340
<< "(D) Ret Node : " << problem.DtoString(retNode));
341341
auto key =
342-
std::tie(callSite, calleeMethod, exitStmt, exitNode, reSite, retNode);
342+
std::tie(callSite, calleeFunction, exitStmt, exitNode, reSite, retNode);
343343
if (ReturnEdgeFunctionCache.count(key)) {
344344
INC_COUNTER("Return-EF Cache Hit", 1, PAMM_SEVERITY_LEVEL::Full);
345345
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -348,7 +348,7 @@ class FlowEdgeFunctionCache {
348348
return ReturnEdgeFunctionCache.at(key);
349349
} else {
350350
INC_COUNTER("Return-EF Construction", 1, PAMM_SEVERITY_LEVEL::Full);
351-
auto ef = problem.getReturnEdgeFunction(callSite, calleeMethod, exitStmt,
351+
auto ef = problem.getReturnEdgeFunction(callSite, calleeFunction, exitStmt,
352352
exitNode, reSite, retNode);
353353
ReturnEdgeFunctionCache.insert(std::make_pair(key, ef));
354354
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "Edge function constructed");
@@ -359,7 +359,7 @@ class FlowEdgeFunctionCache {
359359

360360
std::shared_ptr<EdgeFunction<L>>
361361
getCallToRetEdgeFunction(N callSite, D callNode, N retSite, D retSiteNode,
362-
std::set<M> callees) {
362+
std::set<F> callees) {
363363
PAMM_GET_INSTANCE;
364364
auto &lg = lg::get();
365365
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
@@ -372,7 +372,7 @@ class FlowEdgeFunctionCache {
372372
<< "(N) Ret Site : " << problem.NtoString(retSite));
373373
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
374374
<< "(D) Ret Node : " << problem.DtoString(retSiteNode));
375-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "(M) Callee's : ");
375+
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << "(F) Callee's : ");
376376
for (auto callee : callees) {
377377
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
378378
<< " " << problem.FtoString(callee));

0 commit comments

Comments
 (0)