less debug output
[cacao.git] / src / vm / jit / parse.h
1 /* 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    $Id: parse.h 2406 2005-04-28 12:19:06Z jowenn $
30
31 */
32
33
34 #ifndef _PARSE_H
35 #define _PARSE_H
36
37 #include "vm/global.h"
38 #include "vm/jit/codegen.inc.h"
39 #include "vm/jit/inline/inline.h"
40
41
42 /* intermediate code generating macros */
43
44 #define PINC           iptr++;ipc++
45
46 #define LOADCONST_I(v) \
47     iptr->opc = ICMD_ICONST; \
48     /*iptr->op1=0;*/ \
49     iptr->val.i = (v); \
50     iptr->line = currentline; \
51     iptr->method = inline_env->method; \
52     PINC
53
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
58
59 /* ACONST instructions generated as arguments for builtin functions
60  * have op1 set to non-zero. This is used for stack overflow checking
61  * in stack.c. */
62 #define LOADCONST_A_BUILTIN(v) \
63     iptr->opc = ICMD_ACONST; \
64     iptr->op1 = 1; \
65     iptr->val.a = (v); \
66     iptr->line = currentline; \
67     iptr->method = inline_env->method; \
68     PINC
69
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
73
74 #define OP2A_NOINC(o,o1,v,l) \
75     iptr->opc = (o); \
76     iptr->op1 = (o1); \
77     iptr->val.a = (v); \
78     iptr->line = (l); \
79     iptr->method = inline_env->method
80
81 #define OP2A(o,o1,v,l) \
82     OP2A_NOINC(o,o1,v,l); \
83     PINC
84
85 #define OP2AT(o,o1,v,t,l) \
86     OP2A_NOINC(o,o1,v,l); \
87     iptr->target = (t); \
88     PINC
89
90 #define BUILTIN1(v,o1,l) \
91     inline_env->method->isleafmethod = false; \
92     iptr->opc = ICMD_BUILTIN1; \
93     iptr->op1 = (o1); \
94     iptr->val.fp = (v); \
95     iptr->target = NULL; \
96     iptr->line = (l); \
97     iptr->method = inline_env->method; \
98     PINC
99
100 #define BUILTIN1T(v,o1,t,l) \
101     inline_env->method->isleafmethod = false; \
102     iptr->opc = ICMD_BUILTIN1; \
103     iptr->op1 = (o1); \
104     iptr->val.fp = (v); \
105     iptr->target = (t); \
106     iptr->line = (l); \
107     iptr->method = inline_env->method; \
108     PINC
109
110 #define BUILTIN2(v,o1,l) \
111     inline_env->method->isleafmethod = false; \
112     iptr->opc = ICMD_BUILTIN2; \
113     iptr->op1 = (o1);\
114     iptr->val.fp = (v); \
115     iptr->target = NULL; \
116     iptr->line = (l); \
117     iptr->method = inline_env->method; \
118     PINC
119
120 #define BUILTIN2T(v,o1,t,l) \
121     inline_env->method->isleafmethod = false; \
122     iptr->opc = ICMD_BUILTIN2; \
123     iptr->op1 = (o1);\
124     iptr->val.fp = (v); \
125     iptr->target = (t); \
126     iptr->line = (l); \
127     iptr->method = inline_env->method; \
128     PINC
129
130 #define BUILTIN3(v,o1,l) \
131     inline_env->method->isleafmethod = false; \
132     iptr->opc = ICMD_BUILTIN3; \
133     iptr->op1 = (o1);\
134     iptr->val.fp = (v); \
135     iptr->target = NULL; \
136     iptr->line = (l); \
137     iptr->method = inline_env->method; \
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 #define INDEX_ONEWORD(num) \
145     do { \
146         if ((num) < 0 || (num) >= inline_env->cumlocals) { \
147             *exceptionptr = \
148                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
149             return NULL; \
150         } \
151     } while (0)
152
153 #define INDEX_TWOWORD(num) \
154     do { \
155         if ((num) < 0 || ((num) + 1) >= inline_env->cumlocals) { \
156             *exceptionptr = \
157                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
158             return NULL; \
159         } \
160     } while (0)
161
162 #define OP1LOAD(o,o1)                                                   \
163         do {if (o == ICMD_LLOAD || o == ICMD_DLOAD)     \
164                         INDEX_TWOWORD(o1);                                      \
165                 else                                                                    \
166                         INDEX_ONEWORD(o1);                                      \
167                 OP1(o,o1);} while(0)
168
169 #define OP1STORE(o,o1)                                                          \
170         do {if (o == ICMD_LSTORE || o == ICMD_DSTORE)   \
171                         INDEX_TWOWORD(o1);                                              \
172                 else                                                                            \
173                         INDEX_ONEWORD(o1);                                              \
174                 OP1(o,o1);} while(0)
175
176 /* block generating and checking macros */
177
178 #define block_insert(i) \
179     do { \
180         if (!(m->basicblockindex[(i)] & 1)) { \
181             b_count++; \
182             m->basicblockindex[(i)] |= 1; \
183         } \
184         /*printf("Block has been inserted: %d\n",i); */ \
185     } while (0)
186
187
188 /* FIXME really use cumjcodelength for the bound_checkers ? */
189
190 #define bound_check(i) \
191     do { \
192         if (i < 0 || i >= inline_env->cumjcodelength) { \
193  printf("bound_check i=%i >= %i=cum\n",i,inline_env->cumjcodelength); \
194  fflush(stdout); \
195        /*  if (i < 0 || i >= m->jcodelength) { */ \
196             *exceptionptr = \
197                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
198             return NULL; \
199         } \
200     } while (0)
201
202 /* bound_check1 is used for the inclusive ends of exception handler ranges */
203 #define bound_check1(i) \
204     do { \
205         if (i < 0 || i > inline_env->cumjcodelength) { \
206 /*        if (i < 0 || i > m->jcodelength) { */ \
207             *exceptionptr = \
208                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
209             return NULL; \
210         } \
211     } while (0)
212
213
214 /* macros for byte code fetching ***********************************************
215
216         fetch a byte code of given size from position p in code array jcode
217
218 *******************************************************************************/
219
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]))
228
229 /* function prototypes */
230
231 void compiler_addinitclass(classinfo *c);
232 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env);
233
234 #endif /* _PARSE_H */
235
236
237 /*
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  * ---------------------------------------------------------------------
242  * Local variables:
243  * mode: c
244  * indent-tabs-mode: t
245  * c-basic-offset: 4
246  * tab-width: 4
247  * End:
248  */
249
250