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
39 #include "vm/global.h"
40 #include "vm/jit/codegen-common.h"
43 /* macros for verifier checks during parsing **********************************/
45 #if defined(ENABLE_VERIFIER)
47 /* We have to check local variables indices here because they are */
48 /* used in stack.c to index the locals array. */
50 #define INDEX_ONEWORD(num) \
52 if (((num) < 0) || ((num) >= m->maxlocals)) \
53 goto throw_illegal_local_variable_number; \
56 #define INDEX_TWOWORD(num) \
58 if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
59 goto throw_illegal_local_variable_number; \
62 /* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index. */
63 /* The end of the bytecode (i == m->jcodelength) is considered valid. */
65 #define CHECK_BYTECODE_INDEX(i) \
67 if (((i) < 0) || ((i) >= m->jcodelength)) \
68 goto throw_invalid_bytecode_index; \
71 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */
72 /* of exception handler ranges. */
73 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
75 if ((i) < 0 || (i) > m->jcodelength) \
76 goto throw_invalid_bytecode_index; \
79 #else /* !defined(ENABLE_VERIFIER) */
81 #define INDEX_ONEWORD(num)
82 #define INDEX_TWOWORD(num)
83 #define CHECK_BYTECODE_INDEX(i)
84 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
86 #endif /* defined(ENABLE_VERIFIER) */
89 /* basic block generating macro ***********************************************/
91 #define MARK_BASICBLOCK(pd, i) \
93 (pd)->basicblockstart[(i)] = 1; \
96 #define INSTRUCTIONS_CHECK(i) \
97 if ((ircount + (i)) > pd.instructionslength) \
98 iptr = parse_realloc_instructions(&pd, ircount, (i))
101 /* intermediate code generating macros ****************************************/
103 /* These macros ALWAYS set the following fields of *iptr to valid values: */
108 /* These macros do NOT touch the following fields of *iptr, unless a value is */
109 /* given for them: */
114 /* The _PREPARE macros omit the PINC, so you can set additional fields */
120 #define OP_PREPARE_FLAGS(o, f) \
122 iptr->line = currentline; \
123 iptr->flags.bits |= (f) | (ircount << INS_FLAG_ID_SHIFT);
125 #define OP_PREPARE_ZEROFLAGS(o) \
126 OP_PREPARE_FLAGS(o, 0)
128 #define OP_PREPARE(o) \
129 OP_PREPARE_ZEROFLAGS(o)
132 OP_PREPARE_ZEROFLAGS(o); \
135 #define OP_CHECK_EXCEPTION(o) \
136 OP_PREPARE_FLAGS(o, INS_FLAG_CHECK); \
139 #define OP_LOADCONST_I(v) \
140 OP_PREPARE_ZEROFLAGS(ICMD_ICONST); \
141 iptr->sx.val.i = (v); \
144 #define OP_LOADCONST_L(v) \
145 OP_PREPARE_ZEROFLAGS(ICMD_LCONST); \
146 iptr->sx.val.l = (v); \
149 #define OP_LOADCONST_F(v) \
150 OP_PREPARE_ZEROFLAGS(ICMD_FCONST); \
151 iptr->sx.val.f = (v); \
154 #define OP_LOADCONST_D(v) \
155 OP_PREPARE_ZEROFLAGS(ICMD_DCONST); \
156 iptr->sx.val.d = (v); \
159 #define OP_LOADCONST_NULL() \
160 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
161 iptr->sx.val.anyptr = NULL; \
164 #define OP_LOADCONST_STRING(v) \
165 OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
166 iptr->sx.val.stringconst = (v); \
169 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
170 OP_PREPARE(ICMD_ACONST); \
172 iptr->sx.val.c.cls = (cl); \
173 iptr->flags.bits |= INS_FLAG_CLASS | (extraflags); \
176 iptr->sx.val.c.ref = (cr); \
177 iptr->flags.bits |= INS_FLAG_CLASS | INS_FLAG_UNRESOLVED \
182 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr) \
183 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
185 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr) \
186 OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
188 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
191 iptr->sx.s23.s3.c.cls= (c); \
192 iptr->flags.bits |= (extraflags); \
195 iptr->sx.s23.s3.c.ref= (cr); \
196 iptr->flags.bits |= INS_FLAG_UNRESOLVED | (extraflags); \
200 #define OP_INSINDEX(o, iindex) \
201 OP_PREPARE_ZEROFLAGS(o); \
202 iptr->dst.insindex = (iindex); \
205 # define OP_LOCALINDEX(o,index) \
206 OP_PREPARE_ZEROFLAGS(o); \
207 iptr->s1.varindex = (index); \
210 # define OP_LOCALINDEX_I(o,index,v) \
211 OP_PREPARE_ZEROFLAGS(o); \
212 iptr->s1.varindex = (index); \
213 iptr->sx.val.i = (v); \
216 # define LOCALTYPE_USED(index,type) \
218 local_map[(index) * 5 + (type)] = 1; \
221 #define OP_LOAD_ONEWORD(o,index,type) \
223 INDEX_ONEWORD(index); \
224 OP_LOCALINDEX(o,index); \
225 LOCALTYPE_USED(index,type); \
228 #define OP_LOAD_TWOWORD(o,index,type) \
230 INDEX_TWOWORD(index); \
231 OP_LOCALINDEX(o,index); \
232 LOCALTYPE_USED(index,type); \
235 # define OP_STORE_ONEWORD(o,index,type) \
237 INDEX_ONEWORD(index); \
238 OP_PREPARE_ZEROFLAGS(o); \
239 iptr->dst.varindex = (index); \
240 LOCALTYPE_USED(index,type); \
244 # define OP_STORE_TWOWORD(o,index,type) \
246 INDEX_TWOWORD(index); \
247 OP_PREPARE_ZEROFLAGS(o); \
248 iptr->dst.varindex = (index); \
249 LOCALTYPE_USED(index,type); \
253 #define OP_BUILTIN_CHECK_EXCEPTION(bte) \
254 code_unflag_leafmethod(code); \
255 OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK); \
256 iptr->sx.s23.s3.bte = (bte); \
259 #define OP_BUILTIN_NO_EXCEPTION(bte) \
260 code_unflag_leafmethod(code); \
261 OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN); \
262 iptr->sx.s23.s3.bte = (bte); \
265 #define OP_BUILTIN_ARITHMETIC(opcode, bte) \
266 code_unflag_leafmethod(code); \
267 OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK); \
268 iptr->sx.s23.s3.bte = (bte); \
271 /* CAUTION: You must set iptr->flags yourself when using this! */
272 #define OP_FMIREF_PREPARE(o, fmiref) \
274 iptr->sx.s23.s3.fmiref = (fmiref);
277 /* function prototypes ********************************************************/
279 bool parse(jitdata *jd);
281 #endif /* _PARSE_H */
285 * These are local overrides for various environment variables in Emacs.
286 * Please do not remove this and leave it at the end of the file, where
287 * Emacs will automagically detect them.
288 * ---------------------------------------------------------------------
291 * indent-tabs-mode: t
295 * vim:noexpandtab:sw=4:ts=4: