ClearBlue
SailfishStateBuilder.h
1 //
2 // Created by yongchao on 12/20/22.
3 //
4 
5 #ifndef CLEARBLUE_YSPSASTATEBUILDER_H
6 #define CLEARBLUE_YSPSASTATEBUILDER_H
7 
8 #include "Checker/PSA/SummaryBase.h"
9 #include "Checker/PSA/VulnerabilityTraceBuilder.h"
10 #include "IR/SEG/SymbolicExprGraphSolver.h"
11 
13  public VulnerabilityTraceBuilder {
14 private:
15  PushPopCache<const SEGObject *> SEGObjectCache;
16  PushPopVector<SummaryCacheItem> NonSymDepsCache;
17  PushPopVector<SummaryCacheItem> SymDepsCache;
18 
19 public:
20  SailfishStateBuilder(SMTFactory &Fcty, TSDataLayout &D,
21  ExternalMemorySpec *MemSepc, ExternalIOSpec *IOSpec)
22  : SymbolicExprGraphSolver(Fcty, D, MemSepc, IOSpec),
23  VulnerabilityTraceBuilder() {}
24  virtual ~SailfishStateBuilder() {}
25 
26 public:
27  void pushState() {
28  SymbolicExprGraphSolver::push();
29  VulnerabilityTraceBuilder::push();
30  SEGObjectCache.push();
31  SymDepsCache.push();
32  NonSymDepsCache.push();
33  }
34 
35  void popState() {
36  SymbolicExprGraphSolver::pop();
37  VulnerabilityTraceBuilder::pop();
38  SEGObjectCache.pop();
39  SymDepsCache.pop();
40  NonSymDepsCache.pop();
41  }
42 
43  void resetState() {
44  SymbolicExprGraphSolver::reset();
45  VulnerabilityTraceBuilder::reset();
46  SEGObjectCache.reset();
47  SymDepsCache.reset();
48  NonSymDepsCache.reset();
49  }
50 
51  void recordState(const SEGObject *O) {
52  VulnerabilityTraceBuilder::add(O);
53  SEGObjectCache.add(O);
54  }
55 
56  void recordState(const std::shared_ptr<VulnerabilityTrace> &T) {
57  VulnerabilityTraceBuilder::add(T);
58  }
59 
60  void recordState(const SMTExpr &E) { SymbolicExprGraphSolver::add(E); }
61 
62  void recordState(const SMTExprVec &EV) {
63  SymbolicExprGraphSolver::addAll(EV);
64  }
65 
66  void recordState(const SummaryCacheItem &SCI, bool Sym) {
67  if (Sym)
68  SymDepsCache.push_back(SCI);
69  else
70  NonSymDepsCache.push_back(SCI);
71  }
72 
73 public:
74  bool hasState(const SEGObject *O) const { return SEGObjectCache.contains(O); }
75 
76 public:
77  std::vector<SummaryCacheItem>::const_iterator sym_dep_begin() const {
78  return SymDepsCache.getCacheVector().begin();
79  }
80 
81  std::vector<SummaryCacheItem>::const_iterator sym_dep_end() const {
82  return SymDepsCache.getCacheVector().end();
83  }
84 
85  std::vector<SummaryCacheItem>::const_iterator nonsym_dep_begin() const {
86  return NonSymDepsCache.getCacheVector().begin();
87  }
88 
89  std::vector<SummaryCacheItem>::const_iterator nonsym_dep_end() const {
90  return NonSymDepsCache.getCacheVector().end();
91  }
92 };
93 
94 #endif // CLEARBLUE_YSPSASTATEBUILDER_H
SailfishStateBuilder
Definition: SailfishStateBuilder.h:12
SymbolicExprGraphSolver
Definition: SymbolicExprGraphSolver.h:48
SEGObject
Definition: SymbolicExprGraph.h:76