|
|
1.1 root 1: /*
2: * Routines to print out the
3: * internal data structures in a
4: * human being readable form.
5: * All machines.
6: */
7:
8: #ifdef vax
9: #include "INC$LIB:cc1.h"
10: #else
11: #include "cc1.h"
12: #endif
13:
14: /*
15: * None of this applies in TINY mode.
16: */
17: #if !TINY
18: #define WIDTH 72
19:
20: extern char *milnames[];
21: extern char *mionames[];
22: extern char *mdlnames[];
23: extern char *mdonames[];
24: extern char *segnames[];
25: extern char *regnames[];
26: extern char *tynames[];
27: static char *cxnames[] = {
28: "Effect",
29: "Lvalue",
30: "Rvalue",
31: "Fnarg",
32: "Laddr",
33: "Raddr",
34: "Return",
35: "Switch",
36: "Init",
37: "Flow",
38: "Passed",
39: "Junk",
40: "Hard",
41: "Eq", "Ne",
42: "Gt", "Ge", "Le", "Lt",
43: "Ugt", "Uge", "Ule", "Ult"
44: };
45:
46: /*
47: * Snap a format string, the usual sort of mapping:
48: * %P - print a pointer.
49: * %R - print a register string.
50: * %M - print a register mask.
51: * %C - print a context string.
52: * %W - snap a wall with embedded string.
53: * %A - snap an operator name.
54: * %E - snap an entire tree.
55: * %d - decimal integer.
56: * %D - long decimal integer.
57: * %I - Identify a pattern by file and linenumber
58: */
59: snapf(fp, ap)
60: register char *fp;
61: int ap;
62: {
63: register int *app;
64: register int c;
65: static char *string = "%s";
66: PREGSET m;
67: char *p;
68: PAT *patp;
69:
70: app = ≈
71: while (c = *fp++) {
72: if (c != '%') {
73: putchar(c);
74: continue;
75: }
76: switch (c = *fp++) {
77: case 'A':
78: c = *app++;
79: if (c < MDLBASE)
80: p = milnames[c];
81: else if (c < MIOBASE)
82: p = mdlnames[c-MDLBASE];
83: else if (c < MDOBASE)
84: p = mionames[c-MIOBASE];
85: else
86: p = mdonames[c-MDOBASE];
87: printf(string, p);
88: continue;
89: case 'C':
90: printf(string, cxnames[*app++]);
91: continue;
92: case 'd':
93: printf("%d", *app++);
94: continue;
95: case 'D':
96: printf("%ld", *((long *)app)++);
97: continue;
98: case 'E':
99: snaptree(*((TREE **)app)++, 0);
100: continue;
101: case 'P':
102: psnap(*((char **)app)++);
103: continue;
104: case 'I':
105: patp = *((PAT **)app)++;
106: if (patp != NULL)
107: printf("%8s:%3d", namecache[patp->p_fname],
108: patp->p_fline);
109: else
110: printf("------------");
111: continue;
112: case 'R':
113: if ((c = *app++) >= 0 && c < NREG) {
114: p = regnames[c];
115: printf(string, p);
116: } else
117: printf("Reg %d", c);
118: continue;
119: case 'M':
120: m = *((PREGSET *)app)++;
121: m &= ~NOFREE; /* Forget the default busy set */
122: printf("(");
123: for (c = 0; c < NRREG; c += 1) {
124: if ((reg[c].r_phys&m) == 0)
125: continue;
126: m &= ~reg[c].r_phys;
127: printf("%s", regnames[c]);
128: if (m != 0)
129: putchar('|');
130: else
131: break;
132: }
133: printf(")");
134: continue;
135: case 'W':
136: snapwall(*((char **)app)++);
137: continue;
138: default:
139: cbotch("unknown snapf %c", c);
140: continue;
141: }
142: }
143: }
144:
145: /*
146: * Snap a tree.
147: * The argument 'n' is the
148: * number of spaces to put out
149: * before the node; it is used
150: * to help format the tree in
151: * a tasteful fashon.
152: * Trees are printed in the same format
153: * used in the codetables and the intermediate file printer::
154: * NODE
155: * LEFT
156: * RIGHT
157: */
158: snaptree(tp, n)
159: register TREE *tp;
160: {
161: register i, op;
162:
163: if (tp == NULL)
164: return;
165: op = tp->t_op;
166: snapf("%P %I ", tp, tp->t_patp);
167: i = n;
168: while (i--)
169: putchar(' ');
170: snapnode(tp);
171: if (!isleaf(op)) {
172: snaptree(tp->t_lp, n+2);
173: if (op!=FIELD)
174: snaptree(tp->t_rp, n+2);
175: }
176: }
177:
178: /*
179: * Snap a node.
180: * The required tabbing has
181: * been already put out.
182: */
183: snapnode(tp)
184: register TREE *tp;
185: {
186: register int op;
187: register char *p;
188: register sizeof_t offs;
189:
190: op = tp->t_op;
191: if (op < MDLBASE) {
192: snaptype(tp, milnames[op]);
193: switch(op) {
194:
195: case ICON:
196: isnap(tp->t_ival);
197: break;
198:
199: case LCON:
200: lsnap(tp->t_lval);
201: break;
202:
203: case AID:
204: case PID:
205: printf(" at %ld", (long)tp->t_offs);
206: break;
207:
208: case LID:
209: printf(" %s L%d", segnames[tp->t_seg], tp->t_label);
210: goto snapoffs;
211:
212: case GID:
213: printf(" %s %s", segnames[tp->t_seg], tp->t_sp->s_id);
214: snapoffs:
215: if ((offs=tp->t_offs) != 0) {
216: if (offs >= 0)
217: putchar('+');
218: printf("%ld", (long)offs);
219: }
220: break;
221:
222: case DCON:
223: dsnap(tp->t_dval);
224: break;
225:
226: case REG:
227: snapf(" %R", tp->t_reg);
228: break;
229:
230: }
231: } else if (op < MIOBASE) {
232: snaptype(tp, mdlnames[op-MDLBASE]);
233: mdlsnap(tp);
234: } else if (op < MDOBASE) {
235: snaptype(tp, mionames[op-MIOBASE]);
236: if (op == FIELD)
237: printf(" base=%d width=%d", tp->t_base, tp->t_width);
238: } else if (op < ETCBASE) {
239: snaptype(tp, mdonames[op-MDOBASE]);
240: mdosnap(tp);
241: } else
242: cbotch("bad tree operator: %d", op);
243: printf("\n");
244: }
245:
246: /*
247: * Put out a name.
248: * Tag it with a type.
249: * Used all over.
250: */
251: snaptype(tp, p)
252: register TREE *tp;
253: char *p;
254: {
255: register t;
256:
257: t = tp->t_type;
258: printf("%s %s", p, tynames[t]);
259: if (issized(t))
260: printf(" (%d bytes)", tp->t_size);
261: csnap(tp->t_cost);
262: if (tp->t_treg != NONE)
263: snapf(" nr=%R", tp->t_treg);
264: if (tp->t_rreg != NONE)
265: snapf(" rr=%R", tp->t_rreg);
266: if (tp->t_used != 0)
267: snapf(" used=%M", tp->t_used);
268: fsnap(tp->t_flag);
269: }
270:
271: /*
272: * Put out a titled wall.
273: * If the title is NULL there is no title
274: * at all.
275: */
276: snapwall(s)
277: char *s;
278: {
279: register n, u;
280:
281: if (s == NULL) {
282: snapdash(WIDTH);
283: putchar('\n');
284: return;
285: }
286: u = strlen(s) + 2;
287: n = (WIDTH - u) / 2;
288: u += n;
289: snapdash(n);
290: printf(" %s ", s);
291: snapdash(WIDTH - u);
292: putchar('\n');
293: }
294:
295: /*
296: * Put out `n' dashes.
297: */
298: snapdash(n)
299: register n;
300: {
301: if (n != 0) {
302: do {
303: putchar('-');
304: } while (--n);
305: }
306: }
307:
308: /*
309: * Fill in automatic nodes so they don't print garbage.
310: */
311: snapfix(tp) register TREE *tp;
312: {
313: tp->t_patp = tp->t_lp = tp->t_rp = NULL;
314: tp->t_flag = 0;
315: tp->t_cost = 0;
316: tp->t_rreg = NONE;
317: tp->t_treg = NONE;
318: tp->t_used = 0;
319: }
320:
321: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.