|
|
1.1 root 1: /* Copyright (c) 1979 Regents of the University of California */
2:
3: static char sccsid[] = "@(#)pc2.c 1.13 6/1/83";
4:
5: #include <stdio.h>
6: #include <ctype.h>
7: /*
8: * The hash table must be at least twice as big as the number
9: * of patterns, preferably bigger. It must also be a prime number
10: */
11: #define HSHSIZ 101
12:
13: #ifdef vax
14: #define CALLTEMPLATE "calls\t$"
15: #define TEMPLATESIZE 7
16: #endif vax
17:
18: #ifdef mc68000
19: #define CALLTEMPLATE "jbsr\t"
20: #define TEMPLATESIZE 5
21: #endif mc68000
22:
23: struct pats {
24: char *name;
25: char *replace;
26: } ptab[] = {
27:
28: #ifdef vax
29: /*
30: * C library routines
31: */
32: { "1,_fgetc\n",
33: " sobgeq *(sp),1f\n\
34: calls $1,__filbuf\n\
35: jbr 2f\n\
36: 1:\n\
37: addl3 $4,(sp)+,r1\n\
38: movzbl *(r1),r0\n\
39: incl (r1)\n\
40: 2:\n" },
41:
42: { "2,_fputc\n",
43: " sobgeq *4(sp),1f\n\
44: calls $2,__flsbuf\n\
45: jbr 2f\n\
46: 1:\n\
47: popr $0x3\n\
48: movb r0,*4(r1)\n\
49: incl 4(r1)\n\
50: 2:\n" },
51:
52: /*
53: * VAX special instructions
54: */
55: { "3,_blkcpy\n",
56: " popr $0xa\n\
57: jbr 2f\n\
58: 1:\n\
59: subl2 r0,(sp)\n\
60: movc3 r0,(r1),(r3)\n\
61: 2:\n\
62: movzwl $65535,r0\n\
63: cmpl (sp),r0\n\
64: jgtr 1b\n\
65: movl (sp)+,r0\n\
66: movc3 r0,(r1),(r3)\n" },
67:
68: { "2,_blkclr\n",
69: " movl (sp)+,r3\n\
70: jbr 2f\n\
71: 1:\n\
72: subl2 r0,(sp)\n\
73: movc5 $0,(r3),$0,r0,(r3)\n\
74: 2:\n\
75: movzwl $65535,r0\n\
76: cmpl (sp),r0\n\
77: jgtr 1b\n\
78: movl (sp)+,r0\n\
79: movc5 $0,(r3),$0,r0,(r3)\n" },
80:
81: { "3,_LOCC\n",
82: " popr $0x30\n\
83: movl (sp)+,r1\n\
84: 1:\n\
85: movzwl $65535,r0\n\
86: cmpl r5,r0\n\
87: jleq 1f\n\
88: subl2 r0,r5\n\
89: locc r4,r0,(r1)\n\
90: jeql 1b\n\
91: addl2 r5,r0\n\
92: jbr 2f\n\
93: 1:\n\
94: locc r4,r5,(r1)\n\
95: 2:\n" },
96:
97: { "2,_ROUND\n",
98: " cvtrdl (sp)+,r0\n" },
99:
100: { "2,_TRUNC\n",
101: " cvtdl (sp)+,r0\n" },
102:
103: /*
104: * General Pascal library routines
105: */
106: { "1,_ACTFILE\n",
107: " movl (sp)+,r1\n\
108: movl 12(r1),r0\n" },
109:
110: { "2,_FCALL\n",
111: " movl 4(sp),r0\n\
112: movc3 4(r0),__disply+8,*(sp)+\n\
113: movl (sp)+,r0\n\
114: movc3 4(r0),8(r0),__disply+8\n" },
115:
116: { "2,_FRTN\n",
117: " movl (sp)+,r0\n\
118: movc3 4(r0),*(sp)+,__disply+8\n" },
119:
120: { "3,_FSAV\n",
121: " movl 8(sp),r0\n\
122: movl (sp)+,(r0)\n\
123: ashl $3,(sp)+,4(r0)\n\
124: movc3 4(r0),__disply+8,8(r0)\n\
125: movl (sp)+,r0\n" },
126:
127: /*
128: * Pascal relational comparisons
129: */
130: { "3,_RELEQ\n",
131: " popr $0xb\n\
132: movl r0,r4\n\
133: 1:\n\
134: movzwl $65535,r0\n\
135: cmpl r4,r0\n\
136: jleq 3f\n\
137: subl2 r0,r4\n\
138: cmpc3 r0,(r1),(r3)\n\
139: jeql 1b\n\
140: 2:\n\
141: clrl r0\n\
142: jbr 4f\n\
143: 3:\n\
144: cmpc3 r4,(r1),(r3)\n\
145: jneq 2b\n\
146: incl r0\n\
147: 4:\n" },
148:
149: { "3,_RELNE\n",
150: " popr $0xb\n\
151: movl r0,r4\n\
152: 1:\n\
153: movzwl $65535,r0\n\
154: cmpl r4,r0\n\
155: jleq 3f\n\
156: subl2 r0,r4\n\
157: cmpc3 r0,(r1),(r3)\n\
158: jeql 1b\n\
159: 2:\n\
160: movl $1,r0\n\
161: jbr 4f\n\
162: 3:\n\
163: cmpc3 r4,(r1),(r3)\n\
164: jneq 2b\n\
165: 4:\n" },
166:
167: { "3,_RELSLT\n",
168: " popr $0xb\n\
169: movl r0,r4\n\
170: jbr 2f\n\
171: 1:\n\
172: subl2 r0,r4\n\
173: cmpc3 r0,(r1),(r3)\n\
174: jneq 3f\n\
175: 2:\n\
176: movzwl $65535,r0\n\
177: cmpl r4,r0\n\
178: jgtr 1b\n\
179: cmpc3 r4,(r1),(r3)\n\
180: 3:\n\
181: jlss 4f\n\
182: clrl r0\n\
183: jbr 5f\n\
184: 4:\n\
185: movl $1,r0\n\
186: 5:\n" },
187:
188: { "3,_RELSLE\n",
189: " popr $0xb\n\
190: movl r0,r4\n\
191: jbr 2f\n\
192: 1:\n\
193: subl2 r0,r4\n\
194: cmpc3 r0,(r1),(r3)\n\
195: jneq 3f\n\
196: 2:\n\
197: movzwl $65535,r0\n\
198: cmpl r4,r0\n\
199: jgtr 1b\n\
200: cmpc3 r4,(r1),(r3)\n\
201: 3:\n\
202: jleq 4f\n\
203: clrl r0\n\
204: jbr 5f\n\
205: 4:\n\
206: movl $1,r0\n\
207: 5:\n" },
208:
209: { "3,_RELSGT\n",
210: " popr $0xb\n\
211: movl r0,r4\n\
212: jbr 2f\n\
213: 1:\n\
214: subl2 r0,r4\n\
215: cmpc3 r0,(r1),(r3)\n\
216: jneq 3f\n\
217: 2:\n\
218: movzwl $65535,r0\n\
219: cmpl r4,r0\n\
220: jgtr 1b\n\
221: cmpc3 r4,(r1),(r3)\n\
222: 3:\n\
223: jgtr 4f\n\
224: clrl r0\n\
225: jbr 5f\n\
226: 4:\n\
227: movl $1,r0\n\
228: 5:\n" },
229:
230: { "3,_RELSGE\n",
231: " popr $0xb\n\
232: movl r0,r4\n\
233: jbr 2f\n\
234: 1:\n\
235: subl2 r0,r4\n\
236: cmpc3 r0,(r1),(r3)\n\
237: jneq 3f\n\
238: 2:\n\
239: movzwl $65535,r0\n\
240: cmpl r4,r0\n\
241: jgtr 1b\n\
242: cmpc3 r4,(r1),(r3)\n\
243: 3:\n\
244: jgeq 4f\n\
245: clrl r0\n\
246: jbr 5f\n\
247: 4:\n\
248: movl $1,r0\n\
249: 5:\n" },
250:
251: /*
252: * Pascal set operations.
253: */
254: { "4,_ADDT\n",
255: " popr $0x17\n\
256: movl r0,r3\n\
257: 1:\n\
258: bisl3 (r1)+,(r2)+,(r3)+\n\
259: sobgtr r4,1b\n" },
260:
261: { "4,_SUBT\n",
262: " popr $0x17\n\
263: movl r0,r3\n\
264: 1:\n\
265: bicl3 (r2)+,(r1)+,(r3)+\n\
266: sobgtr r4,1b\n" },
267:
268: { "4,_MULT\n",
269: " popr $0x17\n\
270: movl r0,r3\n\
271: 1:\n\
272: mcoml (r1)+,r5\n\
273: bicl3 r5,(r2)+,(r3)+\n\
274: sobgtr r4,1b\n" },
275:
276: { "4,_IN\n",
277: " popr $0x1e\n\
278: clrl r0\n\
279: subl2 r2,r1\n\
280: cmpl r1,r3\n\
281: jgtru 1f\n\
282: jbc r1,(r4),1f\n\
283: incl r0\n\
284: 1:\n" },
285:
286: /*
287: * Pascal runtime checks
288: */
289: { "1,_ASRT\n",
290: " tstl (sp)+\n\
291: jneq 1f\n\
292: pushl $0\n\
293: pushl $_EASRT\n\
294: calls $2,_ERROR\n\
295: 1:\n" },
296:
297: { "2,_ASRTS\n",
298: " popr $0x03\n\
299: tstl r0\n\
300: jneq 1f\n\
301: pushl r1\n\
302: pushl $_EASRTS\n\
303: calls $2,_ERROR\n\
304: 1:\n" },
305:
306: { "1,_CHR\n",
307: " movl (sp)+,r0\n\
308: cmpl r0,$127\n\
309: jlequ 1f\n\
310: pushl r0\n\
311: pushl $_ECHR\n\
312: calls $2,_ERROR\n\
313: 1:\n" },
314:
315: { "0,_LINO\n",
316: " incl __stcnt\n\
317: cmpl __stcnt,__stlim\n\
318: jlss 1f\n\
319: pushl __stcnt\n\
320: pushl $_ELINO\n\
321: calls $2,_ERROR\n\
322: 1:\n" },
323:
324: { "1,_NIL\n",
325: " movl (sp)+,r0\n\
326: cmpl r0,__maxptr\n\
327: jgtr 1f\n\
328: cmpl r0,__minptr\n\
329: jgeq 2f\n\
330: 1:\n\
331: pushl $0\n\
332: pushl $_ENIL\n\
333: calls $2,_ERROR\n\
334: 2:\n" },
335:
336: { "2,_RANDOM\n",
337: " addl2 $8,sp\n\
338: emul __seed,$1103515245,$0,r0\n\
339: ediv $0x7fffffff,r0,r1,r0\n\
340: movl r0,__seed\n\
341: cvtld r0,r0\n\
342: divd2 $0d2.147483647e+09,r0\n" },
343:
344: { "3,_RANG4\n",
345: " popr $0x07\n\
346: cmpl r0,r1\n\
347: jlss 1f\n\
348: cmpl r0,r2\n\
349: jleq 2f\n\
350: 1:\n\
351: pushl r0\n\
352: pushl $_ERANG\n\
353: calls $2,_ERROR\n\
354: 2:\n" },
355:
356: { "2,_RSNG4\n",
357: " popr $0x03\n\
358: cmpl r0,r1\n\
359: jlequ 1f\n\
360: pushl r0\n\
361: pushl $_ERANG\n\
362: calls $2,_ERROR\n\
363: 1:\n" },
364:
365: { "1,_SEED\n",
366: " movl __seed,r0\n\
367: movl (sp)+,__seed\n" },
368:
369: { "3,_SUBSC\n",
370: " popr $0x07\n\
371: cmpl r0,r1\n\
372: jlss 1f\n\
373: cmpl r0,r2\n\
374: jleq 2f\n\
375: 1:\n\
376: pushl r0\n\
377: pushl $_ESUBSC\n\
378: calls $2,_ERROR\n\
379: 2:\n" },
380:
381: { "2,_SUBSCZ\n",
382: " popr $0x03\n\
383: cmpl r0,r1\n\
384: jlequ 1f\n\
385: pushl r0\n\
386: pushl $_ESUBSC\n\
387: calls $2,_ERROR\n\
388: 1:\n" },
389: #endif vax
390:
391: #ifdef mc68000
392:
393: /*
394: * General Pascal library routines
395: */
396: { "_ACTFILE\n",
397: " movl sp@,a0\n\
398: movl a0@(12),d0\n" },
399:
400: { "_ADDT\n",
401: " movl a2,sp@-\n\
402: movl sp@(8),a2\n\
403: movl sp@(12),a1\n\
404: movl sp@(4),a0\n\
405: movl sp@(16),d1\n\
406: subql #1,d1\n\
407: 1:\n\
408: movl a2@+,d0\n\
409: orl a1@+,d0\n\
410: movl d0,a0@+\n\
411: dbra d1,1b\n\
412: movl sp@+,a2\n\
413: movl sp@,d0\n" },
414:
415: { "_SUBT\n",
416: " movl a2,sp@-\n\
417: movl sp@(8),a2\n\
418: movl sp@(12),a1\n\
419: movl sp@(4),a0\n\
420: movl sp@(16),d1\n\
421: subql #1,d1\n\
422: 1:\n\
423: movl a1@+,d0\n\
424: notl d0\n\
425: andl a2@+,d0\n\
426: movl d0,a0@+\n\
427: dbra d1,1b\n\
428: movl sp@+,a2\n\
429: movl sp@,d0\n" },
430:
431: { "_MULT\n",
432: " movl a2,sp@-\n\
433: movl sp@(8),a2\n\
434: movl sp@(12),a1\n\
435: movl sp@(4),a0\n\
436: movl sp@(16),d1\n\
437: subql #1,d1\n\
438: 1:\n\
439: movl a2@+,d0\n\
440: andl a1@+,d0\n\
441: movl d0,a0@+\n\
442: dbra d1,1b\n\
443: movl sp@+,a2\n\
444: movl sp@,d0\n" },
445:
446: { "_IN\n",
447: " movl sp@,d1\n\
448: subl sp@(4),d1\n\
449: cmpl sp@(8),d1\n\
450: jbhi 1f\n\
451: movl sp@(12),a0\n\
452: movl d1,d0\n\
453: lsrl #3,d0\n\
454: btst d1,a0@(0,d0:l)\n\
455: jbne 1f\n\
456: moveq #1,d0\n\
457: jbra 2f\n\
458: 1:\n\
459: moveq #0,d0\n\
460: 2:\n" },
461: #endif mc68000
462:
463: };
464:
465: struct pats *htbl[HSHSIZ];
466:
467:
468: #define HASH(cp, hp) {\
469: hash = 0; rehash = 1; ccp = cp; \
470: do { \
471: hash *= (int)*ccp++; \
472: } while (*ccp && *ccp != '\n'); \
473: hash >>= 7; hash %= HSHSIZ; hp = &htbl[hash]; size = ccp - cp + 1; \
474: }
475:
476: #define REHASH(hp) {\
477: hp += rehash; rehash += 2; \
478: if (hp >= &htbl[HSHSIZ]) \
479: hp -= HSHSIZ; \
480: }
481:
482:
483: main(argc, argv)
484:
485: int argc;
486: char **argv;
487: {
488: register struct pats *pp;
489: register struct pats **hp;
490: register char *cp, *ccp, *lp;
491: register int hash, rehash, size;
492: char line[BUFSIZ];
493: extern char *index();
494:
495: if (argc > 1)
496: freopen(argv[1], "r", stdin);
497: if (argc > 2)
498: freopen(argv[2], "w", stdout);
499: /*
500: * set up the hash table
501: */
502: for(pp = ptab; pp < &ptab[sizeof ptab/sizeof ptab[0]]; pp++) {
503: HASH(pp->name, hp);
504: while (*hp)
505: REHASH(hp);
506: *hp = pp;
507: }
508: /*
509: * check each line and replace as appropriate
510: */
511: while (fgets(line, BUFSIZ, stdin)) {
512: lp = index(line, ':');
513: for (cp = (lp != NULL) ? ++lp : line; *cp == '\t'; )
514: cp++;
515: if (strcmpn(cp, CALLTEMPLATE, TEMPLATESIZE) != 0) {
516: fputs(line, stdout);
517: continue;
518: }
519: cp += TEMPLATESIZE;
520: HASH(cp, hp);
521: while (*hp) {
522: if (strcmpn((*hp)->name, cp, size)==NULL) {
523: if (lp != NULL) {
524: *lp++ = '\n';
525: *lp = '\0';
526: fputs(line, stdout);
527: }
528: fputs((*hp)->replace, stdout);
529: goto nextline;
530: }
531: REHASH(hp);
532: }
533: fputs(line, stdout);
534: nextline:;
535: }
536: exit(0);
537: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.