1 /* vm/jit/inline/sets.c -
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Carolyn Oates
29 $Id: sets.c 4357 2006-01-22 23:33:38Z twisti $
38 #include "mm/memory.h"
39 #include "vm/global.h"
40 #include "vm/linker.h"
41 #include "vm/loader.h"
43 #include "vm/jit/inline/sets.h"
47 * set.c - functions to manipulate ptr sets.
51 /*------------------------------------------------------------*/
52 /*-- fieldinfo call set fns */
53 /*------------------------------------------------------------*/
54 fldSetNode *inFldSet(fldSetNode *s, fieldinfo *f)
57 for (i=s; i != NULL; i = i->nextfldRef) {
59 return i; /* true = found */
66 /*------------------------------------------------------------*/
68 fldSetNode *addFldRef(fldSetNode *s, fieldinfo *f)
77 s1->lastptrPUT = NULL;
78 s1->lastptrGET = NULL;
83 s1->index = s->index+1;
89 /*------------------------------------------------------------*/
90 fldSet *add2FldSet(fldSet *sf, fieldinfo *f, bool wput, bool rget)
101 s1 = NEW(fldSetNode);
102 if (sf->head == NULL) {
108 sf->tail->nextfldRef = s1;
110 s1->index = sf->length;
112 s1->nextfldRef = NULL;
116 s1->lastptrPUT = NULL;
117 s1->lastptrGET = NULL;
121 if ((s1->writePUT == false) && (wput))
123 if ((s1->readGET == false) && (rget))
130 /*------------------------------------------------------------*/
131 fldSet *createFldSet( )
143 /*------------------------------------------------------------*/
144 /*-- methodinfo call set fns */
145 /*------------------------------------------------------------*/
146 int inMethSet(methSetNode *s, methodinfo *m)
149 for (i = s; i != NULL; i = i->nextmethRef) {
150 if (i->methRef == m) {
151 return (int)1; /* true = found */
158 /*------------------------------------------------------------*/
159 methSetNode *addMethRef(methSetNode *s, methodinfo *m)
162 if (!inMethSet(s,m)) {
163 s1 = NEW(methSetNode);
166 s1->lastptrIntoClassSet2 = NULL;
170 s1->index = s->index+1;
178 /*x------------------------------------------------------------*/
179 methSet *add2MethSet(methSet *sm, methodinfo *m)
185 sm = createMethSet();
188 if (!inMethSet(s,m)) {
189 snew = NEW(methSetNode);
190 if (sm->head == NULL) {
196 sm->tail->nextmethRef = snew;
198 snew->index = sm->length;
200 snew->monoPoly = MONO;
201 snew->nextmethRef= NULL;
203 snew->lastptrIntoClassSet2 = NULL; /* ????? */
210 /*------------------------------------------------------------*/
211 methSet *createMethSet( )
223 /*------------------------------------------------------------*/
224 /*-- classinfo XTA set fns */
225 /*------------------------------------------------------------*/
226 int inSet(classSetNode *s, classinfo *c)
229 for (i = s; i != NULL; i = i->nextClass) {
230 if (i->classType == c) {
231 return ((i->index) + 1); /* true = found */
238 /*------------------------------------------------------------*/
239 classSetNode *addElement(classSetNode *s, classinfo *c)
241 classSetNode *s1 = s;
243 s1 = NEW(classSetNode);
249 s1->index = s->index+1;
255 /*------------------------------------------------------------*/
256 classSet *add2ClassSet(classSet *sc, classinfo *c)
262 sc = createClassSet();
267 s1 = NEW(classSetNode);
268 if (sc->head == NULL) {
274 sc->tail->nextClass = s1;
276 s1->index = sc->length;
286 /*------------------------------------------------------------*/
287 classSet *createClassSet()
299 /*------------------------------------------------------------*/
301 /* -1 c is a subclass of an existing set element */
302 /* 0 c class type cone does not overlap any set element */
303 /* 1 c is a superclass of an existing set element */
305 int inRange(classSetNode *s, classinfo *c)
310 for (i = s; i != NULL; i = i->nextClass) {
311 classinfo *cs = i->classType;
312 LAZYLOADING(c) /* ??? is c reallz needed ???*/
313 if (cs->vftbl->baseval <= c->vftbl->baseval) {
314 if (c->vftbl->baseval <= (cs->vftbl->baseval+cs->vftbl->diffval)) {
315 rc = -1; /* subtype */
319 if (cs->vftbl->baseval < (c->vftbl->baseval+c->vftbl->diffval)) {
320 i->classType = c; /* replace element with its new super */
329 /*------------------------------------------------------------*/
330 /* adds class if not subtype of an existing set element */
331 /* if "new" class is super class of an existing element */
332 /* then replace the existing element with the "new" class */
334 classSetNode *addClassCone(classSetNode *s, classinfo *c)
336 classSetNode *s1 = s;
338 if (inRange(s,c) == 0) {
339 /* not in set nor cone of an existing element so add */
340 s1 = NEW(classSetNode);
346 s1->index = s->index+1;
352 /*------------------------------------------------------------*/
353 /* intersect the subtypes of class t with class set s */
354 classSetNode * intersectSubtypesWithSet(classinfo *t, classSetNode *s) {
355 classSetNode *s1 = NULL;
358 /* for each s class */
359 for (c=s; c != NULL; c = c->nextClass) {
362 LAZYLOADING(c->classType)
365 c_cl_vt = c->classType->vftbl;
366 /* if s class is in the t Class range */
367 if ( (t_cl_vt->baseval <= c_cl_vt->baseval)
368 && (c_cl_vt->baseval <= (t_cl_vt->baseval+t_cl_vt->diffval)) ) {
370 /* add s class to return class set */
371 s1 = addElement(s1,c->classType);
378 /*------------------------------------------------------------*/
379 int sizeOfSet(classSetNode *s) {
380 /*** need to update */
383 for (i=s; i != NULL; i = i->nextClass) cnt++;
389 /*------------------------------------------------------------*/
390 int printSet(classSetNode *s)
396 printf("Set of types: <");
397 printf("\t\tEmpty Set\n");
400 printf("<%i>Set of types: ",s->index);
401 for (i = s; i != NULL; i = i->nextClass) {
402 printf("\t#%i: ",cnt);
403 if (i->classType == NULL) {
404 printf("NULL CLASS");
408 utf_display(i->classType->name);
410 printf("<b%i/d%i> ",i->classType->vftbl->baseval,i->classType->vftbl->diffval);
421 /*------------------------------------------------------------*/
422 int printClassSet(classSet *sc)
425 printf("Class Set not yet created\n");
429 return (printSet(sc->head));
433 /*------------------------------------------------------------*/
434 int printMethSet(methSetNode *s)
439 printf("Set of Methods: "); fflush(stdout);
440 printf("\t\tEmpty Set\n"); fflush(stdout);
443 printf("<%i>Set of Methods: ",s->index);fflush(stdout);
444 for (i=s; i != NULL; i = i->nextmethRef) {
445 printf("\t#%i: ",cnt);
448 utf_display(i->methRef->class->name);
450 method_println(i->methRef);
452 /* lastptr <class> */
454 if (i->lastptrIntoClassSet2 != NULL)
455 utf_display(i->lastptrIntoClassSet2->classType->name);
466 /*------------------------------------------------------------*/
467 int printMethodSet(methSet *sm) {
469 printf("Method Set not yet created\n");fflush(stdout);
473 if (sm->head == NULL) {
474 printf("Set of Methods: "); fflush(stdout);
475 printf("\t\tEmpty Set\n"); fflush(stdout);
479 return (printMethSet(sm->head));
484 /*------------------------------------------------------------*/
485 int printFldSet(fldSetNode *s)
491 printf("Set of Fields: ");
492 printf("\tEmpty Set\n");
495 printf("<%i>Set of Fields: ",s->index);
496 for (i=s; i != NULL; i = i->nextfldRef) {
497 printf("\t#%i: ",cnt);
498 printf("(%ir/%iw)",i->writePUT,i->readGET);
499 field_println(i->fldRef);
508 /*------------------------------------------------------------*/
509 int printFieldSet(fldSet *sf) {
511 printf("Field Set not yet created\n");
515 return (printFldSet(sf->head));
517 /*------------------------------------------------------------*/
518 /*void destroy_set */
519 #endif /* !defined(NDEBUG) */
523 * These are local overrides for various environment variables in Emacs.
524 * Please do not remove this and leave it at the end of the file, where
525 * Emacs will automagically detect them.
526 * ---------------------------------------------------------------------
529 * indent-tabs-mode: t