ClearBlue
SEGArgumentNode.h
1 /*
2  * SEGArgumentNode.h
3  *
4  * Qingkai
5  *
6  * This node is to model arguments of a function.
7  */
8 
9 #ifndef IR_SEG_SEGARGUMENTNODE_H
10 #define IR_SEG_SEGARGUMENTNODE_H
11 
12 #include <llvm/IR/BasicBlock.h>
13 
14 #include "CBAccessPath.h"
15 #include "IR/SEG/SymbolicExprGraph.h"
16 #include "Persistence/PersistenceBasis.h"
17 using namespace llvm;
18 
20 public:
23  SEGArgumentNode(PersistedSEGArgumentNode *Node, SymbolicExprGraph *SEG)
24  : SEGOperandNode(Node, SEG) {}
25 
26  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
27  SEGOperandNode::assembleSEGObject(FuncSEGObjMap);
28  }
29 
30 protected:
31  SEGArgumentNode(SEGObjectKind NTy, Type *Ty, SymbolicExprGraph *SEG,
32  BasicBlock *BB)
33  : SEGOperandNode(NTy, Ty, SEG, BB) {}
34 
35  SEGArgumentNode(SEGObjectKind NTy, Value *Val, Type *Ty,
36  SymbolicExprGraph *SEG, BasicBlock *BB)
37  : SEGOperandNode(NTy, Val, Ty, SEG, BB) {}
38 
39  ~SEGArgumentNode() {}
40 
41  friend class SymbolicExprGraph;
42 
43 public:
44  virtual size_t getIndex() const = 0;
45 
46 public:
47  static bool classof(const SEGObject *N) {
48  return N->getKind() >= SEGOBJK_ArgumentBegin &&
49  N->getKind() <= SEGOBJK_ArgumentEnd;
50  }
51 };
52 
54 public:
57  SEGCommonArgumentNode(PersistedSEGCommonArgumentNode *Node,
58  SymbolicExprGraph *SEG)
59  : SEGArgumentNode(Node, SEG) {
60  this->Index = Node->getIndex();
61  }
62 
63  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
65  }
66 
67 private:
68  // The index is set by SEG
69  size_t Index = -1;
70 
71  SEGCommonArgumentNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB)
72  : SEGArgumentNode(SEGOBJK_CommonArgument, Ty, SEG, BB) {
73  std::string Desc(std::string("carg_") + this->getDescription());
74  this->setDescription(Desc);
75  }
76 
77  SEGCommonArgumentNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG,
78  BasicBlock *BB)
79  : SEGArgumentNode(SEGOBJK_CommonArgument, Val, Ty, SEG, BB) {
80  std::string Desc(std::string("carg_") + this->getDescription());
81  this->setDescription(Desc);
82  }
83 
84  friend class SymbolicExprGraph;
85 
86 public:
87  virtual ~SEGCommonArgumentNode() {}
88 
89  virtual PersistedSEGObject *createPersistedObject() const {
90  PersistedSEGObject *PersistedObj = new PersistedSEGCommonArgumentNode;
91  return PersistedObj;
92  }
93 
94  virtual size_t getIndex() const {
95  assert(Index != (size_t)-1 && "Index of a common argument is not set!");
96  return Index;
97  }
98 
99  virtual std::string getAuxiliaryDebugStr() const {
100  return "the index of this common argument is " + std::to_string(Index);
101  }
102 
103 public:
104  static bool classof(const SEGObject *N) {
105  return N->getKind() == SEGOBJK_CommonArgument;
106  }
107 };
108 
110 public:
113  SEGVarArgumentNode(PersistedSEGVarArgumentNode *Node, SymbolicExprGraph *SEG)
114  : SEGArgumentNode(Node, SEG) {}
115 
116  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
117  SEGArgumentNode::assembleSEGObject(FuncSEGObjMap);
118  }
119 
120 private:
121  SEGVarArgumentNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB)
122  : SEGArgumentNode(SEGOBJK_VarArgument, Ty, SEG, BB) {
123  std::string Desc(std::string("varg_") + this->getDescription());
124  this->setDescription(Desc);
125  }
126 
127  SEGVarArgumentNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG,
128  BasicBlock *BB)
129  : SEGArgumentNode(SEGOBJK_VarArgument, Val, Ty, SEG, BB) {
130  std::string Desc(std::string("varg_") + this->getDescription());
131  this->setDescription(Desc);
132  }
133 
134  friend class SymbolicExprGraph;
135 
136 public:
137  ~SEGVarArgumentNode() {}
138 
139  virtual PersistedSEGObject *createPersistedObject() const {
140  PersistedSEGObject *PersistedObj = new PersistedSEGVarArgumentNode;
141  return PersistedObj;
142  }
143 
144  virtual size_t getIndex() const {
145  assert(false);
146  return -1;
147  }
148 
149 public:
150  static bool classof(const SEGObject *N) {
151  return N->getKind() == SEGOBJK_VarArgument;
152  }
153 };
154 
156 public:
159  SEGPseudoArgumentNode(PersistedSEGPseudoArgumentNode *Node,
160  SymbolicExprGraph *SEG)
161  : SEGArgumentNode(Node, SEG) {
162  this->Index = Node->getIndex();
163  }
164 
165  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
166  SEGArgumentNode::assembleSEGObject(FuncSEGObjMap);
167  }
168 
169 private:
170  // The index is set by SEG
171  size_t Index = -1;
172 
173  CBAccessPath AP;
174 
175  SEGPseudoArgumentNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB)
176  : SEGArgumentNode(SEGOBJK_PseudoArgument, Ty, SEG, BB) {
177  std::string Desc(std::string("parg_") + this->getDescription());
178  this->setDescription(Desc);
179  }
180 
181  SEGPseudoArgumentNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG,
182  BasicBlock *BB)
183  : SEGArgumentNode(SEGOBJK_PseudoArgument, Val, Ty, SEG, BB) {
184  std::string Desc(std::string("parg_") + this->getDescription());
185  this->setDescription(Desc);
186  }
187 
188  friend class SymbolicExprGraph;
189 
190 public:
192 
193  virtual PersistedSEGObject *createPersistedObject() const {
194  PersistedSEGObject *PersistedObj = new PersistedSEGPseudoArgumentNode;
195  return PersistedObj;
196  }
197 
198  virtual size_t getIndex() const {
199  assert(Index != (size_t)-1 && "Index of a pseudo argument is not set!");
200  return Index;
201  }
202 
203 public:
204  static bool classof(const SEGObject *N) {
205  return N->getKind() == SEGOBJK_PseudoArgument;
206  }
207 
208  CBAccessPath &getAccessPath() { return AP; }
209 
210  const CBAccessPath &getAccessPath() const { return AP; }
211 };
212 
213 #endif
SEGVarArgumentNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGArgumentNode.h:116
SEGCommonArgumentNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGArgumentNode.h:63
SEGVarArgumentNode
Definition: SEGArgumentNode.h:109
SEGArgumentNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGArgumentNode.h:26
SEGOperandNode
Definition: SymbolicExprGraph.h:539
SEGPseudoArgumentNode
Definition: SEGArgumentNode.h:155
SEGCommonArgumentNode
Definition: SEGArgumentNode.h:53
SymbolicExprGraph
Definition: SymbolicExprGraph.h:855
SEGArgumentNode
Definition: SEGArgumentNode.h:19
SEGVarArgumentNode::SEGVarArgumentNode
SEGVarArgumentNode(PersistedSEGVarArgumentNode *Node, SymbolicExprGraph *SEG)
Definition: SEGArgumentNode.h:113
SEGObject
Definition: SymbolicExprGraph.h:87
SEGPseudoArgumentNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGArgumentNode.h:165
SEGPseudoArgumentNode::SEGPseudoArgumentNode
SEGPseudoArgumentNode(PersistedSEGPseudoArgumentNode *Node, SymbolicExprGraph *SEG)
Definition: SEGArgumentNode.h:159
CBAccessPath
Definition: CBAccessPath.h:22
SEGArgumentNode::SEGArgumentNode
SEGArgumentNode(PersistedSEGArgumentNode *Node, SymbolicExprGraph *SEG)
Definition: SEGArgumentNode.h:23
SEGCommonArgumentNode::SEGCommonArgumentNode
SEGCommonArgumentNode(PersistedSEGCommonArgumentNode *Node, SymbolicExprGraph *SEG)
Definition: SEGArgumentNode.h:57
SEGOperandNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SymbolicExprGraph.h:545