Annotation of researchv8dc/cmd/trace/trace5.c, revision 1.1.1.1

1.1       root        1: #include "stdio.h"
                      2: #include "trace.h"
                      3: #include "trace.d"
                      4: 
                      5:  extern struct QUEUE **head, **tail;
                      6:  extern int *qsize;
                      7:  extern int nrqs, level, maxreached;
                      8:  extern double iseen, ireseen, zapper;
                      9:  char *Realloc(), *Emalloc(), *Smalloc(), *emalloc();
                     10: 
                     11:  struct HTABLE {
                     12:        struct STATE **index;           /* index [h] [ibound]    */
                     13:        short ibound;                   /* nr of available slots */
                     14:        short nr;                       /* nr of occupied  slots */
                     15:  } oldstates[NOTOOBIG+1];              /* index of hash values  */
                     16: 
                     17:  int hbound = 0, hlast = 0;
                     18:  short igrowth  = 8;
                     19: 
                     20: growindex(h)
                     21: { int nsz = (int) oldstates[h].ibound + igrowth;
                     22: 
                     23:        if (nsz == igrowth)
                     24:                oldstates[h].index = (struct STATE **)
                     25:                        Emalloc(nsz * sizeof(struct STATE *));
                     26:        else
                     27:                oldstates[h].index = (struct STATE **)
                     28:                        Realloc(oldstates[h].index, nsz * sizeof(struct STATE *));
                     29:        
                     30:        oldstates[h].ibound = (short) nsz;
                     31: 
                     32: }
                     33: 
                     34: initable()
                     35: { register int i;
                     36: 
                     37:        for (i = 0; i < NOTOOBIG+1; i++)
                     38:        {       oldstates[i].nr = 0;
                     39:                oldstates[i].ibound = 0;
                     40:        }
                     41:        hbound = NOTOOBIG+1;
                     42: }
                     43: 
                     44: insert(h, pnt)         /* enter state pointer into the table at hash value h */
                     45:        struct STATE *pnt;
                     46: { short cin;
                     47: 
                     48:        if (h >= hbound)
                     49:        {       fprintf(stderr, "h %d, hbound %d, NOTOOBIG %d\n",h,hbound,NOTOOBIG);
                     50:                whoops("cannot happen - insert");
                     51:        }
                     52:        cin = oldstates[h].nr++;
                     53: 
                     54:        iseen += (long) 1;
                     55: 
                     56:        if (cin >= oldstates[h].ibound)
                     57:                growindex(h);
                     58: 
                     59:        oldstates[h].index[cin] = pnt;
                     60: }
                     61: 
                     62: mark(stt, vis)
                     63:        struct STATE *stt;
                     64:        struct VISIT *vis;
                     65: { int h = stt->hash;
                     66: 
                     67:        if (h >= hbound)
                     68:                whoops("cannot happen - mark");
                     69:        efree(vis->prop.h);
                     70:        vis->analyzed = 1;
                     71: 
                     72: }
                     73: 
                     74: relink(vis)
                     75:        struct VISIT *vis;
                     76: { struct CONTS *inqtable();
                     77:   register int i, j, k;
                     78: 
                     79:        for (i = j = 0; i < nrqs ; i++)
                     80:                if (qsize[i] > 0)
                     81:                        j++;
                     82: 
                     83:        vis->howmany = (char) j;
                     84: 
                     85:        if (zapper == 0)        /* grow without bound */
                     86:                vis->prop.c = (struct CONTS **)
                     87:                        Smalloc(j * sizeof(struct CONTS *));
                     88:        else
                     89:                vis->prop.c = (struct CONTS **)
                     90:                        emalloc(j * sizeof(struct CONTS *));
                     91: 
                     92:        for (i = k = 0; i < nrqs; i++)
                     93:        {       if ((j = qsize[i]) == 0)
                     94:                        continue;
                     95: 
                     96:                vis->prop.c[k++] = inqtable(i);
                     97:        }
                     98: }
                     99: 
                    100: member(h) { return (h < hbound) ? oldstates[h].nr : 0; }
                    101: 
                    102: struct STATE *
                    103: giveme(h, n)
                    104: { int m = n - 1;
                    105:        if (h >= hbound || oldstates[h].nr <= m || oldstates[h].index[m] == NULL)
                    106:                whoops("cannot happen - giveme");
                    107: 
                    108:        return oldstates[h].index[m];
                    109: }
                    110: 
                    111: struct VISIT *
                    112: findany(avoid)
                    113:        struct STATE *avoid;
                    114: { register int i, j;
                    115:   struct VISIT *try = NULL;
                    116:   struct VISIT *pickstate();
                    117: 
                    118:        for (i = (hlast+1)%hbound; i != hlast; i++, i %= hbound)
                    119:        for (j = 0; j < oldstates[i].nr; j++)
                    120:                if (oldstates[i].index[j]->nrvisits > 0
                    121:                &&  oldstates[i].index[j] != avoid
                    122:                &&  (try = pickstate(oldstates[i].index[j])) != NULL)
                    123:                {       hlast = i;
                    124:                        return try;
                    125:                }
                    126:        return (struct VISIT *) Smalloc(sizeof(struct VISIT));
                    127: }
                    128: 
                    129: struct VISIT *
                    130: findastate(avoid)
                    131:        struct STATE *avoid;
                    132: { struct VISIT *findany(), *picknown(), *try;
                    133:   struct Spoke   *getspoke(),  *trs2;
                    134:   struct Swiffle *unswiffle(), *trs1;
                    135: 
                    136:        if (ireseen < zapper || zapper == 0)
                    137:                return (struct VISIT *) Smalloc(sizeof(struct VISIT));
                    138: 
                    139:        if ((trs1 = unswiffle(avoid)) != NULL
                    140:        &&  (try = picknown(trs1->st, trs1->vi)) != NULL)
                    141:                return try;
                    142: 
                    143: /*     if ((trs2 = getspoke(avoid)) != NULL
                    144:        &&  (try = picknown(trs2->st, trs2->vi)) != NULL)
                    145:                return try;
                    146: */
                    147:        return findany(avoid);  /* last resort */
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.