* src/mm/boehm-gc/include/private/gcconfig.h: Patch for mips to find
[cacao.git] / src / vm / jit / parse.h
1 /* src/vm/jit/parse.h - parser header
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _PARSE_H
27 #define _PARSE_H
28
29 #include "config.h"
30 #include "vm/types.h"
31
32 #include "vm/global.h"
33 #include "vm/jit/codegen-common.hpp"
34
35
36 /* macros for verifier checks during parsing **********************************/
37
38 #if defined(ENABLE_VERIFIER)
39
40 /* We have to check local variables indices here because they are             */
41 /* used in stack.c to index the locals array.                                 */
42
43 #define INDEX_ONEWORD(num) \
44     do { \
45         if (((num) < 0) || ((num) >= m->maxlocals)) \
46             goto throw_illegal_local_variable_number; \
47     } while (0)
48
49 #define INDEX_TWOWORD(num) \
50     do { \
51         if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
52             goto throw_illegal_local_variable_number; \
53     } while (0)
54
55 /* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index.        */
56 /* The end of the bytecode (i == m->jcodelength) is considered valid.         */
57
58 #define CHECK_BYTECODE_INDEX(i) \
59     do { \
60         if (((i) < 0) || ((i) >= m->jcodelength)) \
61                         goto throw_invalid_bytecode_index; \
62     } while (0)
63
64 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends               */
65 /* of exception handler ranges.                                                */
66 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
67     do { \
68         if ((i) < 0 || (i) > m->jcodelength) \
69                         goto throw_invalid_bytecode_index; \
70     } while (0)
71
72 #else /* !defined(ENABLE_VERIFIER) */
73
74 #define INDEX_ONEWORD(num)
75 #define INDEX_TWOWORD(num)
76 #define CHECK_BYTECODE_INDEX(i)
77 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
78
79 #endif /* defined(ENABLE_VERIFIER) */
80
81
82 /* basic block generating macro ***********************************************/
83
84 #define MARK_BASICBLOCK(pd, i)                                       \
85     do {                                                             \
86         (pd)->basicblockstart[(i)] = 1;                              \
87     } while (0)
88
89 #define INSTRUCTIONS_CHECK(i)                                        \
90     if ((ircount + (i)) > pd.instructionslength)                     \
91         iptr = parse_realloc_instructions(&pd, ircount, (i))
92
93
94 /* intermediate code generating macros ****************************************/
95
96 /* These macros ALWAYS set the following fields of *iptr to valid values:     */
97 /*     iptr->opc                                                              */
98 /*     iptr->flags                                                            */
99 /*     iptr->line                                                             */
100
101 /* These macros do NOT touch the following fields of *iptr, unless a value is */
102 /* given for them:                                                            */
103 /*     iptr->s1                                                               */
104 /*     iptr->sx                                                               */
105 /*     iptr->dst                                                              */
106
107 /* The _PREPARE macros omit the PINC, so you can set additional fields        */
108 /* afterwards.                                                                */
109
110 #define PINC                                                         \
111     iptr++; ircount++
112
113 #define OP_PREPARE_FLAGS(o, f)                                       \
114     iptr->opc         = (o);                                         \
115     iptr->line        = currentline;                                 \
116     iptr->flags.bits |= (f) | (ircount << INS_FLAG_ID_SHIFT);
117
118 #define OP_PREPARE_ZEROFLAGS(o)                                      \
119     OP_PREPARE_FLAGS(o, 0)
120
121 #define OP_PREPARE(o)                                                \
122     OP_PREPARE_ZEROFLAGS(o)
123
124 #define OP(o)                                                        \
125     OP_PREPARE_ZEROFLAGS(o);                                         \
126     PINC
127
128 #define OP_CHECK_EXCEPTION(o)                                        \
129     OP_PREPARE_FLAGS(o, INS_FLAG_CHECK);                             \
130     PINC
131
132 #define OP_LOADCONST_I(v)                                            \
133     OP_PREPARE_ZEROFLAGS(ICMD_ICONST);                               \
134     iptr->sx.val.i           = (v);                                  \
135     PINC
136
137 #define OP_LOADCONST_L(v)                                            \
138     OP_PREPARE_ZEROFLAGS(ICMD_LCONST);                               \
139     iptr->sx.val.l           = (v);                                  \
140     PINC
141
142 #define OP_LOADCONST_F(v)                                            \
143     OP_PREPARE_ZEROFLAGS(ICMD_FCONST);                               \
144     iptr->sx.val.f           = (v);                                  \
145     PINC
146
147 #define OP_LOADCONST_D(v)                                            \
148     OP_PREPARE_ZEROFLAGS(ICMD_DCONST);                               \
149     iptr->sx.val.d           = (v);                                  \
150     PINC
151
152 #define OP_LOADCONST_NULL()                                          \
153     OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK);                   \
154     iptr->sx.val.anyptr      = NULL;                                 \
155     PINC
156
157 #define OP_LOADCONST_STRING(v)                                       \
158     OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK);                   \
159     iptr->sx.val.stringconst = (v);                                  \
160     PINC
161
162 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
163     OP_PREPARE(ICMD_ACONST);                                         \
164     if (cl) {                                                        \
165         iptr->sx.val.c.cls   = (cl);                                 \
166         iptr->flags.bits     |= INS_FLAG_CLASS | (extraflags);       \
167     }                                                                \
168     else {                                                           \
169         iptr->sx.val.c.ref   = (cr);                                 \
170         iptr->flags.bits     |= INS_FLAG_CLASS | INS_FLAG_UNRESOLVED \
171                              | (extraflags);                         \
172     }                                                                \
173     PINC
174
175 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr)              \
176     OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
177
178 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr)            \
179     OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
180
181 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags)            \
182     OP_PREPARE(o);                                                   \
183     if (c) {                                                         \
184         iptr->sx.s23.s3.c.cls= (c);                                  \
185         iptr->flags.bits     |= (extraflags);                        \
186     }                                                                \
187     else {                                                           \
188         iptr->sx.s23.s3.c.ref= (cr);                                 \
189         iptr->flags.bits     |= INS_FLAG_UNRESOLVED | (extraflags);  \
190     }                                                                \
191     PINC
192
193 #define OP_INSINDEX(o, iindex)                                       \
194     OP_PREPARE_ZEROFLAGS(o);                                         \
195     iptr->dst.insindex       = (iindex);                             \
196     PINC
197
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
214 #define OP_LOAD_ONEWORD(o,index,type)                                \
215     do {                                                             \
216         INDEX_ONEWORD(index);                                        \
217         OP_LOCALINDEX(o,index);                                      \
218         LOCALTYPE_USED(index,type);                                  \
219     } while (0)
220
221 #define OP_LOAD_TWOWORD(o,index,type)                                \
222     do {                                                             \
223         INDEX_TWOWORD(index);                                        \
224         OP_LOCALINDEX(o,index);                                      \
225         LOCALTYPE_USED(index,type);                                  \
226     } while (0)
227
228 # define OP_STORE_ONEWORD(o,index,type)                              \
229     do {                                                             \
230         INDEX_ONEWORD(index);                                        \
231         OP_PREPARE_ZEROFLAGS(o);                                     \
232         iptr->dst.varindex = (index);                                \
233         LOCALTYPE_USED(index,type);                                  \
234         PINC;                                                        \
235     } while (0)
236
237 # define OP_STORE_TWOWORD(o,index,type)                              \
238     do {                                                             \
239         INDEX_TWOWORD(index);                                        \
240         OP_PREPARE_ZEROFLAGS(o);                                     \
241         iptr->dst.varindex = (index);                                \
242         LOCALTYPE_USED(index,type);                                  \
243         PINC;                                                        \
244     } while (0)
245
246 #define OP_BUILTIN_CHECK_EXCEPTION(bte)                              \
247     code_unflag_leafmethod(code);                                    \
248     OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK);                  \
249     iptr->sx.s23.s3.bte      = (bte);                                \
250     PINC
251
252 #define OP_BUILTIN_NO_EXCEPTION(bte)                                 \
253     code_unflag_leafmethod(code);                                    \
254     OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN);                              \
255     iptr->sx.s23.s3.bte      = (bte);                                \
256     PINC
257
258 #define OP_BUILTIN_ARITHMETIC(opcode, bte)                           \
259     code_unflag_leafmethod(code);                                    \
260     OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK);                        \
261     iptr->sx.s23.s3.bte      = (bte);                                \
262     PINC
263
264 /* CAUTION: You must set iptr->flags yourself when using this!                */
265 #define OP_FMIREF_PREPARE(o, fmiref)                                 \
266     OP_PREPARE(o);                                                   \
267     iptr->sx.s23.s3.fmiref   = (fmiref);
268
269
270 /* function prototypes ********************************************************/
271
272 #ifdef __cplusplus
273 extern "C" {
274 #endif
275
276 bool parse(jitdata *jd);
277
278 #ifdef __cplusplus
279 }
280 #endif
281
282 #endif /* _PARSE_H */
283
284
285 /*
286  * These are local overrides for various environment variables in Emacs.
287  * Please do not remove this and leave it at the end of the file, where
288  * Emacs will automagically detect them.
289  * ---------------------------------------------------------------------
290  * Local variables:
291  * mode: c
292  * indent-tabs-mode: t
293  * c-basic-offset: 4
294  * tab-width: 4
295  * End:
296  * vim:noexpandtab:sw=4:ts=4:
297  */
298