basic block struct changed
[cacao.git] / ncomp / nstack.c
1 /* -*- mode: c; tab-width: 4; c-basic-offset: 4 -*- */
2 /****************************** ncomp/nstack.c *********************************
3
4         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5
6         See file COPYRIGHT for information on usage and disclaimer of warranties
7
8         Parser for JavaVM to intermediate code translation
9         
10         Authors: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
11
12         Last Change: 1997/11/18
13
14 *******************************************************************************/
15
16 #define CONDITIONAL_LOADCONST
17
18 #ifdef STATISTICS
19 #define COUNT(cnt) cnt++
20 #else
21 #define COUNT(cnt)
22 #endif
23
24 #define STACKRESET {curstack=0;stackdepth=0;}
25
26 #define TYPEPANIC  {show_icmd_method();panic("Stack type mismatch");}
27 #define CURKIND    curstack->varkind
28 #define CURTYPE    curstack->type
29
30 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0;\
31                         new->varkind=v;new->varnum=n;curstack=new;new++;}
32 #define NEWSTACKn(s,n)  NEWSTACK(s,UNDEFVAR,n)
33 #define NEWSTACK0(s)    NEWSTACK(s,UNDEFVAR,0)
34 #define NEWXSTACK   {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
35
36 #define SETDST      {iptr->dst=curstack;}
37 #define POP(s)      {if(s!=curstack->type){TYPEPANIC;}\
38                      if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
39                      curstack=curstack->prev;}
40 #define POPANY      {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
41                      curstack=curstack->prev;}
42 #define COPY(s,d)   {(d)->flags=0;(d)->type=(s)->type;\
43                      (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
44
45 #define CONST(s)    {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
46 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
47 #define STORE(s)    {POP(s);SETDST;stackdepth--;}
48 #define OP1_0(s)    {POP(s);SETDST;stackdepth--;}
49 #define OP1_0ANY    {POPANY;SETDST;stackdepth--;}
50 #define OP0_1(s)    {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
51 #define OP1_1(s,d)  {POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
52 #define OP2_0(s)    {POP(s);POP(s);SETDST;stackdepth-=2;}
53 #define OPTT2_0(t,b){POP(t);POP(b);SETDST;stackdepth-=2;}
54 #define OP2_1(s)    {POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
55 #define OP2IAT_1(s) {POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
56                      SETDST;stackdepth--;}
57 #define OP2IT_1(s)  {POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
58                      SETDST;stackdepth--;}
59 #define OPTT2_1(s,d){POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
60 #define OP2_2(s)    {POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
61                      NEWSTACKn(s,stackdepth-1);SETDST;}
62 #define OP3TIA_0(s) {POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
63 #define OP3_0(s)    {POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
64 #define POPMANY(i)  {stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
65 #define DUP         {NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST;\
66                     stackdepth++;}
67 #define SWAP        {COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
68                     new[0].prev=curstack;new[1].prev=new;\
69                     curstack=new+1;new+=2;SETDST;}
70 #define DUP_X1      {COPY(curstack,new);COPY(curstack,new+2);POPANY;\
71                     COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
72                     new[1].prev=new;new[2].prev=new+1;\
73                     curstack=new+2;new+=3;SETDST;stackdepth++;}
74 #define DUP2_X1     {COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
75                     COPY(curstack,new);COPY(curstack,new+3);POPANY;\
76                     COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
77                     new[1].prev=new;new[2].prev=new+1;\
78                     new[3].prev=new+2;new[4].prev=new+3;\
79                     curstack=new+4;new+=5;SETDST;stackdepth+=2;}
80 #define DUP_X2      {COPY(curstack,new);COPY(curstack,new+3);POPANY;\
81                     COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
82                     new[0].prev=curstack;new[1].prev=new;\
83                     new[2].prev=new+1;new[3].prev=new+2;\
84                     curstack=new+3;new+=4;SETDST;stackdepth++;}
85 #define DUP2_X2     {COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
86                     COPY(curstack,new);COPY(curstack,new+4);POPANY;\
87                     COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
88                     new[0].prev=curstack;new[1].prev=new;\
89                     new[2].prev=new+1;new[3].prev=new+2;\
90                     new[4].prev=new+3;new[5].prev=new+4;\
91                     curstack=new+5;new+=6;SETDST;stackdepth+=2;}
92
93 #define COPYCURSTACK(copy) {\
94         int d;\
95         stackptr s;\
96         if(curstack){\
97                 s=curstack;\
98                 new+=stackdepth;\
99                 d=stackdepth;\
100                 copy=new;\
101                 while(s){\
102                         copy--;d--;\
103                         copy->prev=copy-1;\
104                         copy->type=s->type;\
105                         copy->flags=0;\
106                         copy->varkind=STACKVAR;\
107                         copy->varnum=d;\
108                         s=s->prev;\
109                         }\
110                 copy->prev=NULL;\
111                 copy=new-1;\
112                 }\
113         else\
114                 copy=NULL;\
115 }
116
117
118 #define BBEND(s,i){\
119         i=stackdepth-1;\
120         copy=s;\
121         while(copy){\
122                 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
123                         copy->varkind=TEMPVAR;\
124                 else {\
125                         copy->varkind=STACKVAR;\
126                         copy->varnum=i;\
127                         }\
128                 interfaces[i][copy->type].type = copy->type;\
129                 interfaces[i][copy->type].flags |= copy->flags;\
130                 i--;copy=copy->prev;\
131                 }\
132         i=bptr->indepth-1;\
133         copy=bptr->instack;\
134         while(copy){\
135                 interfaces[i][copy->type].type = copy->type;\
136                 if(copy->varkind==STACKVAR){\
137                         if (copy->flags & SAVEDVAR)\
138                                 interfaces[i][copy->type].flags |= SAVEDVAR;\
139                         }\
140                 i--;copy=copy->prev;\
141                 }\
142 }
143
144         
145 #define MARKREACHED(b,c) {\
146         if(b->flags<0)\
147                 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;}\
148         else {stackptr s=curstack;stackptr t=b->instack;\
149                 if(b->indepth!=stackdepth)\
150                         {show_icmd_method();panic("Stack depth mismatch");}\
151                 while(s){if (s->type!=t->type)\
152                                 TYPEPANIC\
153                         s=s->prev;t=t->prev;\
154                         }\
155                 }\
156 }
157
158
159 static void show_icmd_method();
160
161 static void analyse_stack()
162 {
163         int b_count, b_index;
164         int stackdepth;
165         stackptr curstack, new, copy;
166         int opcode, i, len, loops;
167         int superblockend, repeat, deadcode;
168         instruction *iptr = instr;
169         basicblock *bptr, *tbptr;
170         s4  *s4ptr;
171         
172         arguments_num = 0;
173         new = stack;
174         loops = 0;
175         block[0].flags = BBREACHED;
176         block[0].instack = 0;
177         block[0].indepth = 0;
178
179         for (i = 0; i < exceptiontablelength; i++) {
180                 bptr = &block[block_index[extable[i].handlerpc]];
181                 bptr->flags = BBREACHED;
182                 bptr->type = BBTYPE_EXH;
183                 bptr->instack = new;
184                 bptr->indepth = 1;
185                 bptr->pre_count = 10000;
186                 STACKRESET;
187                 NEWXSTACK;
188                 }
189
190 #ifdef CONDITIONAL_LOADCONST
191         b_count = block_count;
192         bptr = block;
193         while (--b_count >= 0) {
194                 if (bptr->icount != 0) {
195                         iptr = bptr->iinstr + bptr->icount - 1;
196                         switch (iptr->opc) {
197                                 case ICMD_RET:
198                                 case ICMD_RETURN:
199                                 case ICMD_IRETURN:
200                                 case ICMD_LRETURN:
201                                 case ICMD_FRETURN:
202                                 case ICMD_DRETURN:
203                                 case ICMD_ARETURN:
204                                 case ICMD_ATHROW:
205                                         break;
206
207                                 case ICMD_IFEQ:
208                                 case ICMD_IFNE:
209                                 case ICMD_IFLT:
210                                 case ICMD_IFGE:
211                                 case ICMD_IFGT:
212                                 case ICMD_IFLE:
213
214                                 case ICMD_IFNULL:
215                                 case ICMD_IFNONNULL:
216
217                                 case ICMD_IF_ICMPEQ:
218                                 case ICMD_IF_ICMPNE:
219                                 case ICMD_IF_ICMPLT:
220                                 case ICMD_IF_ICMPGE:
221                                 case ICMD_IF_ICMPGT:
222                                 case ICMD_IF_ICMPLE:
223
224                                 case ICMD_IF_ACMPEQ:
225                                 case ICMD_IF_ACMPNE:
226                                         bptr[1].pre_count++;
227                                 case ICMD_GOTO:
228                                         block[block_index[iptr->op1]].pre_count++;
229                                         break;
230
231                                 case ICMD_TABLESWITCH:
232                                         s4ptr = iptr->val.a;
233                                         block[block_index[*s4ptr++]].pre_count++;   /* default */
234                                         i = *s4ptr++;                               /* low     */
235                                         i = *s4ptr++ - i + 1;                       /* high    */
236                                         while (--i >= 0) {
237                                                 block[block_index[*s4ptr++]].pre_count++;
238                                                 }
239                                         break;
240                                         
241                                 case ICMD_LOOKUPSWITCH:
242                                         s4ptr = iptr->val.a;
243                                         block[block_index[*s4ptr++]].pre_count++;   /* default */
244                                         i = *s4ptr++;                               /* count   */
245                                         while (--i >= 0) {
246                                                 block[block_index[s4ptr[1]]].pre_count++;
247                                                 s4ptr += 2;
248                                                 }
249                                         break;
250                                 default:
251                                         bptr[1].pre_count++;
252                                         break;
253                                 }
254                         }
255                 bptr++;
256                 }
257 #endif
258
259
260         do {
261                 loops++;
262                 b_count = block_count;
263                 bptr = block;
264                 superblockend = true;
265                 repeat = false;
266                 STACKRESET;
267                 deadcode = true;
268                 while (--b_count >= 0) {
269                         if (bptr->flags == BBDELETED) {
270                                 /* do nothing */
271                                 }
272                         else if (superblockend && (bptr->flags < BBREACHED))
273                                 repeat = true;
274                         else if (bptr->flags <= BBREACHED) {
275                                 if (superblockend)
276                                         stackdepth = bptr->indepth;
277                                 else if (bptr->flags < BBREACHED) {
278                                         COPYCURSTACK(copy);
279                                         bptr->instack = copy;
280                                         bptr->indepth = stackdepth;
281                                         }
282                                 else if (bptr->indepth != stackdepth) {
283                                         show_icmd_method();
284                                         panic("Stack depth mismatch");
285                                         
286                                         }
287                                 curstack = bptr->instack;
288                                 deadcode = false;
289                                 superblockend = false;
290                                 bptr->flags = BBFINISHED;
291                                 len = bptr->icount;
292                                 iptr = bptr->iinstr;
293                                 b_index = bptr - block;
294                                 while (--len >= 0)  {
295                                         opcode = iptr->opc;
296                                         switch (opcode) {
297
298                                                 /* pop 0 push 0 */
299
300                                                 case ICMD_NOP:
301                                                 case ICMD_CHECKASIZE:
302
303                                                 case ICMD_IFEQ_ICONST:
304                                                 case ICMD_IFNE_ICONST:
305                                                 case ICMD_IFLT_ICONST:
306                                                 case ICMD_IFGE_ICONST:
307                                                 case ICMD_IFGT_ICONST:
308                                                 case ICMD_IFLE_ICONST:
309                                                 case ICMD_ELSE_ICONST:
310                                                         SETDST;
311                                                         break;
312
313                                                 case ICMD_RET:
314                                                         locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
315                                                 case ICMD_RETURN:
316                                                         COUNT(count_pcmd_return);
317                                                         SETDST;
318                                                         superblockend = true;
319                                                         break;
320
321                                                 /* pop 0 push 1 const */
322                                                 
323                                                 case ICMD_ICONST:
324                                                         COUNT(count_pcmd_load);
325                                                         if (len > 0) {
326                                                                 switch (iptr[1].opc) {
327                                                                         case ICMD_IADD:
328                                                                                 iptr[0].opc = ICMD_IADDCONST;
329 icmd_iconst_tail:
330                                                                                 iptr[1].opc = ICMD_NOP;
331                                                                                 OP1_1(TYPE_INT,TYPE_INT);
332                                                                                 COUNT(count_pcmd_op);
333                                                                                 break;
334                                                                         case ICMD_ISUB:
335                                                                                 iptr[0].opc = ICMD_ISUBCONST;
336                                                                                 goto icmd_iconst_tail;
337                                                                         case ICMD_IMUL:
338                                                                                 iptr[0].opc = ICMD_IMULCONST;
339                                                                                 goto icmd_iconst_tail;
340                                                                         case ICMD_IDIV:
341                                                                                 if (iptr[0].val.i == 0x00000002)
342                                                                                         iptr[0].val.i = 1;
343                                                                                 else if (iptr[0].val.i == 0x00000004)
344                                                                                         iptr[0].val.i = 2;
345                                                                                 else if (iptr[0].val.i == 0x00000008)
346                                                                                         iptr[0].val.i = 3;
347                                                                                 else if (iptr[0].val.i == 0x00000010)
348                                                                                         iptr[0].val.i = 4;
349                                                                                 else if (iptr[0].val.i == 0x00000020)
350                                                                                         iptr[0].val.i = 5;
351                                                                                 else if (iptr[0].val.i == 0x00000040)
352                                                                                         iptr[0].val.i = 6;
353                                                                                 else if (iptr[0].val.i == 0x00000080)
354                                                                                         iptr[0].val.i = 7;
355                                                                                 else if (iptr[0].val.i == 0x00000100)
356                                                                                         iptr[0].val.i = 8;
357                                                                                 else if (iptr[0].val.i == 0x00000200)
358                                                                                         iptr[0].val.i = 9;
359                                                                                 else if (iptr[0].val.i == 0x00000400)
360                                                                                         iptr[0].val.i = 10;
361                                                                                 else if (iptr[0].val.i == 0x00000800)
362                                                                                         iptr[0].val.i = 11;
363                                                                                 else if (iptr[0].val.i == 0x00001000)
364                                                                                         iptr[0].val.i = 12;
365                                                                                 else if (iptr[0].val.i == 0x00002000)
366                                                                                         iptr[0].val.i = 13;
367                                                                                 else if (iptr[0].val.i == 0x00004000)
368                                                                                         iptr[0].val.i = 14;
369                                                                                 else if (iptr[0].val.i == 0x00008000)
370                                                                                         iptr[0].val.i = 15;
371                                                                                 else if (iptr[0].val.i == 0x00010000)
372                                                                                         iptr[0].val.i = 16;
373                                                                                 else if (iptr[0].val.i == 0x00020000)
374                                                                                         iptr[0].val.i = 17;
375                                                                                 else if (iptr[0].val.i == 0x00040000)
376                                                                                         iptr[0].val.i = 18;
377                                                                                 else if (iptr[0].val.i == 0x00080000)
378                                                                                         iptr[0].val.i = 19;
379                                                                                 else if (iptr[0].val.i == 0x00100000)
380                                                                                         iptr[0].val.i = 20;
381                                                                                 else if (iptr[0].val.i == 0x00200000)
382                                                                                         iptr[0].val.i = 21;
383                                                                                 else if (iptr[0].val.i == 0x00400000)
384                                                                                         iptr[0].val.i = 22;
385                                                                                 else if (iptr[0].val.i == 0x00800000)
386                                                                                         iptr[0].val.i = 23;
387                                                                                 else if (iptr[0].val.i == 0x01000000)
388                                                                                         iptr[0].val.i = 24;
389                                                                                 else if (iptr[0].val.i == 0x02000000)
390                                                                                         iptr[0].val.i = 25;
391                                                                                 else if (iptr[0].val.i == 0x04000000)
392                                                                                         iptr[0].val.i = 26;
393                                                                                 else if (iptr[0].val.i == 0x08000000)
394                                                                                         iptr[0].val.i = 27;
395                                                                                 else if (iptr[0].val.i == 0x10000000)
396                                                                                         iptr[0].val.i = 28;
397                                                                                 else if (iptr[0].val.i == 0x20000000)
398                                                                                         iptr[0].val.i = 29;
399                                                                                 else if (iptr[0].val.i == 0x40000000)
400                                                                                         iptr[0].val.i = 30;
401                                                                                 else if (iptr[0].val.i == 0x80000000)
402                                                                                         iptr[0].val.i = 31;
403                                                                                 else {
404                                                                                         CONST(TYPE_INT);
405                                                                                         break;
406                                                                                         }
407                                                                                 iptr[0].opc = ICMD_IDIVPOW2;
408                                                                                 goto icmd_iconst_tail;
409                                                                         case ICMD_IREM:
410                                                                                 if (iptr[0].val.i == 0x10001) {
411                                                                                         iptr[0].opc = ICMD_IREM0X10001;
412                                                                                         goto icmd_iconst_tail;
413                                                                                         }
414                                                                                 if ((iptr[0].val.i == 0x00000002) ||
415                                                                                     (iptr[0].val.i == 0x00000004) ||
416                                                                                     (iptr[0].val.i == 0x00000008) ||
417                                                                                     (iptr[0].val.i == 0x00000010) ||
418                                                                                     (iptr[0].val.i == 0x00000020) ||
419                                                                                     (iptr[0].val.i == 0x00000040) ||
420                                                                                     (iptr[0].val.i == 0x00000080) ||
421                                                                                     (iptr[0].val.i == 0x00000100) ||
422                                                                                     (iptr[0].val.i == 0x00000200) ||
423                                                                                     (iptr[0].val.i == 0x00000400) ||
424                                                                                     (iptr[0].val.i == 0x00000800) ||
425                                                                                     (iptr[0].val.i == 0x00001000) ||
426                                                                                     (iptr[0].val.i == 0x00002000) ||
427                                                                                     (iptr[0].val.i == 0x00004000) ||
428                                                                                     (iptr[0].val.i == 0x00008000) ||
429                                                                                     (iptr[0].val.i == 0x00010000) ||
430                                                                                     (iptr[0].val.i == 0x00020000) ||
431                                                                                     (iptr[0].val.i == 0x00040000) ||
432                                                                                     (iptr[0].val.i == 0x00080000) ||
433                                                                                     (iptr[0].val.i == 0x00100000) ||
434                                                                                     (iptr[0].val.i == 0x00200000) ||
435                                                                                     (iptr[0].val.i == 0x00400000) ||
436                                                                                     (iptr[0].val.i == 0x00800000) ||
437                                                                                     (iptr[0].val.i == 0x01000000) ||
438                                                                                     (iptr[0].val.i == 0x02000000) ||
439                                                                                     (iptr[0].val.i == 0x04000000) ||
440                                                                                     (iptr[0].val.i == 0x08000000) ||
441                                                                                     (iptr[0].val.i == 0x10000000) ||
442                                                                                     (iptr[0].val.i == 0x20000000) ||
443                                                                                     (iptr[0].val.i == 0x40000000) ||
444                                                                                     (iptr[0].val.i == 0x80000000)) {
445                                                                                         iptr[0].opc = ICMD_IREMPOW2;
446                                                                                         iptr[0].val.i -= 1;
447                                                                                         goto icmd_iconst_tail;
448                                                                                         }
449                                                                                 CONST(TYPE_INT);
450                                                                                 break;
451                                                                         case ICMD_IAND:
452                                                                                 iptr[0].opc = ICMD_IANDCONST;
453                                                                                 goto icmd_iconst_tail;
454                                                                         case ICMD_IOR:
455                                                                                 iptr[0].opc = ICMD_IORCONST;
456                                                                                 goto icmd_iconst_tail;
457                                                                         case ICMD_IXOR:
458                                                                                 iptr[0].opc = ICMD_IXORCONST;
459                                                                                 goto icmd_iconst_tail;
460                                                                         case ICMD_ISHL:
461                                                                                 iptr[0].opc = ICMD_ISHLCONST;
462                                                                                 goto icmd_iconst_tail;
463                                                                         case ICMD_ISHR:
464                                                                                 iptr[0].opc = ICMD_ISHRCONST;
465                                                                                 goto icmd_iconst_tail;
466                                                                         case ICMD_IUSHR:
467                                                                                 iptr[0].opc = ICMD_IUSHRCONST;
468                                                                                 goto icmd_iconst_tail;
469                                                                         case ICMD_IF_ICMPEQ:
470                                                                                 iptr[0].opc = ICMD_IFEQ;
471 icmd_if_icmp_tail:
472                                                                                 iptr[0].op1 = iptr[1].op1;
473                                                                                 bptr->icount--;
474                                                                                 len--;
475                                                                                 /* iptr[1].opc = ICMD_NOP; */
476                                                                                 OP1_0(TYPE_INT);
477                                                                                 tbptr = block + block_index[iptr->op1];
478                                                                                 MARKREACHED(tbptr, copy);
479                                                                                 COUNT(count_pcmd_bra);
480                                                                                 break;
481                                                                         case ICMD_IF_ICMPLT:
482                                                                                 iptr[0].opc = ICMD_IFLT;
483                                                                                 goto icmd_if_icmp_tail;
484                                                                         case ICMD_IF_ICMPLE:
485                                                                                 iptr[0].opc = ICMD_IFLE;
486                                                                                 goto icmd_if_icmp_tail;
487                                                                         case ICMD_IF_ICMPNE:
488                                                                                 iptr[0].opc = ICMD_IFNE;
489                                                                                 goto icmd_if_icmp_tail;
490                                                                         case ICMD_IF_ICMPGT:
491                                                                                 iptr[0].opc = ICMD_IFGT;
492                                                                                 goto icmd_if_icmp_tail;
493                                                                         case ICMD_IF_ICMPGE:
494                                                                                 iptr[0].opc = ICMD_IFGE;
495                                                                                 goto icmd_if_icmp_tail;
496                                                                         default:
497                                                                                 CONST(TYPE_INT);
498                                                                         }
499                                                                 }
500                                                         else
501                                                                 CONST(TYPE_INT);
502                                                         break;
503                                                 case ICMD_LCONST:
504                                                         COUNT(count_pcmd_load);
505                                                         if (len > 0) {
506                                                                 switch (iptr[1].opc) {
507                                                                         case ICMD_LADD:
508                                                                                 iptr[0].opc = ICMD_LADDCONST;
509 icmd_lconst_tail:
510                                                                                 iptr[1].opc = ICMD_NOP;
511                                                                                 OP1_1(TYPE_LNG,TYPE_LNG);
512                                                                                 COUNT(count_pcmd_op);
513                                                                                 break;
514                                                                         case ICMD_LSUB:
515                                                                                 iptr[0].opc = ICMD_LSUBCONST;
516                                                                                 goto icmd_lconst_tail;
517                                                                         case ICMD_LMUL:
518                                                                                 iptr[0].opc = ICMD_LMULCONST;
519                                                                                 goto icmd_lconst_tail;
520                                                                         case ICMD_LDIV:
521                                                                                 if (iptr[0].val.l == 0x00000002)
522                                                                                         iptr[0].val.l = 1;
523                                                                                 else if (iptr[0].val.l == 0x00000004)
524                                                                                         iptr[0].val.l = 2;
525                                                                                 else if (iptr[0].val.l == 0x00000008)
526                                                                                         iptr[0].val.l = 3;
527                                                                                 else if (iptr[0].val.l == 0x00000010)
528                                                                                         iptr[0].val.l = 4;
529                                                                                 else if (iptr[0].val.l == 0x00000020)
530                                                                                         iptr[0].val.l = 5;
531                                                                                 else if (iptr[0].val.l == 0x00000040)
532                                                                                         iptr[0].val.l = 6;
533                                                                                 else if (iptr[0].val.l == 0x00000080)
534                                                                                         iptr[0].val.l = 7;
535                                                                                 else if (iptr[0].val.l == 0x00000100)
536                                                                                         iptr[0].val.l = 8;
537                                                                                 else if (iptr[0].val.l == 0x00000200)
538                                                                                         iptr[0].val.l = 9;
539                                                                                 else if (iptr[0].val.l == 0x00000400)
540                                                                                         iptr[0].val.l = 10;
541                                                                                 else if (iptr[0].val.l == 0x00000800)
542                                                                                         iptr[0].val.l = 11;
543                                                                                 else if (iptr[0].val.l == 0x00001000)
544                                                                                         iptr[0].val.l = 12;
545                                                                                 else if (iptr[0].val.l == 0x00002000)
546                                                                                         iptr[0].val.l = 13;
547                                                                                 else if (iptr[0].val.l == 0x00004000)
548                                                                                         iptr[0].val.l = 14;
549                                                                                 else if (iptr[0].val.l == 0x00008000)
550                                                                                         iptr[0].val.l = 15;
551                                                                                 else if (iptr[0].val.l == 0x00010000)
552                                                                                         iptr[0].val.l = 16;
553                                                                                 else if (iptr[0].val.l == 0x00020000)
554                                                                                         iptr[0].val.l = 17;
555                                                                                 else if (iptr[0].val.l == 0x00040000)
556                                                                                         iptr[0].val.l = 18;
557                                                                                 else if (iptr[0].val.l == 0x00080000)
558                                                                                         iptr[0].val.l = 19;
559                                                                                 else if (iptr[0].val.l == 0x00100000)
560                                                                                         iptr[0].val.l = 20;
561                                                                                 else if (iptr[0].val.l == 0x00200000)
562                                                                                         iptr[0].val.l = 21;
563                                                                                 else if (iptr[0].val.l == 0x00400000)
564                                                                                         iptr[0].val.l = 22;
565                                                                                 else if (iptr[0].val.l == 0x00800000)
566                                                                                         iptr[0].val.l = 23;
567                                                                                 else if (iptr[0].val.l == 0x01000000)
568                                                                                         iptr[0].val.l = 24;
569                                                                                 else if (iptr[0].val.l == 0x02000000)
570                                                                                         iptr[0].val.l = 25;
571                                                                                 else if (iptr[0].val.l == 0x04000000)
572                                                                                         iptr[0].val.l = 26;
573                                                                                 else if (iptr[0].val.l == 0x08000000)
574                                                                                         iptr[0].val.l = 27;
575                                                                                 else if (iptr[0].val.l == 0x10000000)
576                                                                                         iptr[0].val.l = 28;
577                                                                                 else if (iptr[0].val.l == 0x20000000)
578                                                                                         iptr[0].val.l = 29;
579                                                                                 else if (iptr[0].val.l == 0x40000000)
580                                                                                         iptr[0].val.l = 30;
581                                                                                 else if (iptr[0].val.l == 0x80000000)
582                                                                                         iptr[0].val.l = 31;
583                                                                                 else {
584                                                                                         CONST(TYPE_LNG);
585                                                                                         break;
586                                                                                         }
587                                                                                 iptr[0].opc = ICMD_LDIVPOW2;
588                                                                                 goto icmd_lconst_tail;
589                                                                         case ICMD_LREM:
590                                                                                 if (iptr[0].val.l == 0x10001) {
591                                                                                         iptr[0].opc = ICMD_LREM0X10001;
592                                                                                         goto icmd_lconst_tail;
593                                                                                         }
594                                                                                 if ((iptr[0].val.l == 0x00000002) ||
595                                                                                     (iptr[0].val.l == 0x00000004) ||
596                                                                                     (iptr[0].val.l == 0x00000008) ||
597                                                                                     (iptr[0].val.l == 0x00000010) ||
598                                                                                     (iptr[0].val.l == 0x00000020) ||
599                                                                                     (iptr[0].val.l == 0x00000040) ||
600                                                                                     (iptr[0].val.l == 0x00000080) ||
601                                                                                     (iptr[0].val.l == 0x00000100) ||
602                                                                                     (iptr[0].val.l == 0x00000200) ||
603                                                                                     (iptr[0].val.l == 0x00000400) ||
604                                                                                     (iptr[0].val.l == 0x00000800) ||
605                                                                                     (iptr[0].val.l == 0x00001000) ||
606                                                                                     (iptr[0].val.l == 0x00002000) ||
607                                                                                     (iptr[0].val.l == 0x00004000) ||
608                                                                                     (iptr[0].val.l == 0x00008000) ||
609                                                                                     (iptr[0].val.l == 0x00010000) ||
610                                                                                     (iptr[0].val.l == 0x00020000) ||
611                                                                                     (iptr[0].val.l == 0x00040000) ||
612                                                                                     (iptr[0].val.l == 0x00080000) ||
613                                                                                     (iptr[0].val.l == 0x00100000) ||
614                                                                                     (iptr[0].val.l == 0x00200000) ||
615                                                                                     (iptr[0].val.l == 0x00400000) ||
616                                                                                     (iptr[0].val.l == 0x00800000) ||
617                                                                                     (iptr[0].val.l == 0x01000000) ||
618                                                                                     (iptr[0].val.l == 0x02000000) ||
619                                                                                     (iptr[0].val.l == 0x04000000) ||
620                                                                                     (iptr[0].val.l == 0x08000000) ||
621                                                                                     (iptr[0].val.l == 0x10000000) ||
622                                                                                     (iptr[0].val.l == 0x20000000) ||
623                                                                                     (iptr[0].val.l == 0x40000000) ||
624                                                                                     (iptr[0].val.l == 0x80000000)) {
625                                                                                         iptr[0].opc = ICMD_LREMPOW2;
626                                                                                         iptr[0].val.l -= 1;
627                                                                                         goto icmd_lconst_tail;
628                                                                                         }
629                                                                                 CONST(TYPE_LNG);
630                                                                                 break;
631                                                                         case ICMD_LAND:
632                                                                                 iptr[0].opc = ICMD_LANDCONST;
633                                                                                 goto icmd_lconst_tail;
634                                                                         case ICMD_LOR:
635                                                                                 iptr[0].opc = ICMD_LORCONST;
636                                                                                 goto icmd_lconst_tail;
637                                                                         case ICMD_LXOR:
638                                                                                 iptr[0].opc = ICMD_LXORCONST;
639                                                                                 goto icmd_lconst_tail;
640                                                                         case ICMD_LSHL:
641                                                                                 iptr[0].opc = ICMD_LSHLCONST;
642                                                                                 goto icmd_lconst_tail;
643                                                                         case ICMD_LSHR:
644                                                                                 iptr[0].opc = ICMD_LSHRCONST;
645                                                                                 goto icmd_lconst_tail;
646                                                                         case ICMD_LUSHR:
647                                                                                 iptr[0].opc = ICMD_LUSHRCONST;
648                                                                                 goto icmd_lconst_tail;
649                                                                         case ICMD_LCMP:
650                                                                                 if ((len > 1) && (iptr[2].val.i == 0)) {
651                                                                                         switch (iptr[2].opc) {
652                                                                                         case ICMD_IFEQ:
653                                                                                                 iptr[0].opc = ICMD_IF_LEQ;
654 icmd_lconst_lcmp_tail:
655                                                                                                 iptr[0].op1 = iptr[2].op1;
656                                                                                                 bptr->icount -= 2;
657                                                                                                 len -= 2;
658                                                                                                 /* iptr[1].opc = ICMD_NOP;
659                                                                                                 iptr[2].opc = ICMD_NOP; */
660                                                                                                 OP1_0(TYPE_LNG);
661                                                                                                 tbptr = block + block_index[iptr->op1];
662                                                                                                 MARKREACHED(tbptr, copy);
663                                                                                                 COUNT(count_pcmd_bra);
664                                                                                                 COUNT(count_pcmd_op);
665                                                                                                 break;
666                                                                                         case ICMD_IFNE:
667                                                                                                 iptr[0].opc = ICMD_IF_LNE;
668                                                                                                 goto icmd_lconst_lcmp_tail;
669                                                                                         case ICMD_IFLT:
670                                                                                                 iptr[0].opc = ICMD_IF_LLT;
671                                                                                                 goto icmd_lconst_lcmp_tail;
672                                                                                         case ICMD_IFGT:
673                                                                                                 iptr[0].opc = ICMD_IF_LGT;
674                                                                                                 goto icmd_lconst_lcmp_tail;
675                                                                                         case ICMD_IFLE:
676                                                                                                 iptr[0].opc = ICMD_IF_LLE;
677                                                                                                 goto icmd_lconst_lcmp_tail;
678                                                                                         case ICMD_IFGE:
679                                                                                                 iptr[0].opc = ICMD_IF_LGE;
680                                                                                                 goto icmd_lconst_lcmp_tail;
681                                                                                         default:
682                                                                                                 CONST(TYPE_LNG);
683                                                                                         } /* switch (iptr[2].opc) */
684                                                                                         } /* if (iptr[2].val.i == 0) */
685                                                                                 else
686                                                                                         CONST(TYPE_LNG);
687                                                                                 break;
688                                                                         default:
689                                                                                 CONST(TYPE_LNG);
690                                                                         }
691                                                                 }
692                                                         else
693                                                                 CONST(TYPE_LNG);
694                                                         break;
695                                                 case ICMD_FCONST:
696                                                         COUNT(count_pcmd_load);
697                                                         CONST(TYPE_FLT);
698                                                         break;
699                                                 case ICMD_DCONST:
700                                                         COUNT(count_pcmd_load);
701                                                         CONST(TYPE_DBL);
702                                                         break;
703                                                 case ICMD_ACONST:
704                                                         COUNT(count_pcmd_load);
705                                                         CONST(TYPE_ADR);
706                                                         break;
707
708                                                 /* pop 0 push 1 load */
709                                                 
710                                                 case ICMD_ILOAD:
711                                                 case ICMD_LLOAD:
712                                                 case ICMD_FLOAD:
713                                                 case ICMD_DLOAD:
714                                                 case ICMD_ALOAD:
715                                                         COUNT(count_load_instruction);
716                                                         i = opcode-ICMD_ILOAD;
717                                                         locals[iptr->op1][i].type = i;
718                                                         LOAD(i, LOCALVAR, iptr->op1);
719                                                         break;
720
721                                                 /* pop 2 push 1 */
722
723                                                 case ICMD_IALOAD:
724                                                 case ICMD_LALOAD:
725                                                 case ICMD_FALOAD:
726                                                 case ICMD_DALOAD:
727                                                 case ICMD_AALOAD:
728                                                         COUNT(count_check_null);
729                                                         COUNT(count_check_bound);
730                                                         COUNT(count_pcmd_mem);
731                                                         OP2IAT_1(opcode-ICMD_IALOAD);
732                                                         break;
733
734                                                 case ICMD_BALOAD:
735                                                 case ICMD_CALOAD:
736                                                 case ICMD_SALOAD:
737                                                         COUNT(count_check_null);
738                                                         COUNT(count_check_bound);
739                                                         COUNT(count_pcmd_mem);
740                                                         OP2IAT_1(TYPE_INT);
741                                                         break;
742
743                                                 /* pop 0 push 0 iinc */
744
745                                                 case ICMD_IINC:
746 #ifdef STATISTICS
747                                                         i = stackdepth;
748                                                         if (i >= 10)
749                                                                 count_store_depth[10]++;
750                                                         else
751                                                                 count_store_depth[i]++;
752 #endif
753                                                         copy = curstack;
754                                                         i = stackdepth - 1;
755                                                         while (copy) {
756                                                                 if ((copy->varkind == LOCALVAR) &&
757                                                                     (copy->varnum == curstack->varnum)) {
758                                                                         copy->varkind = TEMPVAR;
759                                                                         copy->varnum = i;
760                                                                         }
761                                                                 i--;
762                                                                 copy = copy->prev;
763                                                                 }
764                                                         SETDST;
765                                                         break;
766
767                                                 /* pop 1 push 0 store */
768
769                                                 case ICMD_ISTORE:
770                                                 case ICMD_LSTORE:
771                                                 case ICMD_FSTORE:
772                                                 case ICMD_DSTORE:
773                                                 case ICMD_ASTORE:
774                                                         i = opcode-ICMD_ISTORE;
775                                                         locals[iptr->op1][i].type = i;
776 #ifdef STATISTICS
777                                                         count_pcmd_store++;
778                                                         i = new - curstack;
779                                                         if (i >= 20)
780                                                                 count_store_length[20]++;
781                                                         else
782                                                                 count_store_length[i]++;
783                                                         i = stackdepth - 1;
784                                                         if (i >= 10)
785                                                                 count_store_depth[10]++;
786                                                         else
787                                                                 count_store_depth[i]++;
788 #endif
789                                                         copy = curstack->prev;
790                                                         i = stackdepth - 2;
791                                                         while (copy) {
792                                                                 if ((copy->varkind == LOCALVAR) &&
793                                                                     (copy->varnum == curstack->varnum)) {
794                                                                         copy->varkind = TEMPVAR;
795                                                                         copy->varnum = i;
796                                                                         }
797                                                                 i--;
798                                                                 copy = copy->prev;
799                                                                 }
800                                                         if ((new - curstack) == 1) {
801                                                                 curstack->varkind = LOCALVAR;
802                                                                 curstack->varnum = iptr->op1;
803                                                                 };
804                                                         STORE(opcode-ICMD_ISTORE);
805                                                         break;
806
807                                                 /* pop 3 push 0 */
808
809                                                 case ICMD_IASTORE:
810                                                 case ICMD_LASTORE:
811                                                 case ICMD_FASTORE:
812                                                 case ICMD_DASTORE:
813                                                 case ICMD_AASTORE:
814                                                         COUNT(count_check_null);
815                                                         COUNT(count_check_bound);
816                                                         COUNT(count_pcmd_mem);
817                                                         OP3TIA_0(opcode-ICMD_IASTORE);
818                                                         break;
819                                                 case ICMD_BASTORE:
820                                                 case ICMD_CASTORE:
821                                                 case ICMD_SASTORE:
822                                                         COUNT(count_check_null);
823                                                         COUNT(count_check_bound);
824                                                         COUNT(count_pcmd_mem);
825                                                         OP3TIA_0(TYPE_INT);
826                                                         break;
827
828                                                 /* pop 1 push 0 */
829
830                                                 case ICMD_POP:
831                                                         OP1_0ANY;
832                                                         break;
833
834                                                 case ICMD_IRETURN:
835                                                 case ICMD_LRETURN:
836                                                 case ICMD_FRETURN:
837                                                 case ICMD_DRETURN:
838                                                 case ICMD_ARETURN:
839                                                         COUNT(count_pcmd_return);
840                                                         OP1_0(opcode-ICMD_IRETURN);
841                                                         superblockend = true;
842                                                         break;
843
844                                                 case ICMD_ATHROW:
845                                                         COUNT(count_check_null);
846                                                         OP1_0(TYPE_ADR);
847                                                         STACKRESET;
848                                                         SETDST;
849                                                         superblockend = true;
850                                                         break;
851
852                                                 case ICMD_PUTSTATIC:
853                                                         COUNT(count_pcmd_mem);
854                                                         OP1_0(iptr->op1);
855                                                         break;
856
857                                                 /* pop 1 push 0 branch */
858
859                                                 case ICMD_IFNULL:
860                                                 case ICMD_IFNONNULL:
861                                                         COUNT(count_pcmd_bra);
862                                                         OP1_0(TYPE_ADR);
863                                                         tbptr = block + block_index[iptr->op1];
864                                                         MARKREACHED(tbptr, copy);
865                                                         break;
866
867                                                 case ICMD_IFEQ:
868                                                 case ICMD_IFNE:
869                                                 case ICMD_IFLT:
870                                                 case ICMD_IFGE:
871                                                 case ICMD_IFGT:
872                                                 case ICMD_IFLE:
873                                                         COUNT(count_pcmd_bra);
874 #ifdef CONDITIONAL_LOADCONST
875                                                         {
876                                                         tbptr = block + b_index;
877                                                         if ((b_count >= 3) &&
878                                                             ((b_index + 2) == block_index[iptr[0].op1]) &&
879                                                             (tbptr[1].pre_count == 1) &&
880                                                             (iptr[1].opc == ICMD_ICONST) &&
881                                                             (iptr[2].opc == ICMD_GOTO)   &&
882                                                             ((b_index + 3) == block_index[iptr[2].op1]) &&
883                                                             (tbptr[2].pre_count == 1) &&
884                                                             (iptr[3].opc == ICMD_ICONST)) {
885                                                                 OP1_1(TYPE_INT, TYPE_INT);
886                                                                 switch (iptr[0].opc) {
887                                                                         case ICMD_IFEQ:
888                                                                                 iptr[0].opc = ICMD_IFNE_ICONST;
889                                                                                 break;
890                                                                         case ICMD_IFNE:
891                                                                                 iptr[0].opc = ICMD_IFEQ_ICONST;
892                                                                                 break;
893                                                                         case ICMD_IFLT:
894                                                                                 iptr[0].opc = ICMD_IFGE_ICONST;
895                                                                                 break;
896                                                                         case ICMD_IFGE:
897                                                                                 iptr[0].opc = ICMD_IFLT_ICONST;
898                                                                                 break;
899                                                                         case ICMD_IFGT:
900                                                                                 iptr[0].opc = ICMD_IFLE_ICONST;
901                                                                                 break;
902                                                                         case ICMD_IFLE:
903                                                                                 iptr[0].opc = ICMD_IFGT_ICONST;
904                                                                                 break;
905                                                                         }
906                                                                 iptr[0].val.i = iptr[1].val.i;
907                                                                 iptr[1].opc = ICMD_ELSE_ICONST;
908                                                                 iptr[1].val.i = iptr[3].val.i;
909                                                                 iptr[2].opc = ICMD_NOP;
910                                                                 iptr[3].opc = ICMD_NOP;
911                                                                 tbptr[1].flags = BBDELETED;
912                                                                 tbptr[2].flags = BBDELETED;
913                                                                 tbptr[1].icount = 0;
914                                                                 tbptr[2].icount = 0;
915                                                                 if (tbptr[3].pre_count == 2) {
916                                                                         len += tbptr[3].icount + 3;
917                                                                         bptr->icount += tbptr[3].icount + 3;
918                                                                         tbptr[3].flags = BBDELETED;
919                                                                         tbptr[3].icount = 0;
920                                                                         b_index++;
921                                                                         }
922                                                                 else {
923                                                                         bptr->icount++;
924                                                                         len ++;
925                                                                         }
926                                                                 b_index += 2;
927                                                                 break;
928                                                                 }
929                                                         }
930 #endif
931                                                         OP1_0(TYPE_INT);
932                                                         tbptr = block + block_index[iptr->op1];
933                                                         MARKREACHED(tbptr, copy);
934                                                         break;
935
936                                                 /* pop 0 push 0 branch */
937
938                                                 case ICMD_GOTO:
939                                                         COUNT(count_pcmd_bra);
940                                                         tbptr = block + block_index[iptr->op1];
941                                                         MARKREACHED(tbptr, copy);
942                                                         SETDST;
943                                                         superblockend = true;
944                                                         break;
945
946                                                 /* pop 1 push 0 table branch */
947
948                                                 case ICMD_TABLESWITCH:
949                                                         COUNT(count_pcmd_table);
950                                                         OP1_0(TYPE_INT);
951                                                         s4ptr = iptr->val.a;
952                                                         tbptr = block + block_index[*s4ptr++]; /* default */
953                                                         MARKREACHED(tbptr, copy);
954                                                         i = *s4ptr++;                          /* low     */
955                                                         i = *s4ptr++ - i + 1;                  /* high    */
956                                                         while (--i >= 0) {
957                                                                 tbptr = block + block_index[*s4ptr++];
958                                                                 MARKREACHED(tbptr, copy);
959                                                                 }
960                                                         SETDST;
961                                                         superblockend = true;
962                                                         break;
963                                                         
964                                                 /* pop 1 push 0 table branch */
965
966                                                 case ICMD_LOOKUPSWITCH:
967                                                         COUNT(count_pcmd_table);
968                                                         OP1_0(TYPE_INT);
969                                                         s4ptr = iptr->val.a;
970                                                         tbptr = block + block_index[*s4ptr++]; /* default */
971                                                         MARKREACHED(tbptr, copy);
972                                                         i = *s4ptr++;                          /* count   */
973                                                         while (--i >= 0) {
974                                                                 tbptr = block + block_index[s4ptr[1]];
975                                                                 MARKREACHED(tbptr, copy);
976                                                                 s4ptr += 2;
977                                                                 }
978                                                         SETDST;
979                                                         superblockend = true;
980                                                         break;
981
982                                                 case ICMD_NULLCHECKPOP:
983                                                 case ICMD_MONITORENTER:
984                                                         COUNT(count_check_null);
985                                                 case ICMD_MONITOREXIT:
986                                                         OP1_0(TYPE_ADR);
987                                                         break;
988
989                                                 /* pop 2 push 0 branch */
990
991                                                 case ICMD_IF_ICMPEQ:
992                                                 case ICMD_IF_ICMPNE:
993                                                 case ICMD_IF_ICMPLT:
994                                                 case ICMD_IF_ICMPGE:
995                                                 case ICMD_IF_ICMPGT:
996                                                 case ICMD_IF_ICMPLE:
997                                                         COUNT(count_pcmd_bra);
998                                                         OP2_0(TYPE_INT);
999                                                         tbptr = block + block_index[iptr->op1];
1000                                                         MARKREACHED(tbptr, copy);
1001                                                         break;
1002
1003                                                 case ICMD_IF_ACMPEQ:
1004                                                 case ICMD_IF_ACMPNE:
1005                                                         COUNT(count_pcmd_bra);
1006                                                         OP2_0(TYPE_ADR);
1007                                                         tbptr = block + block_index[iptr->op1];
1008                                                         MARKREACHED(tbptr, copy);
1009                                                         break;
1010
1011                                                 /* pop 2 push 0 */
1012
1013                                                 case ICMD_PUTFIELD:
1014                                                         COUNT(count_check_null);
1015                                                         COUNT(count_pcmd_mem);
1016                                                         OPTT2_0(iptr->op1,TYPE_ADR);
1017                                                         break;
1018
1019                                                 case ICMD_POP2:
1020                                                         if (! IS_2_WORD_TYPE(curstack->type)) {
1021                                                                 OP1_0ANY;                /* second pop */
1022                                                                 }
1023                                                         else
1024                                                                 iptr->opc = ICMD_POP;
1025                                                         OP1_0ANY;
1026                                                         break;
1027
1028                                                 /* pop 0 push 1 dup */
1029                                                 
1030                                                 case ICMD_DUP:
1031                                                         COUNT(count_dup_instruction);
1032                                                         DUP;
1033                                                         break;
1034
1035                                                 case ICMD_DUP2:
1036                                                         if (IS_2_WORD_TYPE(curstack->type)) {
1037                                                                 iptr->opc = ICMD_DUP;
1038                                                                 DUP;
1039                                                                 }
1040                                                         else {
1041                                                                 copy = curstack;
1042                                                                 NEWSTACK(copy[-1].type, copy[-1].varkind,
1043                                                                          copy[-1].varnum);
1044                                                                 NEWSTACK(copy[ 0].type, copy[ 0].varkind,
1045                                                                          copy[ 0].varnum);
1046                                                                 SETDST;
1047                                                                 stackdepth+=2;
1048                                                                 }
1049                                                         break;
1050
1051                                                 /* pop 2 push 3 dup */
1052                                                 
1053                                                 case ICMD_DUP_X1:
1054                                                         DUP_X1;
1055                                                         break;
1056
1057                                                 case ICMD_DUP2_X1:
1058                                                         if (IS_2_WORD_TYPE(curstack->type)) {
1059                                                                 iptr->opc = ICMD_DUP_X1;
1060                                                                 DUP_X1;
1061                                                                 }
1062                                                         else {
1063                                                                 DUP2_X1;
1064                                                                 }
1065                                                         break;
1066
1067                                                 /* pop 3 push 4 dup */
1068                                                 
1069                                                 case ICMD_DUP_X2:
1070                                                         if (IS_2_WORD_TYPE(curstack[-1].type)) {
1071                                                                 iptr->opc = ICMD_DUP_X1;
1072                                                                 DUP_X1;
1073                                                                 }
1074                                                         else {
1075                                                                 DUP_X2;
1076                                                                 }
1077                                                         break;
1078
1079                                                 case ICMD_DUP2_X2:
1080                                                         if (IS_2_WORD_TYPE(curstack->type)) {
1081                                                                 if (IS_2_WORD_TYPE(curstack[-1].type)) {
1082                                                                         iptr->opc = ICMD_DUP_X1;
1083                                                                         DUP_X1;
1084                                                                         }
1085                                                                 else {
1086                                                                         iptr->opc = ICMD_DUP_X2;
1087                                                                         DUP_X2;
1088                                                                         }
1089                                                                 }
1090                                                         else
1091                                                                 if (IS_2_WORD_TYPE(curstack[-2].type)) {
1092                                                                         iptr->opc = ICMD_DUP2_X1;
1093                                                                         DUP2_X1;
1094                                                                         }
1095                                                                 else {
1096                                                                         DUP2_X2;
1097                                                                         }
1098                                                         break;
1099
1100                                                 /* pop 2 push 2 swap */
1101                                                 
1102                                                 case ICMD_SWAP:
1103                                                         SWAP;
1104                                                         break;
1105
1106                                                 /* pop 2 push 1 */
1107                                                 
1108                                                 case ICMD_IDIV:
1109                                                         if (!(SUPPORT_DIVISION)) {
1110                                                                 iptr[0].opc = ICMD_BUILTIN2;
1111                                                                 iptr[0].op1 = TYPE_INT;
1112                                                                 iptr[0].val.a = (functionptr) asm_builtin_idiv;
1113                                                                 isleafmethod = false;
1114                                                                 goto builtin2;
1115                                                                 }
1116
1117                                                 case ICMD_LDIV:
1118                                                         if (!(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_MULDIV)) {
1119                                                                 iptr[0].opc = ICMD_BUILTIN2;
1120                                                                 iptr[0].op1 = TYPE_LNG;
1121                                                                 iptr[0].val.a = (functionptr) asm_builtin_ldiv;
1122                                                                 isleafmethod = false;
1123                                                                 goto builtin2;
1124                                                                 }
1125
1126                                                 case ICMD_IREM:
1127                                                         if (!(SUPPORT_DIVISION)) {
1128                                                                 iptr[0].opc = ICMD_BUILTIN2;
1129                                                                 iptr[0].op1 = TYPE_INT;
1130                                                                 iptr[0].val.a = (functionptr) asm_builtin_irem;
1131                                                                 isleafmethod = false;
1132                                                                 goto builtin2;
1133                                                                 }
1134
1135                                                 case ICMD_LREM:
1136                                                         if (!(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_MULDIV)) {
1137                                                                 iptr[0].opc = ICMD_BUILTIN2;
1138                                                                 iptr[0].op1 = TYPE_LNG;
1139                                                                 iptr[0].val.a = (functionptr) asm_builtin_lrem;
1140                                                                 isleafmethod = false;
1141                                                                 goto builtin2;
1142                                                                 }
1143
1144                                                 case ICMD_IADD:
1145                                                 case ICMD_ISUB:
1146                                                 case ICMD_IMUL:
1147
1148                                                 case ICMD_ISHL:
1149                                                 case ICMD_ISHR:
1150                                                 case ICMD_IUSHR:
1151                                                 case ICMD_IAND:
1152                                                 case ICMD_IOR:
1153                                                 case ICMD_IXOR:
1154                                                         COUNT(count_pcmd_op);
1155                                                         OP2_1(TYPE_INT);
1156                                                         break;
1157
1158                                                 case ICMD_LADD:
1159                                                 case ICMD_LSUB:
1160                                                 case ICMD_LMUL:
1161
1162                                                 case ICMD_LOR:
1163                                                 case ICMD_LAND:
1164                                                 case ICMD_LXOR:
1165                                                         COUNT(count_pcmd_op);
1166                                                         OP2_1(TYPE_LNG);
1167                                                         break;
1168
1169                                                 case ICMD_LSHL:
1170                                                 case ICMD_LSHR:
1171                                                 case ICMD_LUSHR:
1172                                                         COUNT(count_pcmd_op);
1173                                                         OP2IT_1(TYPE_LNG);
1174                                                         break;
1175
1176                                                 case ICMD_FADD:
1177                                                 case ICMD_FSUB:
1178                                                 case ICMD_FMUL:
1179                                                 case ICMD_FDIV:
1180                                                 case ICMD_FREM:
1181                                                         COUNT(count_pcmd_op);
1182                                                         OP2_1(TYPE_FLT);
1183                                                         break;
1184
1185                                                 case ICMD_DADD:
1186                                                 case ICMD_DSUB:
1187                                                 case ICMD_DMUL:
1188                                                 case ICMD_DDIV:
1189                                                 case ICMD_DREM:
1190                                                         COUNT(count_pcmd_op);
1191                                                         OP2_1(TYPE_DBL);
1192                                                         break;
1193
1194                                                 case ICMD_LCMP:
1195                                                         COUNT(count_pcmd_op);
1196                                                         if ((len > 0) && (iptr[1].val.i == 0)) {
1197                                                                 switch (iptr[1].opc) {
1198                                                                         case ICMD_IFEQ:
1199                                                                                 iptr[0].opc = ICMD_IF_LCMPEQ;
1200 icmd_lcmp_if_tail:
1201                                                                                 iptr[0].op1 = iptr[1].op1;
1202                                                                                 len--;
1203                                                                                 bptr->icount--;
1204                                                                                 /* iptr[1].opc = ICMD_NOP; */
1205                                                                                 OP2_0(TYPE_LNG);
1206                                                                                 tbptr = block + block_index[iptr->op1];
1207                                                                                 MARKREACHED(tbptr, copy);
1208                                                                                 COUNT(count_pcmd_bra);
1209                                                                                 break;
1210                                                                         case ICMD_IFNE:
1211                                                                                 iptr[0].opc = ICMD_IF_LCMPNE;
1212                                                                                 goto icmd_lcmp_if_tail;
1213                                                                         case ICMD_IFLT:
1214                                                                                 iptr[0].opc = ICMD_IF_LCMPLT;
1215                                                                                 goto icmd_lcmp_if_tail;
1216                                                                         case ICMD_IFGT:
1217                                                                                 iptr[0].opc = ICMD_IF_LCMPGT;
1218                                                                                 goto icmd_lcmp_if_tail;
1219                                                                         case ICMD_IFLE:
1220                                                                                 iptr[0].opc = ICMD_IF_LCMPLE;
1221                                                                                 goto icmd_lcmp_if_tail;
1222                                                                         case ICMD_IFGE:
1223                                                                                 iptr[0].opc = ICMD_IF_LCMPGE;
1224                                                                                 goto icmd_lcmp_if_tail;
1225                                                                         default:
1226                                                                                 OPTT2_1(TYPE_LNG, TYPE_INT);
1227                                                                         }
1228                                                                 }
1229                                                         else
1230                                                                 OPTT2_1(TYPE_LNG, TYPE_INT);
1231                                                         break;
1232                                                 case ICMD_FCMPL:
1233                                                 case ICMD_FCMPG:
1234                                                         COUNT(count_pcmd_op);
1235                                                         OPTT2_1(TYPE_FLT, TYPE_INT);
1236                                                         break;
1237                                                 case ICMD_DCMPL:
1238                                                 case ICMD_DCMPG:
1239                                                         COUNT(count_pcmd_op);
1240                                                         OPTT2_1(TYPE_DBL, TYPE_INT);
1241                                                         break;
1242
1243                                                 /* pop 1 push 1 */
1244                                                 
1245                                                 case ICMD_INEG:
1246                                                 case ICMD_INT2BYTE:
1247                                                 case ICMD_INT2CHAR:
1248                                                 case ICMD_INT2SHORT:
1249                                                         COUNT(count_pcmd_op);
1250                                                         OP1_1(TYPE_INT, TYPE_INT);
1251                                                         break;
1252                                                 case ICMD_LNEG:
1253                                                         COUNT(count_pcmd_op);
1254                                                         OP1_1(TYPE_LNG, TYPE_LNG);
1255                                                         break;
1256                                                 case ICMD_FNEG:
1257                                                         COUNT(count_pcmd_op);
1258                                                         OP1_1(TYPE_FLT, TYPE_FLT);
1259                                                         break;
1260                                                 case ICMD_DNEG:
1261                                                         COUNT(count_pcmd_op);
1262                                                         OP1_1(TYPE_DBL, TYPE_DBL);
1263                                                         break;
1264
1265                                                 case ICMD_I2L:
1266                                                         COUNT(count_pcmd_op);
1267                                                         OP1_1(TYPE_INT, TYPE_LNG);
1268                                                         break;
1269                                                 case ICMD_I2F:
1270                                                         COUNT(count_pcmd_op);
1271                                                         OP1_1(TYPE_INT, TYPE_FLT);
1272                                                         break;
1273                                                 case ICMD_I2D:
1274                                                         COUNT(count_pcmd_op);
1275                                                         OP1_1(TYPE_INT, TYPE_DBL);
1276                                                         break;
1277                                                 case ICMD_L2I:
1278                                                         COUNT(count_pcmd_op);
1279                                                         OP1_1(TYPE_LNG, TYPE_INT);
1280                                                         break;
1281                                                 case ICMD_L2F:
1282                                                         COUNT(count_pcmd_op);
1283                                                         OP1_1(TYPE_LNG, TYPE_FLT);
1284                                                         break;
1285                                                 case ICMD_L2D:
1286                                                         COUNT(count_pcmd_op);
1287                                                         OP1_1(TYPE_LNG, TYPE_DBL);
1288                                                         break;
1289                                                 case ICMD_F2I:
1290                                                         COUNT(count_pcmd_op);
1291                                                         OP1_1(TYPE_FLT, TYPE_INT);
1292                                                         break;
1293                                                 case ICMD_F2L:
1294                                                         COUNT(count_pcmd_op);
1295                                                         OP1_1(TYPE_FLT, TYPE_LNG);
1296                                                         break;
1297                                                 case ICMD_F2D:
1298                                                         COUNT(count_pcmd_op);
1299                                                         OP1_1(TYPE_FLT, TYPE_DBL);
1300                                                         break;
1301                                                 case ICMD_D2I:
1302                                                         COUNT(count_pcmd_op);
1303                                                         OP1_1(TYPE_DBL, TYPE_INT);
1304                                                         break;
1305                                                 case ICMD_D2L:
1306                                                         COUNT(count_pcmd_op);
1307                                                         OP1_1(TYPE_DBL, TYPE_LNG);
1308                                                         break;
1309                                                 case ICMD_D2F:
1310                                                         COUNT(count_pcmd_op);
1311                                                         OP1_1(TYPE_DBL, TYPE_FLT);
1312                                                         break;
1313
1314                                                 case ICMD_CHECKCAST:
1315                                                         OP1_1(TYPE_ADR, TYPE_ADR);
1316                                                         break;
1317
1318                                                 case ICMD_ARRAYLENGTH:
1319                                                 case ICMD_INSTANCEOF:
1320                                                         OP1_1(TYPE_ADR, TYPE_INT);
1321                                                         break;
1322
1323                                                 case ICMD_NEWARRAY:
1324                                                 case ICMD_ANEWARRAY:
1325                                                         OP1_1(TYPE_INT, TYPE_ADR);
1326                                                         break;
1327
1328                                                 case ICMD_GETFIELD:
1329                                                         COUNT(count_check_null);
1330                                                         COUNT(count_pcmd_mem);
1331                                                         OP1_1(TYPE_ADR, iptr->op1);
1332                                                         break;
1333
1334                                                 /* pop 0 push 1 */
1335                                                 
1336                                                 case ICMD_GETSTATIC:
1337                                                         COUNT(count_pcmd_mem);
1338                                                         OP0_1(iptr->op1);
1339                                                         break;
1340
1341                                                 case ICMD_NEW:
1342                                                         OP0_1(TYPE_ADR);
1343                                                         break;
1344
1345                                                 case ICMD_JSR:
1346                                                         OP0_1(TYPE_ADR);
1347                                                         tbptr = block + block_index[iptr->op1];
1348                                                         tbptr->type=BBTYPE_SBR;
1349                                                         MARKREACHED(tbptr, copy);
1350                                                         OP1_0ANY;
1351                                                         break;
1352
1353                                                 /* pop many push any */
1354                                                 
1355                                                 case ICMD_INVOKEVIRTUAL:
1356                                                 case ICMD_INVOKESPECIAL:
1357                                                 case ICMD_INVOKEINTERFACE:
1358                                                 case ICMD_INVOKESTATIC:
1359                                                         COUNT(count_pcmd_met);
1360                                                         {
1361                                                         methodinfo *m = iptr->val.a;
1362                                                         if (m->flags & ACC_STATIC)
1363                                                                 {COUNT(count_check_null);}
1364                                                         i = iptr->op1;
1365                                                         if (i > arguments_num)
1366                                                                 arguments_num = i;
1367                                                         copy = curstack;
1368                                                         while (--i >= 0) {
1369                                                                 if (! (copy->flags & SAVEDVAR)) {
1370                                                                         copy->varkind = ARGVAR;
1371                                                                         copy->varnum = i;
1372                                                                         }
1373                                                                 copy = copy->prev;
1374                                                                 }
1375                                                         while (copy) {
1376                                                                 copy->flags |= SAVEDVAR;
1377                                                                 copy = copy->prev;
1378                                                                 }
1379                                                         i = iptr->op1;
1380                                                         POPMANY(i);
1381                                                         if (m->returntype != TYPE_VOID) {
1382                                                                 OP0_1(m->returntype);
1383                                                                 }
1384                                                         break;
1385                                                         }
1386
1387                                                 case ICMD_BUILTIN3:
1388                                                         if (! (curstack->flags & SAVEDVAR)) {
1389                                                                 curstack->varkind = ARGVAR;
1390                                                                 curstack->varnum = 2;
1391                                                                 }
1392                                                         OP1_0ANY;
1393                                                 case ICMD_BUILTIN2:
1394 builtin2:
1395                                                         if (! (curstack->flags & SAVEDVAR)) {
1396                                                                 curstack->varkind = ARGVAR;
1397                                                                 curstack->varnum = 1;
1398                                                                 }
1399                                                         OP1_0ANY;
1400                                                 case ICMD_BUILTIN1:
1401                                                         if (! (curstack->flags & SAVEDVAR)) {
1402                                                                 curstack->varkind = ARGVAR;
1403                                                                 curstack->varnum = 0;
1404                                                                 }
1405                                                         OP1_0ANY;
1406                                                         copy = curstack;
1407                                                         while (copy) {
1408                                                                 copy->flags |= SAVEDVAR;
1409                                                                 copy = copy->prev;
1410                                                                 }
1411                                                         if (iptr->op1 != TYPE_VOID)
1412                                                                 OP0_1(iptr->op1);
1413                                                         break;
1414
1415                                                 case ICMD_MULTIANEWARRAY:
1416                                                         i = iptr->op1;
1417                                                         if ((i + intreg_argnum) > arguments_num)
1418                                                                 arguments_num = i + intreg_argnum;
1419                                                         copy = curstack;
1420                                                         while (--i >= 0) {
1421                                                                 if (! (copy->flags & SAVEDVAR)) {
1422                                                                         copy->varkind = ARGVAR;
1423                                                                         copy->varnum = i + intreg_argnum;
1424                                                                         }
1425                                                                 copy = copy->prev;
1426                                                                 }
1427                                                         while (copy) {
1428                                                                 copy->flags |= SAVEDVAR;
1429                                                                 copy = copy->prev;
1430                                                                 }
1431                                                         i = iptr->op1;
1432                                                         POPMANY(i);
1433                                                         OP0_1(TYPE_ADR);
1434                                                         break;
1435
1436                                                 default:
1437                                                         printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1438                                                         panic("Missing ICMD code during stack analysis");
1439                                                 } /* switch */
1440                                         iptr++;
1441                                         } /* while instructions */
1442                                 bptr->outstack = curstack;
1443                                 bptr->outdepth = stackdepth;
1444                                 BBEND(curstack, i);
1445                                 } /* if */
1446                         else
1447                                 superblockend = true;
1448                         bptr++;
1449                 } /* while blocks */
1450         } while (repeat && ! deadcode);
1451
1452 #ifdef STATISTICS
1453         if (block_count > count_max_basic_blocks)
1454                 count_max_basic_blocks = block_count;
1455         count_basic_blocks += block_count;
1456         if ((block[block_count].iinstr - instr) > count_max_javainstr)
1457                 count_max_javainstr = block[block_count].iinstr - instr;
1458         count_javainstr += block[block_count].iinstr - instr;
1459         if (stack_count > count_upper_bound_new_stack)
1460                 count_upper_bound_new_stack = stack_count;
1461         if ((new - stack) > count_max_new_stack)
1462                 count_max_new_stack = (new - stack);
1463
1464         b_count = block_count;
1465         bptr = block;
1466         while (--b_count >= 0) {
1467                 if (bptr->flags > BBREACHED) {
1468                         if (bptr->indepth >= 10)
1469                                 count_block_stack[10]++;
1470                         else
1471                                 count_block_stack[bptr->indepth]++;
1472                         len = bptr->icount;
1473                         if (len <= 10) 
1474                                 count_block_size_distribution[len - 1]++;
1475                         else if (len <= 12)
1476                                 count_block_size_distribution[10]++;
1477                         else if (len <= 14)
1478                                 count_block_size_distribution[11]++;
1479                         else if (len <= 16)
1480                                 count_block_size_distribution[12]++;
1481                         else if (len <= 18)
1482                                 count_block_size_distribution[13]++;
1483                         else if (len <= 20)
1484                                 count_block_size_distribution[14]++;
1485                         else if (len <= 25)
1486                                 count_block_size_distribution[15]++;
1487                         else if (len <= 30)
1488                                 count_block_size_distribution[16]++;
1489                         else
1490                                 count_block_size_distribution[17]++;
1491                         }
1492                 bptr++;
1493                 }
1494
1495         if (loops == 1)
1496                 count_analyse_iterations[0]++;
1497         else if (loops == 2)
1498                 count_analyse_iterations[1]++;
1499         else if (loops == 3)
1500                 count_analyse_iterations[2]++;
1501         else if (loops == 4)
1502                 count_analyse_iterations[3]++;
1503         else
1504                 count_analyse_iterations[4]++;
1505
1506         if (block_count <= 5)
1507                 count_method_bb_distribution[0]++;
1508         else if (block_count <= 10)
1509                 count_method_bb_distribution[1]++;
1510         else if (block_count <= 15)
1511                 count_method_bb_distribution[2]++;
1512         else if (block_count <= 20)
1513                 count_method_bb_distribution[3]++;
1514         else if (block_count <= 30)
1515                 count_method_bb_distribution[4]++;
1516         else if (block_count <= 40)
1517                 count_method_bb_distribution[5]++;
1518         else if (block_count <= 50)
1519                 count_method_bb_distribution[6]++;
1520         else if (block_count <= 75)
1521                 count_method_bb_distribution[7]++;
1522         else
1523                 count_method_bb_distribution[8]++;
1524 #endif
1525 }
1526
1527
1528 static void print_stack(stackptr s) {
1529         int i, j;
1530         stackptr t;
1531
1532         i = maxstack;
1533         t = s;
1534         
1535         while (t) {
1536                 i--;
1537                 t = t->prev;
1538                 }
1539         j = maxstack - i;
1540         while (--i >= 0)
1541                 printf("    ");
1542         while (s) {
1543                 j--;
1544                 if (s->flags & SAVEDVAR)
1545                         switch (s->varkind) {
1546                                 case TEMPVAR:
1547                                         if (s->flags & INMEMORY)
1548                                                 printf(" m%02d", s->regoff);
1549                                         else
1550                                                 printf(" r%02d", s->regoff);
1551                                         break;
1552                                 case STACKVAR:
1553                                         printf(" s%02d", s->varnum);
1554                                         break;
1555                                 case LOCALVAR:
1556                                         printf(" l%02d", s->varnum);
1557                                         break;
1558                                 case ARGVAR:
1559                                         printf(" a%02d", s->varnum);
1560                                         break;
1561                                 default:
1562                                         printf(" !%02d", j);
1563                                 }
1564                 else
1565                         switch (s->varkind) {
1566                                 case TEMPVAR:
1567                                         if (s->flags & INMEMORY)
1568                                                 printf(" M%02d", s->regoff);
1569                                         else
1570                                                 printf(" R%02d", s->regoff);
1571                                         break;
1572                                 case STACKVAR:
1573                                         printf(" S%02d", s->varnum);
1574                                         break;
1575                                 case LOCALVAR:
1576                                         printf(" L%02d", s->varnum);
1577                                         break;
1578                                 case ARGVAR:
1579                                         printf(" A%02d", s->varnum);
1580                                         break;
1581                                 default:
1582                                         printf(" ?%02d", j);
1583                                 }
1584                 s = s->prev;
1585                 }
1586 }
1587
1588
1589 static void print_reg(stackptr s) {
1590         if (s) {
1591                 if (s->flags & SAVEDVAR)
1592                         switch (s->varkind) {
1593                                 case TEMPVAR:
1594                                         if (s->flags & INMEMORY)
1595                                                 printf(" tm%02d", s->regoff);
1596                                         else
1597                                                 printf(" tr%02d", s->regoff);
1598                                         break;
1599                                 case STACKVAR:
1600                                         printf(" s %02d", s->varnum);
1601                                         break;
1602                                 case LOCALVAR:
1603                                         printf(" l %02d", s->varnum);
1604                                         break;
1605                                 case ARGVAR:
1606                                         printf(" a %02d", s->varnum);
1607                                         break;
1608                                 default:
1609                                         printf(" ! %02d", s->varnum);
1610                                 }
1611                 else
1612                         switch (s->varkind) {
1613                                 case TEMPVAR:
1614                                         if (s->flags & INMEMORY)
1615                                                 printf(" Tm%02d", s->regoff);
1616                                         else
1617                                                 printf(" Tr%02d", s->regoff);
1618                                         break;
1619                                 case STACKVAR:
1620                                         printf(" S %02d", s->varnum);
1621                                         break;
1622                                 case LOCALVAR:
1623                                         printf(" L %02d", s->varnum);
1624                                         break;
1625                                 case ARGVAR:
1626                                         printf(" A %02d", s->varnum);
1627                                         break;
1628                                 default:
1629                                         printf(" ? %02d", s->varnum);
1630                                 }
1631                 }
1632         else
1633                 printf("     ");
1634                 
1635 }
1636
1637
1638 static char *builtin_name(functionptr bptr)
1639 {
1640         builtin_descriptor *bdesc = builtin_desc;
1641         while ((bdesc->bptr != NULL) && (bdesc->bptr != bptr))
1642                 bdesc++;
1643         return bdesc->name;
1644 }
1645
1646
1647 static void show_icmd_method()
1648 {
1649         int b, i, j, last;
1650         int deadcode;
1651         s4  *s4ptr;
1652         instruction *iptr;
1653         
1654         printf("\n");
1655         unicode_fprint(stdout, class->name);
1656         printf(".");
1657         unicode_fprint(stdout, method->name);
1658         printf(" ");
1659         unicode_fprint(stdout, method->descriptor);
1660         printf ("\n\nMax locals: %d\n", (int) maxlocals);
1661         printf ("Max stack:  %d\n", (int) maxstack);
1662
1663         printf ("Exceptions:\n");
1664         for (i = 0; i < exceptiontablelength; i++) {
1665                 printf("    L%03d ... ", block_index[extable[i].startpc]);
1666                 printf("L%03d = ", block_index[extable[i].endpc]);
1667                 printf("L%03d\n", block_index[extable[i].handlerpc]);
1668                 }
1669         
1670         printf ("Local Table:\n");
1671         for (i = 0; i < maxlocals; i++) {
1672                 printf("   %3d: ", i);
1673                 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1674                         if (locals[i][j].type >= 0) {
1675                                 printf("   (%d) ", j);
1676                                 if (locals[i][j].flags)
1677                                         printf("m");
1678                                 else
1679                                         printf("r");
1680                                 printf("%2d", locals[i][j].regoff);
1681                                 }
1682                 printf("\n");
1683                 }
1684         printf("\n");
1685
1686         printf ("Interface Table:\n");
1687         for (i = 0; i < maxstack; i++) {
1688                 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
1689                     (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
1690                     (interfaces[i][4].type >= 0)) {
1691                         printf("   %3d: ", i);
1692                         for (j = TYPE_INT; j <= TYPE_ADR; j++)
1693                                 if (interfaces[i][j].type >= 0) {
1694                                         printf("   (%d) ", j);
1695                                         if (interfaces[i][j].flags & SAVEDVAR)
1696                                                 printf("s");
1697                                         else
1698                                                 printf("t");
1699                                         if (interfaces[i][j].flags & INMEMORY)
1700                                                 printf("m");
1701                                         else
1702                                                 printf("r");
1703                                         printf("%2d", interfaces[i][j].regoff);
1704                                         }
1705                         printf("\n");
1706                         }
1707                 }
1708         printf("\n");
1709
1710         if (showdisassemble) {
1711                 s4ptr = (s4 *) (method->mcode + dseglen);
1712                 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
1713                         disasscmd (*s4ptr, i); 
1714                         }
1715                 printf("\n");
1716                 }
1717
1718         for (b = 0; b < block_count; b++)
1719                 if (block[b].flags != BBDELETED) {
1720                 deadcode = block[b].flags <= BBREACHED;
1721                 printf("[");
1722                 if (deadcode)
1723                         for (j = maxstack; j > 0; j--)
1724                                 printf(" ?  ");
1725                 else
1726                         print_stack(block[b].instack);
1727                 printf("] L%03d(%d):\n", b, block[b].pre_count);
1728                 iptr = block[b].iinstr;
1729                 i = iptr - instr;
1730                 for (last = i + block[b].icount; i < last; i++, iptr++) {
1731                         printf("[");
1732                         if (deadcode) {
1733                                 for (j = maxstack; j > 0; j--)
1734                                         printf(" ?  ");
1735                                 }
1736                         else
1737                                 print_stack(iptr->dst);
1738                         printf("]     %4d  %s", i, icmd_names[iptr->opc]);
1739                         switch ((int) iptr->opc) {
1740                                 case ICMD_IADDCONST:
1741                                 case ICMD_ISUBCONST:
1742                                 case ICMD_IMULCONST:
1743                                 case ICMD_IDIVPOW2:
1744                                 case ICMD_IREMPOW2:
1745                                 case ICMD_IREM0X10001:
1746                                 case ICMD_IANDCONST:
1747                                 case ICMD_IORCONST:
1748                                 case ICMD_IXORCONST:
1749                                 case ICMD_ISHLCONST:
1750                                 case ICMD_ISHRCONST:
1751                                 case ICMD_IUSHRCONST:
1752                                 case ICMD_ICONST:
1753                                 case ICMD_ELSE_ICONST:
1754                                 case ICMD_IFEQ_ICONST:
1755                                 case ICMD_IFNE_ICONST:
1756                                 case ICMD_IFLT_ICONST:
1757                                 case ICMD_IFGE_ICONST:
1758                                 case ICMD_IFGT_ICONST:
1759                                 case ICMD_IFLE_ICONST:
1760                                         printf(" %d", iptr->val.i);
1761                                         break;
1762                                 case ICMD_LADDCONST:
1763                                 case ICMD_LSUBCONST:
1764                                 case ICMD_LMULCONST:
1765                                 case ICMD_LDIVPOW2:
1766                                 case ICMD_LREMPOW2:
1767                                 case ICMD_LANDCONST:
1768                                 case ICMD_LORCONST:
1769                                 case ICMD_LXORCONST:
1770                                 case ICMD_LSHLCONST:
1771                                 case ICMD_LSHRCONST:
1772                                 case ICMD_LUSHRCONST:
1773                                 case ICMD_LCONST:
1774                                         printf(" %ld", iptr->val.l);
1775                                         break;
1776                                 case ICMD_FCONST:
1777                                         printf(" %f", iptr->val.f);
1778                                         break;
1779                                 case ICMD_DCONST:
1780                                         printf(" %f", iptr->val.d);
1781                                         break;
1782                                 case ICMD_ACONST:
1783                                         printf(" %p", iptr->val.a);
1784                                         break;
1785                                 case ICMD_GETFIELD:
1786                                 case ICMD_PUTFIELD:
1787                                         printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
1788                                 case ICMD_PUTSTATIC:
1789                                 case ICMD_GETSTATIC:
1790                                         printf(" ");
1791                                         unicode_fprint(stdout,
1792                                                         ((fieldinfo *) iptr->val.a)->name);
1793                                         break;
1794                                 case ICMD_IINC:
1795                                         printf(" %d + %d", iptr->op1, iptr->val.i);
1796                                         break;
1797                                 case ICMD_RET:
1798                                 case ICMD_ILOAD:
1799                                 case ICMD_LLOAD:
1800                                 case ICMD_FLOAD:
1801                                 case ICMD_DLOAD:
1802                                 case ICMD_ALOAD:
1803                                 case ICMD_ISTORE:
1804                                 case ICMD_LSTORE:
1805                                 case ICMD_FSTORE:
1806                                 case ICMD_DSTORE:
1807                                 case ICMD_ASTORE:
1808                                         printf(" %d", iptr->op1);
1809                                         break;
1810                                 case ICMD_NEW:
1811                                         printf(" ");
1812                                         unicode_fprint(stdout,
1813                                                        ((classinfo *) iptr->val.a)->name);
1814                                         break;
1815                                 case ICMD_NEWARRAY:
1816                                         switch (iptr->op1) {
1817                                                 case 4:
1818                                                         printf(" boolean");
1819                                                         break;
1820                                                 case 5:
1821                                                         printf(" char");
1822                                                         break;
1823                                                 case 6:
1824                                                         printf(" float");
1825                                                         break;
1826                                                 case 7:
1827                                                         printf(" double");
1828                                                         break;
1829                                                 case 8:
1830                                                         printf(" byte");
1831                                                         break;
1832                                                 case 9:
1833                                                         printf(" short");
1834                                                         break;
1835                                                 case 10:
1836                                                         printf(" int");
1837                                                         break;
1838                                                 case 11:
1839                                                         printf(" long");
1840                                                         break;
1841                                                 }
1842                                         break;
1843                                 case ICMD_ANEWARRAY:
1844                                         if (iptr->op1) {
1845                                                 printf(" ");
1846                                                 unicode_fprint(stdout,
1847                                                                ((classinfo *) iptr->val.a)->name);
1848                                                 }
1849                                         break;
1850                                 case ICMD_CHECKCAST:
1851                                 case ICMD_INSTANCEOF:
1852                                         if (iptr->op1) {
1853                                                 classinfo *c = iptr->val.a;
1854                                                 if (c->flags & ACC_INTERFACE)
1855                                                         printf(" (INTERFACE) ");
1856                                                 else
1857                                                         printf(" (CLASS,%3d) ", c->vftbl->diffval);
1858                                                 unicode_fprint(stdout, c->name);
1859                                                 }
1860                                         break;
1861                                 case ICMD_BUILTIN3:
1862                                 case ICMD_BUILTIN2:
1863                                 case ICMD_BUILTIN1:
1864                                         printf(" %s", builtin_name((functionptr) iptr->val.a));
1865                                         break;
1866                                 case ICMD_INVOKEVIRTUAL:
1867                                 case ICMD_INVOKESPECIAL:
1868                                 case ICMD_INVOKESTATIC:
1869                                 case ICMD_INVOKEINTERFACE:
1870                                         printf(" ");
1871                                         unicode_fprint(stdout,
1872                                                        ((methodinfo *) iptr->val.a)->class->name);
1873                                         printf(".");
1874                                         unicode_fprint(stdout,
1875                                                        ((methodinfo *) iptr->val.a)->name);
1876                                         break;
1877                                 case ICMD_IFEQ:
1878                                 case ICMD_IFNE:
1879                                 case ICMD_IFLT:
1880                                 case ICMD_IFGE:
1881                                 case ICMD_IFGT:
1882                                 case ICMD_IFLE:
1883                                 case ICMD_IF_LEQ:
1884                                 case ICMD_IF_LNE:
1885                                 case ICMD_IF_LLT:
1886                                 case ICMD_IF_LGE:
1887                                 case ICMD_IF_LGT:
1888                                 case ICMD_IF_LLE:
1889                                         printf("(%d) L%03d", iptr->val.i, block_index[iptr->op1]);
1890                                         break;
1891                                 case ICMD_JSR:
1892                                 case ICMD_GOTO:
1893                                 case ICMD_IFNULL:
1894                                 case ICMD_IFNONNULL:
1895                                 case ICMD_IF_ICMPEQ:
1896                                 case ICMD_IF_ICMPNE:
1897                                 case ICMD_IF_ICMPLT:
1898                                 case ICMD_IF_ICMPGE:
1899                                 case ICMD_IF_ICMPGT:
1900                                 case ICMD_IF_ICMPLE:
1901                                 case ICMD_IF_LCMPEQ:
1902                                 case ICMD_IF_LCMPNE:
1903                                 case ICMD_IF_LCMPLT:
1904                                 case ICMD_IF_LCMPGE:
1905                                 case ICMD_IF_LCMPGT:
1906                                 case ICMD_IF_LCMPLE:
1907                                 case ICMD_IF_ACMPEQ:
1908                                 case ICMD_IF_ACMPNE:
1909                                         printf(" L%03d", block_index[iptr->op1]);
1910                                         break;
1911                                 case ICMD_TABLESWITCH:
1912                                         s4ptr = iptr->val.a;
1913                                         printf(" L%03d;", block_index[*s4ptr++]); /* default */
1914                                         j = *s4ptr++;                               /* low     */
1915                                         j = *s4ptr++ - j;                           /* high    */
1916                                         while (j >= 0) {
1917                                                 printf(" L%03d", block_index[*s4ptr++]);
1918                                                 j--;
1919                                                 }
1920                                         break;
1921                                 case ICMD_LOOKUPSWITCH:
1922                                         s4ptr = iptr->val.a;
1923                                         printf(" L%d", block_index[*s4ptr++]);   /* default */
1924                                         j = *s4ptr++;                               /* count   */
1925                                         while (--j >= 0) {
1926                                                 printf(" L%03d", block_index[s4ptr[1]]);
1927                                                 s4ptr += 2;
1928                                                 }
1929                                         break;
1930                                 }
1931                         printf("\n");
1932                         }
1933
1934                 if (showdisassemble && (!deadcode)) {
1935                         printf("\n");
1936                         i = block[b].mpc;
1937                         s4ptr = (s4 *) (method->mcode + dseglen + i);
1938                         for (; i < block[b + 1].mpc; i += 4, s4ptr++) {
1939                                 disasscmd (*s4ptr, i); 
1940                                 }
1941                         printf("\n");
1942                         }
1943         }
1944         i = block[b].mpc;
1945         s4ptr = (s4 *) (method->mcode + dseglen + i);
1946         if (showdisassemble && (s4ptr < (s4 *) (method->mcode + method->mcodelength))) {
1947                 printf("\n");
1948                 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
1949                         disasscmd (*s4ptr, i); 
1950                         }
1951                 printf("\n");
1952                 }
1953 }