* Removed all Id tags.
[cacao.git] / src / vm / jit / stack.h
1 /* vm/jit/stack.h - stack analysis 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    Authors: Christian Thalinger
28
29    Changes: Christian Ullrich
30                         Edwin Steiner
31
32 */
33
34
35 #ifndef _STACK_H
36 #define _STACK_H
37
38 #include "config.h"
39
40 #include "vm/types.h"
41
42 #include "vm/exceptions.h"
43 #include "vm/global.h"
44 #include "vm/jit/jit.h"
45 #include "vm/jit/reg.h"
46
47
48 /* macros used internally by analyse_stack ************************************/
49
50 /*--------------------------------------------------*/
51 /* BASIC TYPE CHECKING                              */
52 /*--------------------------------------------------*/
53
54 /* XXX would be nice if we did not have to pass the expected type */
55
56 #if defined(ENABLE_VERIFIER)
57 #define CHECK_BASIC_TYPE(expected,actual)                            \
58     do {                                                             \
59         if ((actual) != (expected)) {                                \
60             expectedtype = (expected);                               \
61             goto throw_stack_type_error;                             \
62         }                                                            \
63     } while (0)
64 #else /* !ENABLE_VERIFIER */
65 #define CHECK_BASIC_TYPE(expected,actual)
66 #endif /* ENABLE_VERIFIER */
67
68 /*--------------------------------------------------*/
69 /* STACK UNDERFLOW/OVERFLOW CHECKS                  */
70 /*--------------------------------------------------*/
71
72 /* underflow checks */
73
74 #if defined(ENABLE_VERIFIER)
75 #define REQUIRE(num)                                                 \
76     do {                                                             \
77         if (stackdepth < (num))                                      \
78             goto throw_stack_underflow;                              \
79     } while (0)
80 #else /* !ENABLE_VERIFIER */
81 #define REQUIRE(num)
82 #endif /* ENABLE_VERIFIER */
83
84
85 /* overflow check */
86 /* We allow ACONST instructions inserted as arguments to builtin
87  * functions to exceed the maximum stack depth.  Maybe we should check
88  * against maximum stack depth only at block boundaries?
89  */
90
91 /* XXX we should find a way to remove the opc/op1 check */
92 #if defined(ENABLE_VERIFIER)
93 #define CHECKOVERFLOW                                                \
94     do {                                                             \
95         if (stackdepth > m->maxstack)                                \
96             if ((iptr->opc != ICMD_ACONST) || INSTRUCTION_MUST_CHECK(iptr))\
97                 goto throw_stack_overflow;                           \
98     } while(0)
99 #else /* !ENABLE_VERIFIER */
100 #define CHECKOVERFLOW
101 #endif /* ENABLE_VERIFIER */
102
103 /*--------------------------------------------------*/
104 /* ALLOCATING STACK SLOTS                           */
105 /*--------------------------------------------------*/
106
107 #define NEWSTACK(s,v,n)                                              \
108     do {                                                             \
109         sd.new->prev = curstack;                                     \
110         sd.new->type = (s);                                          \
111         sd.new->flags = 0;                                           \
112         sd.new->varkind = (v);                                       \
113         sd.new->varnum = (n);                                        \
114         curstack = sd.new;                                           \
115         sd.var[(n)].type = (s);                                      \
116         sd.var[(n)].flags = 0;                                       \
117         sd.new++;                                                    \
118     } while (0)
119
120 /* Initialize regoff, so -sia can show regnames even before reg.inc */
121 /* regs[rd->intregargnum] has to be set for this                    */
122 /* new->regoff = (IS_FLT_DBL_TYPE(s))?-1:rd->intreg_argnum; }       */
123
124 #define NEWSTACKn(s,n)  NEWSTACK(s,UNDEFVAR,n)
125 #define NEWSTACK0(s)    NEWSTACK(s,UNDEFVAR,0)
126
127
128 /* function prototypes ********************************************************/
129
130 bool stack_init(void);
131
132 bool stack_analyse(jitdata *jd);
133
134 void stack_javalocals_store(instruction *iptr, s4 *javalocals);
135
136 #endif /* _STACK_H */
137
138
139 /*
140  * These are local overrides for various environment variables in Emacs.
141  * Please do not remove this and leave it at the end of the file, where
142  * Emacs will automagically detect them.
143  * ---------------------------------------------------------------------
144  * Local variables:
145  * mode: c
146  * indent-tabs-mode: t
147  * c-basic-offset: 4
148  * tab-width: 4
149  * End:
150  * vim:noexpandtab:sw=4:ts=4:
151  */