|
|
1.1 root 1: /* Copyright (c) 1979 Regents of the University of California */
2: #
3: /*
4: * pxp - Pascal execution profiler
5: *
6: * Bill Joy UCB
7: * Version 1.2 January 1979
8: */
9:
10: #include "0.h"
11: #include "tree.h"
12:
13: int cntstat;
14: int cnts 3;
15:
16: statlist(r)
17: int *r;
18: {
19: register int *sl;
20:
21: sl = r;
22: if (sl != NIL)
23: for (;;) {
24: statement(sl[1]);
25: sl = sl[2];
26: if (sl == NIL)
27: break;
28: ppsep(";");
29: }
30: else
31: statement(NIL);
32: }
33:
34:
35: statement(r)
36: int *r;
37: {
38: register int *s;
39:
40: s = r;
41: top:
42: if (cntstat) {
43: cntstat = 0;
44: getcnt();
45: }
46: if (s == NIL) {
47: putcm();
48: ppitem();
49: ppid("null");
50: return;
51: }
52: if (s[0] == T_REPEAT)
53: setinfo(s[1]);
54: else
55: setline(s[1]);
56: if (s[0] == T_LABEL) {
57: cntstat = 1;
58: ppnl();
59: labeled(s[2]);
60: statement(s[3]);
61: return;
62: }
63: switch (s[0]) {
64: default:
65: panic("stat");
66: case T_PCALL:
67: ppitem();
68: proc(s);
69: break;
70: case T_IF:
71: case T_IFEL:
72: ppnl();
73: indent();
74: ifop(s);
75: break;
76: case T_WHILE:
77: ppnl();
78: indent();
79: whilop(s);
80: break;
81: case T_REPEAT:
82: ppnl();
83: indent();
84: repop(s);
85: break;
86: case T_FORU:
87: case T_FORD:
88: ppnl();
89: indent();
90: forop(s);
91: break;
92: case T_BLOCK:
93: ppnl();
94: indent();
95: ppstbl(s, DECL);
96: break;
97: case T_ASGN:
98: ppitem();
99: asgnop(s);
100: break;
101: case T_GOTO:
102: ppitem();
103: gotoop(s[2]);
104: cntstat = 1;
105: break;
106: case T_CASE:
107: ppnl();
108: indent();
109: caseop(s);
110: break;
111: case T_WITH:
112: ppnl();
113: indent();
114: withop(s);
115: break;
116: case T_ASRT:
117: ppitem();
118: asrtop(s);
119: break;
120: }
121: setinfo(s[1]);
122: putcm();
123: }
124:
125: withop(s)
126: int *s;
127: {
128: register *p;
129:
130: ppkw("with");
131: ppspac();
132: p = s[2];
133: if (p != NIL)
134: for (;;) {
135: lvalue(p[1]);
136: p = p[2];
137: if (p == NIL)
138: break;
139: ppsep(", ");
140: }
141: else
142: ppid("{record variable list}");
143: ppstdo(s[3], DECL);
144: }
145:
146: asgnop(r)
147: int *r;
148: {
149:
150: lvalue(r[2]);
151: ppsep(" := ");
152: rvalue(r[3], NIL);
153: }
154:
155: forop(r)
156: int *r;
157: {
158: struct pxcnt scnt;
159:
160: savecnt(&scnt);
161: ppkw("for");
162: ppspac();
163: asgnop(r[2]);
164: ppspac();
165: ppkw(r[0] == T_FORU ? "to" : "downto");
166: ppspac();
167: rvalue(r[3], NIL);
168: getcnt();
169: ppstdo(r[4], STAT);
170: if (rescnt(&scnt))
171: getcnt();
172: }
173:
174: ifop(r)
175: int *r;
176: {
177: register *s;
178: struct pxcnt scnt;
179:
180: ppkw("if");
181: ppspac();
182: rvalue(r[2], NIL);
183: ppspac();
184: ppkw("then");
185: ppspac();
186: s = r[3];
187: savecnt(&scnt);
188: getcnt();
189: if (s != NIL && s[0] == T_BLOCK)
190: ppstbl1(s, STAT);
191: else {
192: ppgoin(STAT);
193: statement(s);
194: ppgoout(STAT);
195: }
196: if (r[0] == T_IFEL) {
197: setcnt(cntof(&scnt)-nowcnt());
198: if (s == NIL || s[0] != T_BLOCK) {
199: ppnl();
200: indent();
201: } else {
202: ppstbl2();
203: ppspac();
204: }
205: s = r[4];
206: ppkw("else");
207: unprint();
208: ppspac();
209: if (s == NIL)
210: goto burp;
211: if (s[0] == T_BLOCK)
212: ppstbl1(s, STAT);
213: else if (s[0] == T_IF || s[0] == T_IFEL)
214: ifop(s);
215: else {
216: burp:
217: ppgoin(STAT);
218: statement(s);
219: ppgoout(STAT);
220: }
221: }
222: if (rescnt(&scnt))
223: getcnt();
224: if (r[4] != NIL)
225: unprint();
226: if (s != NIL && s[0] == T_BLOCK)
227: ppstbl2();
228: }
229:
230: whilop(r)
231: int *r;
232: {
233: struct pxcnt scnt;
234:
235: ppkw("while");
236: ppspac();
237: rvalue(r[2], NIL);
238: savecnt(&scnt);
239: getcnt();
240: ppstdo(r[3], STAT);
241: if (rescnt(&scnt))
242: getcnt();
243: }
244:
245: repop(r)
246: int *r;
247: {
248: struct pxcnt scnt;
249:
250: ppkw("repeat");
251: ppgoin(STAT);
252: savecnt(&scnt);
253: getcnt();
254: statlist(r[2]);
255: ppgoout(DECL);
256: ppnl();
257: indent();
258: ppkw("until");
259: ppspac();
260: rvalue(r[3], NIL);
261: ppgoin(DECL);
262: ppgoout(STAT);
263: if (rescnt(&scnt))
264: getcnt();
265: }
266:
267: ppstbl(r, m)
268: int *r;
269: {
270: ppstbl1(r, m);
271: ppstbl2();
272: }
273:
274: ppstbl1(r, m)
275: int *r;
276: {
277: ppkw("begin");
278: ppgoin(m);
279: statlist(r[2]);
280: ppgoout(m);
281: }
282:
283: ppstbl2()
284: {
285: ppnl();
286: indent();
287: ppkw("end");
288: }
289:
290: ppstdo(r, l)
291: int *r;
292: {
293: register *s;
294:
295: ppspac();
296: ppkw("do");
297: ppspac();
298: s = r;
299: if (s != NIL && s[0] == T_BLOCK)
300: ppstbl(s, l);
301: else {
302: ppgoin(l);
303: statement(s);
304: ppgoout(l);
305: }
306: }
307:
308: asrtop(s)
309: int *s;
310: {
311:
312: ppkw("assert");
313: ppspac();
314: rvalue(s[2], NIL);
315: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.