* src/vm/method.h (vm/jit/code.h): Added.
[cacao.git] / src / vm / jit / parse.h
1 /* src/vm/jit/parse.h - parser header
2
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
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Author: Christian Thalinger
28
29    Changes:
30
31    $Id: parse.h 4699 2006-03-28 14:52:32Z 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-common.h"
44
45
46 /* intermediate code generating macros ****************************************/
47
48 #define PINC           iptr++;ipc++
49
50 #define LOADCONST_I(v) \
51     iptr->opc    = ICMD_ICONST; \
52     iptr->val.i  = (v); \
53     iptr->line   = currentline; \
54     iptr->method = m; \
55     PINC
56
57 #define LOADCONST_L(v) \
58     iptr->opc    = ICMD_LCONST; \
59     iptr->val.l  = (v); \
60     iptr->line   = currentline; \
61     iptr->method = m; \
62     PINC
63
64 #define LOADCONST_F(v) \
65     iptr->opc    = ICMD_FCONST; \
66     iptr->val.f  = (v); \
67     iptr->line   = currentline; \
68     iptr->method = m; \
69     PINC
70
71 #define LOADCONST_D(v) \
72     iptr->opc    = ICMD_DCONST; \
73     iptr->val.d  = (v); \
74     iptr->line   = currentline; \
75     iptr->method = m; \
76     PINC
77
78 #define LOADCONST_A(v) \
79     iptr->opc    = ICMD_ACONST; \
80     iptr->val.a  = (v); \
81     iptr->line   = currentline; \
82     iptr->method = m; \
83     PINC
84
85 #define LOADCONST_A_CLASS(v,t) \
86     iptr->opc    = ICMD_ACONST; \
87     iptr->val.a  = (v); \
88     iptr->target = (t); \
89     iptr->line   = currentline; \
90     iptr->method = m; \
91     PINC
92
93 /* ACONST instructions generated as arguments for builtin functions
94  * have op1 set to non-zero. This is used for stack overflow checking
95  * in stack.c. */
96 #define LOADCONST_A_BUILTIN(v,t) \
97     iptr->opc    = ICMD_ACONST; \
98     iptr->op1    = 1; \
99     iptr->val.a  = (v); \
100     iptr->target = (t); \
101     iptr->line   = currentline; \
102     iptr->method = m; \
103     PINC
104
105 #define OP(o) \
106     iptr->opc    = (o); \
107     iptr->line   = currentline; \
108     iptr->method = m; \
109     PINC
110
111 #define OP1(o,o1) \
112     iptr->opc    = (o); \
113     iptr->op1    = (o1); \
114     iptr->line   = currentline; \
115     iptr->method = m; \
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 = m; \
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 = m
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     m->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 = m; \
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) >= m->maxlocals)) \
159             goto throw_illegal_local_variable_number; \
160     } while (0)
161
162 #define INDEX_TWOWORD(num) \
163     do { \
164         if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
165             goto throw_illegal_local_variable_number; \
166     } while (0)
167
168 #define OP1LOAD(o,o1) \
169     do { \
170         if (((o) == ICMD_LLOAD) || ((o) == ICMD_DLOAD)) \
171             INDEX_TWOWORD(o1); \
172         else \
173             INDEX_ONEWORD(o1); \
174         OP1(o,o1); \
175     } while (0)
176
177 #define OP1STORE(o,o1) \
178     do { \
179         if (((o) == ICMD_LSTORE) || ((o) == ICMD_DSTORE)) \
180             INDEX_TWOWORD(o1); \
181         else \
182             INDEX_ONEWORD(o1); \
183         OP1(o,o1); \
184     } while (0)
185
186 /* block generating and checking macros */
187
188 #define block_insert(i) \
189     do { \
190         if (!(m->basicblockindex[(i)] & 1)) { \
191             b_count++; \
192             m->basicblockindex[(i)] |= 1; \
193         } \
194     } while (0)
195
196
197 #if defined(ENABLE_VERIFIER)
198
199 #define CHECK_BYTECODE_INDEX(i) \
200     do { \
201         if (((i) < 0) || ((i) >= m->jcodelength)) \
202                         goto throw_invalid_bytecode_index; \
203     } while (0)
204
205 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */ 
206 /* of exception handler ranges                                   */
207 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
208     do { \
209         if ((i) < 0 || (i) > m->jcodelength) \
210                         goto throw_invalid_bytecode_index; \
211     } while (0)
212
213 #else /* !ENABLE_VERIFIER */
214
215 #define CHECK_BYTECODE_INDEX(i)
216 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
217
218 #endif
219
220 /* macros for byte code fetching ***********************************************
221
222         fetch a byte code of given size from position p in code array jcode
223
224 *******************************************************************************/
225
226 #define code_get_u1(p,m)  m->jcode[p]
227 #define code_get_s1(p,m)  ((s1)m->jcode[p])
228 #define code_get_u2(p,m)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
229 #define code_get_s2(p,m)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
230 #define code_get_u4(p,m)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
231                         +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
232 #define code_get_s4(p,m)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
233                              +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
234
235
236 /* function prototypes ********************************************************/
237
238 bool parse(jitdata *jd);
239
240 #endif /* _PARSE_H */
241
242
243 /*
244  * These are local overrides for various environment variables in Emacs.
245  * Please do not remove this and leave it at the end of the file, where
246  * Emacs will automagically detect them.
247  * ---------------------------------------------------------------------
248  * Local variables:
249  * mode: c
250  * indent-tabs-mode: t
251  * c-basic-offset: 4
252  * tab-width: 4
253  * End:
254  * vim:noexpandtab:sw=4:ts=4:
255  */
256
257