1 /* vm/jit/inline/sets.c -
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Carolyn Oates
29 $Id: sets.c 1735 2004-12-07 14:33:27Z twisti $
37 #include "mm/memory.h"
38 #include "vm/global.h"
39 #include "vm/loader.h"
40 #include "vm/tables.h"
41 #include "vm/jit/inline/sets.h"
45 * set.c - functions to manipulate ptr sets.
49 /*------------------------------------------------------------*/
50 /*-- fieldinfo call set fns */
51 /*------------------------------------------------------------*/
52 fldSetNode *inFldSet(fldSetNode *s, fieldinfo *f)
55 for (i=s; i != NULL; i = i->nextfldRef) {
57 return i; /* true = found */
64 /*------------------------------------------------------------*/
66 fldSetNode *addFldRef(fldSetNode *s, fieldinfo *f)
75 s1->lastptrPUT = NULL;
76 s1->lastptrGET = NULL;
81 s1->index = s->index+1;
87 /*------------------------------------------------------------*/
88 fldSet *add2FldSet(fldSet *sf, fieldinfo *f, bool wput, bool rget)
100 if (sf->head == NULL) {
106 sf->tail->nextfldRef = s1;
108 s1->index = sf->length;
110 s1->nextfldRef = NULL;
114 s1->lastptrPUT = NULL;
115 s1->lastptrGET = NULL;
119 if ((s1->writePUT == false) && (wput))
121 if ((s1->readGET == false) && (rget))
128 /*------------------------------------------------------------*/
129 fldSet *createFldSet( )
141 /*------------------------------------------------------------*/
142 /*-- methodinfo call set fns */
143 /*------------------------------------------------------------*/
144 int inMethSet(methSetNode *s, methodinfo *m)
147 for (i = s; i != NULL; i = i->nextmethRef) {
148 if (i->methRef == m) {
149 return (int)1; /* true = found */
156 /*------------------------------------------------------------*/
157 methSetNode *addMethRef(methSetNode *s, methodinfo *m)
160 if (!inMethSet(s,m)) {
161 s1 = NEW(methSetNode);
164 s1->lastptrIntoClassSet2 = NULL;
168 s1->index = s->index+1;
176 /*------------------------------------------------------------*/
177 methSet *add2MethSet(methSet *sm, methodinfo *m)
183 sm = createMethSet();
186 if (!inMethSet(s,m)) {
187 s1 = NEW(methSetNode);
188 if (sm->head == NULL) {
194 sm->tail->nextmethRef = s1;
196 s1->index = sm->length;
199 s1->nextmethRef= NULL;
201 s1->lastptrIntoClassSet2 = NULL;
208 /*------------------------------------------------------------*/
209 methSet *createMethSet( )
221 /*------------------------------------------------------------*/
222 /*-- classinfo XTA set fns */
223 /*------------------------------------------------------------*/
224 int inSet(classSetNode *s, classinfo *c)
227 for (i = s; i != NULL; i = i->nextClass) {
228 if (i->classType == c) {
229 return ((i->index) + 1); /* true = found */
236 /*------------------------------------------------------------*/
237 classSetNode *addElement(classSetNode *s, classinfo *c)
239 classSetNode *s1 = s;
241 s1 = NEW(classSetNode);
247 s1->index = s->index+1;
253 /*------------------------------------------------------------*/
254 classSet *add2ClassSet(classSet *sc, classinfo *c)
260 sc = createClassSet();
265 s1 = NEW(classSetNode);
266 if (sc->head == NULL) {
272 sc->tail->nextClass = s1;
274 s1->index = sc->length;
284 /*------------------------------------------------------------*/
285 classSet *createClassSet()
297 /*------------------------------------------------------------*/
299 /* -1 c is a subclass of an existing set element */
300 /* 0 c class type cone does not overlap any set element */
301 /* 1 c is a superclass of an existing set element */
303 int inRange(classSetNode *s, classinfo *c)
308 for (i = s; i != NULL; i = i->nextClass) {
309 classinfo *cs = i->classType;
310 if (cs->vftbl->baseval <= c->vftbl->baseval) {
311 if (c->vftbl->baseval <= (cs->vftbl->baseval+cs->vftbl->diffval)) {
312 rc = -1; /* subtype */
316 if (cs->vftbl->baseval < (c->vftbl->baseval+c->vftbl->diffval)) {
317 i->classType = c; /* replace element with its new super */
326 /*------------------------------------------------------------*/
327 /* adds class if not subtype of an existing set element */
328 /* if "new" class is super class of an existing element */
329 /* then replace the existing element with the "new" class */
331 classSetNode *addClassCone(classSetNode *s, classinfo *c)
333 classSetNode *s1 = s;
335 if (inRange(s,c) == 0) {
336 /* not in set nor cone of an existing element so add */
337 s1 = NEW(classSetNode);
343 s1->index = s->index+1;
349 /*------------------------------------------------------------*/
350 /* intersect the subtypes of class t with class set s */
351 classSetNode * intersectSubtypesWithSet(classinfo *t, classSetNode *s) {
352 classSetNode *s1 = NULL;
355 /* for each s class */
356 for (c=s; c != NULL; c = c->nextClass) {
357 vftbl_t *t_cl_vt = t->vftbl;
358 vftbl_t *c_cl_vt = c->classType->vftbl;
360 /* if s class is in the t Class range */
361 if ( (t_cl_vt->baseval <= c_cl_vt->baseval)
362 && (c_cl_vt->baseval <= (t_cl_vt->baseval+t_cl_vt->diffval)) ) {
364 /* add s class to return class set */
365 s1 = addElement(s1,c->classType);
372 /*------------------------------------------------------------*/
373 int sizeOfSet(classSetNode *s) {
374 /*** need to update */
377 for (i=s; i != NULL; i = i->nextClass) cnt++;
382 /*------------------------------------------------------------*/
383 int printSet(classSetNode *s)
389 printf("Set of types: <");
390 printf("\t\tEmpty Set\n");
393 printf("<%i>Set of types: ",s->index);
394 for (i = s; i != NULL; i = i->nextClass) {
395 printf("\t#%i: ",cnt);
396 if (i->classType == NULL) {
397 printf("NULL CLASS");
401 utf_display(i->classType->name);
403 printf("<b%i/d%i> ",i->classType->vftbl->baseval,i->classType->vftbl->diffval);
414 /*------------------------------------------------------------*/
415 int printClassSet(classSet *sc)
418 printf("Class Set not yet created\n");
422 return (printSet(sc->head));
426 /*------------------------------------------------------------*/
427 int printMethSet(methSetNode *s)
432 printf("Set of Methods: "); fflush(stdout);
433 printf("\t\tEmpty Set\n"); fflush(stdout);
436 printf("<%i>Set of Methods: ",s->index);fflush(stdout);
437 for (i=s; i != NULL; i = i->nextmethRef) {
438 printf("\t#%i: ",cnt);
441 utf_display(i->methRef->class->name);
443 method_display(i->methRef);
445 /* lastptr <class> */
447 if (i->lastptrIntoClassSet2 != NULL)
448 utf_display(i->lastptrIntoClassSet2->classType->name);
459 /*------------------------------------------------------------*/
460 int printMethodSet(methSet *sm) {
462 printf("Method Set not yet created\n");fflush(stdout);
466 if (sm->head == NULL) {
467 printf("Set of Methods: "); fflush(stdout);
468 printf("\t\tEmpty Set\n"); fflush(stdout);
472 return (printMethSet(sm->head));
477 /*------------------------------------------------------------*/
478 int printFldSet(fldSetNode *s)
484 printf("Set of Fields: ");
485 printf("\tEmpty Set\n");
488 printf("<%i>Set of Fields: ",s->index);
489 for (i=s; i != NULL; i = i->nextfldRef) {
490 printf("\t#%i: ",cnt);
491 printf("(%ir/%iw)",i->writePUT,i->readGET);
492 field_display(i->fldRef);
501 /*------------------------------------------------------------*/
502 int printFieldSet(fldSet *sf) {
504 printf("Field Set not yet created\n");
508 return (printFldSet(sf->head));
510 /*------------------------------------------------------------*/
511 /*void destroy_set */
515 * These are local overrides for various environment variables in Emacs.
516 * Please do not remove this and leave it at the end of the file, where
517 * Emacs will automagically detect them.
518 * ---------------------------------------------------------------------
521 * indent-tabs-mode: t