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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [stab.c] - Blame information for rev 227

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

Line No. Rev Author Line
1 4 hellwig
#include <string.h>
2
#include <stdlib.h>
3
#include "c.h"
4
#include "stab.h"
5
 
6
static char rcsid[] = "$Id: stab.c,v 1.1 2002/08/28 23:12:46 drh Exp $";
7
 
8
static char *currentfile;       /* current file name */
9
static int ntypes;
10
 
11
extern Interface sparcIR;
12
 
13
char *stabprefix = "L";
14
 
15
extern char *stabprefix;
16
extern void stabblock(int, int, Symbol*);
17
extern void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
18
extern void stabfend(Symbol, int);
19
extern void stabinit(char *, int, char *[]);
20
extern void stabline(Coordinate *);
21
extern void stabsym(Symbol);
22
extern void stabtype(Symbol);
23
 
24
static void asgncode(Type, int);
25
static void dbxout(Type);
26
static int dbxtype(Type);
27
static int emittype(Type, int, int);
28
 
29
/* asgncode - assign type code to ty */
30
static void asgncode(Type ty, int lev) {
31
        if (ty->x.marked || ty->x.typeno)
32
                return;
33
        ty->x.marked = 1;
34
        switch (ty->op) {
35
        case VOLATILE: case CONST: case VOLATILE+CONST:
36
                asgncode(ty->type, lev);
37
                ty->x.typeno = ty->type->x.typeno;
38
                break;
39
        case POINTER: case FUNCTION: case ARRAY:
40
                asgncode(ty->type, lev + 1);
41
                /* fall thru */
42
        case VOID: case INT: case UNSIGNED: case FLOAT:
43
                break;
44
        case STRUCT: case UNION: {
45
                Field p;
46
                for (p = fieldlist(ty); p; p = p->link)
47
                        asgncode(p->type, lev + 1);
48
                /* fall thru */
49
        case ENUM:
50
                if (ty->x.typeno == 0)
51
                        ty->x.typeno = ++ntypes;
52
                if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9'))
53
                        dbxout(ty);
54
                break;
55
                }
56
        default:
57
                assert(0);
58
        }
59
}
60
 
61
/* dbxout - output .stabs entry for type ty */
62
static void dbxout(Type ty) {
63
        ty = unqual(ty);
64
        if (!ty->x.printed) {
65
                int col = 0;
66
                print(".stabs \""), col += 8;
67
                if (ty->u.sym && !(isfunc(ty) || isarray(ty) || isptr(ty)))
68
                        print("%s", ty->u.sym->name), col += strlen(ty->u.sym->name);
69
                print(":%c", isstruct(ty) || isenum(ty) ? 'T' : 't'), col += 2;
70
                emittype(ty, 0, col);
71
                print("\",%d,0,0,0\n", N_LSYM);
72
        }
73
}
74
 
75
/* dbxtype - emit a stabs entry for type ty, return type code */
76
static int dbxtype(Type ty) {
77
        asgncode(ty, 0);
78
        dbxout(ty);
79
        return ty->x.typeno;
80
}
81
 
82
/*
83
 * emittype - emit ty's type number, emitting its definition if necessary.
84
 * Returns the output column number after emission; col is the approximate
85
 * output column before emission and is used to emit continuation lines for long
86
 * struct, union, and enum types. Continuations are not emitted for other types,
87
 * even if the definition is long. lev is the depth of calls to emittype.
88
 */
