1 /* jit/parse.h - parser header
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Author: Christian Thalinger
29 $Id: parse.h 2406 2005-04-28 12:19:06Z jowenn $
37 #include "vm/global.h"
38 #include "vm/jit/codegen.inc.h"
39 #include "vm/jit/inline/inline.h"
42 /* intermediate code generating macros */
44 #define PINC iptr++;ipc++
46 #define LOADCONST_I(v) \
47 iptr->opc = ICMD_ICONST; \
50 iptr->line = currentline; \
51 iptr->method = inline_env->method; \
54 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;/*iptr->op1=0*/;iptr->val.l=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
55 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;/*iptr->op1=0*/;iptr->val.f=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
56 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;/*iptr->op1=0*/;iptr->val.d=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
57 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;/*iptr->op1=0*/;iptr->val.a=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
59 /* ACONST instructions generated as arguments for builtin functions
60 * have op1 set to non-zero. This is used for stack overflow checking
62 #define LOADCONST_A_BUILTIN(v) \
63 iptr->opc = ICMD_ACONST; \
66 iptr->line = currentline; \
67 iptr->method = inline_env->method; \
70 #define OP(o) iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
71 #define OP1(o,o1) iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
72 #define OP2I(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
74 #define OP2A_NOINC(o,o1,v,l) \
79 iptr->method = inline_env->method
81 #define OP2A(o,o1,v,l) \
82 OP2A_NOINC(o,o1,v,l); \
85 #define OP2AT(o,o1,v,t,l) \
86 OP2A_NOINC(o,o1,v,l); \
90 #define BUILTIN1(v,o1,l) \
91 inline_env->method->isleafmethod = false; \
92 iptr->opc = ICMD_BUILTIN1; \
95 iptr->target = NULL; \
97 iptr->method = inline_env->method; \
100 #define BUILTIN1T(v,o1,t,l) \
101 inline_env->method->isleafmethod = false; \
102 iptr->opc = ICMD_BUILTIN1; \
104 iptr->val.fp = (v); \
105 iptr->target = (t); \
107 iptr->method = inline_env->method; \
110 #define BUILTIN2(v,o1,l) \
111 inline_env->method->isleafmethod = false; \
112 iptr->opc = ICMD_BUILTIN2; \
114 iptr->val.fp = (v); \
115 iptr->target = NULL; \
117 iptr->method = inline_env->method; \
120 #define BUILTIN2T(v,o1,t,l) \
121 inline_env->method->isleafmethod = false; \
122 iptr->opc = ICMD_BUILTIN2; \
124 iptr->val.fp = (v); \
125 iptr->target = (t); \
127 iptr->method = inline_env->method; \
130 #define BUILTIN3(v,o1,l) \
131 inline_env->method->isleafmethod = false; \
132 iptr->opc = ICMD_BUILTIN3; \
134 iptr->val.fp = (v); \
135 iptr->target = NULL; \
137 iptr->method = inline_env->method; \
141 /* We have to check local variables indices here because they are
142 * used in stack.c to index the locals array. */
144 #define INDEX_ONEWORD(num) \
146 if ((num) < 0 || (num) >= inline_env->cumlocals) { \
148 new_verifyerror(inline_env->method, "Illegal local variable number"); \
153 #define INDEX_TWOWORD(num) \
155 if ((num) < 0 || ((num) + 1) >= inline_env->cumlocals) { \
157 new_verifyerror(inline_env->method, "Illegal local variable number"); \
162 #define OP1LOAD(o,o1) \
163 do {if (o == ICMD_LLOAD || o == ICMD_DLOAD) \
169 #define OP1STORE(o,o1) \
170 do {if (o == ICMD_LSTORE || o == ICMD_DSTORE) \
176 /* block generating and checking macros */
178 #define block_insert(i) \
180 if (!(m->basicblockindex[(i)] & 1)) { \
182 m->basicblockindex[(i)] |= 1; \
184 /*printf("Block has been inserted: %d\n",i); */ \
188 /* FIXME really use cumjcodelength for the bound_checkers ? */
190 #define bound_check(i) \
192 if (i < 0 || i >= inline_env->cumjcodelength) { \
193 printf("bound_check i=%i >= %i=cum\n",i,inline_env->cumjcodelength); \
195 /* if (i < 0 || i >= m->jcodelength) { */ \
197 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
202 /* bound_check1 is used for the inclusive ends of exception handler ranges */
203 #define bound_check1(i) \
205 if (i < 0 || i > inline_env->cumjcodelength) { \
206 /* if (i < 0 || i > m->jcodelength) { */ \
208 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
214 /* macros for byte code fetching ***********************************************
216 fetch a byte code of given size from position p in code array jcode
218 *******************************************************************************/
220 #define code_get_u1(p,m) m->jcode[p]
221 #define code_get_s1(p,m) ((s1)m->jcode[p])
222 #define code_get_u2(p,m) ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
223 #define code_get_s2(p,m) ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
224 #define code_get_u4(p,m) ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
225 +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
226 #define code_get_s4(p,m) ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
227 +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
229 /* function prototypes */
231 void compiler_addinitclass(classinfo *c);
232 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env);
234 #endif /* _PARSE_H */
238 * These are local overrides for various environment variables in Emacs.
239 * Please do not remove this and leave it at the end of the file, where
240 * Emacs will automagically detect them.
241 * ---------------------------------------------------------------------
244 * indent-tabs-mode: t