1 /* src/vm/jit/parse.h - parser header
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Author: Christian Thalinger
30 $Id: parse.h 6171 2006-12-11 11:47:42Z twisti $
41 #include "vm/global.h"
42 #include "vm/jit/codegen-common.h"
45 /* macros for verifier checks during parsing **********************************/
47 #if defined(ENABLE_VERIFIER)
49 /* We have to check local variables indices here because they are */
50 /* used in stack.c to index the locals array. */
52 #define INDEX_ONEWORD(num) \
54 if (((num) < 0) || ((num) >= m->maxlocals)) \
55 goto throw_illegal_local_variable_number; \
58 #define INDEX_TWOWORD(num) \
60 if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
61 goto throw_illegal_local_variable_number; \
64 /* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index. */
65 /* The end of the bytecode (i == m->jcodelength) is considered valid. */
67 #define CHECK_BYTECODE_INDEX(i) \
69 if (((i) < 0) || ((i) >= m->jcodelength)) \
70 goto throw_invalid_bytecode_index; \
73 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */
74 /* of exception handler ranges. */
75 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
77 if ((i) < 0 || (i) > m->jcodelength) \
78 goto throw_invalid_bytecode_index; \
81 #else /* !defined(ENABLE_VERIFIER) */
83 #define INDEX_ONEWORD(num)
84 #define INDEX_TWOWORD(num)
85 #define CHECK_BYTECODE_INDEX(i)
86 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
88 #endif /* defined(ENABLE_VERIFIER) */
91 /* basic block generating macro ***********************************************/
93 #define MARK_BASICBLOCK(i) \
95 if (!(jd->basicblockindex[(i)] & 1)) { \
97 jd->basicblockindex[(i)] |= 1; \
101 #define INSTRUCTIONS_CHECK(i) \
102 if ((ipc + (i)) > pd.instructionslength) \
103 iptr = parse_realloc_instructions(&pd, ipc, (i))
106 /* intermediate code generating macros ****************************************/
108 /* These macros ALWAYS set the following fields of *iptr to valid values: */
113 /* These macros do NOT touch the following fields of *iptr, unless a value is */
114 /* given for them: */
119 /* The _PREPARE macros omit the PINC, so you can set additional fields */
125 #define OP_PREPARE_FLAGS(o, f) \
127 iptr->line = currentline; \
128 iptr->flags.bits = (f) | (ipc << INS_FLAG_ID_SHIFT);
130 #define OP_PREPARE_ZEROFLAGS(o) \
131 OP_PREPARE_FLAGS(o, 0)
133 #define OP_PREPARE(o) \
134 OP_PREPARE_ZEROFLAGS(o)
137 OP_PREPARE_ZEROFLAGS(o); \
140 #define OP_CHECK_EXCEPTION(o) \
141 OP_PREPARE_FLAGS(o, INS_FLAG_CHECK); \
144 #define OP_LOADCONST_I(v) \
145 OP_PREPARE_ZEROFLAGS(ICMD_ICONST); \
146 iptr->sx.val.i = (v); \
149 #define OP_LOADCONST_L(v) \
150 OP_PREPARE_ZEROFLAGS(ICMD_LCONST); \
151 iptr->sx.val.l = (v); \
154 #define OP_LOADCONST_F(v) \
155 OP_PREPARE_ZEROFLAGS(ICMD_FCONST); \
156 iptr->sx.val.f = (v); \
159 #define OP_LOADCONST_D(v) \
160 OP_PREPARE_ZEROFLAGS(ICMD_DCONST); \
161 iptr->sx.val.d = (v); \
164 #define OP_LOADCONST_NULL() \
165 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
166 iptr->sx.val.anyptr = NULL; \
169 #define OP_LOADCONST_STRING(v) \
170 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
171 iptr->sx.val.stringconst = (v); \
174 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
175 OP_PREPARE(ICMD_ACONST); \
177 iptr->sx.val.c.cls = (cl); \
178 iptr->flags.bits |= INS_FLAG_CLASS | (extraflags); \
181 iptr->sx.val.c.ref = (cr); \
182 iptr->flags.bits |= INS_FLAG_CLASS | INS_FLAG_UNRESOLVED \
187 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr) \
188 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
190 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr) \
191 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
193 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
196 iptr->sx.s23.s3.c.cls= (c); \
197 iptr->flags.bits |= (extraflags); \
200 iptr->sx.s23.s3.c.ref= (cr); \
201 iptr->flags.bits |= INS_FLAG_UNRESOLVED | (extraflags); \
205 #define OP_INSINDEX(o, iindex) \
206 OP_PREPARE_ZEROFLAGS(o); \
207 iptr->dst.insindex = (iindex); \
210 # define OP_LOCALINDEX(o,index) \
211 OP_PREPARE_ZEROFLAGS(o); \
212 iptr->s1.varindex = (index); \
215 # define OP_LOCALINDEX_I(o,index,v) \
216 OP_PREPARE_ZEROFLAGS(o); \
217 iptr->s1.varindex = (index); \
218 iptr->sx.val.i = (v); \
221 # define LOCALTYPE_USED(index,type) \
223 local_map[(index) * 5 + (type)] = 1; \
226 #define OP_LOAD_ONEWORD(o,index,type) \
228 INDEX_ONEWORD(index); \
229 OP_LOCALINDEX(o,index); \
230 LOCALTYPE_USED(index,type); \
233 #define OP_LOAD_TWOWORD(o,index,type) \
235 INDEX_TWOWORD(index); \
236 OP_LOCALINDEX(o,index); \
237 LOCALTYPE_USED(index,type); \
240 # define OP_STORE_ONEWORD(o,index,type) \
242 INDEX_ONEWORD(index); \
243 OP_PREPARE_ZEROFLAGS(o); \
244 iptr->dst.varindex = (index); \
245 LOCALTYPE_USED(index,type); \
249 # define OP_STORE_TWOWORD(o,index,type) \
251 INDEX_TWOWORD(index); \
252 OP_PREPARE_ZEROFLAGS(o); \
253 iptr->dst.varindex = (index); \
254 LOCALTYPE_USED(index,type); \
258 #define OP_BUILTIN_CHECK_EXCEPTION(bte) \
259 jd->isleafmethod = false; \
260 OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK); \
261 iptr->sx.s23.s3.bte = (bte); \
264 #define OP_BUILTIN_NO_EXCEPTION(bte) \
265 jd->isleafmethod = false; \
266 OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN); \
267 iptr->sx.s23.s3.bte = (bte); \
270 #define OP_BUILTIN_ARITHMETIC(opcode, bte) \
271 jd->isleafmethod = false; \
272 OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK); \
273 iptr->sx.s23.s3.bte = (bte); \
276 /* CAUTION: You must set iptr->flags yourself when using this! */
277 #define OP_FMIREF_PREPARE(o, fmiref) \
279 iptr->sx.s23.s3.fmiref = (fmiref);
282 /* external macros ************************************************************/
284 #define BLOCK_OF(index) \
285 (jd->basicblocks + jd->basicblockindex[index])
288 /* function prototypes ********************************************************/
290 bool parse(jitdata *jd);
292 #endif /* _PARSE_H */
296 * These are local overrides for various environment variables in Emacs.
297 * Please do not remove this and leave it at the end of the file, where
298 * Emacs will automagically detect them.
299 * ---------------------------------------------------------------------
302 * indent-tabs-mode: t
306 * vim:noexpandtab:sw=4:ts=4: