* Double_Store: 32-bit fix.
[cacao.git] / src / vm / jit / intrp / intrp.h
1 /* src/vm/jit/intrp/intrp.h - definitions for Interpreter
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28             Anton Ertl
29
30    Changes:
31
32    $Id: intrp.h 3212 2005-09-19 11:30:08Z twisti $
33
34 */
35
36
37 #ifndef _INTRP_H
38 #define _INTRP_H
39
40 #include <stdio.h>
41
42 /* #define VM_PROFILING */
43
44 #include "vm/jit/intrp/arch.h"
45 #include "vm/jit/intrp/types.h"
46
47 #include "vm/class.h"
48 #include "vm/global.h"
49 #include "vm/method.h"
50 #include "vm/references.h"
51 #include "vm/resolve.h"
52
53 typedef void *Inst;
54 typedef ptrint Cell;
55
56 #if 1
57 #define MAYBE_UNUSED __attribute__((unused))
58 #else
59 #define MAYBE_UNUSED
60 #endif
61
62 #if SIZEOF_VOID_P == 4
63 typedef union {
64     struct {
65                 u4 low;
66                 s4 high;
67     } cells;
68     s8 l;
69     double d;
70 } Double_Store;
71
72 #define FETCH_DCELL_T(d_,lo,hi,t_)      ({ \
73                                      Double_Store _d; \
74                                      _d.cells.low = (lo); \
75                                      _d.cells.high = (hi); \
76                                      (d_) = _d.t_; \
77                                  })
78
79 #define STORE_DCELL_T(d_,lo,hi,t_)      ({ \
80                                      Double_Store _d; \
81                                      _d.t_ = (d_); \
82                                      (lo) = _d.cells.low; \
83                                      (hi) = _d.cells.high; \
84                                  })
85
86 #else /* 64-bit */
87 typedef union {
88   s8 low;
89   s8 l;
90   double d;
91 } Double_Store;
92
93
94 #define FETCH_DCELL_T(d_,lo,hi,t_)      ({ (d_) = ((Double_Store)(lo)).t_; })
95 #define STORE_DCELL_T(d_,lo,hi,t_)      ({ (lo) = ((Double_Store)(d_)).low; })
96 #endif /* 64-bit */
97
98 #define vm_twoCell2l(hi,lo,d_)  FETCH_DCELL_T(d_,lo,hi,l);
99 #define vm_twoCell2d(hi,lo,d_)  FETCH_DCELL_T(d_,lo,hi,d);
100                                                                                                  
101 #define vm_l2twoCell(d_,hi,lo)  STORE_DCELL_T(d_,lo,hi,l);
102 #define vm_d2twoCell(d_,hi,lo)  STORE_DCELL_T(d_,lo,hi,d);
103
104 #define vm_Cell2v(cell, v) ((v)=(Cell)(cell))
105 #define vm_Cell2b(cell, b) ((b)=(u1)(Cell)(cell))
106 #define vm_Cell2i(cell, i) ((i)=(s4)(Cell)(cell))
107
108 #define vm_Cell2aRef(x1,x2)       ((x2) = (java_objectheader *)(x1))
109 #define vm_Cell2aArray(x1,x2)     ((x2) = (java_arrayheader * )(x1))
110 #define vm_Cell2aaTarget(x1,x2)   ((x2) = (Inst **            )(x1))
111 #define vm_Cell2aClass(x1,x2)     ((x2) = (classinfo *        )(x1))
112 #define vm_Cell2acr(x1,x2)        ((x2) = (constant_classref *)(x1))
113 #define vm_Cell2addr(x1,x2)       ((x2) = (u1 *               )(x1))
114 #define vm_Cell2af(x1,x2)         ((x2) = (functionptr        )(x1))
115 #define vm_Cell2am(x1,x2)         ((x2) = (methodinfo *       )(x1))
116 #define vm_Cell2acell(x1,x2)      ((x2) = (Cell *             )(x1))
117 #define vm_Cell2ainst(x1,x2)      ((x2) = (Inst *             )(x1))
118 #define vm_Cell2auf(x1,x2)        ((x2) = (unresolved_field * )(x1))
119 #define vm_Cell2aum(x1,x2)        ((x2) = (unresolved_method *)(x1))
120 #define vm_Cell2avftbl(x1,x2)     ((x2) = (vftbl_t *          )(x1))
121
122 #define vm_ui2Cell(x1,x2) ((x2) = (Cell)(x1))
123 #define vm_v2Cell(x1,x2) ((x2) = (Cell)(x1))
124 #define vm_b2Cell(x1,x2) ((x2) = (Cell)(x1))
125 #define vm_s2Cell(x1,x2) ((x2) = (Cell)(x1))
126 #define vm_i2Cell(x1,x2) ((x2) = (Cell)(x1))
127 #define vm_aRef2Cell(x1,x2) ((x2) = (Cell)(x1))
128 #define vm_aArray2Cell(x1,x2) ((x2) = (Cell)(x1))
129 #define vm_aaTarget2Cell(x1,x2) ((x2) = (Cell)(x1))
130 #define vm_aClass2Cell(x1,x2) ((x2) = (Cell)(x1))
131 #define vm_acr2Cell(x1,x2) ((x2) = (Cell)(x1))
132 #define vm_addr2Cell(x1,x2) ((x2) = (Cell)(x1))
133 #define vm_af2Cell(x1,x2) ((x2) = (Cell)(x1))
134 #define vm_am2Cell(x1,x2) ((x2) = (Cell)(x1))
135 #define vm_acell2Cell(x1,x2) ((x2) = (Cell)(x1))
136 #define vm_ainst2Cell(x1,x2) ((x2) = (Cell)(x1))
137 #define vm_auf2Cell(x1,x2) ((x2) = (Cell)(x1))
138 #define vm_aum2Cell(x1,x2) ((x2) = (Cell)(x1))
139 #define vm_avftbl2Cell(x1,x2) ((x2) = (Cell)(x1))
140
141 #define vm_Cell2Cell(x1,x2) ((x2)=(Cell)(x1))
142
143 #define IMM_ARG(access,value)           (access)
144
145 /* for disassembler and tracer */
146 #define VM_IS_INST(inst, n) ((inst) == vm_prim[n])
147
148
149 #define gen_BBSTART (cd->last_compiled = NULL)
150
151
152 union Cell_float {
153     Cell cell;
154     float f;
155 };
156
157 typedef struct block_count block_count;
158
159 #define vm_f2Cell(x1,x2)        ((x2) =(((union Cell_float)(x1)).cell))
160 #define vm_Cell2f(x1,x2)        ((x2) =(((union Cell_float)(x1)).f))
161
162 extern Inst *vm_prim;
163 extern Cell peeptable;
164 extern Inst *last_compiled;
165 extern FILE *vm_out;
166
167 void init_peeptable(void);
168 Inst peephole_opt(Inst inst1, Inst inst2, Cell peeptable);
169 void vm_disassemble(Inst *ip, Inst *endp, Inst vm_prim[]);
170 Inst *vm_disassemble_inst(Inst *ip, Inst vm_prim[]);
171
172 java_objectheader *engine(Inst *ip0, Cell * sp, Cell * fp);
173
174 /* print types for disassembler and tracer */
175 void printarg_ui      (u4                 ui      );
176 void printarg_v       (Cell               v       );
177 void printarg_b       (s4                 b       );
178 void printarg_s       (s4                 s       );
179 void printarg_i       (s4                 i       );
180 void printarg_l       (s8                 l       );
181 void printarg_f       (float              f       );
182 void printarg_d       (double             d       );
183 void printarg_aRef    (java_objectheader *aRef    );
184 void printarg_aArray  (java_arrayheader * aArray  );
185 void printarg_aaTarget(Inst **            aaTarget);
186 void printarg_aClass  (classinfo *        aClass  );
187 void printarg_acr     (constant_classref *acr     );
188 void printarg_addr    (u1 *               addr    );
189 void printarg_af      (functionptr        af      );
190 void printarg_am      (methodinfo *       am      );
191 void printarg_acell   (Cell *             acell   );
192 void printarg_ainst   (Inst *             ainst   );
193 void printarg_auf     (unresolved_field * auf     );
194 void printarg_aum     (unresolved_method *aum     );
195 void printarg_avftbl  (vftbl_t *          avftbl  );
196 void printarg_Cell    (Cell               x       );
197
198 /* gen_... functions used in engine.c */
199 void gen_INVOKESTATIC(Inst **ctp, Inst ** aaTarget, s4 iNargs, unresolved_method * aum);
200 void gen_END(Inst **ctp);
201
202 void vm_uncount_block(Inst *ip);
203 block_count *vm_block_insert(Inst *ip);
204
205
206 functionptr createcalljavafunction(methodinfo *m);
207
208 #endif /* _INTRP_H */
209
210
211 /*
212  * These are local overrides for various environment variables in Emacs.
213  * Please do not remove this and leave it at the end of the file, where
214  * Emacs will automagically detect them.
215  * ---------------------------------------------------------------------
216  * Local variables:
217  * mode: c
218  * indent-tabs-mode: t
219  * c-basic-offset: 4
220  * tab-width: 4
221  * End:
222  */