1 /* src/vm/jit/parse.h - parser header
3 Copyright (C) 1996-2005, 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
32 #include "vm/global.h"
33 #include "vm/jit/codegen-common.h"
36 /* macros for verifier checks during parsing **********************************/
38 #if defined(ENABLE_VERIFIER)
40 /* We have to check local variables indices here because they are */
41 /* used in stack.c to index the locals array. */
43 #define INDEX_ONEWORD(num) \
45 if (((num) < 0) || ((num) >= m->maxlocals)) \
46 goto throw_illegal_local_variable_number; \
49 #define INDEX_TWOWORD(num) \
51 if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
52 goto throw_illegal_local_variable_number; \
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. */
58 #define CHECK_BYTECODE_INDEX(i) \
60 if (((i) < 0) || ((i) >= m->jcodelength)) \
61 goto throw_invalid_bytecode_index; \
64 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */
65 /* of exception handler ranges. */
66 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
68 if ((i) < 0 || (i) > m->jcodelength) \
69 goto throw_invalid_bytecode_index; \
72 #else /* !defined(ENABLE_VERIFIER) */
74 #define INDEX_ONEWORD(num)
75 #define INDEX_TWOWORD(num)
76 #define CHECK_BYTECODE_INDEX(i)
77 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
79 #endif /* defined(ENABLE_VERIFIER) */
82 /* basic block generating macro ***********************************************/
84 #define MARK_BASICBLOCK(pd, i) \
86 (pd)->basicblockstart[(i)] = 1; \
89 #define INSTRUCTIONS_CHECK(i) \
90 if ((ircount + (i)) > pd.instructionslength) \
91 iptr = parse_realloc_instructions(&pd, ircount, (i))
94 /* intermediate code generating macros ****************************************/
96 /* These macros ALWAYS set the following fields of *iptr to valid values: */
101 /* These macros do NOT touch the following fields of *iptr, unless a value is */
102 /* given for them: */
107 /* The _PREPARE macros omit the PINC, so you can set additional fields */
113 #define OP_PREPARE_FLAGS(o, f) \
115 iptr->line = currentline; \
116 iptr->flags.bits |= (f) | (ircount << INS_FLAG_ID_SHIFT);
118 #define OP_PREPARE_ZEROFLAGS(o) \
119 OP_PREPARE_FLAGS(o, 0)
121 #define OP_PREPARE(o) \
122 OP_PREPARE_ZEROFLAGS(o)
125 OP_PREPARE_ZEROFLAGS(o); \
128 #define OP_CHECK_EXCEPTION(o) \
129 OP_PREPARE_FLAGS(o, INS_FLAG_CHECK); \
132 #define OP_LOADCONST_I(v) \
133 OP_PREPARE_ZEROFLAGS(ICMD_ICONST); \
134 iptr->sx.val.i = (v); \
137 #define OP_LOADCONST_L(v) \
138 OP_PREPARE_ZEROFLAGS(ICMD_LCONST); \
139 iptr->sx.val.l = (v); \
142 #define OP_LOADCONST_F(v) \
143 OP_PREPARE_ZEROFLAGS(ICMD_FCONST); \
144 iptr->sx.val.f = (v); \
147 #define OP_LOADCONST_D(v) \
148 OP_PREPARE_ZEROFLAGS(ICMD_DCONST); \
149 iptr->sx.val.d = (v); \
152 #define OP_LOADCONST_NULL() \
153 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
154 iptr->sx.val.anyptr = NULL; \
157 #define OP_LOADCONST_STRING(v) \
158 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
159 iptr->sx.val.stringconst = (v); \
162 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
163 OP_PREPARE(ICMD_ACONST); \
165 iptr->sx.val.c.cls = (cl); \
166 iptr->flags.bits |= INS_FLAG_CLASS | (extraflags); \
169 iptr->sx.val.c.ref = (cr); \
170 iptr->flags.bits |= INS_FLAG_CLASS | INS_FLAG_UNRESOLVED \
175 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr) \
176 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
178 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr) \
179 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
181 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
184 iptr->sx.s23.s3.c.cls= (c); \
185 iptr->flags.bits |= (extraflags); \
188 iptr->sx.s23.s3.c.ref= (cr); \
189 iptr->flags.bits |= INS_FLAG_UNRESOLVED | (extraflags); \
193 #define OP_INSINDEX(o, iindex) \
194 OP_PREPARE_ZEROFLAGS(o); \
195 iptr->dst.insindex = (iindex); \
198 # define OP_LOCALINDEX(o,index) \
199 OP_PREPARE_ZEROFLAGS(o); \
200 iptr->s1.varindex = (index); \
203 # define OP_LOCALINDEX_I(o,index,v) \
204 OP_PREPARE_ZEROFLAGS(o); \
205 iptr->s1.varindex = (index); \
206 iptr->sx.val.i = (v); \
209 # define LOCALTYPE_USED(index,type) \
211 local_map[(index) * 5 + (type)] = 1; \
214 #define OP_LOAD_ONEWORD(o,index,type) \
216 INDEX_ONEWORD(index); \
217 OP_LOCALINDEX(o,index); \
218 LOCALTYPE_USED(index,type); \
221 #define OP_LOAD_TWOWORD(o,index,type) \
223 INDEX_TWOWORD(index); \
224 OP_LOCALINDEX(o,index); \
225 LOCALTYPE_USED(index,type); \
228 # define OP_STORE_ONEWORD(o,index,type) \
230 INDEX_ONEWORD(index); \
231 OP_PREPARE_ZEROFLAGS(o); \
232 iptr->dst.varindex = (index); \
233 LOCALTYPE_USED(index,type); \
237 # define OP_STORE_TWOWORD(o,index,type) \
239 INDEX_TWOWORD(index); \
240 OP_PREPARE_ZEROFLAGS(o); \
241 iptr->dst.varindex = (index); \
242 LOCALTYPE_USED(index,type); \
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); \
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); \
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); \
264 /* CAUTION: You must set iptr->flags yourself when using this! */
265 #define OP_FMIREF_PREPARE(o, fmiref) \
267 iptr->sx.s23.s3.fmiref = (fmiref);
270 /* function prototypes ********************************************************/
276 bool parse(jitdata *jd);
282 #endif /* _PARSE_H */
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 * ---------------------------------------------------------------------
292 * indent-tabs-mode: t
296 * vim:noexpandtab:sw=4:ts=4: