ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PtrAnal.h
Go to the documentation of this file.
1 #ifndef PTR_ANAL_H
2 #define PTR_ANAL_H
3 #include <boost/unordered_map.hpp>
4 #include <ProcessAstTree.h>
5 #include <AstInterface.h>
6 #include <StmtInfoCollect.h>
7 #include <CFG.h>
8 
9 class PtrAnal
10 : public ProcessAstTreeBase, public AliasAnalysisInterface
11 {
12  public:
13  typedef enum { EQ, NE, LT, GT, LE, GE, OTHER } OpType;
14  typedef void* Stmt;
15  struct VarRef { Stmt stmt; std::string name;
16  VarRef(Stmt _stmt=0, const std::string& _name="")
17  : stmt(_stmt), name(_name) {};
18  };
19  typedef std::list<Stmt> StmtRef;
20 
21  void operator()( AstInterface& fa, const AstNodePtr& program);
22  bool may_alias(AstInterface& fa, const AstNodePtr& r1, const AstNodePtr& r2);
23  VarRef translate_exp(const AstNodePtr& exp) const;
24  StmtRef translate_stmt(const AstNodePtr& stmt) const;
25 
26  virtual bool may_alias(const std::string& x, const std::string& y) = 0;
27  virtual Stmt x_eq_y(const std::string& x, const std::string& y) = 0;
28  virtual Stmt x_eq_addr_y(const std::string& x, const std::string& y) = 0;
29  virtual Stmt x_eq_deref_y(const std::string& x,
30  const std::string& field,
31  const std::string& y) = 0;
32  virtual Stmt x_eq_field_y(const std::string& x,
33  const std::string& field,
34  const std::string& y) = 0;
35  virtual Stmt deref_x_eq_y(const std::string& x,
36  const std::list<std::string>& field,
37  const std::string& y) = 0;
38  virtual Stmt field_x_eq_y(const std::string& x,
39  const std::list<std::string>& field,
40  const std::string& y) = 0;
41  virtual Stmt allocate_x(const std::string& x) = 0;
42  virtual Stmt x_eq_op_y(OpType op, const std::string& x, const std::list<std::string>& y) =0;
43  virtual Stmt funcdef_x(const std::string& x, const std::list<std::string>& params,
44  const std::list<std::string>& ouput) = 0;
45  virtual Stmt funccall_x ( const std::string& x, const std::list<std::string>& args,
46  const std::list<std::string>& result)=0;
47  virtual Stmt funcexit_x( const std::string& x) = 0;
48 
49  virtual void contrl_flow(Stmt stmt1, Stmt stmt2, CFGConfig::EdgeType t) {}
50 
51 private:
52  class hash {
53  public:
54  size_t operator()(void * p) const { return (size_t) p; }
55  };
56  typedef boost::unordered_map<void*, VarRef, PtrAnal::hash> NameMap;
57  typedef boost::unordered_map<void*, std::pair<size_t,size_t>, PtrAnal::hash> StmtMap;
58 
59  std::list<std::string> fdefined;
62  std::vector<Stmt> stmts;
63  std::list<size_t> stmt_active;
64 
65  protected:
66  void ProcessAssign( AstInterface& fa, const AstNodePtr& mod, const AstNodePtr& rhs, bool readlhs=0);
67  void ProcessExpression( AstInterface& fa, const std::string& modname, const AstNodePtr& rhs);
68  void ProcessMod(AstInterface& fa, const std::string& readname,
69  std::list<std::string>& fields, const AstNodePtr& mod);
70 
71  void ControlFlowAnalysis(AstInterface& fa, const AstNodePtr& head, Stmt defn);
72 
73  std::string Get_VarName(AstInterface& fa, const AstNodePtr& rhs);
74 
75  virtual bool ProcessTree( AstInterface &_fa, const AstNodePtr& s,
76  AstInterface::TraversalVisitType t);
77  static std::string get_func_output(const std::string& fname, int i)
78  { return InterProcVariableUniqueRepr::get_unique_name(fname+"-return",i); }
79  static std::string get_func_par(const std::string& fname, int i)
80  { return InterProcVariableUniqueRepr::get_unique_name(fname+"-par",i); }
81 };
82 #endif