* src/vm/jit/parse.h (code_get_u1, code_get_s1, code_get_u2)
[cacao.git] / src / vm / jit / parse.h
index 49bccbb71e49c2f3e59bf24408c6915d459bffa5..4c22d260f28ff0431af3ba6db92cfefc5268d99b 100644 (file)
 
    Contact: cacao@cacaojvm.org
 
-   Author: Christian Thalinger
+   Author:  Christian Thalinger
 
-   Changes:
+   Changes: Edwin Steiner
 
-   $Id: parse.h 4863 2006-04-30 16:17:44Z edwin $
+   $Id: parse.h 5181 2006-07-26 13:27:54Z twisti $
 
 */
 
 #include "vm/jit/codegen-common.h"
 
 
+/* macros for verifier checks during parsing **********************************/
+
+#if defined(ENABLE_VERIFIER)
+
+/* We have to check local variables indices here because they are             */
+/* used in stack.c to index the locals array.                                 */
+
+#define INDEX_ONEWORD(num) \
+    do { \
+        if (((num) < 0) || ((num) >= m->maxlocals)) \
+            goto throw_illegal_local_variable_number; \
+    } while (0)
+
+#define INDEX_TWOWORD(num) \
+    do { \
+        if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
+            goto throw_illegal_local_variable_number; \
+    } while (0)
+
+/* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index.        */
+/* The end of the bytecode (i == m->jcodelength) is considered valid.         */
+
+#define CHECK_BYTECODE_INDEX(i) \
+    do { \
+        if (((i) < 0) || ((i) >= m->jcodelength)) \
+                       goto throw_invalid_bytecode_index; \
+    } while (0)
+
+/* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends               */
+/* of exception handler ranges.                                                */
+#define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
+    do { \
+        if ((i) < 0 || (i) > m->jcodelength) \
+                       goto throw_invalid_bytecode_index; \
+    } while (0)
+
+#else /* !define(ENABLE_VERIFIER) */
+
+#define INDEX_ONEWORD(num)
+#define INDEX_TWOWORD(num)
+#define CHECK_BYTECODE_INDEX(i)
+#define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
+
+#endif /* define(ENABLE_VERIFIER) */
+
+
+/* basic block generating macro ***********************************************/
+
+#define new_block_insert(i) \
+    do { \
+        if (!(jd->new_basicblockindex[(i)] & 1)) { \
+            b_count++; \
+            jd->new_basicblockindex[(i)] |= 1; \
+        } \
+    } while (0)
+
+#define block_insert(i) \
+    do { \
+        if (!(m->basicblockindex[(i)] & 1)) { \
+            b_count++; \
+            m->basicblockindex[(i)] |= 1; \
+        } \
+    } while (0)
+
+
 /* intermediate code generating macros ****************************************/
 
