GNU header update.
[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 1735 2004-12-07 14:33:27Z twisti $
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;iptr->op1=1;iptr->val.a=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
64
65 #define OP(o)          iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
66 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
67 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
68
69 #define OP2A(o,o1,v,l) \
70     iptr->opc = (o); \
71     iptr->op1 = (o1); \
72     iptr->val.a = (v); \
73     iptr->line = (l); \
74     iptr->method = inline_env->method; \
75     PINC
76
77 #define BUILTIN1(v,t,l) \
78     inline_env->method->isleafmethod = false; \
79     iptr->opc = ICMD_BUILTIN1; \
80     iptr->op1 = (t); \
81     iptr->val.fp = (v); \
82     iptr->line = (l); \
83     iptr->method = inline_env->method; \
84     PINC
85
86 #define BUILTIN2(v,t,l) \
87     inline_env->method->isleafmethod = false; \
88     iptr->opc = ICMD_BUILTIN2; \
89     iptr->op1 = (t);\
90     iptr->val.fp = (v); \
91     iptr->line = (l); \
92     iptr->method = inline_env->method; \
93     PINC
94
95 #define BUILTIN3(v,t,l) \
96     inline_env->method->isleafmethod = false; \
97     iptr->opc = ICMD_BUILTIN3; \
98     iptr->op1 = (t);\
99     iptr->val.fp = (v); \
100     iptr->line = (l); \
101     iptr->method = inline_env->method; \
102     PINC
103
104
105 /* We have to check local variables indices here because they are
106  * used in stack.c to index the locals array. */
107
108 #define INDEX_ONEWORD(num) \
109     do { \
110         if ((num) < 0 || (num) >= inline_env->cumlocals) { \
111             *exceptionptr = \
112                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
113             return NULL; \
114         } \
115     } while (0)
116
117 #define INDEX_TWOWORD(num) \
118     do { \
119         if ((num) < 0 || ((num) + 1) >= inline_env->cumlocals) { \
120             *exceptionptr = \
121                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
122             return NULL; \
123         } \
124     } while (0)
125
126 #define OP1LOAD(o,o1)                                                   \
127         do {if (o == ICMD_LLOAD || o == ICMD_DLOAD)     \
128                         INDEX_TWOWORD(o1);                                      \
129                 else                                                                    \
130                         INDEX_ONEWORD(o1);                                      \
131                 OP1(o,o1);} while(0)
132
133 #define OP1STORE(o,o1)                                                          \
134         do {if (o == ICMD_LSTORE || o == ICMD_DSTORE)   \
135                         INDEX_TWOWORD(o1);                                              \
136                 else                                                                            \
137                         INDEX_ONEWORD(o1);                                              \
138                 OP1(o,o1);} while(0)
139
140 /* block generating and checking macros */
141
142 #define block_insert(i) \
143     do { \
144         if (!(m->basicblockindex[(i)] & 1)) { \
145             b_count++; \
146             m->basicblockindex[(i)] |= 1; \
147         } \
148     } while (0)
149
150
151 /* FIXME really use cumjcodelength for the bound_checkers ? */
152
153 #define bound_check(i) \
154     do { \
155         if (i < 0 || i >= inline_env->cumjcodelength) { \
156  printf("bound_check i=%i >= %i=cum\n",i,inline_env->cumjcodelength); \
157  fflush(stdout); \
158        /*  if (i < 0 || i >= m->jcodelength) { */ \
159             *exceptionptr = \
160                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
161             return NULL; \
162         } \
163     } while (0)
164
165 /* bound_check1 is used for the inclusive ends of exception handler ranges */
166 #define bound_check1(i) \
167     do { \
168         if (i < 0 || i > inline_env->cumjcodelength) { \
169 /*        if (i < 0 || i > m->jcodelength) { */ \
170             *exceptionptr = \
171                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
172             return NULL; \
173         } \
174     } while (0)
175
176
177 /* macros for byte code fetching ***********************************************
178
179         fetch a byte code of given size from position p in code array jcode
180
181 *******************************************************************************/
182
183 #define code_get_u1(p,m)  m->jcode[p]
184 #define code_get_s1(p,m)  ((s1)m->jcode[p])
185 #define code_get_u2(p,m)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
186 #define code_get_s2(p,m)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
187 #define code_get_u4(p,m)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
188                         +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
189 #define code_get_s4(p,m)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
190                              +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
191
192 /* function prototypes */
193
194 void compiler_addinitclass(classinfo *c);
195 classSetNode * descriptor2typesL(methodinfo *m);
196 void descriptor2types(methodinfo *m);
197 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env);
198
199 #endif /* _PARSE_H */
200
201
202 /*
203  * These are local overrides for various environment variables in Emacs.
204  * Please do not remove this and leave it at the end of the file, where
205  * Emacs will automagically detect them.
206  * ---------------------------------------------------------------------
207  * Local variables:
208  * mode: c
209  * indent-tabs-mode: t
210  * c-basic-offset: 4
211  * tab-width: 4
212  * End:
213  */
214
215