-/* jit/stack.h - stack analysis header
+/* src/vm/jit/stack.h - stack analysis header
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005, 2006, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Christian Thalinger
-
- $Id: stack.h 1203 2004-06-22 23:14:55Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
#ifndef _STACK_H
#define _STACK_H
+/* forward typedefs ***********************************************************/
+
+typedef struct stackelement_t stackelement_t;
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "vm/types.h"
+
+#include "vm/global.h"
+
+#include "vm/jit/jit.hpp"
+#include "vm/jit/reg.h"
+
+
+/* stack element structure ****************************************************/
+
+/* flags */
+
+#define SAVEDVAR 1 /* variable has to survive method invocations */
+#define INMEMORY 2 /* variable stored in memory */
+#define SAVREG 4 /* allocated to a saved register */
+#define ARGREG 8 /* allocated to an arg register */
+#define PASSTHROUGH 32 /* stackslot was passed-through by an ICMD */
+#define PREALLOC 64 /* preallocated var like for ARGVARS. Used */
+ /* with the new var system */
+#define INOUT 128 /* variable is an invar or/and an outvar */
+
+#define IS_SAVEDVAR(x) ((x) & SAVEDVAR)
+#define IS_INMEMORY(x) ((x) & INMEMORY)
+
+
+/* variable kinds */
+
+#define UNDEFVAR 0 /* stack slot will become temp during regalloc*/
+#define TEMPVAR 1 /* stack slot is temp register */
+#define STACKVAR 2 /* stack slot is numbered stack slot */
+#define LOCALVAR 3 /* stack slot is local variable */
+#define ARGVAR 4 /* stack slot is argument variable */
+
+
+struct stackelement_t {
+ stackelement_t *prev; /* pointer to next element towards bottom */
+ instruction *creator; /* instruction that created this element */
+ s4 type; /* slot type of stack element */
+ s4 flags; /* flags (SAVED, INMEMORY) */
+ s4 varkind; /* kind of variable or register */
+ s4 varnum; /* number of variable */
+};
+
+
+/* macros used internally by analyse_stack ************************************/
+
+/*--------------------------------------------------*/
+/* BASIC TYPE CHECKING */
+/*--------------------------------------------------*/
+
+/* XXX would be nice if we did not have to pass the expected type */
+
+#if defined(ENABLE_VERIFIER)
+#define CHECK_BASIC_TYPE(expected,actual) \
+ do { \
+ if ((actual) != (expected)) { \
+ expectedtype = (expected); \
+ goto throw_stack_type_error; \
+ } \
+ } while (0)
+#else /* !ENABLE_VERIFIER */
+#define CHECK_BASIC_TYPE(expected,actual)
+#endif /* ENABLE_VERIFIER */
+
+/*--------------------------------------------------*/
+/* STACK UNDERFLOW/OVERFLOW CHECKS */
+/*--------------------------------------------------*/
+
+/* underflow checks */
+
+#if defined(ENABLE_VERIFIER)
+#define REQUIRE(num) \
+ do { \
+ if (stackdepth < (num)) \
+ goto throw_stack_underflow; \
+ } while (0)
+#else /* !ENABLE_VERIFIER */
+#define REQUIRE(num)
+#endif /* ENABLE_VERIFIER */
+
+
+/* overflow check */
+/* We allow ACONST instructions inserted as arguments to builtin
+ * functions to exceed the maximum stack depth. Maybe we should check
+ * against maximum stack depth only at block boundaries?
+ */
+
+/* XXX we should find a way to remove the opc/op1 check */
+#if defined(ENABLE_VERIFIER)
+#define CHECKOVERFLOW \
+ do { \
+ if (stackdepth > m->maxstack) \
+ if ((iptr->opc != ICMD_ACONST) || INSTRUCTION_MUST_CHECK(iptr))\
+ goto throw_stack_overflow; \
+ } while(0)
+#else /* !ENABLE_VERIFIER */
+#define CHECKOVERFLOW
+#endif /* ENABLE_VERIFIER */
+
+/*--------------------------------------------------*/
+/* ALLOCATING STACK SLOTS */
+/*--------------------------------------------------*/
+
+#define NEWSTACK(s,v,n) \
+ do { \
+ sd.new->prev = curstack; \
+ sd.new->type = (s); \
+ sd.new->flags = 0; \
+ sd.new->varkind = (v); \
+ sd.new->varnum = (n); \
+ curstack = sd.new; \
+ sd.var[(n)].type = (s); \
+ sd.var[(n)].flags = 0; \
+ sd.new++; \
+ } while (0)
+
+/* Initialize regoff, so -sia can show regnames even before reg.inc */
+/* regs[rd->intregargnum] has to be set for this */
+/* new->regoff = (IS_FLT_DBL_TYPE(s))?-1:rd->intreg_argnum; } */
+
+#define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
+#define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
+
+
+/* function prototypes ********************************************************/
-#include "global.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+bool stack_init(void);
-/* function prototypes */
+bool stack_analyse(jitdata *jd);
-methodinfo *analyse_stack(methodinfo *m);
+void stack_javalocals_store(instruction *iptr, s4 *javalocals);
-void icmd_print_stack(methodinfo *m, stackptr s);
-char *icmd_builtin_name(functionptr bptr);
-void show_icmd_method(methodinfo *m);
-void show_icmd_block(methodinfo *m, basicblock *bptr);
-void show_icmd(instruction *iptr, bool deadcode);
+#ifdef __cplusplus
+}
+#endif
#endif /* _STACK_H */
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/