Unified variables changes for common/i386.
[cacao.git] / src / vm / jit / parse.h
1 /* src/vm/jit/parse.h - parser header
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Author:  Christian Thalinger
28
29    Changes: Edwin Steiner
30
31    $Id: parse.h 5404 2006-09-07 13:29:05Z christian $
32
33 */
34
35
36 #ifndef _PARSE_H
37 #define _PARSE_H
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include "vm/global.h"
43 #include "vm/jit/codegen-common.h"
44
45
46 /* macros for verifier checks during parsing **********************************/
47
48 #if defined(ENABLE_VERIFIER)
49
50 /* We have to check local variables indices here because they are             */
51 /* used in stack.c to index the locals array.                                 */
52
53 #define INDEX_ONEWORD(num) \
54     do { \
55         if (((num) < 0) || ((num) >= m->maxlocals)) \
56             goto throw_illegal_local_variable_number; \
57     } while (0)
58
59 #define INDEX_TWOWORD(num) \
60     do { \
61         if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
62             goto throw_illegal_local_variable_number; \
63     } while (0)
64
65 /* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index.        */
66 /* The end of the bytecode (i == m->jcodelength) is considered valid.         */
67
68 #define CHECK_BYTECODE_INDEX(i) \
69     do { \
70         if (((i) < 0) || ((i) >= m->jcodelength)) \
71                         goto throw_invalid_bytecode_index; \
72     } while (0)
73
74 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends               */
75 /* of exception handler ranges.                                                */
76 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
77     do { \
78         if ((i) < 0 || (i) > m->jcodelength) \
79                         goto throw_invalid_bytecode_index; \
80     } while (0)
81
82 #else /* !define(ENABLE_VERIFIER) */
83
84 #define INDEX_ONEWORD(num)
85 #define INDEX_TWOWORD(num)
86 #define CHECK_BYTECODE_INDEX(i)
87 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
88
89 #endif /* define(ENABLE_VERIFIER) */
90
91
92 /* basic block generating macro ***********************************************/
93
94 #define MARK_BASICBLOCK(i) \
95     do { \
96         if (!(jd->new_basicblockindex[(i)] & 1)) { \
97             b_count++; \
98             jd->new_basicblockindex[(i)] |= 1; \
99         } \
100     } while (0)
101
102 #define INSTRUCTIONS_CHECK(i) \
103             if ((ipc + (i)) > pd.instructionslength) \
104         iptr = parse_check_instructions(&pd, ipc)
105
106
107 /* intermediate code generating macros ****************************************/
108
109 /* These macros ALWAYS set the following fields of *iptr to valid values:     */
110 /*     iptr->opc                                                              */
111 /*     iptr->flags                                                            */
112 /*     iptr->line                                                             */
113
114 /* These macros do NOT touch the following fields of *iptr, unless a value is */
115 /* given for them:                                                            */
116 /*     iptr->s1                                                               */
117 /*     iptr->sx                                                               */
118 /*     iptr->dst                                                              */
119
120 /* The _PREPARE macros omit the PINC, so you can set additional fields        */
121 /* afterwards.                                                                */
122 /* CAUTION: Some of the _PREPARE macros don't set iptr->flags!                */
123
124 #define PINC                                                           \
125     iptr++; ipc++
126
127 /* CAUTION: You must set iptr->flags yourself when using this!                */
128 #define OP_PREPARE(o)                                                  \
129     iptr->opc                = (o);                                    \
130     iptr->line               = currentline;
131
132 #define OP_PREPARE_FLAGS(o, f)                                         \
133     iptr->opc                = (o);                                    \
134     iptr->line               = currentline;                            \
135     iptr->flags.bits         = (f);
136
137 #define OP_PREPARE_ZEROFLAGS(o)                                        \
138         OP_PREPARE_FLAGS(o, 0)
139
140 #define OP(o)                                                          \
141         OP_PREPARE_ZEROFLAGS(o);                                           \
142     PINC
143
144 #define OP_LOADCONST_I(v)                                              \
145         OP_PREPARE_ZEROFLAGS(ICMD_ICONST);                                 \
146     iptr->sx.val.i           = (v);                                    \
147     PINC
148
149 #define OP_LOADCONST_L(v)                                              \
150         OP_PREPARE_ZEROFLAGS(ICMD_LCONST);                                 \
151     iptr->sx.val.l           = (v);                                    \
152     PINC
153
154 #define OP_LOADCONST_F(v)                                              \
155         OP_PREPARE_ZEROFLAGS(ICMD_FCONST);                                 \
156     iptr->sx.val.f           = (v);                                    \
157     PINC
158
159 #define OP_LOADCONST_D(v)                                              \
160         OP_PREPARE_ZEROFLAGS(ICMD_DCONST);                                 \
161     iptr->sx.val.d           = (v);                                    \
162     PINC
163
164 #define OP_LOADCONST_NULL()                                            \
165         OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK);                     \
166     iptr->sx.val.anyptr      = NULL;                                   \
167     PINC
168
169 #define OP_LOADCONST_STRING(v)                                         \
170         OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK);                     \
171     iptr->sx.val.stringconst = (v);                                    \
172     PINC
173
174 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags)   \
175         OP_PREPARE(ICMD_ACONST);                                           \
176     if (cl) {                                                          \
177         iptr->sx.val.c.cls   = (cl);                                   \
178         iptr->flags.bits     = INS_FLAG_CLASS | (extraflags);          \
179     }                                                                  \
180     else {                                                             \
181         iptr->sx.val.c.ref   = (cr);                                   \
182         iptr->flags.bits     = INS_FLAG_CLASS | INS_FLAG_UNRESOLVED    \
183                              | (extraflags);                           \
184     }                                                                  \
185     PINC
186
187 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr)                \
188         OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
189
190 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr)              \
191         OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
192
193 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags)              \
194         OP_PREPARE(o);                                                     \
195     if (c) {                                                           \
196         iptr->sx.s23.s3.c.cls= (c);                                    \
197         iptr->flags.bits     = (extraflags);                           \
198     }                                                                  \
199     else {                                                             \
200         iptr->sx.s23.s3.c.ref= (cr);                                   \
201         iptr->flags.bits     = INS_FLAG_UNRESOLVED | (extraflags);     \
202     }                                                                  \
203     PINC
204
205 #define OP_INSINDEX(o, iindex)                                         \
206         OP_PREPARE_ZEROFLAGS(o);                                           \
207     iptr->dst.insindex       = (iindex);                               \
208     PINC
209
210 #if defined(NEW_VAR)
211 # define OP_LOCALINDEX(o,index)                                        \
212         OP_PREPARE_ZEROFLAGS(o);                                           \
213     iptr->s1.varindex      = (index);                                \
214     PINC
215
216 # define OP_LOCALINDEX_I(o,index,v)                                    \
217         OP_PREPARE_ZEROFLAGS(o);                                           \
218     iptr->s1.varindex      = (index);                                  \
219     iptr->sx.val.i           = (v);                                    \
220     PINC
221
222 # define LOCALTYPE_USED(index,type)                                                                        \
223         do {                                                                                                                       \
224                 local_map[(index) * 5 + (type)] = 1;                                               \
225         } while (0)
226 #else 
227 # define OP_LOCALINDEX(o,index)                                        \
228         OP_PREPARE_ZEROFLAGS(o);                                           \
229     iptr->s1.localindex      = (index);                                  \
230     PINC
231
232 # define OP_LOCALINDEX_I(o,index,v)                                    \
233         OP_PREPARE_ZEROFLAGS(o);                                           \
234     iptr->s1.localindex      = (index);                                \
235     iptr->sx.val.i           = (v);                                    \
236     PINC
237 #error 333
238 # define LOCALTYPE_USED(index,type)
239 #endif /* defined(NEW_VAR) */
240
241 #define OP_LOAD_ONEWORD(o,index,type)                                                          \
242     do {                                                               \
243         INDEX_ONEWORD(index);                                          \
244         OP_LOCALINDEX(o,index);                                        \
245                 LOCALTYPE_USED(index,type);                                                                    \
246     } while (0)
247
248 #define OP_LOAD_TWOWORD(o,index,type)                                                          \
249     do {                                                               \
250         INDEX_TWOWORD(index);                                          \
251         OP_LOCALINDEX(o,index);                                        \
252                 LOCALTYPE_USED(index,type);                                                                        \
253         } while (0)
254
255 #if defined(NEW_VAR)
256 # define OP_STORE_ONEWORD(o,index,type)                                                        \
257     do {                                                               \
258         INDEX_ONEWORD(index);                                          \
259         OP_PREPARE_ZEROFLAGS(o);                                       \
260         iptr->dst.varindex = (index);                                  \
261                 LOCALTYPE_USED(index,type);                                                                        \
262         PINC;                                                          \
263     } while (0)
264
265 # define OP_STORE_TWOWORD(o,index,type)                                                        \
266     do {                                                               \
267         INDEX_TWOWORD(index);                                          \
268         OP_PREPARE_ZEROFLAGS(o);                                       \
269         iptr->dst.varindex = (index);                                  \
270                 LOCALTYPE_USED(index,type);                                                                        \
271         PINC;                                                          \
272     } while (0)
273 #else
274 # define OP_STORE_ONEWORD(o,index,type)                                                        \
275     do {                                                               \
276         INDEX_ONEWORD(index);                                          \
277         OP_PREPARE_ZEROFLAGS(o);                                       \
278         iptr->dst.localindex = (index);                                \
279                 LOCALTYPE_USED(index,type);                                                                        \
280         PINC;                                                          \
281     } while (0)
282
283 # define OP_STORE_TWOWORD(o,index,type)                                                        \
284     do {                                                               \
285         INDEX_TWOWORD(index);                                          \
286         OP_PREPARE_ZEROFLAGS(o);                                       \
287         iptr->dst.localindex = (index);                                \
288                 LOCALTYPE_USED(index,type);                                                                        \
289         PINC;                                                          \
290     } while (0)
291 #endif /*  defined(NEW_VAR) */
292
293 #define OP_BUILTIN_CHECK_EXCEPTION(bte)                                \
294     jd->isleafmethod         = false;                                  \
295         OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK);                    \
296     iptr->sx.s23.s3.bte      = (bte);                                  \
297     PINC
298
299 #define OP_BUILTIN_NO_EXCEPTION(bte)                                   \
300     jd->isleafmethod         = false;                                  \
301         OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN);                                \
302     iptr->sx.s23.s3.bte      = (bte);                                  \
303     PINC
304
305 #define OP_BUILTIN_ARITHMETIC(opcode, bte)                             \
306     jd->isleafmethod         = false;                                  \
307         OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK);                          \
308     iptr->sx.s23.s3.bte      = (bte);                                  \
309     PINC
310
311 /* CAUTION: You must set iptr->flags yourself when using this!                */
312 #define OP_FMIREF_PREPARE(o, fmiref)                                   \
313         OP_PREPARE(o);                                                     \
314     iptr->sx.s23.s3.fmiref   = (fmiref);
315
316
317 /* function prototypes ********************************************************/
318
319 bool new_parse(jitdata *jd);
320
321 #endif /* _PARSE_H */
322
323
324 /*
325  * These are local overrides for various environment variables in Emacs.
326  * Please do not remove this and leave it at the end of the file, where
327  * Emacs will automagically detect them.
328  * ---------------------------------------------------------------------
329  * Local variables:
330  * mode: c
331  * indent-tabs-mode: t
332  * c-basic-offset: 4
333  * tab-width: 4
334  * End:
335  * vim:noexpandtab:sw=4:ts=4:
336  */
337