* src/vm/jit/stack.c (new_stack_analyse): Ifdeffed handling of new var
[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 5370 2006-09-06 13:46:37Z 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
103 /* intermediate code generating macros ****************************************/
104
105 /* These macros ALWAYS set the following fields of *iptr to valid values:     */
106 /*     iptr->opc                                                              */
107 /*     iptr->flags                                                            */
108 /*     iptr->line                                                             */
109
110 /* These macros do NOT touch the following fields of *iptr, unless a value is */
111 /* given for them:                                                            */
112 /*     iptr->s1                                                               */
113 /*     iptr->sx                                                               */
114 /*     iptr->dst                                                              */
115
116 /* The _PREPARE macros omit the PINC, so you can set additional fields        */
117 /* afterwards.                                                                */
118 /* CAUTION: Some of the _PREPARE macros don't set iptr->flags!                */
119
120 #define PINC                                                           \
121     iptr++; ipc++
122
123 /* CAUTION: You must set iptr->flags yourself when using this!                */
124 #define OP_PREPARE(o)                                                  \
125     iptr->opc                = (o);                                    \
126     iptr->line               = currentline;
127
128 #define OP_PREPARE_ZEROFLAGS(o)                                        \
129     iptr->opc                = (o);                                    \
130     iptr->line               = currentline;                            \
131     iptr->flags.bits         = 0;
132
133 #define OP(o)                                                          \
134         OP_PREPARE_ZEROFLAGS(o);                                           \
135     PINC
136
137 #define OP_LOADCONST_I(v)                                              \
138         OP_PREPARE_ZEROFLAGS(ICMD_ICONST);                                 \
139     iptr->sx.val.i           = (v);                                    \
140     PINC
141
142 #define OP_LOADCONST_L(v)                                              \
143         OP_PREPARE_ZEROFLAGS(ICMD_LCONST);                                 \
144     iptr->sx.val.l           = (v);                                    \
145     PINC
146
147 #define OP_LOADCONST_F(v)                                              \
148         OP_PREPARE_ZEROFLAGS(ICMD_FCONST);                                 \
149     iptr->sx.val.f           = (v);                                    \
150     PINC
151
152 #define OP_LOADCONST_D(v)                                              \
153         OP_PREPARE_ZEROFLAGS(ICMD_DCONST);                                 \
154     iptr->sx.val.d           = (v);                                    \
155     PINC
156
157 #define OP_LOADCONST_NULL()                                            \
158         OP_PREPARE_ZEROFLAGS(ICMD_ACONST);                                 \
159     iptr->sx.val.anyptr      = NULL;                                   \
160     PINC
161
162 #define OP_LOADCONST_STRING(v)                                         \
163         OP_PREPARE_ZEROFLAGS(ICMD_ACONST);                                 \
164     iptr->sx.val.stringconst = (v);                                    \
165     PINC
166
167 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, extraflags)          \
168         OP_PREPARE(ICMD_ACONST);                                           \
169     if (c) {                                                           \
170         iptr->sx.val.c.cls   = (c);                                    \
171         iptr->flags.bits     = INS_FLAG_CLASS | (extraflags);          \
172     }                                                                  \
173     else {                                                             \
174         iptr->sx.val.c.ref   = (cr);                                   \
175         iptr->flags.bits     = INS_FLAG_CLASS | INS_FLAG_UNRESOLVED    \
176                              | (extraflags);                           \
177     }                                                                  \
178     PINC
179
180 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags)              \
181         OP_PREPARE(o);                                                     \
182     if (c) {                                                           \
183         iptr->sx.s23.s3.c.cls= (c);                                    \
184         iptr->flags.bits     = (extraflags);                           \
185     }                                                                  \
186     else {                                                             \
187         iptr->sx.s23.s3.c.ref= (cr);                                   \
188         iptr->flags.bits     = INS_FLAG_UNRESOLVED | (extraflags);     \
189     }                                                                  \
190     PINC
191
192 #define OP_INSINDEX(o, iindex)                                         \
193         OP_PREPARE_ZEROFLAGS(o);                                           \
194     iptr->dst.insindex       = (iindex);                               \
195     PINC
196
197 #if defined(NEW_VAR)
198 # define OP_LOCALINDEX(o,index)                                        \
199         OP_PREPARE_ZEROFLAGS(o);                                           \
200     iptr->s1.varindex      = (index);                                \
201     PINC
202
203 # define OP_LOCALINDEX_I(o,index,v)                                    \
204         OP_PREPARE_ZEROFLAGS(o);                                           \
205     iptr->s1.varindex      = (index);                                  \
206     iptr->sx.val.i           = (v);                                    \
207     PINC
208
209 # define LOCALTYPE_USED(index,type)                                                                        \
210         do {                                                                                                                       \
211                 local_map[index * 5 +type] = 1;                                                            \
212         } while (0)
213 #else 
214 # define OP_LOCALINDEX(o,index)                                        \
215         OP_PREPARE_ZEROFLAGS(o);                                           \
216     iptr->s1.localindex      = (index);                                  \
217     PINC
218
219 # define OP_LOCALINDEX_I(o,index,v)                                    \
220         OP_PREPARE_ZEROFLAGS(o);                                           \
221     iptr->s1.localindex      = (index);                                \
222     iptr->sx.val.i           = (v);                                    \
223     PINC
224
225 # define LOCALTYPE_USED(index,type)
226 #endif /* defined(NEW_VAR) */
227
228 #define OP_LOAD_ONEWORD(o,index,type)                                                          \
229     do {                                                               \
230         INDEX_ONEWORD(index);                                          \
231         OP_LOCALINDEX(o,index);                                        \
232                 LOCALTYPE_USED(index,type);                                                                    \
233     } while (0)
234
235 #define OP_LOAD_TWOWORD(o,index,type)                                                          \
236     do {                                                               \
237         INDEX_TWOWORD(index);                                          \
238         OP_LOCALINDEX(o,index);                                        \
239                 LOCALTYPE_USED(index,type);                                                                        \
240         } while (0)
241
242 #if defined(NEW_VAR)
243 # define OP_STORE_ONEWORD(o,index,type)                                                        \
244     do {                                                               \
245         INDEX_ONEWORD(index);                                          \
246         OP_PREPARE_ZEROFLAGS(o);                                       \
247         iptr->dst.varindex = (index);                                  \
248                 LOCALTYPE_USED(index,type);                                                                        \
249         PINC;                                                          \
250     } while (0)
251
252 # define OP_STORE_TWOWORD(o,index,type)                                                        \
253     do {                                                               \
254         INDEX_TWOWORD(index);                                          \
255         OP_PREPARE_ZEROFLAGS(o);                                       \
256         iptr->dst.varindex = (index);                                  \
257                 LOCALTYPE_USED(index,type);                                                                        \
258         PINC;                                                          \
259     } while (0)
260 #else
261 # define OP_STORE_ONEWORD(o,index,type)                                                        \
262     do {                                                               \
263         INDEX_ONEWORD(index);                                          \
264         OP_PREPARE_ZEROFLAGS(o);                                       \
265         iptr->dst.localindex = (index);                                \
266                 LOCALTYPE_USED(index,type);                                                                        \
267         PINC;                                                          \
268     } while (0)
269
270 # define OP_STORE_TWOWORD(o,index,type)                                                        \
271     do {                                                               \
272         INDEX_TWOWORD(index);                                          \
273         OP_PREPARE_ZEROFLAGS(o);                                       \
274         iptr->dst.localindex = (index);                                \
275                 LOCALTYPE_USED(index,type);                                                                        \
276         PINC;                                                          \
277     } while (0)
278 #endif /*  defined(NEW_VAR) */
279
280 #define OP_BUILTIN_CHECK_EXCEPTION(bte)                                \
281     jd->isleafmethod         = false;                                  \
282         OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN);                                \
283     iptr->sx.s23.s3.bte      = (bte);                                  \
284     PINC
285
286 #define OP_BUILTIN_NO_EXCEPTION(bte)                                   \
287     jd->isleafmethod         = false;                                  \
288         OP_PREPARE(ICMD_BUILTIN);                                          \
289     iptr->sx.s23.s3.bte      = (bte);                                  \
290     iptr->flags.bits         = INS_FLAG_NOCHECK;                       \
291     PINC
292
293 #define OP_BUILTIN_ARITHMETIC(opcode, bte)                             \
294     jd->isleafmethod         = false;                                  \
295         OP_PREPARE_ZEROFLAGS(opcode);                                      \
296     iptr->sx.s23.s3.bte      = (bte);                                  \
297     PINC
298
299 /* CAUTION: You must set iptr->flags yourself when using this!                */
300 #define OP_FMIREF_PREPARE(o, fmiref)                                   \
301         OP_PREPARE(o);                                                     \
302     iptr->sx.s23.s3.fmiref   = (fmiref);
303
304
305 /* function prototypes ********************************************************/
306
307 bool new_parse(jitdata *jd);
308
309 #endif /* _PARSE_H */
310
311
312 /*
313  * These are local overrides for various environment variables in Emacs.
314  * Please do not remove this and leave it at the end of the file, where
315  * Emacs will automagically detect them.
316  * ---------------------------------------------------------------------
317  * Local variables:
318  * mode: c
319  * indent-tabs-mode: t
320  * c-basic-offset: 4
321  * tab-width: 4
322  * End:
323  * vim:noexpandtab:sw=4:ts=4:
324  */
325