* bp: Defined.
[cacao.git] / src / vm / jit / parse.h
1 /* src/vm/jit/parse.h - parser header
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Author: Christian Thalinger
28
29    Changes:
30
31    $Id: parse.h 3499 2005-10-26 16:49:18Z twisti $
32
33 */
34
35
36 #ifndef _PARSE_H
37 #define _PARSE_H
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include "vm/global.h"
43 #include "vm/jit/codegen.inc.h"
44 #include "vm/jit/inline/inline.h"
45
46
47 /* intermediate code generating macros ****************************************/
48
49 #define PINC           iptr++;ipc++
50
51 #define LOADCONST_I(v) \
52     iptr->opc    = ICMD_ICONST; \
53     /*iptr->op1=0;*/ \
54     iptr->val.i  = (v); \
55     iptr->line   = currentline; \
56     iptr->method = inline_env->method; \
57     PINC
58
59 #define LOADCONST_L(v) \
60     iptr->opc    = ICMD_LCONST; \
61     /*iptr->op1=0*/; \
62     iptr->val.l  = (v); \
63     iptr->line   = currentline; \
64     iptr->method = inline_env->method; \
65     PINC
66
67 #define LOADCONST_F(v) \
68     iptr->opc    = ICMD_FCONST; \
69     /*iptr->op1=0*/; \
70     iptr->val.f  = (v); \
71     iptr->line   = currentline; \
72     iptr->method = inline_env->method; \
73     PINC
74
75 #define LOADCONST_D(v) \
76     iptr->opc    = ICMD_DCONST; \
77     /*iptr->op1=0*/; \
78     iptr->val.d  = (v); \
79     iptr->line   = currentline; \
80     iptr->method = inline_env->method; \
81     PINC
82
83 #define LOADCONST_A(v) \
84     iptr->opc    = ICMD_ACONST; \
85     /*iptr->op1=0*/; \
86     iptr->val.a  = (v); \
87     iptr->line   = currentline; \
88     iptr->method = inline_env->method; \
89     PINC
90
91 /* ACONST instructions generated as arguments for builtin functions
92  * have op1 set to non-zero. This is used for stack overflow checking
93  * in stack.c. */
94 #define LOADCONST_A_BUILTIN(v) \
95     iptr->opc = ICMD_ACONST; \
96     iptr->op1 = 1; \
97     iptr->val.a = (v); \
98     iptr->line = currentline; \
99     iptr->method = inline_env->method; \
100     PINC
101
102 #define OP(o) \
103     iptr->opc    = (o); \
104     /*iptr->op1=0*/; \
105     /*iptr->val.l=0*/; \
106     iptr->line   = currentline; \
107     iptr->method = inline_env->method; \
108     PINC
109
110 #define OP1(o,o1) \
111     iptr->opc    = (o); \
112     iptr->op1    = (o1); \
113     /*iptr->val.l=(0)*/; \
114     iptr->line   = currentline; \
115     iptr->method = inline_env->method; \
116     PINC
117
118 #define OP2I(o,o1,v) \
119     iptr->opc    = (o); \
120     iptr->op1    = (o1); \
121     iptr->val.i  = (v); \
122     iptr->line   = currentline; \
123     iptr->method = inline_env->method; \
124     PINC
125
126 #define OP2A_NOINC(o,o1,v,l) \
127     iptr->opc    = (o); \
128     iptr->op1    = (o1); \
129     iptr->val.a  = (v); \
130     iptr->line   = (l); \
131     iptr->method = inline_env->method
132
133 #define OP2A(o,o1,v,l) \
134     OP2A_NOINC(o,o1,v,l); \
135     PINC
136
137 #define OP2AT(o,o1,v,t,l) \
138     OP2A_NOINC(o,o1,v,l); \
139     iptr->target = (t); \
140     PINC
141
142 #define BUILTIN(v,o1,t,l) \
143     inline_env->method->isleafmethod = false; \
144     iptr->opc    = ICMD_BUILTIN; \
145     iptr->op1    = (o1); \
146     iptr->val.a  = (v); \
147     iptr->target = (t); \
148     iptr->line   = (l); \
149     iptr->method = inline_env->method; \
150     PINC
151
152
153 /* We have to check local variables indices here because they are
154  * used in stack.c to index the locals array. */
155
156 #define INDEX_ONEWORD(num) \
157     do { \
158         if ((num) < 0 || (num) >= inline_env->cumlocals) { \
159             *exceptionptr = \
160                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
161             return NULL; \
162         } \
163     } while (0)
164
165 #define INDEX_TWOWORD(num) \
166     do { \
167         if ((num) < 0 || ((num) + 1) >= inline_env->cumlocals) { \
168             *exceptionptr = \
169                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
170             return NULL; \
171         } \
172     } while (0)
173
174 #define OP1LOAD(o,o1)                                                   \
175         do {if (o == ICMD_LLOAD || o == ICMD_DLOAD)     \
176                         INDEX_TWOWORD(o1);                                      \
177                 else                                                                    \
178                         INDEX_ONEWORD(o1);                                      \
179                 OP1(o,o1);} while(0)
180
181 #define OP1STORE(o,o1)                                                          \
182         do {if (o == ICMD_LSTORE || o == ICMD_DSTORE)   \
183                         INDEX_TWOWORD(o1);                                              \
184                 else                                                                            \
185                         INDEX_ONEWORD(o1);                                              \
186                 OP1(o,o1);} while(0)
187
188 /* block generating and checking macros */
189
190 #define block_insert(i) \
191     do { \
192         if (!(m->basicblockindex[(i)] & 1)) { \
193             b_count++; \
194             m->basicblockindex[(i)] |= 1; \
195         } \
196     } while (0)
197
198
199 /* FIXME really use cumjcodelength for the bound_checkers ? */
200
201 #define bound_check(i) \
202     do { \
203         if (i < 0 || i >= inline_env->cumjcodelength) { \
204        /*  if (i < 0 || i >= m->jcodelength) { */ \
205             *exceptionptr = \
206                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
207             return NULL; \
208         } \
209     } while (0)
210
211 /* bound_check1 is used for the inclusive ends of exception handler ranges */
212 #define bound_check1(i) \
213     do { \
214         if (i < 0 || i > inline_env->cumjcodelength) { \
215 /*        if (i < 0 || i > m->jcodelength) { */ \
216             *exceptionptr = \
217                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
218             return NULL; \
219         } \
220     } while (0)
221
222
223 /* macros for byte code fetching ***********************************************
224
225         fetch a byte code of given size from position p in code array jcode
226
227 *******************************************************************************/
228
229 #define code_get_u1(p,m)  m->jcode[p]
230 #define code_get_s1(p,m)  ((s1)m->jcode[p])
231 #define code_get_u2(p,m)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
232 #define code_get_s2(p,m)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
233 #define code_get_u4(p,m)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
234                         +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
235 #define code_get_s4(p,m)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
236                              +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
237
238
239 /* function prototypes ********************************************************/
240
241 void compiler_addinitclass(classinfo *c);
242 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env);
243
244 #endif /* _PARSE_H */
245
246
247 /*
248  * These are local overrides for various environment variables in Emacs.
249  * Please do not remove this and leave it at the end of the file, where
250  * Emacs will automagically detect them.
251  * ---------------------------------------------------------------------
252  * Local variables:
253  * mode: c
254  * indent-tabs-mode: t
255  * c-basic-offset: 4
256  * tab-width: 4
257  * End:
258  */
259
260