inline updates (almost finished) to separate class and other variables merged inadver...
[cacao.git] / src / vm / jit / parse.h
1 /* jit/parse.h - parser header
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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 1414 2004-10-04 12:55:33Z carolyn $
30
31 */
32
33
34 #ifndef _PARSE_H
35 #define _PARSE_H
36
37 #include "global.h"
38 #include "inline.h"
39
40
41 /* intermediate code generating macros */
42
43 #define PINC           iptr++;ipc++
44
45 #define LOADCONST_I(v) \
46     iptr->opc = ICMD_ICONST; \
47     /*iptr->op1=0;*/ \
48     iptr->val.i = (v); \
49     iptr->line = currentline; \
50     iptr->method = inline_env->method; \
51     PINC
52
53 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;/*iptr->op1=0*/;iptr->val.l=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
54 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;/*iptr->op1=0*/;iptr->val.f=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
55 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;/*iptr->op1=0*/;iptr->val.d=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
56 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;/*iptr->op1=0*/;iptr->val.a=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
57
58 /* ACONST instructions generated as arguments for builtin functions
59  * have op1 set to non-zero. This is used for stack overflow checking
60  * in stack.c. */
61 #define LOADCONST_A_BUILTIN(v) \
62                        iptr->opc=ICMD_ACONST;iptr->op1=1;iptr->val.a=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
63
64 #define OP(o)          iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
65 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;iptr->line=currentline;iptr->method=inline_env->method;PINC
66 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);iptr->line=currentline;iptr->method=inline_env->method;PINC
67
68 #define OP2A(o,o1,v,l) \
69     iptr->opc = (o); \
70     iptr->op1 = (o1); \
71     iptr->val.a = (v); \
72     iptr->line = l; \
73     iptr->method = inline_env->method; \
74     PINC
75
76 #define BUILTIN1(v,t,l) \
77     inline_env->method->isleafmethod = false; \
78     iptr->opc = ICMD_BUILTIN1; \
79     iptr->val.a = (v); \
80     iptr->op1 = (t); \
81     iptr->line = (l); \
82     iptr->method = inline_env->method; \
83     PINC
84
85 #define BUILTIN2(v,t,l)  inline_env->method->isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
86                        iptr->val.a=(v);iptr->line=l;iptr->method=inline_env->method;PINC
87 #define BUILTIN3(v,t,l)  inline_env->method->isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
88                        iptr->val.a=(v);iptr->line=l;iptr->method=inline_env->method;PINC
89
90
91 /* We have to check local variables indices here because they are
92  * used in stack.c to index the locals array. */
93
94 #define INDEX_ONEWORD(num) \
95     do { \
96         if ((num) < 0 || (num) >= inline_env->cumlocals) { \
97             *exceptionptr = \
98                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
99             return NULL; \
100         } \
101     } while (0)
102
103 #define INDEX_TWOWORD(num) \
104     do { \
105         if ((num) < 0 || ((num) + 1) >= inline_env->cumlocals) { \
106             *exceptionptr = \
107                 new_verifyerror(inline_env->method, "Illegal local variable number"); \
108             return NULL; \
109         } \
110     } while (0)
111
112 #define OP1LOAD(o,o1)                                                   \
113         do {if (o == ICMD_LLOAD || o == ICMD_DLOAD)     \
114                         INDEX_TWOWORD(o1);                                      \
115                 else                                                                    \
116                         INDEX_ONEWORD(o1);                                      \
117                 OP1(o,o1);} while(0)
118
119 #define OP1STORE(o,o1)                                                          \
120         do {if (o == ICMD_LSTORE || o == ICMD_DSTORE)   \
121                         INDEX_TWOWORD(o1);                                              \
122                 else                                                                            \
123                         INDEX_ONEWORD(o1);                                              \
124                 OP1(o,o1);} while(0)
125
126 /* block generating and checking macros */
127
128 #define block_insert(i) \
129     do { \
130         if (!(m->basicblockindex[(i)] & 1)) { \
131             b_count++; \
132             m->basicblockindex[(i)] |= 1; \
133  if (DEBUG==true){printf("---------------------block_inserted:b_count=%i m->basicblockindex[(i=%i)]=%i=%p\n",b_count,i,m->basicblockindex[(i)],m->basicblockindex[(i)]); \
134   fflush(stdout); }   \
135         } \
136     } while (0)
137
138
139 /* FIXME really use cumjcodelength for the bound_checkers ? */
140
141 #define bound_check(i) \
142     do { \
143         if (i < 0 || i >= inline_env->cumjcodelength) { \
144  printf("bound_check i=%i >= %i=cum\n",i,inline_env->cumjcodelength); \
145  fflush(stdout); \
146        /*  if (i < 0 || i >= m->jcodelength) { */ \
147             *exceptionptr = \
148                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
149             return NULL; \
150         } \
151     } while (0)
152
153 /* bound_check1 is used for the inclusive ends of exception handler ranges */
154 #define bound_check1(i) \
155     do { \
156         if (i < 0 || i > inline_env->cumjcodelength) { \
157 /*        if (i < 0 || i > m->jcodelength) { */ \
158             *exceptionptr = \
159                 new_verifyerror(inline_env->method, "Illegal target of jump or branch"); \
160             return NULL; \
161         } \
162     } while (0)
163
164
165 /* macros for byte code fetching ***********************************************
166
167         fetch a byte code of given size from position p in code array jcode
168
169 *******************************************************************************/
170
171 #define code_get_u1(p,m)  m->jcode[p]
172 #define code_get_s1(p,m)  ((s1)m->jcode[p])
173 #define code_get_u2(p,m)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
174 #define code_get_s2(p,m)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
175 #define code_get_u4(p,m)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
176                         +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
177 #define code_get_s4(p,m)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
178                              +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
179
180
181 extern classinfo  *rt_class;
182 extern methodinfo *rt_method;
183 extern utf *rt_descriptor;
184 extern int rt_jcodelength;
185 extern u1  *rt_jcode;
186
187
188 /* function prototypes */
189
190 void compiler_addinitclass(classinfo *c);
191 classSetNode * descriptor2typesL(methodinfo *m);
192 void descriptor2types(methodinfo *m);
193 methodinfo *parse(methodinfo *m,t_inlining_globals *inline_env);
194
195 #endif /* _PARSE_H */
196
197
198 /*
199  * These are local overrides for various environment variables in Emacs.
200  * Please do not remove this and leave it at the end of the file, where
201  * Emacs will automagically detect them.
202  * ---------------------------------------------------------------------
203  * Local variables:
204  * mode: c
205  * indent-tabs-mode: t
206  * c-basic-offset: 4
207  * tab-width: 4
208  * End:
209  */
210
211