- compile without warnings with -Wall
[cacao.git] / src / vm / jit / parse.c
1 /* jit/parse.c *****************************************************************
2
3         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5         See file COPYRIGHT for information on usage and disclaimer of warranties
6
7         Parser for JavaVM to intermediate code translation
8         
9         Author: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
10
11         Last Change: $Id: parse.c 485 2003-10-20 17:16:25Z twisti $
12                      include Rapid Type Analysis parse - 5/2003 - carolyn
13
14
15 *******************************************************************************/
16
17 #include "math.h"
18 #include "sets.h"
19                                 /* data about the currently parsed   method   */
20
21 static classinfo  *rt_class;    /* class the compiled method belongs to       */
22 static methodinfo *rt_method;   /* pointer to method info of compiled method  */
23 static utf      *rt_descriptor; /* type descriptor of compiled method         */
24 static int       rt_jcodelength; /*length of JavaVM-codes                     */
25 static u1       *rt_jcode;      /* pointer to start of JavaVM-code            */
26
27
28 /* macros for byte code fetching ***********************************************
29
30         fetch a byte code of given size from position p in code array jcode
31
32 *******************************************************************************/
33
34 #define code_get_u1(p)  jcode[p]
35 #define code_get_s1(p)  ((s1)jcode[p])
36 #define code_get_u2(p)  ((((u2)jcode[p])<<8)+jcode[p+1])
37 #define code_get_s2(p)  ((s2)((((u2)jcode[p])<<8)+jcode[p+1]))
38 #define code_get_u4(p)  ((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
39                            +(((u4)jcode[p+2])<<8)+jcode[p+3])
40 #define code_get_s4(p)  ((s4)((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
41                            +(((u4)jcode[p+2])<<8)+jcode[p+3]))
42
43
44
45 /*INLINING*/
46 #include "inline.c"
47 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
48 #define debug_writebranch
49
50 /* functionc compiler_addinitclass *********************************************
51
52         add class into the list of classes to initialize
53
54 *******************************************************************************/
55                                 
56 static void compiler_addinitclass (classinfo *c)
57 {
58         classinfo *cl;
59
60         if (c->initialized) return;
61         
62         cl = chain_first(uninitializedclasses);
63         if (cl == c)
64                 return;
65         
66         if (cl == class)
67                 cl = chain_next(uninitializedclasses);
68         for (;;) {
69                 if (cl == c)
70                         return;
71                 if (cl == NULL) {
72                         if (runverbose) {
73                                 sprintf(logtext, "compiler_addinitclass: ");
74                                 utf_sprint(logtext+strlen(logtext), c->name);
75                                 dolog();
76                                 }
77                         chain_addlast(uninitializedclasses, c);
78                         return;
79                         }
80                 if (c < cl) {
81                         if (runverbose) {
82                                 sprintf(logtext, "compiler_addinitclass: ");
83                                 utf_sprint(logtext+strlen(logtext), c->name);
84                                 dolog();
85                                 }
86                         chain_addbefore(uninitializedclasses, c);
87                         return;
88                         }
89                 cl = chain_next(uninitializedclasses);
90                 }
91 }                       
92
93
94 /* function descriptor2typesL ***************************************************
95
96         decodes a already checked method descriptor. The parameter count, the
97         return type and the argument types are stored in the passed methodinfo.
98         gets and saves classptr for object ref.s
99
100 *******************************************************************************/                
101
102 classSetNode * descriptor2typesL (methodinfo *m)
103 {
104 int debugInfo = 0;
105         int i;
106         u1 *types, *tptr;
107         int pcount, c;
108         char *utf_ptr;
109         classinfo** classtypes;
110         char *class; 
111         char *desc;
112         classSetNode *p=NULL;
113 if (debugInfo >= 1) {
114         printf("In descriptor2typesL >>>\t"); fflush(stdout);
115         utf_display(m->class->name); printf(".");
116         method_display(m);fflush(stdout);
117         }
118
119         pcount = 0;
120         desc =       MNEW (char, 256); 
121         types = DMNEW (u1, m->descriptor->blength); 
122         classtypes = MNEW (classinfo*, m->descriptor->blength+1);
123         m->returnclass = NULL;
124         tptr = types;
125         if (!(m->flags & ACC_STATIC)) {
126                 *tptr++ = TYPE_ADR;
127                 if (debugInfo >= 1) {
128                         printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
129                         }
130                 classtypes[pcount] = m->class;
131                 p = addClassCone(p,  m->class);
132                 pcount++;
133                 }
134
135         utf_ptr = m->descriptor->text + 1;
136         strcpy (desc,utf_ptr);
137    
138         while ((c = *desc++) != ')') {
139                 pcount++;
140                 switch (c) {
141                         case 'B':
142                         case 'C':
143                         case 'I':
144                         case 'S':
145                         case 'Z':  *tptr++ = TYPE_INT;
146                                    break;
147                         case 'J':  *tptr++ = TYPE_LNG;
148                                    break;
149                         case 'F':  *tptr++ = TYPE_FLT;
150                                    break;
151                         case 'D':  *tptr++ = TYPE_DBL;
152                                    break;
153                         case 'L':  *tptr++ = TYPE_ADR;
154                                    /* get class string */
155                                    class = strtok(desc,";");
156                                    desc = strtok(NULL,"\0");
157                                    /* get/save classinfo ptr */
158                                    classtypes[pcount-1] = class_get(utf_new_char(class));
159                                    p = addClassCone(p,  class_get(utf_new_char(class)));
160                                         if (debugInfo >= 1) {
161                                                 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
162                                                 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
163                                                 utf_display(classtypes[pcount-1]->name);
164                                                 }
165                                    break;
166                         case '[':  *tptr++ = TYPE_ADR;
167                                    while (c == '[')
168                                        c = *desc++;
169                                    /* get class string */
170                                    if (c == 'L') {
171                                         class = strtok(desc,";");
172                                         desc = strtok(NULL,"\0");
173                                         /* get/save classinfo ptr */
174                                         classtypes[pcount-1] = class_get(utf_new_char(class));
175                                         p= addClassCone(p,  class_get(utf_new_char(class)));
176                                         if (debugInfo >= 1) {
177                                                 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
178                                                 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
179                                                 utf_display(classtypes[pcount-1]->name);
180                                                 printf("\n");
181                                                 }
182                                         }
183                                    else
184                                         classtypes[pcount-1] = NULL;
185                                    break;
186                         default:   
187                                 panic("Ill formed methodtype-descriptor");
188                         }
189                 }
190
191         /* compute return type */
192         switch (*desc++) {
193                 case 'B':
194                 case 'C':
195                 case 'I':
196                 case 'S':
197                 case 'Z':  m->returntype = TYPE_INT;
198                            break;
199                 case 'J':  m->returntype = TYPE_LNG;
200                            break;
201                 case 'F':  m->returntype = TYPE_FLT;
202                            break;
203                 case 'D':  m->returntype = TYPE_DBL;
204                            break;
205                 case '[':
206                            m->returntype = TYPE_ADR;
207                            c = *desc;
208                            while (c == '[')
209                                c = *desc++;
210                            if (c != 'L') break;
211                            *(desc++);
212                            
213                 case 'L':  
214                            m->returntype = TYPE_ADR;
215                           
216                             /* get class string */
217                             class = strtok(desc,";");
218                             m->returnclass = class_get(utf_new_char(class));
219                             if (m->returnclass == NULL) {
220                                 printf("class=%s :\t",class);
221                                 panic ("return class not found");
222                                 }
223                            break;
224                 case 'V':  m->returntype = TYPE_VOID;
225                            break;
226
227         default:   panic("Ill formed methodtype-descriptor-ReturnType");
228                 }
229
230         m->paramcount = pcount;
231         m->paramtypes = types;
232         m->paramclass = classtypes;
233
234 if (debugInfo >=1) {
235         if (pcount > 0) {
236                 for (i=0; i< m->paramcount; i++) {
237                         if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
238                               printf("Param #%i is:\t",i);
239                               utf_display(m->paramclass[i]->name);
240                               printf("\n");
241                               }
242                          }
243                }
244         if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) { 
245                   printf("\tReturn Type is:\t"); fflush(stdout);
246                   utf_display(m->returnclass->name);
247                   printf("\n");
248                   }
249
250         printf("params2types: START  results in a set \n");
251         printf("param2types: A Set size=%i=\n",sizeOfSet(p));
252         printSet(p);
253         }
254
255 return p;
256 }
257
258 /* function descriptor2types ***************************************************
259
260         decodes a already checked method descriptor. The parameter count, the
261         return type and the argument types are stored in the passed methodinfo.
262
263 *******************************************************************************/                
264
265 static void descriptor2types (methodinfo *m)
266 {
267         u1 *types, *tptr;
268         int pcount, c;
269         char *utf_ptr;
270         pcount = 0;
271         types = DMNEW (u1, m->descriptor->blength); 
272         
273         tptr = types;
274         if (!(m->flags & ACC_STATIC)) {
275                 *tptr++ = TYPE_ADR;
276                 pcount++;
277                 }
278
279         utf_ptr = m->descriptor->text + 1;
280    
281         while ((c = *utf_ptr++) != ')') {
282                 pcount++;
283                 switch (c) {
284                         case 'B':
285                         case 'C':
286                         case 'I':
287                         case 'S':
288                         case 'Z':  *tptr++ = TYPE_INT;
289                                    break;
290                         case 'J':  *tptr++ = TYPE_LNG;
291                                    break;
292                         case 'F':  *tptr++ = TYPE_FLT;
293                                    break;
294                         case 'D':  *tptr++ = TYPE_DBL;
295                                    break;
296                         case 'L':  *tptr++ = TYPE_ADR;
297                                    while (*utf_ptr++ != ';');
298                                    break;
299                         case '[':  *tptr++ = TYPE_ADR;
300                                    while (c == '[')
301                                        c = *utf_ptr++;
302                                    if (c == 'L')
303                                        while (*utf_ptr++ != ';') /* skip */;
304                                    break;
305                         default:   panic ("Ill formed methodtype-descriptor");
306                         }
307                 }
308
309         /* compute return type */
310
311         switch (*utf_ptr++) {
312                 case 'B':
313                 case 'C':
314                 case 'I':
315                 case 'S':
316                 case 'Z':  m->returntype = TYPE_INT;
317                            break;
318                 case 'J':  m->returntype = TYPE_LNG;
319                            break;
320                 case 'F':  m->returntype = TYPE_FLT;
321                            break;
322                 case 'D':  m->returntype = TYPE_DBL;
323                            break;
324                 case '[':
325                 case 'L':  m->returntype = TYPE_ADR;
326                            break;
327                 case 'V':  m->returntype = TYPE_VOID;
328                            break;
329
330                 default:   panic ("Ill formed methodtype-descriptor");
331                 }
332
333         m->paramcount = pcount;
334         m->paramtypes = types;
335 }
336
337
338 #ifdef OLD_COMPILER
339
340 /* function allocate_literals **************************************************
341
342         Scans the JavaVM code of a method and allocates string literals (in the
343         same order as the old JIT). Needed to generate the same addresses as the
344         old JIT compiler.
345         
346 *******************************************************************************/
347
348 static void allocate_literals()
349 {
350         int     p, nextp;
351         int     opcode, i;
352         s4      num;
353         utf     *s;
354
355         for (p = 0; p < jcodelength; p = nextp) {
356
357                 opcode = jcode[p];
358                 nextp = p + jcommandsize[opcode];
359
360                 switch (opcode) {
361                         case JAVA_WIDE:
362                                 if (code_get_u1(p + 1) == JAVA_IINC)
363                                         nextp = p + 6;
364                                 else
365                                         nextp = p + 4;
366                                 break;
367                                                         
368                         case JAVA_LOOKUPSWITCH:
369                                 nextp = ALIGN((p + 1), 4);
370                                 num = code_get_u4(nextp + 4);
371                                 nextp = nextp + 8 + 8 * num;
372                                 break;
373
374                         case JAVA_TABLESWITCH:
375                                 nextp = ALIGN ((p + 1),4);
376                                 num = code_get_s4(nextp + 4);
377                                 num = code_get_s4(nextp + 8) - num;
378                                 nextp = nextp + 16 + 4 * num;
379                                 break;
380
381                         case JAVA_LDC1:
382                                 i = code_get_u1(p+1);
383                                 goto pushconstantitem;
384                         case JAVA_LDC2:
385                         case JAVA_LDC2W:
386                                 i = code_get_u2(p + 1);
387                         pushconstantitem:
388                                 if (class_constanttype(class, i) == CONSTANT_String) {
389                                         s = class_getconstant(class, i, CONSTANT_String);
390                                         (void) literalstring_new(s);
391                                         }
392                                 break;
393                         } /* end switch */
394                 } /* end while */
395 }
396 #endif
397
398
399 /*******************************************************************************
400
401         function 'parse' scans the JavaVM code and generates intermediate code
402
403         During parsing the block index table is used to store at bit pos 0
404         a flag which marks basic block starts and at position 1 to 31 the
405         intermediate instruction index. After parsing the block index table
406         is scanned, for marked positions a block is generated and the block
407         number is stored in the block index table.
408
409 *******************************************************************************/
410
411 /* intermediate code generating macros */
412
413 #define PINC           iptr++;ipc++
414 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;iptr->op1=0;iptr->val.i=(v);PINC
415 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;iptr->op1=0;iptr->val.l=(v);PINC
416 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;iptr->op1=0;iptr->val.f=(v);PINC
417 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;iptr->op1=0;iptr->val.d=(v);PINC
418 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;iptr->op1=0;iptr->val.a=(v);PINC
419 #define OP(o)          iptr->opc=(o);iptr->op1=0;iptr->val.l=0;PINC
420 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);iptr->val.l=(0);PINC
421 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
422 #define OP2A(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
423 #define BUILTIN1(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
424                        iptr->val.a=(v);PINC
425 #define BUILTIN2(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
426                        iptr->val.a=(v);PINC
427 #define BUILTIN3(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
428                        iptr->val.a=(v);PINC
429
430
431 /* block generating and checking macros */
432
433 #define block_insert(i)    {if(!(block_index[i]&1))\
434                                {b_count++;block_index[i] |= 1;}}
435 #define bound_check(i)     {if((i< 0) || (i>=cumjcodelength)) \
436                                panic("branch target out of code-boundary");}
437 #define bound_check1(i)    {if((i< 0) || (i>cumjcodelength)) \
438                                panic("branch target out of code-boundary");}
439 /* FIXME really use cumjcodelength for the bound_checkers ? */
440
441 static xtable* fillextable (xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
442 {
443         int b_count, i, p;
444         
445         if (exceptiontablelength == 0) 
446                 return extable;
447         
448         b_count = *block_count;
449         for (i = 0; i < exceptiontablelength; i++) {
450                                                                  
451                 p = raw_extable[i].startpc;
452                 if (label_index != NULL) p = label_index[p];
453                 extable[i].startpc = p;
454                 bound_check(p);
455                 block_insert(p);
456                 
457                 p = raw_extable[i].endpc;
458                 if (label_index != NULL) p = label_index[p];
459                 extable[i].endpc = p;
460                 bound_check1(p);
461                 if (p < cumjcodelength)
462                         block_insert(p);
463
464                 p = raw_extable[i].handlerpc;
465                 if (label_index != NULL) p = label_index[p];
466                 extable[i].handlerpc = p;
467                 bound_check(p);
468                 block_insert(p);
469
470                 extable[i].catchtype  = raw_extable[i].catchtype;
471
472                 extable[i].next = NULL;
473                 extable[i].down = &extable[i+1];
474                 }
475         *block_count = b_count;
476         return &extable[i];  /* return the next free xtable* */
477 }
478
479 static void parse()
480 {
481         int  p;                     /* java instruction counter                   */
482         int  nextp;                 /* start of next java instruction             */
483         int  opcode;                /* java opcode                                */
484         int  i;                     /* temporary for different uses (counters)    */
485         int  ipc = 0;               /* intermediate instruction counter           */
486         int  b_count = 0;           /* basic block counter                        */
487         int  s_count = 0;           /* stack element counter                      */
488         bool blockend = false;      /* true if basic block end has been reached   */
489         bool iswide = false;        /* true if last instruction was a wide        */
490         instruction *iptr;          /* current pointer into instruction array     */
491         int gp;                     /* global java instruction counter            */
492                                     /* inlining info for current method           */
493         inlining_methodinfo *inlinfo = inlining_rootinfo, *tmpinlinf; 
494         int nextgp = -1;            /* start of next method to be inlined         */
495         int *label_index = NULL;    /* label redirection table                    */
496         int firstlocal = 0;         /* first local variable of method             */
497         xtable* nextex;             /* points next free entry in extable          */
498
499         bool useinltmp;
500
501 /*INLINING*/
502         if (useinlining)
503                 {
504                         label_index = inlinfo->label_index;
505                         maxstack = cummaxstack;
506                         exceptiontablelength=cumextablelength;
507                 }
508         
509         useinltmp = useinlining; /*FIXME remove this after debugging */
510     /*useinlining = false;*/     /* and merge the if-statements  */
511         
512         if (!useinlining) {
513           cumjcodelength = jcodelength;
514         } else {
515           tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
516           if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
517         }
518
519                 /*RTAprint*/ if  ( ((opt_rt) ||(opt_xta) || (opt_vta)) && ((pOpcodes == 2) || (pOpcodes == 3)) )
520                 /*RTAprint*/    {printf("PARSE method name =");
521                 /*RTAprint*/    utf_display(method->class->name);printf(".");
522                 /*RTAprint*/    method_display(method); printf(">\n\n");fflush(stdout);}
523         if ((opt_rt) || (opt_xta)) { 
524             RT_jit_parse(method);
525             }
526         else    {
527                 if (opt_vta) 
528                         printf("VTA requested, but not yet implemented\n");
529                 }
530          
531
532 #ifdef OLD_COMPILER
533         /* generate the same addresses as the old JIT compiler */
534
535         if (runverbose)
536                 allocate_literals();
537 #endif
538
539         /* allocate instruction array and block index table */
540         
541         /* 1 additional for end ipc and 3 for loop unrolling */
542         
543         block_index = DMNEW(int, cumjcodelength + 4);
544
545         /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
546         /* additional MONITOREXITS are reached by branches which are 3 bytes */
547         
548         iptr = instr = DMNEW(instruction, cumjcodelength + 5); 
549         
550         /* initialize block_index table (unrolled four times) */
551
552         {
553         int *ip;
554         
555         for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) {
556                 ip[0] = 0;
557                 ip[1] = 0;
558                 ip[2] = 0;
559                 ip[3] = 0;
560                 }
561         }
562
563         /* compute branch targets of exception table */
564
565         extable = DMNEW(xtable, exceptiontablelength + 1);
566         /*
567         for (i = 0; i < method->exceptiontablelength; i++) {
568
569                 p = extable[i].startpc = raw_extable[i].startpc;
570                 if (useinlining) p = label_index[p];
571                 bound_check(p);
572                 block_insert(p);
573
574                 p = extable[i].endpc = raw_extable[i].endpc;
575                 if (useinlining) p = label_index[p];
576                 bound_check1(p);
577                 if (p < cumjcodelength)
578                         block_insert(p);
579
580                 p = extable[i].handlerpc = raw_extable[i].handlerpc;
581                 bound_check(p);
582                 block_insert(p);
583
584                 extable[i].catchtype  = raw_extable[i].catchtype;
585
586                 extable[i].next = NULL;
587                 extable[i].down = &extable[i+1];
588                 }
589         */
590
591         nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count);
592
593         s_count = 1 + exceptiontablelength; /* initialize stack element counter   */
594
595 #ifdef USE_THREADS
596         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
597                 isleafmethod=false;
598                 }                       
599 #endif
600
601         /* scan all java instructions */
602
603         for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
604           
605           /* DEBUG        printf("p:%d gp:%d ",p,gp); */
606
607 /*INLINING*/
608           if ((useinlining) && (gp == nextgp)) {
609                   u1 *tptr;
610                   bool *readonly = NULL;
611
612                   opcode = code_get_u1 (p);
613                   nextp = p += jcommandsize[opcode];
614                   tmpinlinf = list_first(inlinfo->inlinedmethods);
615                   firstlocal = tmpinlinf->firstlocal;
616                   label_index = tmpinlinf->label_index;
617                   readonly = tmpinlinf->readonly;
618                   for (i=0, tptr=tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1 ; i<tmpinlinf->method->paramcount; i++, tptr--)
619                           {
620                                   int op;
621
622                                   if ( (i==0) && inlineparamopt) {
623                                           OP1(ICMD_CLEAR_ARGREN, firstlocal);
624                                   }
625
626                                   if ( !inlineparamopt || !readonly[i] )
627                                           op = ICMD_ISTORE;
628                                   else op = ICMD_READONLY_ARG;   
629
630                                   op += *tptr;
631                                   OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
632
633                                   /* block_index[gp] |= (ipc << 1);*/  /*FIXME: necessary ? */
634                           }
635                   inlining_save_compiler_variables();
636                   inlining_set_compiler_variables(tmpinlinf);
637                   if (inlinfo->inlinedmethods == NULL) gp = -1;
638                   else {
639                           tmpinlinf = list_first(inlinfo->inlinedmethods);
640                           nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
641                   }
642                   if (method->exceptiontablelength > 0) 
643                           nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count);
644                   continue;
645           }
646           
647           opcode = code_get_u1 (p);           /* fetch op code                  */
648
649           
650           /*RTAprint*/ if  ((opt_rt) && ((pOpcodes == 2) || (pOpcodes == 3)) )
651           /*RTAprint*/    {printf("Parse<%i> p=%i<%i<   opcode=<%i> %s\n",
652           /*RTAprint*/            pOpcodes, p,rt_jcodelength,opcode,icmd_names[opcode]);}
653           
654           block_index[gp] |= (ipc << 1);       /* store intermediate count       */
655
656           if (blockend) {
657                   block_insert(gp);                /* start new block                */
658                   blockend = false;
659           }
660
661                 nextp = p + jcommandsize[opcode];   /* compute next instruction start */
662                 s_count += stackreq[opcode];            /* compute stack element count    */
663
664                 switch (opcode) {
665
666                         case JAVA_NOP:
667                                 break;
668
669                         /* pushing constants onto the stack p */
670
671                         case JAVA_BIPUSH:
672                                 LOADCONST_I(code_get_s1(p+1));
673                                 break;
674
675                         case JAVA_SIPUSH:
676                                 LOADCONST_I(code_get_s2(p+1));
677                                 break;
678
679                         case JAVA_LDC1:
680                                 i = code_get_u1(p+1);
681                                 goto pushconstantitem;
682                         case JAVA_LDC2:
683                         case JAVA_LDC2W:
684                                 i = code_get_u2(p + 1);
685
686                         pushconstantitem:
687
688                                 if (i >= class->cpcount) 
689                                         panic ("Attempt to access constant outside range");
690
691                                 switch (class->cptags[i]) {
692                                         case CONSTANT_Integer:
693                                                 LOADCONST_I(((constant_integer*)
694                                                              (class->cpinfos[i]))->value);
695                                                 break;
696                                         case CONSTANT_Long:
697                                                 LOADCONST_L(((constant_long*)
698                                                              (class->cpinfos[i]))->value);
699                                                 break;
700                                         case CONSTANT_Float:
701                                                 LOADCONST_F(((constant_float*)
702                                                              (class->cpinfos[i]))->value);
703                                                 break;
704                                         case CONSTANT_Double:
705                                                 LOADCONST_D(((constant_double*)
706                                                              (class->cpinfos[i]))->value);
707                                                 break;
708                                         case CONSTANT_String:
709                                                 LOADCONST_A(literalstring_new((utf*)
710                                                                               (class->cpinfos[i])));
711                                                 break;
712                                         default: panic("Invalid constant type to push");
713                                         }
714                                 break;
715
716                         case JAVA_ACONST_NULL:
717                                 LOADCONST_A(NULL);
718                                 break;
719
720                         case JAVA_ICONST_M1:
721                         case JAVA_ICONST_0:
722                         case JAVA_ICONST_1:
723                         case JAVA_ICONST_2:
724                         case JAVA_ICONST_3:
725                         case JAVA_ICONST_4:
726                         case JAVA_ICONST_5:
727                                 LOADCONST_I(opcode - JAVA_ICONST_0);
728                                 break;
729
730                         case JAVA_LCONST_0:
731                         case JAVA_LCONST_1:
732                                 LOADCONST_L(opcode - JAVA_LCONST_0);
733                                 break;
734
735                         case JAVA_FCONST_0:
736                         case JAVA_FCONST_1:
737                         case JAVA_FCONST_2:
738                                 LOADCONST_F(opcode - JAVA_FCONST_0);
739                                 break;
740
741                         case JAVA_DCONST_0:
742                         case JAVA_DCONST_1:
743                                 LOADCONST_D(opcode - JAVA_DCONST_0);
744                                 break;
745
746                         /* loading variables onto the stack */
747
748                         case JAVA_ILOAD:
749                         case JAVA_LLOAD:
750                         case JAVA_FLOAD:
751                         case JAVA_DLOAD:
752                         case JAVA_ALOAD:
753                                 if (!iswide)
754                                         i = code_get_u1(p+1);
755                                 else {
756                                         i = code_get_u2(p+1);
757                                         nextp = p+3;
758                                         iswide = false;
759                                         }
760                                 OP1(opcode, i + firstlocal);
761                                 break;
762
763                         case JAVA_ILOAD_0:
764                         case JAVA_ILOAD_1:
765                         case JAVA_ILOAD_2:
766                         case JAVA_ILOAD_3:
767                                 OP1(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
768                                 break;
769
770                         case JAVA_LLOAD_0:
771                         case JAVA_LLOAD_1:
772                         case JAVA_LLOAD_2:
773                         case JAVA_LLOAD_3:
774                                 OP1(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
775                                 break;
776
777                         case JAVA_FLOAD_0:
778                         case JAVA_FLOAD_1:
779                         case JAVA_FLOAD_2:
780                         case JAVA_FLOAD_3:
781                                 OP1(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
782                                 break;
783
784                         case JAVA_DLOAD_0:
785                         case JAVA_DLOAD_1:
786                         case JAVA_DLOAD_2:
787                         case JAVA_DLOAD_3:
788                                 OP1(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
789                                 break;
790
791                         case JAVA_ALOAD_0:
792                         case JAVA_ALOAD_1:
793                         case JAVA_ALOAD_2:
794                         case JAVA_ALOAD_3:
795                                 OP1(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
796                                 break;
797
798                         /* storing stack values into local variables */
799
800                         case JAVA_ISTORE:
801                         case JAVA_LSTORE:
802                         case JAVA_FSTORE:
803                         case JAVA_DSTORE:
804                         case JAVA_ASTORE:
805                                 if (!iswide)
806                                         i = code_get_u1(p+1);
807                                 else {
808                                         i = code_get_u2(p+1);
809                                         iswide=false;
810                                         nextp = p+3;
811                                         }
812                                 OP1(opcode, i + firstlocal);
813                                 break;
814
815                         case JAVA_ISTORE_0:
816                         case JAVA_ISTORE_1:
817                         case JAVA_ISTORE_2:
818                         case JAVA_ISTORE_3:
819                                 OP1(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
820                                 break;
821
822                         case JAVA_LSTORE_0:
823                         case JAVA_LSTORE_1:
824                         case JAVA_LSTORE_2:
825                         case JAVA_LSTORE_3:
826                                 OP1(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
827                                 break;
828
829                         case JAVA_FSTORE_0:
830                         case JAVA_FSTORE_1:
831                         case JAVA_FSTORE_2:
832                         case JAVA_FSTORE_3:
833                                 OP1(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
834                                 break;
835
836                         case JAVA_DSTORE_0:
837                         case JAVA_DSTORE_1:
838                         case JAVA_DSTORE_2:
839                         case JAVA_DSTORE_3:
840                                 OP1(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
841                                 break;
842
843                         case JAVA_ASTORE_0:
844                         case JAVA_ASTORE_1:
845                         case JAVA_ASTORE_2:
846                         case JAVA_ASTORE_3:
847                                 OP1(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
848                                 break;
849
850                         case JAVA_IINC:
851                                 {
852                                 int v;
853                                 
854                                 if (!iswide) {
855                                         i = code_get_u1(p + 1);
856                                         v = code_get_s1(p + 2);
857                                         }
858                                 else {
859                                         i = code_get_u2(p + 1);
860                                         v = code_get_s2(p + 3);
861                                         iswide = false;
862                                         nextp = p+5;
863                                         }
864                                 OP2I(opcode, i + firstlocal, v);
865                                 }
866                                 break;
867
868                         /* wider index for loading, storing and incrementing */
869
870                         case JAVA_WIDE:
871                                 iswide = true;
872                                 nextp = p + 1;
873                                 break;
874
875                         /* managing arrays ************************************************/
876
877                         case JAVA_NEWARRAY:
878                                 OP2I(ICMD_CHECKASIZE, 0, 0);
879                                 switch (code_get_s1(p+1)) {
880                                         case 4:
881                                                 BUILTIN1((functionptr)builtin_newarray_boolean, TYPE_ADR);
882                                                 break;
883                                         case 5:
884                                                 BUILTIN1((functionptr)builtin_newarray_char, TYPE_ADR);
885                                                 break;
886                                         case 6:
887                                                 BUILTIN1((functionptr)builtin_newarray_float, TYPE_ADR);
888                                                 break;
889                                         case 7:
890                                                 BUILTIN1((functionptr)builtin_newarray_double, TYPE_ADR);
891                                                 break;
892                                         case 8:
893                                                 BUILTIN1((functionptr)builtin_newarray_byte, TYPE_ADR);
894                                                 break;
895                                         case 9:
896                                                 BUILTIN1((functionptr)builtin_newarray_short, TYPE_ADR);
897                                                 break;
898                                         case 10:
899                                                 BUILTIN1((functionptr)builtin_newarray_int, TYPE_ADR);
900                                                 break;
901                                         case 11:
902                                                 BUILTIN1((functionptr)builtin_newarray_long, TYPE_ADR);
903                                                 break;
904                                         default: panic("Invalid array-type to create");
905                                         }
906                                 break;
907
908                         case JAVA_ANEWARRAY:
909                                 OP2I(ICMD_CHECKASIZE, 0, 0);
910                                 i = code_get_u2(p+1);
911                                 /* array or class type ? */
912                                 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
913                                         s_count++;
914                                         LOADCONST_A(class_getconstant(class, i,
915                                                                       CONSTANT_Arraydescriptor));
916 #if defined(__I386__)
917                                         BUILTIN2((functionptr) asm_builtin_newarray_array, TYPE_ADR);
918 #else
919                                         BUILTIN2((functionptr)builtin_newarray_array, TYPE_ADR);
920 #endif
921                                         }
922                                 else {
923                                         LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
924                                         s_count++;
925 #if defined(__I386__)
926                                         BUILTIN2((functionptr) asm_builtin_anewarray, TYPE_ADR);
927 #else
928                                         BUILTIN2((functionptr)builtin_anewarray, TYPE_ADR);
929 #endif
930                                         }
931                                 break;
932
933                         case JAVA_MULTIANEWARRAY:
934                                 isleafmethod=false;
935                                 i = code_get_u2(p+1);
936                                 {
937                                 int v = code_get_u1(p+3);
938                                 constant_arraydescriptor *desc =
939                                     class_getconstant (class, i, CONSTANT_Arraydescriptor);
940                                 OP2A(opcode, v, desc);
941                                 }
942                                 break;
943
944                         case JAVA_IFEQ:
945                         case JAVA_IFLT:
946                         case JAVA_IFLE:
947                         case JAVA_IFNE:
948                         case JAVA_IFGT:
949                         case JAVA_IFGE:
950                         case JAVA_IFNULL:
951                         case JAVA_IFNONNULL:
952                         case JAVA_IF_ICMPEQ:
953                         case JAVA_IF_ICMPNE:
954                         case JAVA_IF_ICMPLT:
955                         case JAVA_IF_ICMPGT:
956                         case JAVA_IF_ICMPLE:
957                         case JAVA_IF_ICMPGE:
958                         case JAVA_IF_ACMPEQ:
959                         case JAVA_IF_ACMPNE:
960                         case JAVA_GOTO:
961                         case JAVA_JSR:
962                                 i = p + code_get_s2(p+1);
963                                 if (useinlining) { 
964                                   debug_writebranch
965                                   i = label_index[i];
966                                 }
967                                 bound_check(i);
968                                 block_insert(i);
969                                 blockend = true;
970                                 OP1(opcode, i);
971                                 break;
972                         case JAVA_GOTO_W:
973                         case JAVA_JSR_W:
974                                 i = p + code_get_s4(p+1);
975                                 if (useinlining) { 
976                                   debug_writebranch
977                                   i = label_index[i];
978                                 }
979                                 bound_check(i);
980                                 block_insert(i);
981                                 blockend = true;
982                                 OP1(opcode, i);
983                                 break;
984
985                         case JAVA_RET:
986                                 if (!iswide)
987                                         i = code_get_u1(p+1);
988                                 else {
989                                         i = code_get_u2(p+1);
990                                         nextp = p+3;
991                                         iswide = false;
992                                         }
993                                 blockend = true;
994                                 
995                                 /*
996                                 if (isinlinedmethod) {
997                                   OP1(ICMD_GOTO, inlinfo->stopgp);
998                                   break;
999                                   }*/
1000
1001                                 OP1(opcode, i + firstlocal);
1002                                 break;
1003
1004                         case JAVA_IRETURN:
1005                         case JAVA_LRETURN:
1006                         case JAVA_FRETURN:
1007                         case JAVA_DRETURN:
1008                         case JAVA_ARETURN:
1009                         case JAVA_RETURN:
1010
1011
1012                                 if (isinlinedmethod) {
1013 /*                                      if (p==jcodelength-1) {*/ /* return is at end of inlined method */
1014 /*                                              OP(ICMD_NOP); */
1015 /*                                              break; */
1016 /*                                      } */
1017                                         blockend = true;
1018                                         OP1(ICMD_GOTO, inlinfo->stopgp);
1019                                         break;
1020                                 }
1021
1022                                 blockend = true;
1023                                 OP(opcode);
1024                                 break;
1025
1026                         case JAVA_ATHROW:
1027                                 blockend = true;
1028                                 OP(opcode);
1029                                 break;
1030                                 
1031
1032                         /* table jumps ********************************/
1033
1034                         case JAVA_LOOKUPSWITCH:
1035                                 {
1036                                 s4 num, j;
1037                                 s4 *tablep;
1038
1039                                 blockend = true;
1040                                 nextp = ALIGN((p + 1), 4);
1041                                 if (!useinlining) {
1042                                         tablep = (s4*)(jcode + nextp);
1043                                 }
1044                                 else {
1045                                         num = code_get_u4(nextp + 4);
1046                                         tablep = DMNEW(s4, num * 2 + 2);
1047                                 }
1048
1049                                 OP2A(opcode, 0, tablep);
1050
1051                                 /* default target */
1052
1053                                 j =  p + code_get_s4(nextp);
1054                                 if (useinlining) j = label_index[j];
1055                                 *tablep = j;     /* restore for little endian */
1056                                 tablep++;
1057                                 nextp += 4;
1058                                 bound_check(j);
1059                                 block_insert(j);
1060
1061                                 /* number of pairs */
1062
1063                                 num = code_get_u4(nextp);
1064                                 *tablep = num;
1065                                 tablep++;
1066                                 nextp += 4;
1067
1068                                 for (i = 0; i < num; i++) {
1069
1070                                         /* value */
1071
1072                                         j = code_get_s4(nextp);
1073                                         *tablep = j; /* restore for little endian */
1074                                         tablep++;
1075                                         nextp += 4;
1076
1077                                         /* target */
1078
1079                                         j = p + code_get_s4(nextp);
1080                                         if (useinlining) j = label_index[j];
1081                                         *tablep = j; /* restore for little endian */
1082                                         tablep++;
1083                                         nextp += 4;
1084                                         bound_check(j);
1085                                         block_insert(j);
1086                                         }
1087
1088                                 break;
1089                                 }
1090
1091
1092                         case JAVA_TABLESWITCH:
1093                                 {
1094                                 s4 num, j;
1095                                 s4 *tablep;
1096
1097                                 blockend = true;
1098                                 nextp = ALIGN((p + 1), 4);
1099                                 if (!useinlining) {
1100                                         tablep = (s4*)(jcode + nextp);
1101                                 }
1102                                 else {
1103                                         num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1104                                         tablep = DMNEW(s4, num + 1 + 3);
1105                                 }
1106
1107                                 OP2A(opcode, 0, tablep);
1108
1109                                 /* default target */
1110
1111                                 j = p + code_get_s4(nextp);
1112                                 if (useinlining) j = label_index[j];
1113                                 *tablep = j;     /* restore for little endian */
1114                                 tablep++;
1115                                 nextp += 4;
1116                                 bound_check(j);
1117                                 block_insert(j);
1118
1119                                 /* lower bound */
1120
1121                                 j = code_get_s4(nextp);
1122                                 *tablep = j;     /* restore for little endian */
1123                                 tablep++;
1124                                 nextp += 4;
1125
1126                                 /* upper bound */
1127
1128                                 num = code_get_s4(nextp);
1129                                 *tablep = num;   /* restore for little endian */
1130                                 tablep++;
1131                                 nextp += 4;
1132
1133                                 num -= j;
1134
1135                                 for (i = 0; i <= num; i++) {
1136                                         j = p + code_get_s4(nextp);
1137                                         if (useinlining) j = label_index[j];
1138                                         *tablep = j; /* restore for little endian */
1139                                         tablep++;
1140                                         nextp += 4;
1141                                         bound_check(j);
1142                                         block_insert(j);
1143                                         }
1144
1145                                 break;
1146                                 }
1147
1148
1149                         /* load and store of object fields *******************/
1150
1151                         case JAVA_AASTORE:
1152                                 BUILTIN3((functionptr) asm_builtin_aastore, TYPE_VOID);
1153                                 break;
1154
1155                         case JAVA_PUTSTATIC:
1156                         case JAVA_GETSTATIC:
1157                                 i = code_get_u2(p + 1);
1158                                 {
1159                                 constant_FMIref *fr;
1160                                 fieldinfo *fi;
1161                                 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1162                                 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1163                                 compiler_addinitclass (fr->class);
1164                                 OP2A(opcode, fi->type, fi);
1165                                 }
1166                                 break;
1167                         case JAVA_PUTFIELD:
1168                         case JAVA_GETFIELD:
1169                                 i = code_get_u2(p + 1);
1170                                 {
1171                                 constant_FMIref *fr;
1172                                 fieldinfo *fi;
1173                                 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1174                                 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1175                                 OP2A(opcode, fi->type, fi);
1176                                 }
1177                                 break;
1178
1179
1180                         /* method invocation *****/
1181
1182                         case JAVA_INVOKESTATIC:
1183                                 i = code_get_u2(p + 1);
1184                                 {
1185                                 constant_FMIref *mr;
1186                                 methodinfo *mi;
1187                                 
1188                                 mr = class_getconstant (class, i, CONSTANT_Methodref);
1189                                 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1190                                         /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1191                                         /*RTAprint*/    {printf(" method name =");
1192                                         /*RTAprint*/    utf_display(mi->class->name); printf(".");
1193                                         /*RTAprint*/    utf_display(mi->name);printf("\tINVOKE STATIC\n");
1194                                         /*RTAprint*/    fflush(stdout);}
1195                                 if (! (mi->flags & ACC_STATIC))
1196                                         panic ("Static/Nonstatic mismatch calling static method");
1197                                 descriptor2types(mi);
1198
1199                                 isleafmethod=false;
1200                                 OP2A(opcode, mi->paramcount, mi);
1201                                 }
1202                                 break;
1203                         case JAVA_INVOKESPECIAL:
1204                         case JAVA_INVOKEVIRTUAL:
1205                                 i = code_get_u2(p + 1);
1206                                 {
1207                                 constant_FMIref *mr;
1208                                 methodinfo *mi;
1209                                 
1210                                 mr = class_getconstant (class, i, CONSTANT_Methodref);
1211                                 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1212                                         /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1213                                         /*RTAprint*/    {printf(" method name =");
1214                                                         method_display(mi);
1215                                         /*RTAprint*/    utf_display(mi->class->name); printf(".");
1216                                         /*RTAprint*/    utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1217                                         /*RTAprint*/    fflush(stdout);}
1218
1219                                 if (mi->flags & ACC_STATIC)
1220                                         panic ("Static/Nonstatic mismatch calling static method");
1221                                 descriptor2types(mi);
1222                                 isleafmethod=false;
1223                                 OP2A(opcode, mi->paramcount, mi);
1224                                 }
1225                                 break;
1226                         case JAVA_INVOKEINTERFACE:
1227                                 i = code_get_u2(p + 1);
1228                                 {
1229                                 constant_FMIref *mr;
1230                                 methodinfo *mi;
1231                                 
1232                                 mr = class_getconstant (class, i, CONSTANT_InterfaceMethodref);
1233                                 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1234                                 if (mi->flags & ACC_STATIC)
1235                                         panic ("Static/Nonstatic mismatch calling static method");
1236                                 descriptor2types(mi);
1237                                 isleafmethod=false;
1238                                 OP2A(opcode, mi->paramcount, mi);
1239                                 }
1240                                 break;
1241
1242                         /* miscellaneous object operations *******/
1243
1244                         case JAVA_NEW:
1245                                 i = code_get_u2 (p+1);
1246
1247                                 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1248                                 s_count++;
1249                                 BUILTIN1((functionptr) builtin_new, TYPE_ADR);
1250                                 break;
1251
1252                         case JAVA_CHECKCAST:
1253                                 i = code_get_u2(p+1);
1254
1255                                 /* array type cast-check */
1256                                 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1257                                         LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1258                                         s_count++;
1259                                         BUILTIN2((functionptr) asm_builtin_checkarraycast, TYPE_ADR);
1260                                         }
1261                                 else { /* object type cast-check */
1262                                         /*
1263                                         LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1264                                         s_count++;
1265                                         BUILTIN2((functionptr) asm_builtin_checkcast, TYPE_ADR);
1266                                         */
1267                                         OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1268                                         }
1269                                 break;
1270
1271                         case JAVA_INSTANCEOF:
1272                                 i = code_get_u2(p+1);
1273
1274                                 /* array type cast-check */
1275                                 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1276                                         LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1277                                         s_count++;
1278 #if defined(__I386__)
1279                                         BUILTIN2((functionptr) asm_builtin_arrayinstanceof, TYPE_INT);
1280 #else
1281                                         BUILTIN2((functionptr) builtin_arrayinstanceof, TYPE_INT);
1282 #endif
1283                                         }
1284                                 else { /* object type cast-check */
1285                                         /*
1286                                         LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1287                                         s_count++;
1288                                         BUILTIN2((functionptr) builtin_instanceof, TYPE_INT);
1289                                         */
1290                                         OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1291                                         }
1292                                 break;
1293
1294                         case JAVA_MONITORENTER:
1295 #ifdef USE_THREADS
1296                                 if (checksync) {
1297                                         BUILTIN1((functionptr) asm_builtin_monitorenter, TYPE_VOID);
1298                                 } else
1299 #endif
1300                                         {
1301                                         OP(ICMD_NULLCHECKPOP);
1302                                         }
1303                                 break;
1304
1305                         case JAVA_MONITOREXIT:
1306 #ifdef USE_THREADS
1307                                 if (checksync) {
1308                                         BUILTIN1((functionptr) asm_builtin_monitorexit, TYPE_VOID);
1309                                         }
1310                                 else
1311 #endif
1312                                         {
1313                                         OP(ICMD_POP);
1314                                         }
1315                                 break;
1316
1317                         /* any other basic operation **************************************/
1318
1319                         case JAVA_IDIV:
1320                                 OP(opcode);
1321                                 break;
1322
1323                         case JAVA_IREM:
1324                                 OP(opcode);
1325                                 break;
1326
1327                         case JAVA_LDIV:
1328                                 OP(opcode);
1329                                 break;
1330
1331                         case JAVA_LREM:
1332                                 OP(opcode);
1333                                 break;
1334
1335                         case JAVA_FREM:
1336 #if defined(__I386__)
1337                                 OP(opcode);
1338 #else
1339                                 BUILTIN2((functionptr) builtin_frem, TYPE_FLOAT);
1340 #endif
1341                                 break;
1342
1343                         case JAVA_DREM:
1344 #if defined(__I386__)
1345                                 OP(opcode);
1346 #else
1347                                 BUILTIN2((functionptr) builtin_drem, TYPE_DOUBLE);
1348 #endif
1349                                 break;
1350
1351                         case JAVA_F2I:
1352                                 if (checkfloats) {
1353                                         BUILTIN1((functionptr) builtin_f2i, TYPE_INT);
1354                                         }
1355                                 else {
1356                                         OP(opcode);
1357                                         }
1358                                 break;
1359
1360                         case JAVA_F2L:
1361                                 if (checkfloats) {
1362                                         BUILTIN1((functionptr) builtin_f2l, TYPE_LONG);
1363                                         }
1364                                 else {
1365                                         OP(opcode);
1366                                         }
1367                                 break;
1368
1369                         case JAVA_D2I:
1370                                 if (checkfloats) {
1371                                         BUILTIN1((functionptr) builtin_d2i, TYPE_INT);
1372                                         }
1373                                 else {
1374                                         OP(opcode);
1375                                         }
1376                                 break;
1377
1378                         case JAVA_D2L:
1379                                 if (checkfloats) {
1380                                         BUILTIN1((functionptr) builtin_d2l, TYPE_LONG);
1381                                         }
1382                                 else {
1383                                         OP(opcode);
1384                                         }
1385                                 break;
1386
1387                         case JAVA_BREAKPOINT:
1388                                 panic("Illegal opcode Breakpoint encountered");
1389                                 break;
1390
1391                         case 203:
1392                         case 204:
1393                         case 205:
1394                         case 206:
1395                         case 207:
1396                         case 208:
1397                         case 209:
1398                         case 210:
1399                         case 211:
1400                         case 212:
1401                         case 213:
1402                         case 214:
1403                         case 215:
1404                         case 216:
1405                         case 217:
1406                         case 218:
1407                         case 219:
1408                         case 220:
1409                         case 221:
1410                         case 222:
1411                         case 223:
1412                         case 224:
1413                         case 225:
1414                         case 226:
1415                         case 227:
1416                         case 228:
1417                         case 229:
1418                         case 230:
1419                         case 231:
1420                         case 232:
1421                         case 233:
1422                         case 234:
1423                         case 235:
1424                         case 236:
1425                         case 237:
1426                         case 238:
1427                         case 239:
1428                         case 240:
1429                         case 241:
1430                         case 242:
1431                         case 243:
1432                         case 244:
1433                         case 245:
1434                         case 246:
1435                         case 247:
1436                         case 248:
1437                         case 249:
1438                         case 250:
1439                         case 251:
1440                         case 252:
1441                         case 253:
1442                         case 254:
1443                         case 255:
1444                                 printf("Illegal opcode %d at instr %d", opcode, ipc);
1445                                 panic("encountered");
1446                                 break;
1447
1448                         default:
1449                                 OP(opcode);
1450                                 break;
1451                                 
1452                     } /* end switch */
1453                 
1454                 /* INLINING */
1455                   
1456                 if ((isinlinedmethod) && (p==jcodelength-1)) { /*end of an inlined method */
1457                   /*              printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1458                   gp = inlinfo->stopgp; 
1459                   inlining_restore_compiler_variables();
1460                   list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1461                   if (inlinfo->inlinedmethods == NULL) nextgp = -1;
1462                   else {
1463                           tmpinlinf = list_first(inlinfo->inlinedmethods);
1464                           nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1465                   }
1466                   /*              printf("nextpgp: %d\n", nextgp); */
1467                   label_index=inlinfo->label_index;
1468                   firstlocal = inlinfo->firstlocal;
1469                 }
1470
1471                 } /* end for */
1472         if (p != jcodelength)
1473                 panic("Command-sequence crosses code-boundary");
1474
1475         if (!blockend)
1476                 panic("Code does not end with branch/return/athrow - stmt");    
1477
1478         /* adjust block count if target 0 is not first intermediate instruction   */
1479
1480         if (!block_index[0] || (block_index[0] > 1))
1481                 b_count++;
1482
1483         /* copy local to global variables   */
1484
1485         instr_count = ipc;
1486         block_count = b_count;
1487         stack_count = s_count + block_count * maxstack;
1488
1489         /* allocate stack table */
1490
1491         stack = DMNEW(stackelement, stack_count);
1492
1493         {
1494         basicblock  *bptr;
1495
1496         bptr = block = DMNEW(basicblock, b_count + 1);    /* one more for end ipc */
1497
1498         b_count = 0;
1499         c_debug_nr = 0;
1500         
1501         /* additional block if target 0 is not first intermediate instruction     */
1502
1503         if (!block_index[0] || (block_index[0] > 1)) {
1504                 bptr->iinstr = instr;
1505                 bptr->mpc = -1;
1506                 bptr->flags = -1;
1507                 bptr->type = BBTYPE_STD;
1508                 bptr->branchrefs = NULL;
1509                 bptr->pre_count = 0;
1510                 bptr->debug_nr = c_debug_nr++;
1511                 bptr++;
1512                 b_count++;
1513                 (bptr - 1)->next = bptr;
1514         
1515                 }
1516
1517         /* allocate blocks */
1518
1519
1520         for (p = 0; p < cumjcodelength; p++)
1521                 
1522                 if (block_index[p] & 1) {
1523                         bptr->iinstr = instr + (block_index[p] >> 1);
1524                         bptr->debug_nr = c_debug_nr++;
1525                         if (b_count != 0)
1526                                 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1527                         bptr->mpc = -1;
1528                         bptr->flags = -1;
1529                         bptr->lflags = 0;
1530                         bptr->type = BBTYPE_STD;
1531                         bptr->branchrefs = NULL;
1532                         block_index[p] = b_count;
1533                         bptr->pre_count = 0;
1534                         bptr++;
1535                         b_count++;
1536
1537                         (bptr - 1)->next = bptr;
1538                         }
1539
1540         /* allocate additional block at end */
1541
1542         
1543         bptr->instack = bptr->outstack = NULL;
1544         bptr->indepth = bptr->outdepth = 0;
1545         bptr->iinstr = NULL;
1546         (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
1547         bptr->icount = 0;
1548         bptr->mpc = -1;
1549         bptr->flags = -1;
1550         bptr->lflags = 0;
1551         bptr->type = BBTYPE_STD;
1552         bptr->branchrefs = NULL;
1553         bptr->pre_count = 0;
1554         bptr->debug_nr = c_debug_nr++;
1555                         
1556         (bptr - 1)->next = bptr;
1557         bptr->next = NULL;
1558
1559         last_block = bptr;
1560
1561         if (exceptiontablelength > 0)
1562                 extable[exceptiontablelength-1].down = NULL;
1563         else
1564                 extable = NULL;
1565
1566         for (i = 0; i < exceptiontablelength; ++i) {
1567                 p = extable[i].startpc;
1568                 extable[i].start = block + block_index[p];
1569
1570                 p = extable[i].endpc;
1571                 extable[i].end = block + block_index[p]; 
1572
1573                 p = extable[i].handlerpc;
1574                 extable[i].handler = block + block_index[p];
1575             }
1576         }
1577         
1578         if (useinlining) inlining_cleanup();
1579         useinlining = useinltmp;
1580 }
1581 #include "sets.c"
1582 #include "parseRT.h"
1583
1584 /*
1585  * These are local overrides for various environment variables in Emacs.
1586  * Please do not remove this and leave it at the end of the file, where
1587  * Emacs will automagically detect them.
1588  * ---------------------------------------------------------------------
1589  * Local variables:
1590  * mode: c
1591  * indent-tabs-mode: t
1592  * c-basic-offset: 4
1593  * tab-width: 4
1594  * End:
1595  */