89
static int emittype(Type ty, int lev, int col) {
90
        int tc = ty->x.typeno;
91
 
92
        if (isconst(ty) || isvolatile(ty)) {
93
                col = emittype(ty->type, lev, col);
94
                ty->x.typeno = ty->type->x.typeno;
95
                ty->x.printed = 1;
96
                return col;
97
        }
98
        if (tc == 0) {
99
                ty->x.typeno = tc = ++ntypes;
100
/*              fprint(2,"`%t'=%d\n", ty, tc); */
101
        }
102
        print("%d", tc), col += 3;
103
        if (ty->x.printed)
104
                return col;
105
        ty->x.printed = 1;
106
        switch (ty->op) {
107
        case VOID:      /* void is defined as itself */
108
                print("=%d", tc), col += 1+3;
109
                break;
110
        case INT:
111
                if (ty == chartype)     /* plain char is a subrange of itself */
112
                        print("=r%d;%d;%d;", tc, ty->u.sym->u.limits.min.i, ty->u.sym->u.limits.max.i),
113
                                col += 2+3+2*2.408*ty->size+2;
114
                else                    /* other signed ints are subranges of int */
115
                        print("=r1;%D;%D;", ty->u.sym->u.limits.min.i, ty->u.sym->u.limits.max.i),
116
                                col += 4+2*2.408*ty->size+2;
117
                break;
118
        case UNSIGNED:
119
                if (ty == chartype)     /* plain char is a subrange of itself */
120
                        print("=r%d;0;%u;", tc, ty->u.sym->u.limits.max.i),
121
                                col += 2+3+2+2.408*ty->size+1;
122
                else                    /* other signed ints are subranges of int */
123
                        print("=r1;0;%U;", ty->u.sym->u.limits.max.i),
124
                                col += 4+2.408*ty->size+1;
125
                break;
126
        case FLOAT:     /* float, double, long double get sizes, not ranges */
127
                print("=r1;%d;0;", ty->size), col += 4+1+3;
128
                break;
129
        case POINTER:
130
                print("=*"), col += 2;
131
                col = emittype(ty->type, lev + 1, col);
132
                break;
133
        case FUNCTION:
134
                print("=f"), col += 2;
135
                col = emittype(ty->type, lev + 1, col);
136
                break;
137
        case ARRAY:     /* array includes subscript as an int range */
138
                if (ty->size && ty->type->size)
139
                        print("=ar1;0;%d;", ty->size/ty->type->size - 1), col += 7+3+1;
140
                else
141
                        print("=ar1;0;-1;"), col += 10;
142
                col = emittype(ty->type, lev + 1, col);
143
                break;
144
        case STRUCT: case UNION: {
145
                Field p;
146
                if (!ty->u.sym->defined) {
147
                        print("=x%c%s:", ty->op == STRUCT ? 's' : 'u', ty->u.sym->name);
148
                        col += 2+1+strlen(ty->u.sym->name)+1;
149
                        break;
150
                }
151
                if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9')) {
152
                        ty->x.printed = 0;
153
                        break;
154
                }
155
                print("=%c%d", ty->op == STRUCT ? 's' : 'u', ty->size), col += 1+1+3;
156
                for (p = fieldlist(ty); p; p = p->link) {
157
                        if (p->name)
158
                                print("%s:", p->name), col += strlen(p->name)+1;
159
                        else
160
                                print(":"), col += 1;
161
                        col = emittype(p->type, lev + 1, col);
162
                        if (p->lsb)
163
                                print(",%d,%d;", 8*p->offset +
164
                                        (IR->little_endian ? fieldright(p) : fieldleft(p)),
165
                                        fieldsize(p));
166
                        else
167
                                print(",%d,%d;", 8*p->offset, 8*p->type->size);
168
                        col += 1+3+1+3+1;       /* accounts for ,%d,%d; */
169
                        if (col >= 80 && p->link) {
170
                                print("\\\\\",%d,0,0,0\n.stabs \"", N_LSYM);
171
                                col = 8;
172
                        }
173
                }
174
                print(";"), col += 1;
175
                break;
176
                }
177
        case ENUM: {
178
                Symbol *p;
179
                if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9')) {
180
                        ty->x.printed = 0;
181
                        break;
182
                }
183
                print("=e"), col += 2;
184
                for (p = ty->u.sym->u.idlist; *p; p++) {
185
                        print("%s:%d,", (*p)->name, (*p)->u.value), col += strlen((*p)->name)+3;
186
                        if (col >= 80 && p[1]) {
187
                                print("\\\\\",%d,0,0,0\n.stabs \"", N_LSYM);
188
                                col = 8;
189
                        }
190
                }
191
                print(";"), col += 1;
192
                break;
193
                }
194
        default:
195
                assert(0);
196
        }
197
        return col;
198
}
199
 
200
/* stabblock - output a stab entry for '{' or '}' at level lev */
201
void stabblock(int brace, int lev, Symbol *p) {
202
        if (brace == '{')
203
                while (*p)
204
                        stabsym(*p++);
205
        if (IR == &sparcIR)
206
                print(".stabd 0x%x,0,%d\n", brace == '{' ? N_LBRAC : N_RBRAC, lev);
207
        else {
208
                int lab = genlabel(1);
209
                print(".stabn 0x%x,0,%d,%s%d-%s\n", brace == '{' ? N_LBRAC : N_RBRAC, lev,
210
                        stabprefix, lab, cfunc->x.name);
211
                print("%s%d:\n", stabprefix, lab);
212
        }
213
}
214
 
