Merge from subtype.
[cacao.git] / src / vm / jit / stack.h
index dde07d52a7b70e108f1752b292cfcce5123ade7e..803d2db11d83ed7ae3d5c3e5c561e6554613e1bd 100644 (file)
@@ -1,9 +1,7 @@
-/* vm/jit/stack.h - stack analysis header
+/* src/vm/jit/stack.h - stack analysis header
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   Changes: Christian Ullrich
-                       Edwin Steiner
-
-   $Id: stack.h 5443 2006-09-09 14:49:25Z edwin $
-
 */
 
 
 #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/exceptions.h"
 #include "vm/global.h"
-#include "vm/jit/jit.h"
+
+#include "vm/jit/jit.hpp"
 #include "vm/jit/reg.h"
 
 
-/* macros used internally by analyse_stack ************************************/
+/* stack element structure ****************************************************/
 
-/*--------------------------------------------------*/
-/* STACK DEPTH CHECKING                             */
-/*--------------------------------------------------*/
+/* 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)
 
-#if defined(ENABLE_VERIFIER)
-#define CHECK_STACK_DEPTH(depthA,depthB)                             \
-    do {                                                             \
-        if ((depthA) != (depthB))                                    \
-            goto throw_stack_depth_error;                            \
-    } while (0)
-#else /* !ENABLE_VERIFIER */
-#define CHECK_STACK_DEPTH(depthA,depthB)
-#endif /* ENABLE_VERIFIER */
 
+/* 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                              */
 #define NEWSTACK0(s)    NEWSTACK(s,UNDEFVAR,0)
 
 
-/*--------------------------------------------------*/
-/* MACROS FOR HANDLING BASIC BLOCKS                 */
-/*--------------------------------------------------*/
-
-/* COPYCURSTACK makes a copy of the current operand stack (curstack)
- * and returns it in the variable copy.
- *
- * This macro is used to propagate the operand stack from one basic
- * block to another. The destination block receives the copy as its
- * input stack.
- */
-#define COPYCURSTACK(sd, copy) {                                     \
-    stackptr s;                                                      \
-    if (curstack) {                                                  \
-        s = curstack;                                                \
-        (sd).new += stackdepth;                                      \
-        copy = (sd).new;                                             \
-        while (s) {                                                  \
-                       GET_NEW_VAR(sd, new_index, s->type);                     \
-            copy--;                                                  \
-            copy->prev = copy-1;                                     \
-            copy->creator = NULL;                                    \
-            copy->type = s->type;                                    \
-            copy->flags = 0;                                         \
-            copy->varkind = STACKVAR;                                \
-            copy->varnum = new_index;                                \
-                       (sd).var[new_index].flags = OUTVAR;                      \
-            s = s->prev;                                             \
-        }                                                            \
-        copy->prev = NULL;                                           \
-        copy = (sd).new-1;                                           \
-    }                                                                \
-    else                                                             \
-        copy = NULL;                                                 \
-}
-
-
-/* external macros ************************************************************/
+/* function prototypes ********************************************************/
 
-#define BLOCK_OF(index)                                              \
-    (jd->new_basicblocks + jd->new_basicblockindex[index])
+#ifdef __cplusplus
+extern "C" {
+#endif
 
+bool stack_init(void);
 
-/* function prototypes ********************************************************/
+bool stack_analyse(jitdata *jd);
 
-bool stack_init(void);
+void stack_javalocals_store(instruction *iptr, s4 *javalocals);
 
-bool new_stack_analyse(jitdata *jd);
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _STACK_H */