- New file to extract type info from executables in Coff format
[dyninst.git] / dyninstAPI / h / BPatch_snippet.h
1 /*
2  * Copyright (c) 1996 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * This license is for research uses.  For such uses, there is no
12  * charge. We define "research use" to mean you may freely use it
13  * inside your organization for whatever purposes you see fit. But you
14  * may not re-distribute Paradyn or parts of Paradyn, in any form
15  * source or binary (including derivatives), electronic or otherwise,
16  * to any other organization or entity without our permission.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
24  * By your use of Paradyn, you understand and agree that we (or any
25  * other person or entity with proprietary rights in Paradyn) are
26  * under no obligation to provide either maintenance services,
27  * update services, notices of latent defects, or correction of
28  * defects for Paradyn.
29  * 
30  * Even if advised of the possibility of such damages, under no
31  * circumstances shall we (or any other person or entity with
32  * proprietary rights in the software licensed hereunder) be liable
33  * to you or any third party for direct, indirect, or consequential
34  * damages of any character regardless of type of action, including,
35  * without limitation, loss of profits, loss of use, loss of good
36  * will, or computer failure or malfunction.  You agree to indemnify
37  * us (and any other person or entity with proprietary rights in the
38  * software licensed hereunder) for any and all liability it may
39  * incur to third parties resulting from your use of Paradyn.
40  */
41
42 #ifndef _BPatch_snippet_h_
43 #define _BPatch_snippet_h_
44
45 #include "BPatch_Vector.h"
46 #include "BPatch_point.h"
47 #include "BPatch_type.h"
48 #include "BPatch_module.h"
49
50 class AstNode;
51 class function_base;
52 class process;
53
54 class BPatch_localVarCollection;
55 class BPatch_function;
56 class BPatch_point;
57
58 typedef enum {
59     BPatch_lt,
60     BPatch_eq,
61     BPatch_gt,
62     BPatch_le,
63     BPatch_ne,
64     BPatch_ge,
65     BPatch_and,
66     BPatch_or
67 } BPatch_relOp;
68
69 typedef enum {
70     BPatch_assign,
71     BPatch_plus,
72     BPatch_minus,
73     BPatch_divide,
74     BPatch_times,
75     BPatch_mod,
76     BPatch_ref,
77     BPatch_seq
78 } BPatch_binOp;
79
80 typedef enum {
81     BPatch_negate,
82     BPatch_addr,
83     BPatch_deref
84 } BPatch_unOp;
85
86
87 class BPatch_function {
88     process *proc;
89     BPatch_type * retType;
90     BPatch_Vector<BPatch_localVar *> params;
91     BPatch_module *mod;
92     
93 public:
94 // The following are for  internal use by the library only:
95     function_base *func;
96 // No longer inline but defined in .C file
97     BPatch_function(process *_proc, function_base *_func, BPatch_module *);
98     BPatch_function(process *_proc, function_base *_func,
99                     BPatch_type * _retType, BPatch_module *);
100     BPatch_localVarCollection * localVariables;
101     BPatch_localVarCollection * funcParameters;
102     void setReturnType( BPatch_type * _retType){
103       retType = _retType;}
104     
105 // For users of the library:
106     char         *getName(char *s, int len);
107     void         *getBaseAddr();
108     unsigned int getSize();
109     BPatch_type * getReturnType(){ return retType; }
110     BPatch_module *getModule()  { return mod; }
111     void addParam(char * _name, BPatch_type *_type, int _linenum,
112                   int _frameOffset, int _sc = 5 /* scAbs */ );
113     
114     BPatch_Vector<BPatch_localVar *> *getParams() { 
115       return &params; }
116     BPatch_Vector<BPatch_point *>
117         *findPoint(const BPatch_procedureLocation loc);
118     BPatch_localVar * findLocalVar( const char * name);
119     BPatch_localVar * findLocalParam(const char * name);
120 };
121
122
123 class BPatch_snippet {
124 public:
125 // The following members are for  internal use by the library only:
126     AstNode     *ast; /* XXX It would be better if this was protected */
127 // End members for internal use only.
128
129     BPatch_snippet() : ast(NULL) {};
130     BPatch_snippet(const BPatch_snippet &);
131     BPatch_snippet &operator=(const BPatch_snippet &);
132
133     virtual     ~BPatch_snippet();
134
135     float       getCost();
136 };
137
138 class BPatch_arithExpr: public BPatch_snippet {
139 public:
140     BPatch_arithExpr(BPatch_binOp op,
141                      const BPatch_snippet &lOperand,
142                      const BPatch_snippet &rOperand);
143     BPatch_arithExpr(BPatch_unOp op, const BPatch_snippet &lOperand);
144 };
145
146 class BPatch_boolExpr : public BPatch_snippet {
147 public:
148     BPatch_boolExpr(BPatch_relOp op, const BPatch_snippet &lOperand,
149                     const BPatch_snippet &rOperand);
150 };
151
152 class BPatch_constExpr : public BPatch_snippet {
153 public:
154     BPatch_constExpr(int value);
155 #ifdef BPATCH_NOT_YET
156     BPatch_constExpr(float value);
157 #endif
158     BPatch_constExpr(const char *value);
159 };
160
161 class BPatch_funcCallExpr : public BPatch_snippet {
162 public:
163     BPatch_funcCallExpr(const BPatch_function& func,
164                         const BPatch_Vector<BPatch_snippet *> &args);
165 };
166
167 class BPatch_funcJumpExpr : public BPatch_snippet {
168 public:
169      BPatch_funcJumpExpr(const BPatch_function& func);
170 };
171
172 class BPatch_ifExpr : public BPatch_snippet {
173 public:
174     BPatch_ifExpr(const BPatch_boolExpr &conditional,
175                   const BPatch_snippet &tClase);
176     BPatch_ifExpr(const BPatch_boolExpr &conditional,
177                   const BPatch_snippet &tClase,
178                   const BPatch_snippet &fClause);
179 };
180
181 class BPatch_nullExpr : public BPatch_snippet {
182 public:
183     BPatch_nullExpr();
184 };
185
186 class BPatch_paramExpr : public BPatch_snippet {
187 public:
188     BPatch_paramExpr(int n);
189 };
190
191 class BPatch_retExpr : public BPatch_snippet {
192 public:
193     BPatch_retExpr();
194 };
195
196 class BPatch_sequence : public BPatch_snippet {
197 public:
198     BPatch_sequence(const BPatch_Vector<BPatch_snippet *> &items);
199 };
200
201 class BPatch_variableExpr : public BPatch_snippet {
202     char                *name;
203     process             *proc;
204     void                *address;
205     int                 size;
206     BPatch_point        *scope;
207 public:
208 // The following functions are for internal use by the library only:
209     BPatch_variableExpr(char *name, process *in_process, void *in_address,
210                         const BPatch_type *type);
211     BPatch_variableExpr(process *in_process, void *in_address,
212                         const BPatch_type *type, bool frameRelative = false,
213                         BPatch_point *sc = NULL);
214     BPatch_variableExpr(process *in_process, void *in_address,
215                         int in_size);
216     BPatch_variableExpr(char *in_name, process *in_process, AstNode *_ast,
217                         const BPatch_type *type);
218
219 // Public functions for use by users of the library:
220     bool readValue(void *dst);
221     void readValue(void *dst, int len);
222     bool writeValue(const void *src);
223     void writeValue(const void *src, int len);
224
225     char *getName() { return name; }
226     void *getBaseAddr() const { return address; }
227     const BPatch_type *getType();
228     void setType(BPatch_type *);
229     void setSize(int sz) {  size = sz; }
230     BPatch_Vector<BPatch_variableExpr *> *getComponents();
231 };
232
233 class BPatch_breakPointExpr : public BPatch_snippet {
234 public:
235     BPatch_breakPointExpr();
236 };
237
238 #endif /* _BPatch_snippet_h_ */