OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [lib/] [bbexit.c] - Blame information for rev 257

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include <stdio.h>
2
#include <stdlib.h>
3
#ifndef EXPORT
4
#define EXPORT
5
#endif
6
 
7
static char rcsid[] = "$Id: bbexit.c,v 1.6 2001/06/15 20:58:40 drh Exp $";
8
 
9
EXPORT struct callsite {
10
        char *file, *name;
11
        union coordinate {
12
                struct { unsigned int index:6,x:10,y:16; } be;
13
                struct { unsigned int y:16,x:10,index:6; } le;
14
                unsigned int coord;
15
        } u;
16
} *_caller, **_callerp = &_caller;
17
 
18
EXPORT void _setcallerp(struct callsite **p) {
19
        _callerp = p;
20
}
21
 
22
static struct _bbdata {
23
        struct _bbdata *link;
24
        int npoints, *counts;
25
        union coordinate *coords;
26
        char **files;
27
        struct func {
28
                struct func *link;
29
                struct caller {
30
                        struct caller *link;
31
                        struct callsite *caller;
32
                        int count;
33
                } *callers;
34
                char *name;
35
                union coordinate src;
36
        } *funcs;
37
} tail, *_bblist = &tail;
38
 
39
static void unpack(unsigned int coord, int *index, int *x, int *y) {
40
        static union { int x; char endian; } little = { 1 };
41
        union coordinate u;
42
 
43
        u.coord = coord;
44
        if (little.endian) {
45
                *index = u.le.index;
46
                *x = u.le.x;
47
                *y = u.le.y;
48
        } else {
49
                *index = u.be.index;
50
                *x = u.be.x;
51
                *y = u.be.y;
52
        }
53
}
54
 
55
static void profout(struct _bbdata *p, FILE *fp) {
56
        int i, index, x, y;
57
        struct func *f;
58
        struct caller *q;
59
 
60
        for (i = 0; p->files[i]; i++)
61
                ;
62
        fprintf(fp, "%d\n", i);
63
        for (i = 0; p->files[i]; i++)
64
                fprintf(fp, "%s\n", p->files[i]);
65
        for (i = 0, f = p->funcs; f; i++, f = f->link)
66
                if (q = f->callers)
67
                        for (i--; q; q = q->link)
68
                                i++;
69
        fprintf(fp, "%d\n", i);
70
        for (f = p->funcs; f; f = f->link) {
71
                int n = 0;
72
                for (q = f->callers; q; n += q->count, q = q->link) {
73
                        unpack(f->src.coord, &index, &x, &y);
74
                        fprintf(fp, "%s %d %d %d %d", f->name, index, x, y, q->count);
75
                        if (q->caller) {
76
                                unpack(q->caller->u.coord, &index, &x, &y);
77
                                fprintf(fp, " %s %s %d %d\n", q->caller->name, q->caller->file, x, y);
78
                        } else
79
                                fprintf(fp, " ? ? 0 0\n");
80
                }
81
                if (n == 0) {
82
                        unpack(f->src.coord, &index, &x, &y);
83
                        fprintf(fp, "%s %d %d %d 0 ? ? 0 0\n", f->name, index, x, y);
84
                }
85
        }
86
        fprintf(fp, "%d\n", p->npoints);
87
        for (i = 0; i < p->npoints; i++) {
88
                unpack(p->coords[i].coord, &index, &x, &y);
89
                fprintf(fp, "%d %d %d %d\n", index, x, y, p->counts[i]);
90
        }
91
}
92
 
93
static void bbexit(void) {
94
        FILE *fp;
95
 
96
        if (_bblist != &tail && (fp = fopen("prof.out", "a"))) {
97
                for ( ; _bblist != &tail; _bblist = _bblist->link)
98
                        profout(_bblist, fp);
99
                fclose(fp);
100
        }
101
}
102
 
103
EXPORT void _epilogue(struct func *callee) {
104
        *_callerp = 0;
105
}
106
 
107
EXPORT void _prologue(struct func *callee, struct _bbdata *yylink) {
108
        static struct caller callers[4096];
109
        static int next;
110
        struct caller *p;
111
 
112
        if (!yylink->link) {
113
                yylink->link = _bblist;
114
                _bblist = yylink;
115
                if (next == 0)
116
                        atexit(bbexit);
117
        }
118
        for (p = callee->callers; p; p = p->link)
119
                if (p->caller == *_callerp) {
120
                        p->count++;
121
                        break;
122
                }
123
        if (!p && next < sizeof callers/sizeof callers[0]) {
124
                p = &callers[next++];
125
                p->caller = *_callerp;
126
                p->count = 1;
127
                p->link = callee->callers;
128
                callee->callers = p;
129
        }
130
        *_callerp = 0;
131
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.