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