215
/* stabinit - initialize stab output */
216
void stabinit(char *file, int argc, char *argv[]) {
217
        typedef void (*Closure)(Symbol, void *);
218
 
219
        print(".stabs \"lcc4_compiled.\",0x%x,0,0,0\n", N_OPT);
220
        if (file && *file) {
221
                print(".stabs \"%s\",0x%x,0,3,%stext0\n", file, N_SO, stabprefix);
222
                (*IR->segment)(CODE);
223
                print("%stext0:\n", stabprefix, N_SO);
224
                currentfile = file;
225
        }
226
        dbxtype(inttype);
227
        dbxtype(chartype);
228
        dbxtype(doubletype);
229
        dbxtype(floattype);
230
        dbxtype(longdouble);
231
        dbxtype(longtype);
232
        dbxtype(longlong);
233
        dbxtype(shorttype);
234
        dbxtype(signedchar);
235
        dbxtype(unsignedchar);
236
        dbxtype(unsignedlong);
237
        dbxtype(unsignedlonglong);
238
        dbxtype(unsignedshort);
239
        dbxtype(unsignedtype);
240
        dbxtype(voidtype);
241
        foreach(types, GLOBAL, (Closure)stabtype, NULL);
242
}
243
 
244
/* stabline - emit stab entry for source coordinate *cp */
245
void stabline(Coordinate *cp) {
246
        if (cp->file && cp->file != currentfile) {
247
                int lab = genlabel(1);
248
                print(".stabs \"%s\",0x%x,0,0,%s%d\n", cp->file, N_SOL, stabprefix, lab);
249
                print("%s%d:\n", stabprefix, lab);
250
                currentfile = cp->file;
251
        }
252
        if (IR == &sparcIR)
253
                print(".stabd 0x%x,0,%d\n", N_SLINE, cp->y);
254
        else {
255
                int lab = genlabel(1);
256
                print(".stabn 0x%x,0,%d,%s%d-%s\n", N_SLINE, cp->y,
257
                        stabprefix, lab, cfunc->x.name);
258
                print("%s%d:\n", stabprefix, lab);
259
        }
260
}
261
 
262
/* stabsym - output a stab entry for symbol p */
263
void stabsym(Symbol p) {
264
        int code, tc, sz = p->type->size;
265
 
266
        if (p->generated || p->computed)
267
                return;
268
        if (isfunc(p->type)) {
269
                print(".stabs \"%s:%c%d\",%d,0,0,%s\n", p->name,
270
                        p->sclass == STATIC ? 'f' : 'F', dbxtype(freturn(p->type)),
271
                        N_FUN, p->x.name);
272
                return;
273
        }
274
        if (!IR->wants_argb && p->scope == PARAM && p->structarg) {
275
                assert(isptr(p->type) && isstruct(p->type->type));
276
                tc = dbxtype(p->type->type);
277
                sz = p->type->type->size;
278
        } else
279
                tc = dbxtype(p->type);
280
        if (p->sclass == AUTO && p->scope == GLOBAL || p->sclass == EXTERN) {
281
                print(".stabs \"%s:G", p->name);
282
                code = N_GSYM;
283
        } else if (p->sclass == STATIC) {
284
                print(".stabs \"%s:%c%d\",%d,0,0,%s\n", p->name, p->scope == GLOBAL ? 'S' : 'V',
285
                        tc, p->u.seg == BSS ? N_LCSYM : N_STSYM, p->x.name);
286
                return;
287
        } else if (p->sclass == REGISTER) {
288
                if (p->x.regnode) {
289
                        int r = p->x.regnode->number;
290
                        if (p->x.regnode->set == FREG)
291
                                r += 32;        /* floating point */
292
                                print(".stabs \"%s:%c%d\",%d,0,", p->name,
293
                                        p->scope == PARAM ? 'P' : 'r', tc, N_RSYM);
294
                        print("%d,%d\n", sz, r);
295
                }
296
                return;
297
        } else if (p->scope == PARAM) {
298
                print(".stabs \"%s:p", p->name);
299
                code = N_PSYM;
300
        } else if (p->scope >= LOCAL) {
301
                print(".stabs \"%s:", p->name);
302
                code = N_LSYM;
303
        } else
304
                assert(0);
305
        print("%d\",%d,0,0,%s\n", tc, code,
306
                p->scope >= PARAM && p->sclass != EXTERN ? p->x.name : "0");
307
}
308
 
309
/* stabtype - output a stab entry for type *p */
310
void stabtype(Symbol p) {
311
        if (p->type) {
312
                if (p->sclass == 0)
313
                        dbxtype(p->type);
314
                else if (p->sclass == TYPEDEF)
315
                        print(".stabs \"%s:t%d\",%d,0,0,0\n", p->name, dbxtype(p->type), N_LSYM);
316
        }
317
}
318
 
319
/* stabend - finalize a function */
320
void stabfend(Symbol p, int lineno) {}
321
 
322
/* stabend - finalize stab output */
323
void stabend(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {
324
        (*IR->segment)(CODE);
325
        print(".stabs \"\", %d, 0, 0,%setext\n", N_SO, stabprefix);
326
        print("%setext:\n", stabprefix);
327
}

powered by: WebSVN 2.1.0

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