narray first check in
[cacao.git] / src / vm / jit / parse.c
index 269db0625f92bdc06814606e60038bfee9db8f38..958068eb3b8b424da749681b4ce8741b08fec16a 100644 (file)
@@ -8,27 +8,26 @@
        
        Author: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
 
-       Last Change: 1998/05/07
+       Last Change: $Id: parse.c 132 1999-09-27 15:54:42Z chris $
 
 *******************************************************************************/
 
 #include "math.h"
 
-
 /* macros for byte code fetching ***********************************************
 
-       fetch a byte code of given size from position pos
+       fetch a byte code of given size from position p in code array jcode
 
 *******************************************************************************/
 
-#define code_get_u1(pos)    jcode[pos]
-#define code_get_s1(pos)    ((s1)jcode[pos])
-#define code_get_u2(pos)    ((((u2)jcode[pos])<<8)+jcode[pos+1])
-#define code_get_s2(pos)    ((s2)((((u2)jcode[pos])<<8)+jcode[pos+1]))
-#define code_get_u4(pos)    ((((u4)jcode[pos])<<24)+(((u4)jcode[pos+1])<<16)+\
-                             (((u4)jcode[pos+2])<<8)+jcode[pos+3])
-#define code_get_s4(pos)    ((s4)((((u4)jcode[pos])<<24)+(((u4)jcode[pos+1])<<16)+\
-                             (((u4)jcode[pos+2])<<8)+jcode[pos+3]))
+#define code_get_u1(p)  jcode[p]
+#define code_get_s1(p)  ((s1)jcode[p])
+#define code_get_u2(p)  ((((u2)jcode[p])<<8)+jcode[p+1])
+#define code_get_s2(p)  ((s2)((((u2)jcode[p])<<8)+jcode[p+1]))
+#define code_get_u4(p)  ((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
+                           +(((u4)jcode[p+2])<<8)+jcode[p+3])
+#define code_get_s4(p)  ((s4)((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
+                           +(((u4)jcode[p+2])<<8)+jcode[p+3]))
 
 
 /* functionc compiler_addinitclass *********************************************
@@ -156,10 +155,13 @@ static void descriptor2types (methodinfo *m)
 }
 
 
+#ifdef OLD_COMPILER
+
 /* function allocate_literals **************************************************
 
-       Scans the JavaVM code of a method and allocates string literals. Needed
-       to generate the same addresses as the old JIT compiler.
+       Scans the JavaVM code of a method and allocates string literals (in the
+       same order as the old JIT). Needed to generate the same addresses as the
+       old JIT compiler.
        
 *******************************************************************************/
 
@@ -211,7 +213,7 @@ static void allocate_literals()
                        } /* end switch */
                } /* end while */
 }
-
+#endif
 
 
 /*******************************************************************************
@@ -265,11 +267,18 @@ static void parse()
        int  ipc = 0;               /* intermediate instruction counter           */
        int  b_count = 0;           /* basic block counter                        */
        int  s_count = 0;           /* stack element counter                      */
-       bool blockend = false;      /* true if basic block end has reached        */
+       bool blockend = false;      /* true if basic block end has been reached   */
        bool iswide = false;        /* true if last instruction was a wide        */
        instruction *iptr;          /* current pointer into instruction array     */
 
 
+#ifdef OLD_COMPILER
+       /* generate the same addresses as the old JIT compiler */
+
+       if (runverbose)
+               allocate_literals();
+#endif
+
        /* allocate instruction array and block index table */
        
        /* 1 additional for end ipc and 3 for loop unrolling */
@@ -279,7 +288,7 @@ static void parse()
        /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
        /* additional MONITOREXITS are reached by branches which are 3 bytes */
        
-       iptr = instr = DMNEW(instruction, jcodelength + 5);
+       iptr = instr = DMNEW(instruction, jcodelength + 5); 
        
        /* initialize block_index table (unrolled four times) */
 
@@ -296,25 +305,36 @@ static void parse()
 
        /* compute branch targets of exception table */
 
+       extable = DMNEW(xtable, exceptiontablelength + 1);
+
        for (i = 0; i < exceptiontablelength; i++) {
-               p = extable[i].startpc;
+
+               p = extable[i].startpc = raw_extable[i].startpc;
                bound_check(p);
                block_insert(p);
-               p = extable[i].endpc;
+
+               p = extable[i].endpc = raw_extable[i].endpc;
                bound_check1(p);
                if (p < jcodelength)
                        block_insert(p);
-               p = extable[i].handlerpc;
+
+               p = extable[i].handlerpc = raw_extable[i].handlerpc;
                bound_check(p);
                block_insert(p);
-               }
 
-       s_count = 1 + exceptiontablelength; /* initialize stack element counter   */
+               extable[i].catchtype  = raw_extable[i].catchtype;
 
-       if (runverbose) {
-/*             isleafmethod=false; */
+               extable[i].next = NULL;
+               extable[i].down = &extable[i+1];
                }
 
+       if (exceptiontablelength > 0)
+               extable[exceptiontablelength-1].down = NULL;
+       else
+               extable = NULL;
+
+       s_count = 1 + exceptiontablelength; /* initialize stack element counter   */
+
 #ifdef USE_THREADS
        if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
                isleafmethod=false;
@@ -1061,6 +1081,7 @@ static void parse()
        bptr = block = DMNEW(basicblock, b_count + 1);    /* one more for end ipc */
 
        b_count = 0;
+       c_debug_nr = 0;
        
        /* additional block if target 0 is not first intermediate instruction     */
 
@@ -1071,37 +1092,69 @@ static void parse()
                bptr->type = BBTYPE_STD;
                bptr->branchrefs = NULL;
                bptr->pre_count = 0;
+               bptr->debug_nr = c_debug_nr++;
                bptr++;
                b_count++;
+               (bptr - 1)->next = bptr;
+       
                }
 
        /* allocate blocks */
 
+
        for (p = 0; p < jcodelength; p++)
+               
                if (block_index[p] & 1) {
                        bptr->iinstr = instr + (block_index[p] >> 1);
+                       bptr->debug_nr = c_debug_nr++;
                        if (b_count != 0)
                                (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
                        bptr->mpc = -1;
                        bptr->flags = -1;
+                       bptr->lflags = 0;
                        bptr->type = BBTYPE_STD;
                        bptr->branchrefs = NULL;
                        block_index[p] = b_count;
                        bptr->pre_count = 0;
                        bptr++;
                        b_count++;
+
+                       (bptr - 1)->next = bptr;
                        }
 
        /* allocate additional block at end */
 
+       
+       bptr->instack = bptr->outstack = NULL;
+       bptr->indepth = bptr->outdepth = 0;
        bptr->iinstr = NULL;
        (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
        bptr->icount = 0;
        bptr->mpc = -1;
        bptr->flags = -1;
+       bptr->lflags = 0;
        bptr->type = BBTYPE_STD;
        bptr->branchrefs = NULL;
        bptr->pre_count = 0;
+       bptr->debug_nr = c_debug_nr++;
+                       
+       (bptr - 1)->next = bptr;
+       bptr->next = NULL;
+
+       last_block = bptr;
+
+
+
+       for (i = 0; i < exceptiontablelength; ++i) {
+               p = extable[i].startpc;
+               extable[i].start = block + block_index[p];
+
+               p = extable[i].endpc;
+               extable[i].end = block + block_index[p]; 
+
+               p = extable[i].handlerpc;
+               extable[i].handler = block + block_index[p];
+           }
        }
 }