-#define PINC           iptr++;ipc++
+/* These macros ALWAYS set the following fields of *iptr to valid values:     */
+/*     iptr->opc                                                              */
+/*     iptr->flags                                                            */
+/*     iptr->line                                                             */
+
+/* These macros do NOT touch the following fields of *iptr, unless a value is */
+/* given for them:                                                            */
+/*     iptr->s1                                                               */
+/*     iptr->sx                                                               */
+/*     iptr->dst                                                              */
+
+/* The _PREPARE macros omit the PINC, so you can set additional fields        */
+/* afterwards.                                                                */
+/* CAUTION: Some of the _PREPARE macros don't set iptr->flags!                */
+
+#define PINC                                                           \
+    iptr++; ipc++
+
+/* CAUTION: You must set iptr->flags yourself when using this!                */
+#define NEW_OP_PREPARE(o)                                              \
+    iptr->opc                = (o);                                    \
+    iptr->line               = currentline;
+
+#define NEW_OP_PREPARE_ZEROFLAGS(o)                                    \
+    iptr->opc                = (o);                                    \
+    iptr->line               = currentline;                            \
+    iptr->flags.bits         = 0;
+
+#define NEW_OP(o)                                                      \
+       NEW_OP_PREPARE_ZEROFLAGS(o);                                       \
+    PINC
+
+#define NEW_OP_LOADCONST_I(v)                                          \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_ICONST);                             \
+    iptr->sx.val.i           = (v);                                    \
+    PINC
+
+#define NEW_OP_LOADCONST_L(v)                                          \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_LCONST);                             \
+    iptr->sx.val.l           = (v);                                    \
+    PINC
+
+#define NEW_OP_LOADCONST_F(v)                                          \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_FCONST);                             \
+    iptr->sx.val.f           = (v);                                    \
+    PINC
+
+#define NEW_OP_LOADCONST_D(v)                                          \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_DCONST);                             \
+    iptr->sx.val.d           = (v);                                    \
+    PINC
+
+#define NEW_OP_LOADCONST_NULL()                                        \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_ACONST);                             \
+    iptr->sx.val.anyptr      = NULL;                                   \
+    PINC
+
+#define NEW_OP_LOADCONST_STRING(v)                                     \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_ACONST);                             \
+    iptr->sx.val.stringconst = (v);                                    \
+    PINC
+
+#define NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, extraflags)      \
+       NEW_OP_PREPARE(ICMD_ACONST);                                       \
+    if (c) {                                                           \
+        iptr->sx.val.c.cls   = (c);                                    \
+        iptr->flags.bits     = INS_FLAG_CLASS | (extraflags);          \
+    }                                                                  \
+    else {                                                             \
+        iptr->sx.val.c.ref   = (cr);                                   \
+        iptr->flags.bits     = INS_FLAG_CLASS | INS_FLAG_UNRESOLVED    \
+                             | (extraflags);                           \
+    }                                                                  \
+    PINC
+
+#define NEW_OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags)          \
+       NEW_OP_PREPARE(o);                                                 \
+    if (c) {                                                           \
+        iptr->sx.s23.s3.c.cls= (c);                                    \
+        iptr->flags.bits     = (extraflags);                           \
+    }                                                                  \
+    else {                                                             \
+        iptr->sx.s23.s3.c.ref= (cr);                                   \
+        iptr->flags.bits     = INS_FLAG_UNRESOLVED | (extraflags);     \
+    }                                                                  \
+    PINC
+
+#define NEW_OP_INSINDEX(o, iindex)                                     \
+       NEW_OP_PREPARE_ZEROFLAGS(o);                                       \
+    iptr->dst.insindex       = (iindex);                               \
+    PINC
+
+#define NEW_OP_LOCALINDEX(o,index)                                     \
+       NEW_OP_PREPARE_ZEROFLAGS(o);                                       \
+    iptr->s1.localindex      = (index);                                \
+    PINC
+
+#define NEW_OP_LOCALINDEX_I(o,index,v)                                 \
+       NEW_OP_PREPARE_ZEROFLAGS(o);                                       \
+    iptr->s1.localindex      = (index);                                \
+    iptr->sx.val.i           = (v);                                    \
+    PINC
+
+#define NEW_OP_LOAD_ONEWORD(o,index)                                   \
+    do {                                                               \
+        INDEX_ONEWORD(index);                                          \
+        NEW_OP_LOCALINDEX(o,index);                                    \
+    } while (0)
+
+#define NEW_OP_LOAD_TWOWORD(o,index)                                   \
+    do {                                                               \
+        INDEX_TWOWORD(index);                                          \
+        NEW_OP_LOCALINDEX(o,index);                                    \
+    } while (0)
+
+#define NEW_OP_STORE_ONEWORD(o,index)                                  \
+    do {                                                               \
+        INDEX_ONEWORD(index);                                          \
+        NEW_OP_PREPARE_ZEROFLAGS(o);                                   \
+        iptr->dst.localindex = (index);                                \
+        PINC;                                                          \
+    } while (0)
+
+#define NEW_OP_STORE_TWOWORD(o,index)                                  \
+    do {                                                               \
+        INDEX_TWOWORD(index);                                          \
+        NEW_OP_PREPARE_ZEROFLAGS(o);                                   \
+        iptr->dst.localindex = (index);                                \
+        PINC;                                                          \
+    } while (0)
+
+#define NEW_OP_BUILTIN_CHECK_EXCEPTION(bte)                            \
+    jd->isleafmethod         = false;                                  \
+       NEW_OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN);                            \
+    iptr->sx.s23.s3.bte      = (bte);                                  \
+    PINC
+
+#define NEW_OP_BUILTIN_NO_EXCEPTION(bte)                               \
+    jd->isleafmethod         = false;                                  \
+       NEW_OP_PREPARE(ICMD_BUILTIN);                                      \
+    iptr->sx.s23.s3.bte      = (bte);                                  \
+    iptr->flags.bits         = INS_FLAG_NOCHECK;                       \
+    PINC
+
+#define NEW_OP_BUILTIN_ARITHMETIC(opcode, bte)                         \
+    jd->isleafmethod         = false;                                  \
+       NEW_OP_PREPARE_ZEROFLAGS(opcode);                                  \
+    iptr->sx.s23.s3.bte      = (bte);                                  \
+    PINC
+
+/* CAUTION: You must set iptr->flags yourself when using this!                */
+#define NEW_OP_FMIREF_PREPARE(o, fmiref)                               \
+       NEW_OP_PREPARE(o);                                                 \
+    iptr->sx.s23.s3.fmiref   = (fmiref);
+
+/* old macros for intermediate code generation ********************************/
 
 #define LOADCONST_I(v) \
     iptr->opc    = ICMD_ICONST; \
     PINC
 
 #define BUILTIN(v,o1,t,l) \
