Merge branch 'master' of git.dyninst.org:/pub/dyninst
[dyninst.git] / symEval / h / AbslocInterface.h
1
2
3 #if !defined(Absloc_Interface_H)
4 #define Absloc_Interface_H
5
6 #include "Instruction.h"
7 #include "Register.h"
8 #include "Expression.h"
9 #include "Operand.h"
10 #include "Absloc.h"
11
12 class image_func;
13 class int_function;
14 class BPatch_function;
15
16 namespace Dyninst {
17
18 class AbsRegionConverter {
19  public:
20  AbsRegionConverter(bool cache) : 
21   cacheEnabled_(cache) {};
22
23   // Definition: the first AbsRegion represents the expression.
24   // If it's a memory reference, any other AbsRegions represent
25   // registers used in this expression.
26
27   void convertAll(InstructionAPI::Expression::Ptr expr,
28                   Address addr,
29                   image_func *func,
30                   std::vector<AbsRegion> &regions);
31
32   void convertAll(InstructionAPI::Instruction::Ptr insn,
33                   Address addr,
34                   image_func *func,
35                   std::vector<AbsRegion> &used,
36                   std::vector<AbsRegion> &defined);
37
38   // Single converters
39   
40   AbsRegion convert(InstructionAPI::RegisterAST::Ptr reg);
41
42   AbsRegion convert(InstructionAPI::Expression::Ptr expr,
43                     Address addr,
44                     image_func *func);
45
46   // Cons up a stack reference at the current addr
47   AbsRegion stack(Address addr,
48                   image_func *func,
49                   bool push);
50
51   AbsRegion frame(Address addr,
52                   image_func *func,
53                   bool push);
54
55  private:
56     // Returns false if the current height is unknown.
57   bool getCurrentStackHeight(image_func *func,
58                              Address addr, 
59                              long &height, int &region);
60   bool getCurrentFrameHeight(image_func *func,
61                              Address addr, 
62                              long &height, int &region);
63
64   bool convertResultToAddr(const InstructionAPI::Result &res, Address &addr);
65   bool convertResultToSlot(const InstructionAPI::Result &res, int &slot);
66
67   bool usedCache(Address, image_func *, std::vector<AbsRegion> &used);
68   bool definedCache(Address, image_func *, std::vector<AbsRegion> &defined);
69
70   // Caching mechanism...
71   typedef std::vector<AbsRegion> RegionVec;
72
73   typedef std::map<Address, RegionVec> AddrCache;
74   typedef std::map<image_func *, AddrCache> FuncCache;
75
76   FuncCache used_cache_;
77   FuncCache defined_cache_;
78   bool cacheEnabled_;
79 };
80
81 class AssignmentConverter {
82  public:  
83  AssignmentConverter(bool cache) : cacheEnabled_(cache), aConverter(false) {};
84
85   void convert(InstructionAPI::Instruction::Ptr insn,
86                const Address &addr,
87                image_func *func,
88                std::vector<Assignment::Ptr> &assignments);
89   void convert(InstructionAPI::Instruction::Ptr insn,
90                const Address &addr,
91                int_function *func,
92                std::vector<Assignment::Ptr> &assignments);
93   void convert(InstructionAPI::Instruction::Ptr insn,
94                const Address &addr,
95                BPatch_function *func,
96                std::vector<Assignment::Ptr> &assignments);
97
98
99  private:
100   void handlePushEquivalent(const InstructionAPI::Instruction::Ptr I,
101                             Address addr,
102                             image_func *func,
103                             std::vector<AbsRegion> &operands,
104                             std::vector<Assignment::Ptr> &assignments);
105   void handlePopEquivalent(const InstructionAPI::Instruction::Ptr I,
106                            Address addr,
107                            image_func *func,
108                            std::vector<AbsRegion> &operands,
109                            std::vector<Assignment::Ptr> &assignments);
110
111   bool cache(image_func *func, Address addr, std::vector<Assignment::Ptr> &assignments);
112
113   typedef std::vector<Assignment::Ptr> AssignmentVec;
114   typedef std::map<Address, AssignmentVec> AddrCache;
115   typedef std::map<image_func *, AddrCache> FuncCache;
116
117   FuncCache cache_;
118   bool cacheEnabled_;
119
120   AbsRegionConverter aConverter;
121 };
122
123 };
124 #endif
125