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