-    m->isleafmethod = false; \
-    iptr->opc    = ICMD_BUILTIN; \
-    iptr->op1    = (o1); \
-    iptr->val.a  = (v); \
-    iptr->target = (t); \
-    iptr->line   = (l); \
+    jd->isleafmethod = false; \
+    iptr->opc        = ICMD_BUILTIN; \
+    iptr->op1        = (o1); \
+    iptr->val.a      = (v); \
+    iptr->target     = (t); \
+    iptr->line       = (l); \
     PINC
 
-
-/* We have to check local variables indices here because they are
- * used in stack.c to index the locals array. */
-
-#if defined(ENABLE_VERIFIER)
-
-#define INDEX_ONEWORD(num) \
-    do { \
-        if (((num) < 0) || ((num) >= m->maxlocals)) \
-            goto throw_illegal_local_variable_number; \
-    } while (0)
-
-#define INDEX_TWOWORD(num) \
-    do { \
-        if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
-            goto throw_illegal_local_variable_number; \
-    } while (0)
-
-#else /* !define(ENABLE_VERIFIER) */
-
-#define INDEX_ONEWORD(num)
-#define INDEX_TWOWORD(num)
-
-#endif /* define(ENABLE_VERIFIER) */
-
 #define OP1LOAD_ONEWORD(o,o1) \
     do { \
                INDEX_ONEWORD(o1); \
         OP1(o,o1); \
     } while (0)
 
-/* block generating and checking macros */
-
-#define block_insert(i) \
-    do { \
-        if (!(m->basicblockindex[(i)] & 1)) { \
-            b_count++; \
-            m->basicblockindex[(i)] |= 1; \
-        } \
-    } while (0)
-
-
-#if defined(ENABLE_VERIFIER)
-
-#define CHECK_BYTECODE_INDEX(i) \
-    do { \
-        if (((i) < 0) || ((i) >= m->jcodelength)) \
-                       goto throw_invalid_bytecode_index; \
-    } while (0)
-
-/* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */ 
-/* of exception handler ranges                                   */
-#define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
-    do { \
-        if ((i) < 0 || (i) > m->jcodelength) \
-                       goto throw_invalid_bytecode_index; \
-    } while (0)
-
-#else /* !ENABLE_VERIFIER */
-
-#define CHECK_BYTECODE_INDEX(i)
-#define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
-
-#endif
-
-/* macros for byte code fetching ***********************************************
-
-       fetch a byte code of given size from position p in code array jcode
-
-*******************************************************************************/
-
-#define code_get_u1(p,m)  m->jcode[p]
-#define code_get_s1(p,m)  ((s1)m->jcode[p])
-#define code_get_u2(p,m)  ((((u2)m->jcode[p]) << 8) + m->jcode[p + 1])
-#define code_get_s2(p,m)  ((s2)((((u2)m->jcode[p]) << 8) + m->jcode[p + 1]))
-#define code_get_u4(p,m)  ((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
-                        +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3])
-#define code_get_s4(p,m)  ((s4)((((u4)m->jcode[p]) << 24) + (((u4)m->jcode[p + 1]) << 16) \
-                             +(((u4)m->jcode[p + 2]) << 8) + m->jcode[p + 3]))
-
 
 /* function prototypes ********************************************************/
 
@@ -256,4 +402,3 @@ bool parse(jitdata *jd);
  * vim:noexpandtab:sw=4:ts=4:
  */
 
-