Contact: cacao@cacaojvm.org
Author: Christian Thalinger
+ Edwin Steiner
- Changes: Edwin Steiner
-
- $Id: parse.h 4993 2006-05-30 23:38:32Z edwin $
+ $Id: parse.h 7663 2007-04-04 22:14:42Z twisti $
*/
goto throw_invalid_bytecode_index; \
} while (0)
-#else /* !define(ENABLE_VERIFIER) */
+#else /* !defined(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) */
+#endif /* defined(ENABLE_VERIFIER) */
/* basic block generating macro ***********************************************/
-#define block_insert(i) \
- do { \
- if (!(m->basicblockindex[(i)] & 1)) { \
- b_count++; \
- m->basicblockindex[(i)] |= 1; \
- } \
+#define MARK_BASICBLOCK(pd, i) \
+ do { \
+ (pd)->basicblockstart[(i)] = 1; \
} while (0)
+#define INSTRUCTIONS_CHECK(i) \
+ if ((ircount + (i)) > pd.instructionslength) \
+ iptr = parse_realloc_instructions(&pd, ircount, (i))
-/* intermediate code generating macros ****************************************/
-
-#define PINC \
- iptr++; ipc++
-
-#define NEW_OP_LOADCONST_I(v) \
- iptr->opc = ICMD_ICONST; \
- iptr->sx.val.i = (v); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_L(v) \
- iptr->opc = ICMD_LCONST; \
- iptr->sx.val.l = (v); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_F(v) \
- iptr->opc = ICMD_FCONST; \
- iptr->sx.val.f = (v); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_D(v) \
- iptr->opc = ICMD_DCONST; \
- iptr->sx.val.d = (v); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_NULL() \
- iptr->opc = ICMD_ACONST; \
- iptr->sx.val.anyptr = NULL; \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_STRING(v) \
- iptr->opc = ICMD_ACONST; \
- iptr->sx.val.stringconst = (v); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, extraflags) \
- 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); \
- } \
- iptr->opc = ICMD_ACONST; \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
- 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); \
- } \
- iptr->opc = (o); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_PREPARE(o) \
- iptr->opc = (o); \
- iptr->line = currentline;
-
-#define NEW_OP(o) \
- iptr->opc = (o); \
- iptr->line = currentline; \
- PINC
-#define NEW_OP_INSINDEX(o, iindex) \
- iptr->opc = (o); \
- iptr->dst.insindex = (iindex); \
- iptr->line = currentline; \
- PINC
+/* intermediate code generating macros ****************************************/
-#define NEW_OP_LOCALINDEX(o,index) \
- iptr->opc = (o); \
- iptr->s1.localindex = (index); \
- iptr->line = currentline; \
- PINC
+/* These macros ALWAYS set the following fields of *iptr to valid values: */
+/* iptr->opc */
+/* iptr->flags */
+/* iptr->line */
-#define NEW_OP_LOCALINDEX_I(o,index,v) \
- iptr->opc = (o); \
- iptr->s1.localindex = (index); \
- iptr->sx.val.i = (v); \
- iptr->line = currentline; \
- PINC
+/* These macros do NOT touch the following fields of *iptr, unless a value is */
+/* given for them: */
+/* iptr->s1 */
+/* iptr->sx */
+/* iptr->dst */
-#define NEW_OP_LOAD_ONEWORD(o,index) \
- do { \
- INDEX_ONEWORD(index); \
- NEW_OP_LOCALINDEX(o,index); \
- } while (0)
+/* The _PREPARE macros omit the PINC, so you can set additional fields */
+/* afterwards. */
-#define NEW_OP_LOAD_TWOWORD(o,index) \
- do { \
- INDEX_TWOWORD(index); \
- NEW_OP_LOCALINDEX(o,index); \
- } while (0)
+#define PINC \
+ iptr++; ircount++
-#define NEW_OP_STORE_ONEWORD(o,index) \
- do { \
- INDEX_ONEWORD(index); \
- NEW_OP_LOCALINDEX(o,index); \
- } while (0)
+#define OP_PREPARE_FLAGS(o, f) \
+ iptr->opc = (o); \
+ iptr->line = currentline; \
+ iptr->flags.bits |= (f) | (ircount << INS_FLAG_ID_SHIFT);
-#define NEW_OP_STORE_TWOWORD(o,index) \
- do { \
- INDEX_TWOWORD(index); \
- NEW_OP_LOCALINDEX(o,index); \
- } while (0)
+#define OP_PREPARE_ZEROFLAGS(o) \
+ OP_PREPARE_FLAGS(o, 0)
-#define NEW_OP_BUILTIN_CHECK_EXCEPTION(bte) \
- m->isleafmethod = false; \
- iptr->opc = ICMD_BUILTIN; \
- iptr->sx.s23.s3.bte = (bte); \
- iptr->line = currentline; \
- PINC
-
-#define NEW_OP_BUILTIN_NO_EXCEPTION(bte) \
- m->isleafmethod = false; \
- iptr->opc = ICMD_BUILTIN; \
- iptr->sx.s23.s3.bte = (bte); \
- iptr->flags.bits = INS_FLAG_NOCHECK; \
- iptr->line = currentline; \
- PINC
+#define OP_PREPARE(o) \
+ OP_PREPARE_ZEROFLAGS(o)
-#define NEW_OP_BUILTIN_ARITHMETIC(opcode, bte) \
- m->isleafmethod = false; \
- iptr->opc = (opcode); \
- iptr->sx.s23.s3.bte = (bte); \
- iptr->line = currentline; \
+#define OP(o) \
+ OP_PREPARE_ZEROFLAGS(o); \
PINC
-#define NEW_OP_FMIREF_PREPARE(o, fmiref) \
- iptr->opc = (o); \
- iptr->sx.s23.s3.fmiref = (fmiref); \
- iptr->line = currentline;
-
-/* old macros for intermediate code generation ********************************/
-
-#define LOADCONST_I(v) \
- iptr->opc = ICMD_ICONST; \
- iptr->val.i = (v); \
- iptr->line = currentline; \
+#define OP_CHECK_EXCEPTION(o) \
+ OP_PREPARE_FLAGS(o, INS_FLAG_CHECK); \
PINC
-#define LOADCONST_L(v) \
- iptr->opc = ICMD_LCONST; \
- iptr->val.l = (v); \
- iptr->line = currentline; \
+#define OP_LOADCONST_I(v) \
+ OP_PREPARE_ZEROFLAGS(ICMD_ICONST); \
+ iptr->sx.val.i = (v); \
PINC
-#define LOADCONST_F(v) \
- iptr->opc = ICMD_FCONST; \
- iptr->val.f = (v); \
- iptr->line = currentline; \
+#define OP_LOADCONST_L(v) \
+ OP_PREPARE_ZEROFLAGS(ICMD_LCONST); \
+ iptr->sx.val.l = (v); \
PINC
-#define LOADCONST_D(v) \
- iptr->opc = ICMD_DCONST; \
- iptr->val.d = (v); \
- iptr->line = currentline; \
+#define OP_LOADCONST_F(v) \
+ OP_PREPARE_ZEROFLAGS(ICMD_FCONST); \
+ iptr->sx.val.f = (v); \
PINC
-#define LOADCONST_A(v) \
- iptr->opc = ICMD_ACONST; \
- iptr->val.a = (v); \
- iptr->line = currentline; \
+#define OP_LOADCONST_D(v) \
+ OP_PREPARE_ZEROFLAGS(ICMD_DCONST); \
+ iptr->sx.val.d = (v); \
PINC
-/* ACONST instructions generated as arguments for builtin functions
- * have op1 set to non-zero. This is used for stack overflow checking
- * in stack.c. */
-/* XXX in the new instruction format use a flag for this */
-/* XXX target used temporarily as flag */
-#define LOADCONST_A_BUILTIN(c,cr) \
- iptr->opc = ICMD_ACONST; \
- iptr->op1 = 1; \
- iptr->line = currentline; \
- if (c) { \
- iptr->val.a = c; iptr->target = (void*) 0x02; \
- } \
- else { \
- iptr->val.a = cr; iptr->target = (void*) 0x03; \
- } \
+#define OP_LOADCONST_NULL() \
+ OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
+ iptr->sx.val.anyptr = NULL; \
PINC
-#define OP(o) \
- iptr->opc = (o); \
- iptr->line = currentline; \
+#define OP_LOADCONST_STRING(v) \
+ OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
+ iptr->sx.val.stringconst = (v); \
PINC
-#define OP1(o,o1) \
- iptr->opc = (o); \
- iptr->op1 = (o1); \
- iptr->line = currentline; \
+#define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
+ OP_PREPARE(ICMD_ACONST); \
+ if (cl) { \
+ iptr->sx.val.c.cls = (cl); \
+ 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 OP2I(o,o1,v) \
- iptr->opc = (o); \
- iptr->op1 = (o1); \
- iptr->val.i = (v); \
- iptr->line = currentline; \
+#define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr) \
+ OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
+
+#define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr) \
+ OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
+
+#define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
+ 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 OP2A_NOINC(o,o1,v,l) \
- iptr->opc = (o); \
- iptr->op1 = (o1); \
- iptr->val.a = (v); \
- iptr->line = (l);
-
-#define OP2A(o,o1,v,l) \
- OP2A_NOINC(o,o1,v,l); \
+#define OP_INSINDEX(o, iindex) \
+ OP_PREPARE_ZEROFLAGS(o); \
+ iptr->dst.insindex = (iindex); \
PINC
-#define OP2AT(o,o1,v,t,l) \
- OP2A_NOINC(o,o1,v,l); \
- iptr->target = (t); \
+# define OP_LOCALINDEX(o,index) \
+ OP_PREPARE_ZEROFLAGS(o); \
+ iptr->s1.varindex = (index); \
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); \
+# define OP_LOCALINDEX_I(o,index,v) \
+ OP_PREPARE_ZEROFLAGS(o); \
+ iptr->s1.varindex = (index); \
+ iptr->sx.val.i = (v); \
PINC
-#define OP1LOAD_ONEWORD(o,o1) \
- do { \
- INDEX_ONEWORD(o1); \
- OP1(o,o1); \
+# define LOCALTYPE_USED(index,type) \
+ do { \
+ local_map[(index) * 5 + (type)] = 1; \
} while (0)
-#define OP1LOAD_TWOWORD(o,o1) \
- do { \
- INDEX_TWOWORD(o1); \
- OP1(o,o1); \
+#define OP_LOAD_ONEWORD(o,index,type) \
+ do { \
+ INDEX_ONEWORD(index); \
+ OP_LOCALINDEX(o,index); \
+ LOCALTYPE_USED(index,type); \
} while (0)
-#define OP1STORE_ONEWORD(o,o1) \
- do { \
- INDEX_ONEWORD(o1); \
- OP1(o,o1); \
+#define OP_LOAD_TWOWORD(o,index,type) \
+ do { \
+ INDEX_TWOWORD(index); \
+ OP_LOCALINDEX(o,index); \
+ LOCALTYPE_USED(index,type); \
} while (0)
-#define OP1STORE_TWOWORD(o,o1) \
- do { \
- INDEX_TWOWORD(o1); \
- OP1(o,o1); \
+# define OP_STORE_ONEWORD(o,index,type) \
+ do { \
+ INDEX_ONEWORD(index); \
+ OP_PREPARE_ZEROFLAGS(o); \
+ iptr->dst.varindex = (index); \
+ LOCALTYPE_USED(index,type); \
+ PINC; \
} while (0)
+# define OP_STORE_TWOWORD(o,index,type) \
+ do { \
+ INDEX_TWOWORD(index); \
+ OP_PREPARE_ZEROFLAGS(o); \
+ iptr->dst.varindex = (index); \
+ LOCALTYPE_USED(index,type); \
+ PINC; \
+ } while (0)
-/* macros for byte code fetching ***********************************************
+#define OP_BUILTIN_CHECK_EXCEPTION(bte) \
+ jd->isleafmethod = false; \
+ OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK); \
+ iptr->sx.s23.s3.bte = (bte); \
+ PINC
- fetch a byte code of given size from position p in code array jcode
+#define OP_BUILTIN_NO_EXCEPTION(bte) \
+ jd->isleafmethod = false; \
+ OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN); \
+ iptr->sx.s23.s3.bte = (bte); \
+ PINC
-*******************************************************************************/
+#define OP_BUILTIN_ARITHMETIC(opcode, bte) \
+ jd->isleafmethod = false; \
+ OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK); \
+ iptr->sx.s23.s3.bte = (bte); \
+ PINC
-#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]))
-/* XXX read 32bit aligned big-endian values directly */
+/* CAUTION: You must set iptr->flags yourself when using this! */
+#define OP_FMIREF_PREPARE(o, fmiref) \
+ OP_PREPARE(o); \
+ iptr->sx.s23.s3.fmiref = (fmiref);
/* function prototypes ********************************************************/