1 /***************************** comp/tools.c ************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Ein paar zus"atzlich notwendige Funktionen, die sonst nirgends
10 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
12 Last Change: 1996/11/14
14 *******************************************************************************/
17 /***************** Funktion: compiler_addinitclass ****************************
19 zum Eintragen einer Klasse in die Liste der noch zu initialisierenden
22 ******************************************************************************/
24 void compiler_addinitclass (classinfo *c)
28 if (c->initialized) return;
30 cl = chain_first(uninitializedclasses);
35 cl = chain_next(uninitializedclasses);
41 sprintf(logtext, "compiler_addinitclass: ");
42 unicode_sprint(logtext+strlen(logtext), c->name);
45 chain_addlast(uninitializedclasses, c);
50 sprintf(logtext, "compiler_addinitclass: ");
51 unicode_sprint(logtext+strlen(logtext), c->name);
54 chain_addbefore(uninitializedclasses, c);
57 cl = chain_next(uninitializedclasses);
63 /***************** Hilfsfunktionen zum Decodieren des Bytecodes ***************
65 lesen ein Datum des gew"unschten Typs aus dem Bytecode an der
68 ******************************************************************************/
70 static u1 code_get_u1 (u4 pos)
75 static s1 code_get_s1 (u4 pos)
77 return code_get_u1 (pos);
80 static u2 code_get_u2 (u4 pos)
82 return ( ((u2) jcode[pos]) << 8 ) + jcode[pos+1];
85 static s2 code_get_s2 (u4 pos)
87 return code_get_u2 (pos);
90 static u4 code_get_u4 (u4 pos)
92 return ( ((u4) jcode[pos]) << 24 )
93 + ( ((u4) jcode[pos+1]) << 16 )
94 + ( ((u4) jcode[pos+2]) << 8 )
98 static s4 code_get_s4 (u4 pos)
100 return code_get_u4 (pos);
105 /******************** Funktion: descriptor2types *****************************
107 Decodiert einen Methoddescriptor.
108 Beim Aufruf dieser Funktion MUSS (!!!) der Descriptor ein
109 gueltiges Format haben (wird eh vorher vom loader ueberprueft).
111 Die Funktion erzeugt ein Array von integers (u2), in das die
112 Parametertypen eingetragen werden, und liefert einen Zeiger auf
113 das Array in einem Referenzparameter ('paramtypes') zur"uck.
114 Die L"ange dieses Arrays und der Methodenr"uckgabewert werden ebenfalls
115 in Referenzparametern zur"uckgeliefert.
117 Der Parameter 'isstatic' gibt an (wenn true), dass kein zus"atzlicher
118 erster Eintrag f"ur den this-Zeiger in das Array eingetragen
119 werden soll (sonst wird er n"amlich automatisch erzeugt, mit dem
122 ******************************************************************************/
124 static void descriptor2types (unicode *desc, bool isstatic,
125 s4 *paramnum, u1 **paramtypes, s4 *returntype)
127 u2 *text = desc->text;
132 tnum = (isstatic) ? 0 : 1;
134 while (text[pos] != ')') {
140 case 'L': while (text[pos]!=';') pos++;
147 types = DMNEW (u1, tnum);
149 if (isstatic) tnum=0;
151 types[0] = TYPE_ADDRESS;
155 while (text[pos] != ')') {
161 case 'Z': types[tnum++] = TYPE_INT;
163 case 'J': types[tnum++] = TYPE_LONG;
165 case 'F': types[tnum++] = TYPE_FLOAT;
167 case 'D': types[tnum++] = TYPE_DOUBLE;
169 case 'L': types[tnum++] = TYPE_ADDRESS;
170 while (text[pos] != ';') pos++;
172 case '[': types[tnum++] = TYPE_ADDRESS;
173 while (text[pos] == '[') pos++;
174 if (text[pos] == 'L') while (text[pos] != ';') pos++;
176 default: panic ("Ill formed methodtype-descriptor");
181 pos++; /* ueberlesen von ')' */
188 case 'Z': *returntype = TYPE_INT;
190 case 'J': *returntype = TYPE_LONG;
192 case 'F': *returntype = TYPE_FLOAT;
194 case 'D': *returntype = TYPE_DOUBLE;
197 case 'L': *returntype = TYPE_ADDRESS;
199 case 'V': *returntype = TYPE_VOID;
202 default: panic ("Ill formed methodtype-descriptor");