* src/vm/jit/parse.h, src/vm/jit/parse.c (OP1LOAD):
[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 4742 2006-04-05 20:31:38Z 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
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     PINC
55
56 #define LOADCONST_L(v) \
57     iptr->opc    = ICMD_LCONST; \
58     iptr->val.l  = (v); \
59     iptr->line   = currentline; \
60     PINC
61
62 #define LOADCONST_F(v) \
63     iptr->opc    = ICMD_FCONST; \
64     iptr->val.f  = (v); \
65     iptr->line   = currentline; \
66     PINC
67
68 #define LOADCONST_D(v) \
69     iptr->opc    = ICMD_DCONST; \
70     iptr->val.d  = (v); \
71     iptr->line   = currentline; \
72     PINC
73
74 #define LOADCONST_A(v) \
75     iptr->opc    = ICMD_ACONST; \
76     iptr->val.a  = (v); \
77     iptr->line   = currentline; \
78     PINC
79
80 #define LOADCONST_A_CLASS(v,t) \
81     iptr->opc    = ICMD_ACONST; \
82     iptr->val.a  = (v); \
83     iptr->target = (t); \
84     iptr->line   = currentline; \
85     PINC
86
87 /* ACONST instructions generated as arguments for builtin functions
88  * have op1 set to non-zero. This is used for stack overflow checking
89  * in stack.c. */
90 #define LOADCONST_A_BUILTIN(v,t) \
91     iptr->opc    = ICMD_ACONST; \
92     iptr->op1    = 1; \
93     iptr->val.a  = (v); \
94     iptr->target = (t); \
95     iptr->line   = currentline; \
96     PINC
97
98 #define OP(o) \
99     iptr->opc    = (o); \
100     iptr->line   = currentline; \
101     PINC
102
103 #define OP1(o,o1) \
104     iptr->opc    = (o); \
105     iptr->op1    = (o1); \
106     iptr->line   = currentline; \
107     PINC
108
109 #define OP2I(o,o1,v) \
110     iptr->opc    = (o); \
111     iptr->op1    = (o1); \
112     iptr->val.i  = (v); \
113     iptr->line   = currentline; \
114     PINC
115
116 #define OP2A_NOINC(o,o1,v,l) \
117     iptr->opc    = (o); \
118     iptr->op1    = (o1); \
119     iptr->val.a  = (v); \
120     iptr->line   = (l);
121
122 #define OP2A(o,o1,v,l) \
123     OP2A_NOINC(o,o1,v,l); \
124     PINC
125
126 #define OP2AT(o,o1,v,t,l) \
127     OP2A_NOINC(o,o1,v,l); \
128     iptr->target = (t); \
129     PINC
130
131 #define BUILTIN(v,o1,t,l) \
132     m->isleafmethod = false; \
133     iptr->opc    = ICMD_BUILTIN; \
134     iptr->op1    = (o1); \
135     iptr->val.a  = (v); \
136     iptr->target = (t); \
137     iptr->line   = (l); \
138     PINC
139
140
141 /* We have to check local variables indices here because they are
142  * used in stack.c to index the locals array. */
143
144 #if defined(ENABLE_VERIFIER)
145
146 #define INDEX_ONEWORD(num) \
147     do { \
148         if (((num) < 0) || ((num) >= m->maxlocals)) \
149             goto throw_illegal_local_variable_number; \
150     } while (0)
151
152 #define INDEX_TWOWORD(num) \
153     do { \
154         if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
155             goto throw_illegal_local_variable_number; \
156     } while (0)
157
158 #else /* !define(ENABLE_VERIFIER) */
159
160 #define INDEX_ONEWORD(num)
161 #define INDEX_TWOWORD(num)
162
163 #endif /* define(ENABLE_VERIFIER) */
164
165 #define OP1LOAD_ONEWORD(o,o1) \
166     do { \
167                 INDEX_ONEWORD(o1); \
168         OP1(o,o1); \
169     } while (0)
170
171 #define OP1LOAD_TWOWORD(o,o1) \
172     do { \
173                 INDEX_TWOWORD(o1); \
174         OP1(o,o1); \
175     } while (0)
176
177 #define OP1STORE_ONEWORD(o,o1) \
178     do { \
179                 INDEX_ONEWORD(o1); \
180         OP1(o,o1); \
181     } while (0)
182
183 #define OP1STORE_TWOWORD(o,o1) \
184     do { \
185                 INDEX_TWOWORD(o1); \
186         OP1(o,o1); \
187     } 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 #if defined(ENABLE_VERIFIER)
201
202 #define CHECK_BYTECODE_INDEX(i) \
203     do { \
204         if (((i) < 0) || ((i) >= m->jcodelength)) \
205                         goto throw_invalid_bytecode_index; \
206     } while (0)
207
208 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */ 
209 /* of exception handler ranges                                   */
210 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
211     do { \
212         if ((i) < 0 || (i) > m->jcodelength) \
213                         goto throw_invalid_bytecode_index; \
214     } while (0)
215
216 #else /* !ENABLE_VERIFIER */
217
218 #define CHECK_BYTECODE_INDEX(i)
219 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
220
221 #endif
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 bool parse(jitdata *jd);
242
243 #endif /* _PARSE_H */
244
245
246 /*
247  * These are local overrides for various environment variables in Emacs.
248  * Please do not remove this and leave it at the end of the file, where
249  * Emacs will automagically detect them.
250  * ---------------------------------------------------------------------
251  * Local variables:
252  * mode: c
253  * indent-tabs-mode: t
254  * c-basic-offset: 4
255  * tab-width: 4
256  * End:
257  * vim:noexpandtab:sw=4:ts=4:
258  */
259
260