|
|
1.1 root 1: /*
2: * This program prints out
3: * C compiler intermediate language files.
4: * It is a machine dependent program, however
5: * most, if not all, of the machine dependencies
6: * are in tables. It understands all favours of
7: * intermediate files (that is, it understands
8: * both trees and CODE nodes!).
9: */
10: #ifdef vax
11: #include "INC$LIB:cc3.h"
12: #else
13: #include "cc3.h"
14: #endif
15:
16: /*
17: * Possibly impure areas.
18: * All external impure data is here
19: * and is reinitialized by the overlaid version of the mainline.
20: * This permits the compiler to be called many times if loaded
21: * as one big block.
22: */
23: #if !OVERLAID
24: int line; /* Source line */
25: int dotseg; /* Current segment */
26: char file[NFNAME]; /* Source file name */
27: char id[NCSYMB]; /* Identifier buffer */
28: FILE *ifp; /* Input file pointer */
29: FILE *ofp; /* Output file pointer */
30: VARIANT variant; /* Variant template */
31: #endif
32:
33: extern char *segnames[];
34: /*
35: * Temp. file opcodes.
36: */
37: char *ilonames[] = {
38: 0,
39: "file name",
40: 0,
41: 0,
42: "global label",
43: "static label",
44: "block",
45: "prolog",
46: "epilog",
47: 0,
48: 0,
49: 0,
50: 0,
51: "line number",
52: "return expression",
53: "effect expression",
54: "switch expression",
55: "switch body",
56: "initialization expression",
57: "initialize absolute block",
58: 0,
59: "jump if true",
60: "jump if false",
61: 0, /* ENTER */
62: "module name",
63: 0, /* COMM */
64: "", /* DLOCAT */
65: "", /* DLABEL */
66: "segment guess",
67: "undefined reference"
68: };
69:
70: #if !OVERLAID
71: main(argc, argv)
72: char *argv[];
73: {
74: passname = "cc3";
75: if (argc < 3)
76: usage();
77: getvariant(argv[1]);
78: #if GEMDOS
79: {
80: extern long gemdos();
81: extern char *lmalloc();
82: free(lmalloc((gemdos(0x48,-1L)-4096) & ~1023L));
83: }
84: #endif
85: if ((ifp=fopen(argv[2], SRMODE)) == NULL) {
86: fprintf(stderr, "%s: cannot open.\n", argv[2]);
87: exit(BAD);
88: }
89: if (argc == 4) {
90: if ((ofp=fopen(argv[3], "w")) == NULL) {
91: fprintf(stderr, "%s: cannot create.\n", argv[3]);
92: exit(BAD);
93: }
94: } else {
95: ofp = stdout;
96: }
97: exit(work3());
98: }
99:
100: usage()
101: {
102: fprintf(stderr, "Usage: cc3 variant input [output]\n");
103: exit(BAD);
104: }
105:
106: #else
107: /*
108: * This is the mainline of the intermediate interpreter
109: * if the compiler is being run as an overlay job.
110: * The impure area must be reinitialized if monolithic
111: * because the code can be called over and over again.
112: */
113: cc3()
114: {
115: passname = "cc3";
116: if (setjmp(death) != 0) {
117: return (ABORT);
118: }
119: dotseg = -1;
120: #if MONOLITHIC
121: line = 0;
122: #endif
123: return (work3());
124: }
125: #endif
126:
127: /*
128: * This is the nuts and bolts of the operation.
129: */
130: work3()
131: {
132: register int op;
133: register long ifseek;
134:
135: for (;;) {
136: #if TEMPBUF
137: ifseek = (ifp == NULL) ? inbufp - inbuf : ftell(ifp);
138: #else
139: ifseek = ftell(ifp);
140: #endif
141: if ((op=bget())==EOF || op==FINISH)
142: break;
143: if (notvariant(VASM))
144: fprintf(ofp, "%ld:\t", ifseek);
145: switch (op) {
146:
147: case FNAME:
148: case MNAME:
149: case GLABEL:
150: case SLABEL:
151: case UREFER:
152: sget(id, NCSYMB);
153: if (isvariant(VASM))
154: genname(op, id);
155: else {
156: fprintf(ofp, "\t%s\t%s\n", ilonames[op], id);
157: if (op==GLABEL || op==SLABEL)
158: fprintf(ofp, "\t%s:\n", id);
159: }
160: break;
161:
162: case LLABEL:
163: if (isvariant(VASM))
164: genival(op, (long)iget());
165: else
166: fprintf(ofp, "L%d:\n", iget());
167: break;
168:
169: case LINE:
170: line = iget();
171: if (isvariant(VASM))
172: genival(op, (long)line);
173: else
174: fprintf(ofp, "\t%s\t%d\n", ilonames[op], line);
175: break;
176:
177: case BLOCK:
178: if (isvariant(VASM))
179: genival(op, (long)zget());
180: else
181: fprintf(ofp, "%s\t%ld\n",
182: ilonames[op], (long)zget());
183: break;
184:
185: case DLOCAT:
186: cc3dloc();
187: break;
188: case DLABEL:
189: cc3dbug(1);
190: break;
191:
192: case PROLOG:
193: case EPILOG:
194: fprintf(ofp, "\t%s\n", ilonames[op]);
195: break;
196:
197: case AUTOS:
198: genautos();
199: break;
200:
201: case JUMP:
202: fprintf(ofp, "\tjump\tL%d\n", iget());
203: break;
204:
205: case COMM:
206: gencomm();
207: break;
208:
209: case ENTER:
210: if (isvariant(VASM))
211: genival(op, (long)bget());
212: else
213: fprintf(ofp, "\tenter %s\n", segnames[bget()]);
214: break;
215:
216: case ALIGN:
217: if (isvariant(VASM))
218: genival(op, (long)bget());
219: else
220: fprintf(ofp, "\talign %d\n", bget());
221: break;
222:
223: case SBODY:
224: {
225: register int deflab, ncases, clabel;
226: register ival_t cvalue;
227:
228: deflab = iget();
229: ncases = iget();
230: fprintf(ofp, "%s\n", ilonames[op]);
231: while (ncases--) {
232: cvalue = iget();
233: clabel = iget();
234: fprintf(ofp, "\t\t%d\tL%d\n", cvalue, clabel);
235: }
236: fprintf(ofp, "\t\tdef\tL%d\n", deflab);
237: break;
238: }
239:
240: case IBLOCK:
241: {
242: register int firstb, nitems;
243:
244: fprintf(ofp, "byte block\t");
245: nitems = bget();
246: firstb = 0;
247: while (nitems--) {
248: if (firstb++ != 0)
249: fprintf(ofp, " ");
250: fprintf(ofp, "%d", bget());
251: }
252: fprintf(ofp, "\n");
253: break;
254: }
255:
256: case REXPR:
257: case SEXPR:
258: case TEXPR:
259: case FEXPR:
260: case IEXPR:
261: case EEXPR:
262: itree(op);
263: break;
264:
265: case CODE:
266: icode();
267: break;
268:
269: case EOF:
270: cfatal("unexpected EOF");
271:
272: default:
273: cbotch("bad temporary file opcode %d", op);
274: }
275: }
276: if (op != FINISH)
277: cfatal("unexpected EOF");
278: return (OK);
279: }
280:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.