ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
virtualBinCFG.h
Go to the documentation of this file.
1 #ifndef VIRTUAL_BIN_CFG_H
2 #define VIRTUAL_BIN_CFG_H
3 
4 #include <stdint.h>
5 #include "rosedll.h"
6 
7 //class AttachedPreprocessingInfoType;
8 class SgAsmInstruction;
9 class SgAsmStatement;
10 
11 namespace VirtualBinCFG {
12 
13  class CFGEdge;
14 
16  {
17  eckUnconditional, // Normal, unconditional edge
18  eckTrue, // True case of a two-way branch
19  eckFalse, // False case of a two-way branch
20  eckCaseLabel, // Case label (constant is given by caseLabel())
21  eckDefault // Default label
22  };
23 
24  typedef std::set<rose_addr_t> AddressSet;
25  typedef std::map<rose_addr_t, SgAsmInstruction*> AddressToInstructionMap;
26  typedef std::map<SgAsmInstruction*, AddressSet> InstructionToAddressesMap;
27  typedef std::map<SgAsmStatement*, AddressSet> StatementToAddressesMap;
28 
32  StatementToAddressesMap returnTargets; /* statement is SgAsmBlock or SgAsmFunction */
34 
35  public:
36 
39 
42  AddressToInstructionMap::const_iterator i = addressToInstructionMap.find(addr);
43  if (i == addressToInstructionMap.end()) return NULL;
44  return i->second;
45  }
46 
47  /* NOTE: this is not the transpose of getPossiblePredecessors()! */
48  const AddressSet& getPossibleSuccessors(SgAsmInstruction* insn) const;
49 
51  static const AddressSet emptySet;
52  InstructionToAddressesMap::const_iterator predsIter = incomingEdges.find(insn);
53  if (predsIter == incomingEdges.end()) {
54  return emptySet;
55  } else {
56  return predsIter->second;
57  }
58  }
59  };
60 
61  class CFGNode {
64  public:
66  : node(node), info(info) {
67 #ifdef _MSC_VER
68 //#define __builtin_constant_p(exp) (0)
69 #endif
70  assert(node);
71  }
72  std::string toString() const;
73  // String for debugging graphs
74  std::string toStringForDebugging() const;
75  // ID to use for Dot, etc.
76  std::string id() const;
77 
79  return node;
80  }
81 
82  std::vector<CFGEdge> outEdges() const;
83  std::vector<CFGEdge> inEdges() const;
84  bool operator==(const CFGNode& o) const {
85  return node == o.node;
86  }
87  bool operator!=(const CFGNode& o) const {
88  return !(*this == o);
89  }
90  bool operator<(const CFGNode& o) const {
91  return node < o.node;
92  }
93  };
94 
95  class CFGEdge {
98  public:
100  : src(src), tgt(tgt), info(info)
101  {}
102  std::string toString() const; // Pretty string for Dot node labels, etc.
103  std::string toStringForDebugging() const; // String for debugging graphs
104  std::string id() const; // ID to use for Dot, etc.
105  CFGNode source() const {
106  return src;
107  }
108  CFGNode target() const {
109  return tgt;
110  }
112  //SgExpression* caseLabel() const;
113  //SgExpression* conditionBasedOn() const;
114  //std::vector<SgInitializedName*> scopesBeingExited() const;
115  //std::vector<SgInitializedName*> scopesBeingEntered() const;
116  bool operator==(const CFGEdge& o) const {
117  return src == o.src && tgt == o.tgt;
118  }
119  bool operator!=(const CFGEdge& o) const {
120  return src != o.src || tgt != o.tgt;
121  }
122  bool operator<(const CFGEdge& o) const {
123  return src < o.src || (src == o.src && tgt < o.tgt);
124  }
125  };
126 
127  // Used in inEdges() and outEdges() methods
128  void makeEdge(SgAsmInstruction *from, SgAsmInstruction *to, const AuxiliaryInformation *info, std::vector<CFGEdge> &result);
129 }
130 
131 #endif /* VIRTUAL_CFG_H */