Removed jit.c global variables. Most of them were already in methodinfo,
[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 1203 2004-06-22 23:14:55Z twisti $
30
31 */
32
33
34 #ifndef _PARSE_H
35 #define _PARSE_H
36
37 #include "global.h"
38
39
40 /* intermediate code generating macros */
41
42 #define PINC           iptr++;ipc++
43 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;/*iptr->op1=0*/;iptr->val.i=(v);iptr->line=currentline;iptr->method=m;PINC
44 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;/*iptr->op1=0*/;iptr->val.l=(v);iptr->line=currentline;iptr->method=m;PINC
45 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;/*iptr->op1=0*/;iptr->val.f=(v);iptr->line=currentline;iptr->method=m;PINC
46 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;/*iptr->op1=0*/;iptr->val.d=(v);iptr->line=currentline;iptr->method=m;PINC
47 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;/*iptr->op1=0*/;iptr->val.a=(v);iptr->line=currentline;iptr->method=m;PINC
48
49 /* ACONST instructions generated as arguments for builtin functions
50  * have op1 set to non-zero. This is used for stack overflow checking
51  * in stack.c. */
52 #define LOADCONST_A_BUILTIN(v) \
53                        iptr->opc=ICMD_ACONST;iptr->op1=1;iptr->val.a=(v);iptr->line=currentline;iptr->method=m;PINC
54
55 #define OP(o)          iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;iptr->line=currentline;iptr->method=m;PINC
56 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;iptr->line=currentline;iptr->method=m;PINC
57 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);iptr->line=currentline;iptr->method=m;PINC
58
59 #define OP2A(o,o1,v,l) \
60     iptr->opc = (o); \
61     iptr->op1 = (o1); \
62     iptr->val.a = (v); \
63     iptr->line = l; \
64     iptr->method = m; \
65     PINC
66
67 #define BUILTIN1(v,t,l)  m->isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
68                        iptr->val.a=(v);iptr->line=l;iptr->method=m;PINC
69 #define BUILTIN2(v,t,l)  m->isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
70                        iptr->val.a=(v);iptr->line=l;iptr->method=m;PINC
71 #define BUILTIN3(v,t,l)  m->isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
72                        iptr->val.a=(v);iptr->line=l;iptr->method=m;PINC
73
74 /* We have to check local variables indices here because they are
75  * used in stack.c to index the locals array. */
76
77 #define INDEX_ONEWORD(num)                                                                              \
78         do { if((num)<0 || (num)>=m->maxlocals)                                         \
79                         panic("Invalid local variable index"); } while (0)
80 #define INDEX_TWOWORD(num)                                                                              \
81         do { if((num)<0 || ((num)+1)>=m->maxlocals)                                     \
82                         panic("Invalid local variable index"); } while (0)
83
84 #define OP1LOAD(o,o1)                                                   \
85         do {if (o == ICMD_LLOAD || o == ICMD_DLOAD)     \
86                         INDEX_TWOWORD(o1);                                      \
87                 else                                                                    \
88                         INDEX_ONEWORD(o1);                                      \
89                 OP1(o,o1);} while(0)
90
91 #define OP1STORE(o,o1)                                                          \
92         do {if (o == ICMD_LSTORE || o == ICMD_DSTORE)   \
93                         INDEX_TWOWORD(o1);                                              \
94                 else                                                                            \
95                         INDEX_ONEWORD(o1);                                              \
96                 OP1(o,o1);} while(0)
97
98 /* block generating and checking macros */
99
100 #define block_insert(i) \
101     do { \
102         if (!(m->basicblockindex[(i)] & 1)) { \
103             b_count++; \
104             m->basicblockindex[(i)] |= 1; \
105         } \
106     } while (0)
107
108
109 /* FIXME really use cumjcodelength for the bound_checkers ? */
110
111 #define bound_check(i) \
112     do { \
113         if (i < 0 || i >= cumjcodelength) { \
114             panic("branch target out of code-boundary"); \
115         } \
116     } while (0)
117
118 /* bound_check1 is used for the inclusive ends of exception handler ranges */
119 #define bound_check1(i) \
120     do { \
121         if (i < 0 || i > cumjcodelength) { \
122             panic("branch target out of code-boundary"); \
123         } \
124     } while (0)
125
126
127 /* macros for byte code fetching ***********************************************
128
129         fetch a byte code of given size from position p in code array jcode
130
131 *******************************************************************************/
132
133 #define code_get_u1(p)  m->jcode[p]
134 #define code_get_s1(p)  ((s1)m->jcode[p])
135 #define code_get_u2(p)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
136 #define code_get_s2(p)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
137 #define code_get_u4(p)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
138                         +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
139 #define code_get_s4(p)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
140                              +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
141
142
143 extern classinfo  *rt_class;
144 extern methodinfo *rt_method;
145 extern utf *rt_descriptor;
146 extern int rt_jcodelength;
147 extern u1  *rt_jcode;
148
149
150 /* function prototypes */
151
152 void compiler_addinitclass(classinfo *c);
153 classSetNode * descriptor2typesL(methodinfo *m);
154 void descriptor2types(methodinfo *m);
155 methodinfo *parse(methodinfo *m);
156
157 #endif /* _PARSE_H */
158
159
160 /*
161  * These are local overrides for various environment variables in Emacs.
162  * Please do not remove this and leave it at the end of the file, where
163  * Emacs will automagically detect them.
164  * ---------------------------------------------------------------------
165  * Local variables:
166  * mode: c
167  * indent-tabs-mode: t
168  * c-basic-offset: 4
169  * tab-width: 4
170  * End:
171  */
172
173