Initial revision
[cacao.git] / comp / local.c
1 /**************************** comp/local.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         behandeln der lokalen Java-Variablen
8
9         Authors: Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
10
11         Last Change: 1996/11/14
12
13 *******************************************************************************/
14
15         /* es werden f"ur die lokalen Java-Variablen 5 Tabellen angelegt,
16            f"ur jeden m"oglichen Typ eine, weil mehrere Java-Variablen 
17            verschiendenen Typs die selben Slots belegen k"onnen */
18
19 varid *locals[5];
20
21
22 /*********************** Funktion: local_get **********************************
23
24         erzeugt eine neue Pseudo-Variable f"ur einen JavaVM-Slot und einen
25         gew"unschten Typ, oder eine bereits vorhandene Variable.
26
27 ******************************************************************************/
28
29 static varid local_get (int slot, int type)
30 {
31         varid v;
32         int   secondslot;
33         
34         secondslot = ((type==TYPE_DOUBLE) || (type==TYPE_LONG)) ? 1 : 0;
35
36         if (slot+secondslot>=maxlocals) 
37                 panic ("Local-variable access out of bounds");
38         v = locals[type][slot];
39
40         if (v==NULL) {
41                 v = var_createwithspecialnumber (type, slot);
42                 v -> globalscope = true;
43                 locals[type][slot] = v;
44                 }
45
46         return v;
47 }
48
49
50
51
52 /************************* Funktion: local_init *******************************
53         
54         legt die 5 Tabellen an, und erzeugt auch gleich die Belegungen
55         f"ur die Methodenparameter.
56
57 ******************************************************************************/
58
59 static void local_init()
60 {
61         int t, i, slot;
62         
63         if (TYPE_INT != 0 || TYPE_ADDRESS != 4) 
64           panic ("JAVA-Basictypes have been changed");
65                 
66         for (t=TYPE_INT; t<=TYPE_ADDRESS; t++) {
67                 locals[t] = DMNEW (varid, maxlocals);
68                 for (i=0; i<maxlocals; i++) locals[t][i] = NULL;
69                 }
70
71
72         slot =0;
73         for (i=0; i<mparamnum; i++) {
74                 t = mparamtypes[i];
75                 mparamvars[i] = local_get (slot, t);
76                 slot += ((t==TYPE_DOUBLE || t==TYPE_LONG) ? 2 : 1);
77                 }
78 }
79
80
81 /************************ Funktion: local_regalloc ****************************
82
83         f"uhrt die Registerbelegung f"ur die lokalen Java-Variablen durch
84         
85 ******************************************************************************/
86         
87
88 static void local_regalloc ()
89 {
90         int   s, t;
91         varid v;
92         
93         for (s=0; s<maxlocals; s++) 
94                 for (t=TYPE_INT; t<=TYPE_ADDRESS; t++) {
95                         v = locals[t][s];
96                         if (v) {
97                                 if (! isleafmethod)
98                                         var_makesaved (v);
99                                 if (v->reg == NULL)
100                                         v->reg = reg_allocate (v->type, v->saved, true);
101                                 }
102                         }
103 }
104