Annotation of researchv10no/cmd/lcc/etc/bbexit.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: 
                      3: struct callsite {
                      4:        char *file, *name;
                      5:        union coordinate {
                      6:                struct {
                      7: #if MIPSEB || mc68020 || mc68030 || NeXT || sparc
                      8:                        unsigned int index:6,x:10,y:16;
                      9: #endif
                     10: #if MIPSEL || vax
                     11:                        unsigned int y:16,x:10,index:6;
                     12: #endif
                     13:                } c;
                     14:                unsigned int coord;
                     15:        } u;
                     16: } *_caller;
                     17: 
                     18: static struct _bbdata {
                     19:        struct _bbdata *link;
                     20:        unsigned npoints, *counts;
                     21:        union coordinate *coords;
                     22:        char **files;
                     23:        struct func {
                     24:                struct func *link;
                     25:                struct caller {
                     26:                        struct caller *link;
                     27:                        struct callsite *caller;
                     28:                        unsigned count;
                     29:                } *callers;
                     30:                char *name;
                     31:                union coordinate src;
                     32:        } *funcs;
                     33: } tail, *_bblist = &tail;
                     34: 
                     35: _epilogue(callee) struct func *callee; {
                     36:        _caller = 0;
                     37: }
                     38: 
                     39: _prologue(callee, yylink) struct func *callee; struct _bbdata *yylink; {
                     40:        static struct caller callers[4096];
                     41:        static int next;
                     42:        struct caller *p;
                     43: 
                     44:        if (!yylink->link) {
                     45:                yylink->link = _bblist;
                     46:                _bblist = yylink;
                     47:        }
                     48:        for (p = callee->callers; p; p = p->link)
                     49:                if (p->caller == _caller) {
                     50:                        p->count++;
                     51:                        break;
                     52:                }
                     53:        if (!p && next < sizeof callers/sizeof callers[0]) {
                     54:                p = &callers[next++];
                     55:                p->caller = _caller;
                     56:                p->count = 1;
                     57:                p->link = callee->callers;
                     58:                callee->callers = p;
                     59:        }
                     60:        _caller = 0;
                     61: }
                     62: 
                     63: static void profout(p, fp) struct _bbdata *p; FILE *fp; {
                     64:        int i;
                     65:        struct func *f;
                     66:        struct caller *q;
                     67: 
                     68:        for (i = 0; p->files[i]; i++)
                     69:                ;
                     70:        fprintf(fp, "%d\n", i);
                     71:        for (i = 0; p->files[i]; i++)
                     72:                fprintf(fp, "%s\n", p->files[i]);
                     73:        for (i = 0, f = p->funcs; f; i++, f = f->link)
                     74:                if (q = f->callers)
                     75:                        for (i--; q; q = q->link)
                     76:                                i++;
                     77:        fprintf(fp, "%d\n", i);
                     78:        for (f = p->funcs; f; f = f->link) {
                     79:                int n = 0;
                     80:                for (q = f->callers; q; n += q->count, q = q->link) {
                     81:                        fprintf(fp, "%s %d %d %d %d", f->name, f->src.c.index,
                     82:                                f->src.c.x, f->src.c.y, q->count);
                     83:                        if (q->caller)
                     84:                                fprintf(fp, " %s %s %d %d\n", q->caller->name, q->caller->file,
                     85:                                        q->caller->u.c.x, q->caller->u.c.y);
                     86:                        else
                     87:                                fprintf(fp, " ? ? 0 0\n");
                     88:                }
                     89:                if (n == 0)
                     90:                        fprintf(fp, "%s %d %d %d 0 ? ? 0 0\n", f->name, f->src.c.index,
                     91:                                f->src.c.x, f->src.c.y);
                     92:        }               
                     93:        fprintf(fp, "%d\n", p->npoints);
                     94:        for (i = 0; i < p->npoints; i++)
                     95:                fprintf(fp, "%d %d %d %d\n", p->coords[i].c.index, p->coords[i].c.x,
                     96:                        p->coords[i].c.y, p->counts[i]);
                     97: }
                     98: 
                     99: exit(code) {
                    100:        FILE *fp;
                    101: 
                    102:        if (_bblist != &tail && (fp = fopen("prof.out", "a"))) {
                    103:                for ( ; _bblist != &tail; _bblist = _bblist->link)
                    104:                        profout(_bblist, fp);
                    105:                fclose(fp);
                    106:        }
                    107: #if mips || vax || sparc
                    108:        _cleanup();
                    109: #endif
                    110:        _exit(code);
                    111: }

unix.superglobalmegacorp.com

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