Initial revision
[cacao.git] / ncomp / nblock.c
1 /***************************** ncomp/nblock.c **********************************
2
3         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5         See file COPYRIGHT for information on usage and disclaimer of warranties
6
7         Basic block handling functions.
8
9         Authors: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
10                  Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
11
12         Last Change: 1997/11/05
13
14 *******************************************************************************/
15
16
17 /******************** function determine_basic_blocks **************************
18
19         Scans the JavaVM code of a method and marks each instruction which is the
20         start of a basic block.
21         
22 *******************************************************************************/
23
24 static void allocate_literals()
25 {
26         int  p, nextp;
27         int  opcode, i;
28
29         p = 0;
30         while (p < jcodelength) {
31
32                 opcode = jcode[p];
33                 nextp = p + jcommandsize[opcode];
34
35                 switch (opcode) {
36                         case JAVA_WIDE:
37                                 switch (code_get_u1(p + 1)) {
38                                         case JAVA_RET:  nextp = p + 4;
39                                                         break;
40                                         case JAVA_IINC: nextp = p + 6;
41                                                         break;
42                                         default:        nextp = p + 4;
43                                                         break;
44                                         }
45                                 break;
46                                                         
47                         case JAVA_LOOKUPSWITCH:
48                                 {
49                                 s4 num;
50
51                                 nextp = ALIGN((p + 1), 4);
52                                 num = code_get_u4(nextp + 4);
53                                 nextp = nextp + 8 + 8 * num;
54                                 break;
55                                 }
56
57                         case JAVA_TABLESWITCH:
58                                 {
59                                 s4 num;
60
61                                 nextp = ALIGN ((p + 1),4);
62                                 num = code_get_s4(nextp + 4);
63                                 num = code_get_s4(nextp + 8) - num;
64                                 nextp = nextp + 16 + 4 * num;
65                                 break;
66                                 }       
67
68                         case JAVA_LDC1:
69                                 i = code_get_u1(p+1);
70                                 goto pushconstantitem;
71                         case JAVA_LDC2:
72                         case JAVA_LDC2W:
73                                 i = code_get_u2(p + 1);
74                         pushconstantitem:
75                                 if (class_constanttype(class, i) == CONSTANT_String) {
76                                         unicode *s;
77                                         s = class_getconstant(class, i, CONSTANT_String);
78                                         (void) literalstring_new(s);
79                                         }
80                                 break;
81                         } /* end switch */
82
83                 p = nextp;
84
85                 } /* end while */
86
87 }