1 /* vm/jit/inline/sets.c -
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Carolyn Oates
30 $Id: sets.c 1621 2004-11-30 13:06:55Z twisti $
38 #include "mm/memory.h"
39 #include "vm/global.h"
40 #include "vm/loader.h"
41 #include "vm/tables.h"
42 #include "vm/jit/inline/sets.h"
46 * set.c - functions to manipulate ptr sets.
50 /*------------------------------------------------------------*/
51 /*-- fieldinfo call set fns */
52 /*------------------------------------------------------------*/
53 fldSetNode *inFldSet(fldSetNode *s, fieldinfo *f)
56 for (i=s; i != NULL; i = i->nextfldRef) {
58 return i; /* true = found */
65 /*------------------------------------------------------------*/
67 fldSetNode *addFldRef(fldSetNode *s, fieldinfo *f)
76 s1->lastptrPUT = NULL;
77 s1->lastptrGET = NULL;
82 s1->index = s->index+1;
88 /*------------------------------------------------------------*/
89 fldSet *add2FldSet(fldSet *sf, fieldinfo *f, bool wput, bool rget)
100 s1 = NEW(fldSetNode);
101 if (sf->head == NULL) {
107 sf->tail->nextfldRef = s1;
109 s1->index = sf->length;
111 s1->nextfldRef = NULL;
115 s1->lastptrPUT = NULL;
116 s1->lastptrGET = NULL;
120 if ((s1->writePUT == false) && (wput))
122 if ((s1->readGET == false) && (rget))
129 /*------------------------------------------------------------*/
130 fldSet *createFldSet( )
142 /*------------------------------------------------------------*/
143 /*-- methodinfo call set fns */
144 /*------------------------------------------------------------*/
145 int inMethSet(methSetNode *s, methodinfo *m)
148 for (i = s; i != NULL; i = i->nextmethRef) {
149 if (i->methRef == m) {
150 return (int)1; /* true = found */
157 /*------------------------------------------------------------*/
158 methSetNode *addMethRef(methSetNode *s, methodinfo *m)
161 if (!inMethSet(s,m)) {
162 s1 = NEW(methSetNode);
165 s1->lastptrIntoClassSet2 = NULL;
169 s1->index = s->index+1;
177 /*------------------------------------------------------------*/
178 methSet *add2MethSet(methSet *sm, methodinfo *m)
184 sm = createMethSet();
187 if (!inMethSet(s,m)) {
188 s1 = NEW(methSetNode);
189 if (sm->head == NULL) {
195 sm->tail->nextmethRef = s1;
197 s1->index = sm->length;
200 s1->nextmethRef= NULL;
202 s1->lastptrIntoClassSet2 = NULL;
209 /*------------------------------------------------------------*/
210 methSet *createMethSet( )
222 /*------------------------------------------------------------*/
223 /*-- classinfo XTA set fns */
224 /*------------------------------------------------------------*/
225 int inSet(classSetNode *s, classinfo *c)
228 for (i = s; i != NULL; i = i->nextClass) {
229 if (i->classType == c) {
230 return ((i->index) + 1); /* true = found */
237 /*------------------------------------------------------------*/
238 classSetNode *addElement(classSetNode *s, classinfo *c)
240 classSetNode *s1 = s;
242 s1 = NEW(classSetNode);
248 s1->index = s->index+1;
254 /*------------------------------------------------------------*/
255 classSet *add2ClassSet(classSet *sc, classinfo *c)
261 sc = createClassSet();
266 s1 = NEW(classSetNode);
267 if (sc->head == NULL) {
273 sc->tail->nextClass = s1;
275 s1->index = sc->length;
285 /*------------------------------------------------------------*/
286 classSet *createClassSet()
298 /*------------------------------------------------------------*/
300 /* -1 c is a subclass of an existing set element */
301 /* 0 c class type cone does not overlap any set element */
302 /* 1 c is a superclass of an existing set element */
304 int inRange(classSetNode *s, classinfo *c)
309 for (i = s; i != NULL; i = i->nextClass) {
310 classinfo *cs = i->classType;
311 if (cs->vftbl->baseval <= c->vftbl->baseval) {
312 if (c->vftbl->baseval <= (cs->vftbl->baseval+cs->vftbl->diffval)) {
313 rc = -1; /* subtype */
317 if (cs->vftbl->baseval < (c->vftbl->baseval+c->vftbl->diffval)) {
318 i->classType = c; /* replace element with its new super */
327 /*------------------------------------------------------------*/
328 /* adds class if not subtype of an existing set element */
329 /* if "new" class is super class of an existing element */
330 /* then replace the existing element with the "new" class */
332 classSetNode *addClassCone(classSetNode *s, classinfo *c)
334 classSetNode *s1 = s;
336 if (inRange(s,c) == 0) {
337 /* not in set nor cone of an existing element so add */
338 s1 = NEW(classSetNode);
344 s1->index = s->index+1;
350 /*------------------------------------------------------------*/
351 /* intersect the subtypes of class t with class set s */
352 classSetNode * intersectSubtypesWithSet(classinfo *t, classSetNode *s) {
353 classSetNode *s1 = NULL;
356 /* for each s class */
357 for (c=s; c != NULL; c = c->nextClass) {
358 vftbl_t *t_cl_vt = t->vftbl;
359 vftbl_t *c_cl_vt = c->classType->vftbl;
361 /* if s class is in the t Class range */
362 if ( (t_cl_vt->baseval <= c_cl_vt->baseval)
363 && (c_cl_vt->baseval <= (t_cl_vt->baseval+t_cl_vt->diffval)) ) {
365 /* add s class to return class set */
366 s1 = addElement(s1,c->classType);
373 /*------------------------------------------------------------*/
374 int sizeOfSet(classSetNode *s) {
375 /*** need to update */
378 for (i=s; i != NULL; i = i->nextClass) cnt++;
383 /*------------------------------------------------------------*/
384 int printSet(classSetNode *s)
390 printf("Set of types: <");
391 printf("\t\tEmpty Set\n");
394 printf("<%i>Set of types: ",s->index);
395 for (i = s; i != NULL; i = i->nextClass) {
396 printf("\t#%i: ",cnt);
397 if (i->classType == NULL) {
398 printf("NULL CLASS");
402 utf_display(i->classType->name);
404 printf("<b%i/d%i> ",i->classType->vftbl->baseval,i->classType->vftbl->diffval);
415 /*------------------------------------------------------------*/
416 int printClassSet(classSet *sc)
419 printf("Class Set not yet created\n");
423 return (printSet(sc->head));
427 /*------------------------------------------------------------*/
428 int printMethSet(methSetNode *s)
433 printf("Set of Methods: "); fflush(stdout);
434 printf("\t\tEmpty Set\n"); fflush(stdout);
437 printf("<%i>Set of Methods: ",s->index);fflush(stdout);
438 for (i=s; i != NULL; i = i->nextmethRef) {
439 printf("\t#%i: ",cnt);
442 utf_display(i->methRef->class->name);
444 method_display(i->methRef);
446 /* lastptr <class> */
448 if (i->lastptrIntoClassSet2 != NULL)
449 utf_display(i->lastptrIntoClassSet2->classType->name);
460 /*------------------------------------------------------------*/
461 int printMethodSet(methSet *sm) {
463 printf("Method Set not yet created\n");fflush(stdout);
467 if (sm->head == NULL) {
468 printf("Set of Methods: "); fflush(stdout);
469 printf("\t\tEmpty Set\n"); fflush(stdout);
473 return (printMethSet(sm->head));
478 /*------------------------------------------------------------*/
479 int printFldSet(fldSetNode *s)
485 printf("Set of Fields: ");
486 printf("\tEmpty Set\n");
489 printf("<%i>Set of Fields: ",s->index);
490 for (i=s; i != NULL; i = i->nextfldRef) {
491 printf("\t#%i: ",cnt);
492 printf("(%ir/%iw)",i->writePUT,i->readGET);
493 field_display(i->fldRef);
502 /*------------------------------------------------------------*/
503 int printFieldSet(fldSet *sf) {
505 printf("Field Set not yet created\n");
509 return (printFldSet(sf->head));
511 /*------------------------------------------------------------*/
512 /*void destroy_set */
516 * These are local overrides for various environment variables in Emacs.
517 * Please do not remove this and leave it at the end of the file, where
518 * Emacs will automagically detect them.
519 * ---------------------------------------------------------------------
522 * indent-tabs-mode: t