1 /* src/vm/jit/stack.h - stack analysis header
3 Copyright (C) 1996-2005, 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 /* forward typedefs ***********************************************************/
31 typedef struct stackelement_t stackelement_t;
40 #include "vm/exceptions.h"
41 #include "vm/global.h"
43 #include "vm/jit/jit.h"
44 #include "vm/jit/reg.h"
47 /* stack element structure ****************************************************/
51 #define SAVEDVAR 1 /* variable has to survive method invocations */
52 #define INMEMORY 2 /* variable stored in memory */
53 #define SAVREG 4 /* allocated to a saved register */
54 #define ARGREG 8 /* allocated to an arg register */
55 #define PASSTHROUGH 32 /* stackslot was passed-through by an ICMD */
56 #define PREALLOC 64 /* preallocated var like for ARGVARS. Used */
57 /* with the new var system */
58 #define INOUT 128 /* variable is an invar or/and an outvar */
60 #define IS_SAVEDVAR(x) ((x) & SAVEDVAR)
61 #define IS_INMEMORY(x) ((x) & INMEMORY)
66 #define UNDEFVAR 0 /* stack slot will become temp during regalloc*/
67 #define TEMPVAR 1 /* stack slot is temp register */
68 #define STACKVAR 2 /* stack slot is numbered stack slot */
69 #define LOCALVAR 3 /* stack slot is local variable */
70 #define ARGVAR 4 /* stack slot is argument variable */
73 struct stackelement_t {
74 stackelement_t *prev; /* pointer to next element towards bottom */
75 instruction *creator; /* instruction that created this element */
76 s4 type; /* slot type of stack element */
77 s4 flags; /* flags (SAVED, INMEMORY) */
78 s4 varkind; /* kind of variable or register */
79 s4 varnum; /* number of variable */
83 /* macros used internally by analyse_stack ************************************/
85 /*--------------------------------------------------*/
86 /* BASIC TYPE CHECKING */
87 /*--------------------------------------------------*/
89 /* XXX would be nice if we did not have to pass the expected type */
91 #if defined(ENABLE_VERIFIER)
92 #define CHECK_BASIC_TYPE(expected,actual) \
94 if ((actual) != (expected)) { \
95 expectedtype = (expected); \
96 goto throw_stack_type_error; \
99 #else /* !ENABLE_VERIFIER */
100 #define CHECK_BASIC_TYPE(expected,actual)
101 #endif /* ENABLE_VERIFIER */
103 /*--------------------------------------------------*/
104 /* STACK UNDERFLOW/OVERFLOW CHECKS */
105 /*--------------------------------------------------*/
107 /* underflow checks */
109 #if defined(ENABLE_VERIFIER)
110 #define REQUIRE(num) \
112 if (stackdepth < (num)) \
113 goto throw_stack_underflow; \
115 #else /* !ENABLE_VERIFIER */
117 #endif /* ENABLE_VERIFIER */
121 /* We allow ACONST instructions inserted as arguments to builtin
122 * functions to exceed the maximum stack depth. Maybe we should check
123 * against maximum stack depth only at block boundaries?
126 /* XXX we should find a way to remove the opc/op1 check */
127 #if defined(ENABLE_VERIFIER)
128 #define CHECKOVERFLOW \
130 if (stackdepth > m->maxstack) \
131 if ((iptr->opc != ICMD_ACONST) || INSTRUCTION_MUST_CHECK(iptr))\
132 goto throw_stack_overflow; \
134 #else /* !ENABLE_VERIFIER */
135 #define CHECKOVERFLOW
136 #endif /* ENABLE_VERIFIER */
138 /*--------------------------------------------------*/
139 /* ALLOCATING STACK SLOTS */
140 /*--------------------------------------------------*/
142 #define NEWSTACK(s,v,n) \
144 sd.new->prev = curstack; \
145 sd.new->type = (s); \
147 sd.new->varkind = (v); \
148 sd.new->varnum = (n); \
150 sd.var[(n)].type = (s); \
151 sd.var[(n)].flags = 0; \
155 /* Initialize regoff, so -sia can show regnames even before reg.inc */
156 /* regs[rd->intregargnum] has to be set for this */
157 /* new->regoff = (IS_FLT_DBL_TYPE(s))?-1:rd->intreg_argnum; } */
159 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
160 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
163 /* function prototypes ********************************************************/
165 bool stack_init(void);
167 bool stack_analyse(jitdata *jd);
169 void stack_javalocals_store(instruction *iptr, s4 *javalocals);
171 #endif /* _STACK_H */
175 * These are local overrides for various environment variables in Emacs.
176 * Please do not remove this and leave it at the end of the file, where
177 * Emacs will automagically detect them.
178 * ---------------------------------------------------------------------
181 * indent-tabs-mode: t
185 * vim:noexpandtab:sw=4:ts=4: