ClearBlue
SEGLoadMemNode.h
1 /*
2  * SEGLoadMemNode.h
3  *
4  * Qingkai
5  *
6  * This node is to model value loaded from a memory.
7  */
8 
9 #ifndef IR_SEG_SEGLOADMEMNODE_H
10 #define IR_SEG_SEGLOADMEMNODE_H
11 
12 #include <llvm/IR/BasicBlock.h>
13 
14 #include <sstream>
15 #include <unordered_map>
16 
17 #include "IR/SEG/SymbolicExprGraph.h"
18 
19 using namespace llvm;
20 
21 class PersistedSEGLoadMemNode;
22 
24 public:
27  SEGLoadMemNode(PersistedSEGLoadMemNode *Node, SymbolicExprGraph *SEG);
28 
29  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap);
30 
31 private:
32  // Used when pointer analysis is applied
33  // Loaded Value -> Conditions
34  std::unordered_map<const SEGNodeBase *, SEGRegionNode *> MatchingConditions;
35  friend class SymbolicExprGraph;
36 
37  SEGLoadMemNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB);
38 
39 public:
40  ~SEGLoadMemNode() {}
41 
42  virtual PersistedSEGObject *createPersistedObject() const;
43 
47  void addMatchingCondition(const SEGNodeBase *Node, SEGRegionNode *Cond) {
48  MatchingConditions[Node] = Cond;
49  }
50 
53  auto It = MatchingConditions.find(Node);
54  if (It != MatchingConditions.end()) {
55  return It->second;
56  }
57  // assert(false && "No matching condition for a mem node.");
58  // It may return null when falcon is disabled.
59  return nullptr;
60  }
61 
62  void dot(raw_fd_ostream &O) const;
63 
64  virtual std::string getAuxiliaryDebugStr() const {
65  std::stringstream Result;
66  int Index = 1;
67  for (auto &It : MatchingConditions) {
68  if (It.first) {
69  Result << Index << ". value is from file:" << It.first->getSrcFile()
70  << ", the line is:" << It.first->getSrcLine() << ";";
71  } else {
72  Result << Index << ". value is from file: NA"
73  << ", the line is: NA"
74  << ";";
75  }
76  Index++;
77  }
78  return Result.str();
79  }
80 
81 public:
82  static bool classof(const SEGObject *N) {
83  return N->getKind() == SEGOBJK_LoadMem;
84  }
85 };
86 
87 #endif
SymbolicExprGraph::dot
void dot(const char *FileName) const
Dot this graph to a file with filename.
Definition: SymbolicExprGraph.cpp:1539
SEGOperandNode
Definition: SymbolicExprGraph.h:539
SymbolicExprGraph
Definition: SymbolicExprGraph.h:855
SEGLoadMemNode::addMatchingCondition
void addMatchingCondition(const SEGNodeBase *Node, SEGRegionNode *Cond)
Definition: SEGLoadMemNode.h:47
SEGLoadMemNode::getMatchingCondition
SEGRegionNode * getMatchingCondition(const SEGNodeBase *Node) const
Get the condition of loaded value.
Definition: SEGLoadMemNode.h:52
SEGObject
Definition: SymbolicExprGraph.h:87
SEGRegionNode
Definition: SEGRegionNode.h:36
SEGLoadMemNode
Definition: SEGLoadMemNode.h:23
SEGNodeBase
The node base of symbolic expression graph.
Definition: SymbolicExprGraph.h:288