ClearBlue
SEGCallSitePseudoInputNode.h
1 /*
2  * SEGCallSitePseudoInputNode.h
3  *
4  * Zhou Jinguo
5  *
6  * 2016.5.19
7  *
8  * This node is to model the pseudo input of a call site.
9  */
10 
11 #ifndef IR_SEG_SEGCALLSITEPSEUDOINPUTNODE_H
12 #define IR_SEG_SEGCALLSITEPSEUDOINPUTNODE_H
13 
14 #include <llvm/IR/BasicBlock.h>
15 #include <llvm/IR/CallSite.h>
16 #include <llvm/IR/Constants.h>
17 #include <llvm/IR/Function.h>
18 #include <llvm/IR/Instructions.h>
19 #include <llvm/IR/Value.h>
20 #include <llvm/Support/FileSystem.h>
21 #include <llvm/Support/Format.h>
22 #include <llvm/Support/raw_ostream.h>
23 
24 #include "CBAccessPath.h"
25 #include "IR/SEG/SymbolicExprGraph.h"
26 #include "Persistence/PersistenceBasis.h"
27 
28 using namespace llvm;
29 
31 public:
34  SEGCallSitePseudoInputNode(PersistedSEGCallSitePseudoInputNode *Node,
35  SymbolicExprGraph *SEG)
36  : SEGOperandNode(Node, SEG) {
37  this->index = Node->getIndex();
38  auto *WrappedMod = SEG->getWrappedMod();
39  this->WrappedCallee = dyn_cast<WrappedFunction>(
40  WrappedMod->findWrappedValue(Node->getCalleeFunctionID()));
41  this->WrappedCallSiteInst = dyn_cast<WrappedInstruction>(
42  WrappedMod->findWrappedValue(Node->getCallSiteInstructionID()));
43  if (this->WrappedCallee) {
44  if (Function *callee = this->WrappedCallee->getRealFunc())
45  this->Callee = callee;
46  }
47  if (this->WrappedCallSiteInst) {
48  if (Instruction *CSI = this->WrappedCallSiteInst->getRealInstruction())
49  this->LLVMCS = CallSite(CSI);
50  }
51  }
52 
53  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
54  SEGOperandNode::assembleSEGObject(FuncSEGObjMap);
55  }
56 
57 protected:
58  CallSite LLVMCS;
59  WrappedInstruction *WrappedCallSiteInst = nullptr;
60 
61  Function *Callee = nullptr;
62  WrappedFunction *WrappedCallee = nullptr;
63 
64  SEGCallSitePseudoInputNode(CallSite CS, Function *Callee, Value *Val,
65  Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB)
66  : SEGOperandNode(SEGOBJK_CallSitePseudoInput, Val, Ty, SEG, BB),
67  LLVMCS(CS), Callee(Callee), index(-1) {
68  access_path.reset(Val);
69  WrappedCallee = WrappedValue::findWrappedFunction(Callee);
70  WrappedCallSiteInst =
71  WrappedValue::findWrappedInstruction(CS.getInstruction());
72  }
73 
74  friend class SymbolicExprGraph;
75  friend class SEGCallSite;
76 
77  CBAccessPath access_path;
78 
79  int index;
80 
81 public:
83 
84  virtual PersistedSEGObject *createPersistedObject() const {
85  PersistedSEGObject *PersistedObj = new PersistedSEGCallSitePseudoInputNode;
86  return PersistedObj;
87  }
88 
89  CallSite getCallSite() const { return LLVMCS; }
90 
91  WrappedCallSite getWrappedCallSite() const {
92  return WrappedCallSite(WrappedCallSiteInst);
93  }
94 
95  WrappedInstruction *getWrappedCallSiteInst() const {
96  return WrappedCallSiteInst;
97  }
98 
99  Function *getCallee() const { return Callee; }
100 
101  WrappedFunction *getWrappedCallee() const { return WrappedCallee; }
102 
103  virtual size_t getIndex() const { return index; }
104 
105  const CBAccessPath &getAccessPath() const { return access_path; }
106 
107  CBAccessPath &getAccessPath() { return access_path; }
108 
109  virtual std::string getSrcFile() const {
110  if (WrappedCallSiteInst) {
111  return WrappedCallSiteInst->getSrcFileName();
112  }
113  return SEGNodeBase::getSrcFile();
114  }
115 
116  virtual std::int32_t getSrcLine() const {
117  if (WrappedCallSiteInst) {
118  return WrappedCallSiteInst->getSrcLine();
119  }
120  return SEGNodeBase::getSrcLine();
121  }
122 
123 public:
124  static bool classof(const SEGObject *N) {
125  return N->getKind() == SEGOBJK_CallSitePseudoInput;
126  }
127 };
128 
129 #endif
SEGOperandNode
Definition: SymbolicExprGraph.h:539
SEGCallSite
Definition: SEGCallSite.h:53
SEGCallSitePseudoInputNode::SEGCallSitePseudoInputNode
SEGCallSitePseudoInputNode(PersistedSEGCallSitePseudoInputNode *Node, SymbolicExprGraph *SEG)
Definition: SEGCallSitePseudoInputNode.h:34
SymbolicExprGraph
Definition: SymbolicExprGraph.h:855
SEGObject
Definition: SymbolicExprGraph.h:87
SEGCallSitePseudoInputNode
Definition: SEGCallSitePseudoInputNode.h:30
SEGObject::PersistedObj
PersistedSEGObject * PersistedObj
the persistence object
Definition: SymbolicExprGraph.h:169
CBAccessPath
Definition: CBAccessPath.h:22
SEGCallSitePseudoInputNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGCallSitePseudoInputNode.h:53
SEGOperandNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SymbolicExprGraph.h:545