Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

View File

@@ -0,0 +1,340 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define OPPRI 077
#define OPBIN 0100
#define STKLEN 64
int oprstk[STKLEN]; /*operator stack*/
int opnstk[STKLEN]; /*operand stack*/
int pristk[STKLEN]; /*operator priority stack*/
int *oprptr; /*pointer to operator stack*/
int *opnptr; /*pointer to operand stack*/
int *priptr; /*pointer to priority stack*/
int cvalue;
int opinfo[] {
0, /*EOF=0*/
16|OPBIN, /*SUB=1*/
16|OPBIN, /*ADD=2*/
20, /*NOT=3*/
20, /*NEG=4*/
22, /*LPAREN=5*/
2, /*RPAREN=6*/
6|OPBIN, /*QMARK=7*/
6|OPBIN, /*COLON=8*/
8|OPBIN, /*OR=9*/
10|OPBIN, /*AND=10*/
8|OPBIN, /*XOR=11*/
12|OPBIN, /*EQUAL=12*/
12|OPBIN, /*NEQUAL=13*/
14|OPBIN, /*LESS=14*/
14|OPBIN, /*LSEQUAL=15*/
14|OPBIN, /*GREAT=16*/
14|OPBIN, /*GREQUAL=17*/
4|OPBIN, /*LSHIFT=18*/
4|OPBIN, /*RSHIFT=19*/
18|OPBIN, /*MULT=20*/
18|OPBIN, /*DIV=21*/
18|OPBIN, /*MOD=22*/
20, /*COMPL=23*/
};
/* cexpr - constant expression evaluation*/
/* Does priority-driven operator/operand stack evaluation of*/
/* constant expressions.*/
cexpr() /* returns constant evaluated*/
{
register int lop, type;
oprptr = &oprstk[0];
opnptr = &opnstk[0];
priptr = &pristk[0];
*priptr = 0;
lop = -1;
while(1) {
switch( type = getctok() ) {
case CONST:
if( !lop ) /*last was not operator*/
goto syntax;
if( opnptr >= &opnstk[STKLEN] ) {
error("expression stack overflow");
cexit();
}
lop = FALSE;
*++opnptr = cvalue;
continue;
case SUB:
if( lop )
type = NEG; /*unary minus*/
break;
case ADD:
if( lop )
continue; /*ignore unary +*/
break;
case COMPL:
case LPAREN:
case NOT:
if( !lop )
goto syntax;
break;
case RPAREN:
if( lop )
goto syntax;
lop = FALSE;
if( !stkop(type) )
goto syntax;
continue;
case NEWL:
case EOF:
if( lop || !stkop(EOF) || opnptr != &opnstk[1] )
goto syntax;
type = opnstk[1];
putback('\n');
return(type);
default:
if( lop || type > LASTOP )
goto syntax;
break;
}
lop = TRUE;
if( !stkop(type) )
goto syntax;
}
syntax:
error("expression syntax");
if( type == NEWL )
putback('\n');
return(0);
}
/* getctok - get a constant expression token*/
/* Handles conversion of quoted character strings and numbers.*/
getctok()
{
register int type, c, count;
register char *p;
char token[TOKSIZE];
while( 1 ) {
switch( type = getntok(token) ) {
case DIGIT:
cvalue = const(token);
return(CONST);
case SQUOTE:
for( cvalue = 0, p = &token[1], count = 2; --count >= 0; ) {
if( (c= *p++) == '\'' )
break;
if( c == '\\' ) {
if( *p >= '0' && *p <= '7' ) {
for( c = 0; *p >= '0' && *p <= '7'; )
c = (c<<3) + (*p++ - '0');
}
else switch( c = *p++ ) {
case 'n':
c = '\n';
break;
case 't':
c = '\t';
break;
case 'b':
c = '\b';
break;
case 'r':
c = '\r';
break;
case 'f':
c = '\f';
break;
}
}
cvalue = (cvalue<<8) | c;
}
return(CONST);
case ALPHA:
if( p = lookup(token) )
expand(p);
else
return(ALPHA);
break;
default:
return(type);
}
}
}
/* stkop - stack an operator on the operand stack*/
/* Unstack all operators of lower priority, evaluating them as*/
/* they are unstacked.*/
stkop(opr) /* returns 1 if ok, 0 otherwise*/
int opr; /* operator to stack*/
{
register int i, j, op1, op2, pri;
for( pri = opinfo[opr]&OPPRI; pri < *priptr; ) {
if( *oprptr == LPAREN ) {
if( opr == RPAREN ) {
oprptr--;
priptr--;
return(1);
}
break;
}
op1 = *opnptr;
if( (i=opinfo[*oprptr]) & OPBIN ) {
op2 = op1;
op1 = *--opnptr;
}
switch(*oprptr) { /*operator*/
case ADD:
op1 =+ op2;
break;
case SUB:
op1 =- op2;
break;
case COLON:
priptr--;
if( *--oprptr != QMARK )
return(0);
op1 = (*--opnptr ? op1 : op2);
break;
case QMARK:
return(0);
case XOR:
op1 =^ op2;
break;
case OR:
op1 =| op2;
break;
case AND:
op1 =& op2;
break;
case EQUAL:
op1 = (op1 == op2);
break;
case NEQUAL:
op1 = (op1 != op2);
break;
case LESS:
op1 = (op1 < op2);
break;
case LSEQUAL:
op1 = (op1 <= op2);
break;
case GREAT:
op1 = (op1 > op2);
break;
case GREQUAL:
op1 = (op1 >= op2);
break;
case LSHIFT:
op1 = (op1 << op2);
break;
case RSHIFT:
op1 = (op1 >> op2);
break;
case NEG:
op1 = -op1;
break;
case NOT:
op1 = !op1;
break;
case COMPL:
op1 = ~ op1;
break;
case MULT:
op1 =* op2;
break;
case DIV:
op1 =/ op2;
break;
case MOD:
op1 =% op2;
break;
}
*opnptr = op1;
priptr--;
oprptr--;
}
if( priptr >= &pristk[STKLEN-1] ) {
error("expression operator stack overflow");
cexit();
}
*++oprptr = opr; /*operator value*/
*++priptr = pri; /*operator priority*/
return(1);
}
#define toupper(c) ((c) & ~32)
/* const - alpha to int conversion, handles octal and hexidecimal*/
/* Uses Horner's method to evaluate number.*/
const(str) /* returns number evaluated*/
char *str; /* pointer to string to convert*/
{
register int c, ch, i, radix;
i = 0;
radix = 10;
if( *str == '0' ) {
radix = 8;
if( *++str == 'x' || *str == 'X' ) {
radix = 16;
str++;
}
}
while( c = *str++ ) {
if( (ch=toupper(c)) >= 'A' && ch <= 'F' )
c = ch - ('A'-10);
else if( c >= '0' && c <= '9' )
c =- '0';
else
break;
if( c >= radix )
break;
i = i*radix + c;
}
return(i);
}

View File

@@ -0,0 +1,346 @@
1File: CEXPR.C Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7
8 #include "preproc.h"
9
10 #define OPPRI 077
11 #define OPBIN 0100
12 #define STKLEN 64
13 int oprstk[STKLEN]; /*operator stack*/
14 int opnstk[STKLEN]; /*operand stack*/
15 int pristk[STKLEN]; /*operator priority stack*/
16 int *oprptr; /*pointer to operator stack*/
17 int *opnptr; /*pointer to operand stack*/
18 int *priptr; /*pointer to priority stack*/
19 int cvalue;
20
21 int opinfo[] {
22 0, /*EOF=0*/
23 16|OPBIN, /*SUB=1*/
24 16|OPBIN, /*ADD=2*/
25 20, /*NOT=3*/
26 20, /*NEG=4*/
27 22, /*LPAREN=5*/
28 2, /*RPAREN=6*/
29 6|OPBIN, /*QMARK=7*/
30 6|OPBIN, /*COLON=8*/
31 8|OPBIN, /*OR=9*/
32 10|OPBIN, /*AND=10*/
33 8|OPBIN, /*XOR=11*/
34 12|OPBIN, /*EQUAL=12*/
35 12|OPBIN, /*NEQUAL=13*/
36 14|OPBIN, /*LESS=14*/
37 14|OPBIN, /*LSEQUAL=15*/
38 14|OPBIN, /*GREAT=16*/
39 14|OPBIN, /*GREQUAL=17*/
40 4|OPBIN, /*LSHIFT=18*/
41 4|OPBIN, /*RSHIFT=19*/
42 18|OPBIN, /*MULT=20*/
43 18|OPBIN, /*DIV=21*/
44 18|OPBIN, /*MOD=22*/
45 20, /*COMPL=23*/
46 };
47
48 /* cexpr - constant expression evaluation*/
49 /* Does priority-driven operator/operand stack evaluation of*/
50 /* constant expressions.*/
51 cexpr() /* returns constant evaluated*/
52 {
53 register int lop, type;
54
55 oprptr = &oprstk[0];
56 opnptr = &opnstk[0];
57 priptr = &pristk[0];
58 *priptr = 0;
59 lop = -1;
1File: CEXPR.C Page 2
60 while(1) {
61 switch( type = getctok() ) {
62
63 case CONST:
64 if( !lop ) /*last was not operator*/
65 goto syntax;
66 if( opnptr >= &opnstk[STKLEN] ) {
67 error("expression stack overflow");
68 cexit();
69 }
70 lop = FALSE;
71 *++opnptr = cvalue;
72 continue;
73
74 case SUB:
75 if( lop )
76 type = NEG; /*unary minus*/
77 break;
78
79 case ADD:
80 if( lop )
81 continue; /*ignore unary +*/
82 break;
83
84 case COMPL:
85 case LPAREN:
86 case NOT:
87 if( !lop )
88 goto syntax;
89 break;
90
91 case RPAREN:
92 if( lop )
93 goto syntax;
94 lop = FALSE;
95 if( !stkop(type) )
96 goto syntax;
97 continue;
98
99 case NEWL:
100 case EOF:
101 if( lop || !stkop(EOF) || opnptr != &opnstk[1] )
102 goto syntax;
103 type = opnstk[1];
104 putback('\n');
105 return(type);
106
107 default:
108 if( lop || type > LASTOP )
109 goto syntax;
110 break;
111 }
112 lop = TRUE;
113 if( !stkop(type) )
114 goto syntax;
115 }
116 syntax:
117 error("expression syntax");
118 if( type == NEWL )
1File: CEXPR.C Page 3
119 putback('\n');
120 return(0);
121 }
122
123 /* getctok - get a constant expression token*/
124 /* Handles conversion of quoted character strings and numbers.*/
125 getctok()
126 {
127 register int type, c, count;
128 register char *p;
129 char token[TOKSIZE];
130
131 while( 1 ) {
132 switch( type = getntok(token) ) {
133
134 case DIGIT:
135 cvalue = const(token);
136 return(CONST);
137
138 case SQUOTE:
139 for( cvalue = 0, p = &token[1], count = 2; --count >= 0; ) {
140 if( (c= *p++) == '\'' )
141 break;
142 if( c == '\\' ) {
143 if( *p >= '0' && *p <= '7' ) {
144 for( c = 0; *p >= '0' && *p <= '7'; )
145 c = (c<<3) + (*p++ - '0');
146 }
147 else switch( c = *p++ ) {
148
149 case 'n':
150 c = '\n';
151 break;
152
153 case 't':
154 c = '\t';
155 break;
156
157 case 'b':
158 c = '\b';
159 break;
160
161 case 'r':
162 c = '\r';
163 break;
164
165 case 'f':
166 c = '\f';
167 break;
168 }
169 }
170 cvalue = (cvalue<<8) | c;
171 }
172 return(CONST);
173
174 case ALPHA:
175 if( p = lookup(token) )
176 expand(p);
177 else
1File: CEXPR.C Page 4
178 return(ALPHA);
179 break;
180
181 default:
182 return(type);
183 }
184 }
185 }
186
187 /* stkop - stack an operator on the operand stack*/
188 /* Unstack all operators of lower priority, evaluating them as*/
189 /* they are unstacked.*/
190 stkop(opr) /* returns 1 if ok, 0 otherwise*/
191 int opr; /* operator to stack*/
192 {
193 register int i, j, op1, op2, pri;
194
195 for( pri = opinfo[opr]&OPPRI; pri < *priptr; ) {
196 if( *oprptr == LPAREN ) {
197 if( opr == RPAREN ) {
198 oprptr--;
199 priptr--;
200 return(1);
201 }
202 break;
203 }
204 op1 = *opnptr;
205 if( (i=opinfo[*oprptr]) & OPBIN ) {
206 op2 = op1;
207 op1 = *--opnptr;
208 }
209 switch(*oprptr) { /*operator*/
210
211 case ADD:
212 op1 =+ op2;
213 break;
214
215 case SUB:
216 op1 =- op2;
217 break;
218
219 case COLON:
220 priptr--;
221 if( *--oprptr != QMARK )
222 return(0);
223 op1 = (*--opnptr ? op1 : op2);
224 break;
225
226 case QMARK:
227 return(0);
228
229 case XOR:
230 op1 =^ op2;
231 break;
232
233 case OR:
234 op1 =| op2;
235 break;
236
1File: CEXPR.C Page 5
237 case AND:
238 op1 =& op2;
239 break;
240
241 case EQUAL:
242 op1 = (op1 == op2);
243 break;
244
245 case NEQUAL:
246 op1 = (op1 != op2);
247 break;
248
249 case LESS:
250 op1 = (op1 < op2);
251 break;
252
253 case LSEQUAL:
254 op1 = (op1 <= op2);
255 break;
256
257 case GREAT:
258 op1 = (op1 > op2);
259 break;
260
261 case GREQUAL:
262 op1 = (op1 >= op2);
263 break;
264
265 case LSHIFT:
266 op1 = (op1 << op2);
267 break;
268
269 case RSHIFT:
270 op1 = (op1 >> op2);
271 break;
272
273 case NEG:
274 op1 = -op1;
275 break;
276
277 case NOT:
278 op1 = !op1;
279 break;
280
281 case COMPL:
282 op1 = ~ op1;
283 break;
284
285 case MULT:
286 op1 =* op2;
287 break;
288
289 case DIV:
290 op1 =/ op2;
291 break;
292
293 case MOD:
294 op1 =% op2;
295 break;
1File: CEXPR.C Page 6
296
297 }
298 *opnptr = op1;
299 priptr--;
300 oprptr--;
301 }
302 if( priptr >= &pristk[STKLEN-1] ) {
303 error("expression operator stack overflow");
304 cexit();
305 }
306 *++oprptr = opr; /*operator value*/
307 *++priptr = pri; /*operator priority*/
308 return(1);
309 }
310
311 #define toupper(c) ((c) & ~32)
312 /* const - alpha to int conversion, handles octal and hexidecimal*/
313 /* Uses Horner's method to evaluate number.*/
314 const(str) /* returns number evaluated*/
315 char *str; /* pointer to string to convert*/
316 {
317 register int c, ch, i, radix;
318
319 i = 0;
320 radix = 10;
321 if( *str == '0' ) {
322 radix = 8;
323 if( *++str == 'x' || *str == 'X' ) {
324 radix = 16;
325 str++;
326 }
327 }
328 while( c = *str++ ) {
329 if( (ch=toupper(c)) >= 'A' && ch <= 'F' )
330 c = ch - ('A'-10);
331 else if( c >= '0' && c <= '9' )
332 c =- '0';
333 else
334 break;
335 if( c >= radix )
336 break;
337 i = i*radix + c;
338 }
339 return(i);
340 }

View File

@@ -0,0 +1,251 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "machine.h"
/*
* intermediate code operators
* 0=>EOF, special operator
*/
#define EOF 0
/*1-59=>operators that generate code (entries in code gen optab)*/
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define RSH 6
#define LSH 7
#define AND 8
#define OR 9
#define XOR 10
#define NOT 11
#define UMINUS 12
#define COMPL 13
#define PREDEC 14
#define PREINC 15
#define POSTDEC 16
#define POSTINC 17
#define ASSIGN 18
#define EQADD 19
#define EQSUB 20
#define EQMULT 21
#define EQDIV 22
#define EQMOD 23
#define EQRSH 24
#define EQLSH 25
#define EQAND 26
#define EQOR 27
#define EQXOR 28
#define FJSR 29
#define EQUALS 30
#define NEQUALS 31
#define GREAT 32
#define GREATEQ 33
#define LESS 34
#define LESSEQ 35
#define INT2L 36
#define LONG2I 37
/*machine dependent operators that generate code*/
#define BTST 38
#define LOAD 39
#define LMULT 40
#define LDIV 41
#define LMOD 42
#define LEQMULT 43
#define LEQDIV 44
#define LEQMOD 45
#define EQADDR 46
#define EQNOT 47
#define EQNEG 48
#define DOCAST 49
#define STASSIGN 50 /*[vlh]*/
#define LONG2F 51 /*[vlh] 3.4*/
#define FLOAT2L 52 /*[vlh] 3.4*/
#define INT2F 53 /*[vlh] 3.4*/
#define FLOAT2I 54 /*[vlh] 3.4*/
#define LCGENOP 55 /*change if adding more operators...*/
/*intermediate code operators that do not generate code*/
#define ADDR 60
#define INDR 61
#define LAND 62
#define LOR 63
#define QMARK 64
#define COLON 65
#define COMMA 66
#define CINT 67
#define CLONG 68
#define SYMBOL 69
#define AUTOINC 70
#define AUTODEC 71
#define CALL 72
#define NACALL 73
#define BFIELD 74
#define IFGOTO 75
#define INIT 76
#define CFORREG 77
#define DCLONG 78
#define CFLOAT 79 /*[vlh] 3.4*/
/*operators local to parser*/
#define CAST 80
#define SEMI 81
#define LCURBR 82
#define RCURBR 83
#define LBRACK 84
#define RBRACK 85
#define LPAREN 86
#define RPAREN 87
#define STRING 88
#define RESWORD 89
#define APTR 90
#define PERIOD 91
#define SIZEOF 92
#define MPARENS 93
#define FRETURN 94
#define STACKEND 100
/*data types*/
#define TYPELESS 0
#define CHAR 1
#define SHORT 2
#define INT 3
#define LONG 4
#define UCHAR 5
#define USHORT 6
#define UNSIGNED 7
#define ULONG 8
#define FLOAT 9
#define DOUBLE 10
/*data types local to parser*/
#define STRUCT 11
#define FRSTRUCT 12
#define LLABEL 13
/*type flags and definitions*/
#define TYPE 017
#define SUPTYP 060
#define ALLTYPE 077
#define POINTER 020
#define FUNCTION 040
#define ARRAY 060
#define SUTYPLEN 2
/*data registers*/
#define DREG0 0
#define DREG2 2
#define DREG3 3
#define DREG4 4
#define DREG5 5
#define DREG6 6
#define DREG7 7
#define AREG3 11
#define AREG4 12
#define AREG5 13
/*storage classes*/
#define AUTO 1
#define REGISTER 2
#define EXTERNAL 3
#define STATIC 4
#define REGOFF 5
#define EXTOFF 6
#define STATOFF 7
#define INDEXED 8
/*exclusively code generator storage classes*/
#define CINDR 9
#define CLINDR 10
#define CFINDR 11 /* [vlh] 3.4 */
/*exclusively parser storage classes*/
#define STRPROTO 9
#define PDECLIST 10
#define PARMLIST 11
#define BFIELDCL 12
#define UNELCL 13
#define STELCL 14
/*opinfo table bits*/
#define OPPRI 077
#define OPBIN 0100
#define OPLVAL 0200
#define OPREL 0400
#define OPASSIGN 01000
#define OPLWORD 02000
#define OPRWORD 04000
#define OPCOM 010000
#define OPRAS 020000
#define OPTERM 040000
#define OPCONVS 0100000
/*68000 definitions*/
#define PTRSIZE 4
#define INTSIZE 2
#define LONGSIZE 4
#define SSIZE 8 /* chars per symbol */
#define TRUE 1
#define FALSE 0
#define TABC '\t' /* tab character */
#define EOLC '\n' /* end of line character */
#define BITSPBYTE 8
/*operator class priorities*/
#define TRMPRI 0 /* terminal nodes */
#define RPNPRI 1 /* ) and ] */
#define CALPRI 2 /* in-stack call, ( or [ */
#define COLPRI 3 /* init or case priority for : or , */
#define STKPRI 4 /* priority of end of stack */
#define COMPRI 5 /* normal priority for , */
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
#define QMKPRI 7 /* ?: */
#define LORPRI 8 /* || */
#define LNDPRI 9 /* && */
#define ORPRI 10 /* |, ! */
#define ANDPRI 11 /* & */
#define EQLPRI 12 /* ==, != */
#define RELPRI 13 /* >, <, >=, <= */
#define SHFPRI 14 /* <<, >> */
#define ADDPRI 15 /* +, - */
#define MULPRI 16 /* *, /, % */
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
#define LPNPRI 18 /* ., ->, [, (, function call */
#define PSTPRI 19 /* in-stack post--, post++ */
struct io_buf {
int io_fd;
int io_nc;
char *io_p;
char io_b[512];
};
#ifdef PDP11
struct { short hiword; short loword; };
#endif
#ifdef MC68000
struct { short hiword; short loword; };
#endif
#ifdef VAX
struct { short loword; short hiword; };
#endif
#define EXPSIZE 1024
int exprarea[EXPSIZE];
/* v6io buffer declaration */
#define BLEN 512
struct iobuf{
int fildes;
int nunused;
char *xfree;
char buff[BLEN];
};

View File

@@ -0,0 +1,256 @@
1File: ICODE.H Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7 #include "machine.h"
8 /*
9 * intermediate code operators
10 * 0=>EOF, special operator
11 */
12 #define EOF 0
13
14 /*1-59=>operators that generate code (entries in code gen optab)*/
15 #define ADD 1
16 #define SUB 2
17 #define MULT 3
18 #define DIV 4
19 #define MOD 5
20 #define RSH 6
21 #define LSH 7
22 #define AND 8
23 #define OR 9
24 #define XOR 10
25 #define NOT 11
26 #define UMINUS 12
27 #define COMPL 13
28 #define PREDEC 14
29 #define PREINC 15
30 #define POSTDEC 16
31 #define POSTINC 17
32 #define ASSIGN 18
33 #define EQADD 19
34 #define EQSUB 20
35 #define EQMULT 21
36 #define EQDIV 22
37 #define EQMOD 23
38 #define EQRSH 24
39 #define EQLSH 25
40 #define EQAND 26
41 #define EQOR 27
42 #define EQXOR 28
43 #define FJSR 29
44 #define EQUALS 30
45 #define NEQUALS 31
46 #define GREAT 32
47 #define GREATEQ 33
48 #define LESS 34
49 #define LESSEQ 35
50 #define INT2L 36
51 #define LONG2I 37
52
53 /*machine dependent operators that generate code*/
54 #define BTST 38
55 #define LOAD 39
56 #define LMULT 40
57 #define LDIV 41
58 #define LMOD 42
59 #define LEQMULT 43
1File: ICODE.H Page 2
60 #define LEQDIV 44
61 #define LEQMOD 45
62 #define EQADDR 46
63 #define EQNOT 47
64 #define EQNEG 48
65 #define DOCAST 49
66
67 #define STASSIGN 50 /*[vlh]*/
68 #define LONG2F 51 /*[vlh] 3.4*/
69 #define FLOAT2L 52 /*[vlh] 3.4*/
70 #define INT2F 53 /*[vlh] 3.4*/
71 #define FLOAT2I 54 /*[vlh] 3.4*/
72 #define LCGENOP 55 /*change if adding more operators...*/
73
74 /*intermediate code operators that do not generate code*/
75 #define ADDR 60
76 #define INDR 61
77 #define LAND 62
78 #define LOR 63
79 #define QMARK 64
80 #define COLON 65
81 #define COMMA 66
82 #define CINT 67
83 #define CLONG 68
84 #define SYMBOL 69
85 #define AUTOINC 70
86 #define AUTODEC 71
87 #define CALL 72
88 #define NACALL 73
89 #define BFIELD 74
90 #define IFGOTO 75
91 #define INIT 76
92 #define CFORREG 77
93 #define DCLONG 78
94 #define CFLOAT 79 /*[vlh] 3.4*/
95
96 /*operators local to parser*/
97 #define CAST 80
98 #define SEMI 81
99 #define LCURBR 82
100 #define RCURBR 83
101 #define LBRACK 84
102 #define RBRACK 85
103 #define LPAREN 86
104 #define RPAREN 87
105 #define STRING 88
106 #define RESWORD 89
107 #define APTR 90
108 #define PERIOD 91
109 #define SIZEOF 92
110 #define MPARENS 93
111 #define FRETURN 94
112 #define STACKEND 100
113
114 /*data types*/
115 #define TYPELESS 0
116 #define CHAR 1
117 #define SHORT 2
118 #define INT 3
1File: ICODE.H Page 3
119 #define LONG 4
120 #define UCHAR 5
121 #define USHORT 6
122 #define UNSIGNED 7
123 #define ULONG 8
124 #define FLOAT 9
125 #define DOUBLE 10
126
127 /*data types local to parser*/
128 #define STRUCT 11
129 #define FRSTRUCT 12
130 #define LLABEL 13
131
132 /*type flags and definitions*/
133 #define TYPE 017
134 #define SUPTYP 060
135 #define ALLTYPE 077
136 #define POINTER 020
137 #define FUNCTION 040
138 #define ARRAY 060
139 #define SUTYPLEN 2
140
141 /*data registers*/
142 #define DREG0 0
143 #define DREG2 2
144 #define DREG3 3
145 #define DREG4 4
146 #define DREG5 5
147 #define DREG6 6
148 #define DREG7 7
149 #define AREG3 11
150 #define AREG4 12
151 #define AREG5 13
152
153 /*storage classes*/
154 #define AUTO 1
155 #define REGISTER 2
156 #define EXTERNAL 3
157 #define STATIC 4
158 #define REGOFF 5
159 #define EXTOFF 6
160 #define STATOFF 7
161 #define INDEXED 8
162
163 /*exclusively code generator storage classes*/
164 #define CINDR 9
165 #define CLINDR 10
166 #define CFINDR 11 /* [vlh] 3.4 */
167
168 /*exclusively parser storage classes*/
169 #define STRPROTO 9
170 #define PDECLIST 10
171 #define PARMLIST 11
172 #define BFIELDCL 12
173 #define UNELCL 13
174 #define STELCL 14
175
176
177 /*opinfo table bits*/
1File: ICODE.H Page 4
178 #define OPPRI 077
179 #define OPBIN 0100
180 #define OPLVAL 0200
181 #define OPREL 0400
182 #define OPASSIGN 01000
183 #define OPLWORD 02000
184 #define OPRWORD 04000
185 #define OPCOM 010000
186 #define OPRAS 020000
187 #define OPTERM 040000
188 #define OPCONVS 0100000
189
190 /*68000 definitions*/
191 #define PTRSIZE 4
192 #define INTSIZE 2
193 #define LONGSIZE 4
194 #define SSIZE 8 /* chars per symbol */
195 #define TRUE 1
196 #define FALSE 0
197 #define TABC '\t' /* tab character */
198 #define EOLC '\n' /* end of line character */
199 #define BITSPBYTE 8
200
201 /*operator class priorities*/
202 #define TRMPRI 0 /* terminal nodes */
203 #define RPNPRI 1 /* ) and ] */
204 #define CALPRI 2 /* in-stack call, ( or [ */
205 #define COLPRI 3 /* init or case priority for : or , */
206 #define STKPRI 4 /* priority of end of stack */
207 #define COMPRI 5 /* normal priority for , */
208 #define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
209 #define QMKPRI 7 /* ?: */
210 #define LORPRI 8 /* || */
211 #define LNDPRI 9 /* && */
212 #define ORPRI 10 /* |, ! */
213 #define ANDPRI 11 /* & */
214 #define EQLPRI 12 /* ==, != */
215 #define RELPRI 13 /* >, <, >=, <= */
216 #define SHFPRI 14 /* <<, >> */
217 #define ADDPRI 15 /* +, - */
218 #define MULPRI 16 /* *, /, % */
219 #define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
220 #define LPNPRI 18 /* ., ->, [, (, function call */
221 #define PSTPRI 19 /* in-stack post--, post++ */
222
223 struct io_buf {
224 int io_fd;
225 int io_nc;
226 char *io_p;
227 char io_b[512];
228 };
229
230 #ifdef PDP11
231 struct { short hiword; short loword; };
232 #endif
233 #ifdef MC68000
234 struct { short hiword; short loword; };
235 #endif
236 #ifdef VAX
1File: ICODE.H Page 5
237 struct { short loword; short hiword; };
238 #endif
239
240 #define EXPSIZE 1024
241 int exprarea[EXPSIZE];
242
243 /* v6io buffer declaration */
244 #define BLEN 512
245
246 struct iobuf{
247 int fildes;
248 int nunused;
249 char *xfree;
250 char buff[BLEN];
251 };

View File

@@ -0,0 +1,163 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "icode.h"
#include "machine.h"
/*cexpr operators*/
#define EOF 0
#define SUB 1
#define ADD 2
#define NOT 3
#define NEG 4
#define LPAREN 5
#define RPAREN 6
#define QMARK 7
#define COLON 8
#define OR 9
#define AND 10
#define XOR 11
#define EQUAL 12
#define NEQUAL 13
#define LESS 14
#define LSEQUAL 15
#define GREAT 16
#define GREQUAL 17
#define LSHIFT 18
#define RSHIFT 19
#define MULT 20
#define DIV 21
#define MOD 22
#define COMPL 23
#define CONST 24
#define LASTOP COMPL /*up to here used by cexpr*/
#define SQUOTE 25
#define DQUOTE 26
#define ANYC 27
#define BADC 28
#define COMMA 29
#define NEWL 30
#define POUND 31
#define ALPHA 32
#define DIGIT 33
#define BSLASH 34
#define WHITE 35
#define BUFSIZE 512
#define LINESIZE 512
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define DEFINE 1
#define UNDEF 2
#define INCLUDE 3
#define IFDEF 4
#define IFNDEF 5
#define ELSE 6
#define ENDIF 7
#define IF 8
#define SKIP 0
#define NOSKIP 1
#define SOH '\01'
#define SSIZE 8
#define HSIZE 517 /* 3.4 made prime */
#define FSTACK 10
#define TRUE 1
#define FALSE 0
#define NDEFS 20
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE]=0;
/*buffered I/O structure*/
struct ibuf {
int fd;
int nc;
char *bp;
char buffer[BUFSIZE];
} outbuf=0;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS]=0;
struct stackstruc { /* [vlh] */
int ifd;
char ifile[13];
int lineno;
struct ibuf inbuf;
} filestack[FSTACK]=0, *filep=0; /* stack of incl files, ptr to... */
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
#ifdef VERSADOS
#define NONEST 1
#define NOFORKS 1
#endif
#ifdef VMS
#define NONEST 1
#endif
#ifdef NONEST
struct ibuf holdbuf=0; /* alternate buffer, hold main file info */
#endif
#endif
int mfail=0; /*macro error flag*/
int skip=0; /*skipping current line*/
char *defap=0; /*pointer to available define area*/
char *defp=0; /*pointer to next avail define byte*/
int defcount=0; /*bytes left in define area*/
int defused=0; /*number of bytes used in define area*/
int defmax=0; /*maximum define area used*/
int pflag=0;
int asflag=0;
/*line to output after macro substitution*/
char line[LINESIZE+2]=0; /*line buffer*/
char *linep=0; /*current line pointer*/
int loverflow=0; /*line overflow flag*/
int lineno=0;
/*push back buffer*/
char pbbuf[PBSIZE]=0; /*push back buffer*/
char *pbp=0; /*push back pointer*/
int pbflag=0; /*checks for recursive definition*/
char *lookup();
char *setend();
char *makecopy();
char *makecopy();
char *maketemp();
char *sbrk();
struct symbol *getsp();
#define STKLEN 64
int oprstk[STKLEN]=0;
int opnstk[STKLEN]=0;
int pristk[STKLEN]=0;
int *oprptr=0;
int *opnptr=0;
int *priptr=0;
int nincl=0;
char *incl[10]=0;
char tmp[6]=0;
#define CSTKSIZE 20
char cstack[CSTKSIZE]=0;
char *cstkptr=0;
char inclname[TOKSIZE]=0;
int cvalue=0;
#define EXPSIZE 1024
int exprarea[EXPSIZE]=0;

View File

@@ -0,0 +1,166 @@
1File: INIT.C Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7
8 #include "icode.h"
9 #include "machine.h"
10 /*cexpr operators*/
11 #define EOF 0
12 #define SUB 1
13 #define ADD 2
14 #define NOT 3
15 #define NEG 4
16 #define LPAREN 5
17 #define RPAREN 6
18 #define QMARK 7
19 #define COLON 8
20 #define OR 9
21 #define AND 10
22 #define XOR 11
23 #define EQUAL 12
24 #define NEQUAL 13
25 #define LESS 14
26 #define LSEQUAL 15
27 #define GREAT 16
28 #define GREQUAL 17
29 #define LSHIFT 18
30 #define RSHIFT 19
31 #define MULT 20
32 #define DIV 21
33 #define MOD 22
34 #define COMPL 23
35 #define CONST 24
36 #define LASTOP COMPL /*up to here used by cexpr*/
37 #define SQUOTE 25
38 #define DQUOTE 26
39 #define ANYC 27
40 #define BADC 28
41 #define COMMA 29
42 #define NEWL 30
43 #define POUND 31
44 #define ALPHA 32
45 #define DIGIT 33
46 #define BSLASH 34
47 #define WHITE 35
48 #define BUFSIZE 512
49 #define LINESIZE 512
50 #define ARG -1
51 #define NEWLABEL -2
52 #define LABEL -3
53 #define NOARGS -4
54 #define MAXARGS 60
55 #define ARGBSIZE 1000
56 #define TOKSIZE 300 /*BUG 4/20/82 was 128*/
57 #define DEFSIZE 1024
58 #define PBSIZE 1000
59 #define DEFINE 1
1File: INIT.C Page 2
60 #define UNDEF 2
61 #define INCLUDE 3
62 #define IFDEF 4
63 #define IFNDEF 5
64 #define ELSE 6
65 #define ENDIF 7
66 #define IF 8
67 #define SKIP 0
68 #define NOSKIP 1
69 #define SOH '\01'
70 #define SSIZE 8
71 #define HSIZE 517 /* 3.4 made prime */
72 #define FSTACK 10
73
74 #define TRUE 1
75 #define FALSE 0
76 #define NDEFS 20
77
78 struct symbol {
79 char s_name[SSIZE];
80 char *s_def;
81 } symtab[HSIZE]=0;
82
83 /*buffered I/O structure*/
84 struct ibuf {
85 int fd;
86 int nc;
87 char *bp;
88 char buffer[BUFSIZE];
89 } outbuf=0;
90
91 /* command line define structure */
92 struct defstruc {
93 char *ptr;
94 char *value;
95 } defs[NDEFS]=0;
96
97 struct stackstruc { /* [vlh] */
98 int ifd;
99 char ifile[13];
100 int lineno;
101 struct ibuf inbuf;
102 } filestack[FSTACK]=0, *filep=0; /* stack of incl files, ptr to... */
103 #ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
104 #ifdef VERSADOS
105 #define NONEST 1
106 #define NOFORKS 1
107 #endif
108
109 #ifdef VMS
110 #define NONEST 1
111 #endif
112
113 #ifdef NONEST
114 struct ibuf holdbuf=0; /* alternate buffer, hold main file info */
115 #endif
116 #endif
117 int mfail=0; /*macro error flag*/
118 int skip=0; /*skipping current line*/
1File: INIT.C Page 3
119 char *defap=0; /*pointer to available define area*/
120 char *defp=0; /*pointer to next avail define byte*/
121 int defcount=0; /*bytes left in define area*/
122 int defused=0; /*number of bytes used in define area*/
123 int defmax=0; /*maximum define area used*/
124 int pflag=0;
125 int asflag=0;
126
127 /*line to output after macro substitution*/
128 char line[LINESIZE+2]=0; /*line buffer*/
129 char *linep=0; /*current line pointer*/
130 int loverflow=0; /*line overflow flag*/
131 int lineno=0;
132
133 /*push back buffer*/
134 char pbbuf[PBSIZE]=0; /*push back buffer*/
135 char *pbp=0; /*push back pointer*/
136 int pbflag=0; /*checks for recursive definition*/
137
138
139 char *lookup();
140 char *setend();
141 char *makecopy();
142 char *makecopy();
143 char *maketemp();
144 char *sbrk();
145 struct symbol *getsp();
146 #define STKLEN 64
147 int oprstk[STKLEN]=0;
148 int opnstk[STKLEN]=0;
149 int pristk[STKLEN]=0;
150 int *oprptr=0;
151 int *opnptr=0;
152 int *priptr=0;
153
154 int nincl=0;
155 char *incl[10]=0;
156 char tmp[6]=0;
157 #define CSTKSIZE 20
158 char cstack[CSTKSIZE]=0;
159 char *cstkptr=0;
160 char inclname[TOKSIZE]=0;
161 int cvalue=0;
162 #define EXPSIZE 1024
163 int exprarea[EXPSIZE]=0;

View File

@@ -0,0 +1,328 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
char null[] "";
char ctype[] {
EOF, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, WHITE, NEWL, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, ANYC, ANYC, ANYC, NEWL, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
WHITE, NOT, DQUOTE, POUND, ANYC, MOD, AND, SQUOTE, /*BUG 2*/
LPAREN, RPAREN, MULT, ADD, COMMA, SUB, ANYC, DIV,
DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
DIGIT, DIGIT, COLON, ANYC, LESS, EQUAL, GREAT, QMARK,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, BSLASH, ANYC, XOR, ALPHA,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, OR, ANYC, COMPL, ANYC /*BUG 2*/
};
/* symhash - compute hash value for symbol*/
/* Sums the symbols characters and takes that modulus the hash table*/
/* size.*/
symhash(sym) /* returns hash value for symbol*/
char *sym; /* pointer to symbol*/
{
register char *p;
register int hashval, i;
for( p = sym, i = SSIZE, hashval = 0; *p != '\0' && i > 0; i-- )
hashval =+ *p++;
return( hashval % HSIZE );
}
/* symequal - check for symbol equality*/
/* Does comparison between two symbols.*/
symequal(sym1,sym2) /* returns 1 if equal, 0 otherwise*/
char *sym1; /* pointer to first symbol*/
char *sym2; /* pointer to second symbol*/
{
register char *p, *q;
register int i;
q = sym2;
i = SSIZE;
for( p = sym1; *p == *q++; )
if( *p++ == '\0' || --i == 0 )
return(1);
return(0);
}
/* symcopy - symbol copy*/
/* Copies one symbol to another.*/
symcopy(sym1,sym2) /* returns - none*/
char *sym1; /* pointer to symbol to copy*/
char *sym2; /* pointer to area to copy to*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
if( *p )
*q++ = *p++;
else
*q++ = '\0';
}
/* error - output error message*/
/* Outputs line number and error message and keeps track of errors.*/
error(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* printf string*/
int x1, x2, x3, x4, x5, x6; /* printf args*/
{
if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
printf("# %d: ",lineno);
else
printf("%s : # %d: ",(filep)->ifile,(filep)->lineno);
printf(s,x1,x2,x3,x4,x5,x6);
putchar('\n');
mfail++;
}
/* putback - puts back a single character*/
/* Checks for push back buffer overflow.*/
putback(c)
int c;
{
if( pbp >= &pbbuf[PBSIZE] ) {
error("too many characters pushed back");
cexit();
}
*pbp++ = c;
}
/* pbtok - push back a token*/
/* Reverses token as its pushing it back.*/
pbtok(s)
char *s;
{
register char *p;
for( p = s + strlen(s); p > s ; )
putback(*--p);
}
/* ngetch - get a (possibly) pushed back character*/
/* This handles the include file stack and incrementing the line*/
/* number for the lowest level file.*/
ngetch() /* returns character or EOF*/
{
register int c, i;
register char *p, *q;
if( pbp > &pbbuf[0] )
return(*--pbp);
pbflag = 0;
while( (c=getc(&(filep->inbuf))) < 0 ) {
if( filep == &filestack[0] )
return(EOF);
close(filep->inbuf.fd);
filep--;
if( filep == &filestack[0] ) { /*need line for #include...*/
putc('\n',&outbuf);
lineno++;
}
}
return( c );
}
/* getsp - get symbol pointer*/
/* Calculates the symbol table pointer for a given symbol, if symbol*/
/* is not defined, will point to appropriate place to insert symbol.*/
struct symbol *getsp(name)
char *name;
{
register int wrap;
register struct symbol *sp, *asp;
wrap = 0;
asp = 0;
for( sp = &symtab[symhash(name)]; sp->s_def != null; ) {
if( symequal(sp->s_name,name) )
return(sp);
if( !asp && sp->s_def == null )
asp = sp;
if( ++sp >= &symtab[HSIZE] ) {
if( wrap++ ) {
error("symbol table overflow");
cexit();
}
sp = &symtab[0];
}
}
return( asp ? asp : sp );
}
/* lookup - looks up a symbol to see if it is defined*/
/* Returns pointer to definition if found.*/
char *lookup(name) /* returns 0 or ptr to symbol*/
char *name; /* symbol name*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def == 0 || sp->s_def == null )
return(0);
return(sp);
}
/* gettok - gets next token from input*/
/* Collects character string in token and handles special tokens for*/
/* the expression evaluator.*/
gettok(token) /* returns token type*/
char *token;
{
register char *p, c;
register int type, count, t, l;
p = token;
c = ngetch();
*p++ = c;
switch( type = ctype[c] ) {
case SQUOTE:
case DQUOTE:
getstr(token,TOKSIZE,c);
return(type);
case DIGIT:
case ALPHA:
for( ; p < &token[TOKSIZE]; p++ ) {
*p = ngetch();
if( (t=ctype[*p]) != ALPHA && t != DIGIT )
break;
}
putback(*p);
break;
case NOT:
if( peekis('=') ) {
type = NEQUAL;
*p++ = '=';
}
break;
case GREAT:
if( peekis('>') ) {
type = RSHIFT;
*p++ = '>';
}
else if( peekis('=') ) {
type = GREQUAL;
*p++ = '=';
}
break;
case LESS:
if( peekis('<') ) {
type = LSHIFT;
*p++ = '<';
}
else if( peekis('=') ) {
type = LSEQUAL;
*p++ = '=';
}
break;
case EQUAL:
if( peekis('=') )
*p++ = '=';
else
type = ANYC;
break;
case DIV:
if( peekis('*') ) {
l = lineno;
while( (c=ngetch()) != EOF )
if( c == '\n' ) {
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
putc('\n',&outbuf);
}
}
else if( c == '*' && peekis('/') )
break;
if( c == EOF ) {
lineno = l;
error("no */ before EOF");
}
type = WHITE;
token[0] = ' ';
}
else if( peekis('/') ) {
while( (c=ngetch()) != EOF && c != '\n' )
;
type = NEWL;
token[0] = '\n';
}
break;
case BADC:
error("bad character 0%o",c);
break;
}
*p = '\0';
return(type);
}
/* getstr - get a quoted (single or double) character string*/
/* Gets specified number of characters, handling escapes.*/
getstr(str,nchars,endc) /* returns - none*/
char *str; /* pointer to string buffer*/
int nchars; /* max number of characters*/
char endc; /* ending string character*/
{
register char *p;
register int i;
register int c;
register int j;
p = str;
*p++ = endc;
for( i = nchars-2; (c=ngetch()) != endc; ) {
if( c == EOF || c == '\n' ) {
error("string cannot cross line");
break;
}
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
if( c == '\\' ) {
c = ngetch();
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
}
}
*p++ = endc;
*p = '\0';
}
/* peekis - peeks at next character for specific character*/
/* Gets next (possibly pushed back) character, if it matches*/
/* the given character 1 is returned, otherwise the character*/
/* is put back.*/
peekis(tc) /* returns 1 if match, 0 otherwise*/
int tc; /* test character*/
{
register int c;
if( (c=ngetch()) == tc )
return(1);
putback(c);
return(0);
}

View File

@@ -0,0 +1,334 @@
1File: LEX.C Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7
8 #include "preproc.h"
9 char null[] "";
10
11 char ctype[] {
12 EOF, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
13 ANYC, WHITE, NEWL, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
14 ANYC, ANYC, ANYC, ANYC, NEWL, ANYC, ANYC, ANYC, /*BUG 2*/
15 ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
16 WHITE, NOT, DQUOTE, POUND, ANYC, MOD, AND, SQUOTE, /*BUG 2*/
17 LPAREN, RPAREN, MULT, ADD, COMMA, SUB, ANYC, DIV,
18 DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
19 DIGIT, DIGIT, COLON, ANYC, LESS, EQUAL, GREAT, QMARK,
20 ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
21 ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
22 ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
23 ALPHA, ALPHA, ALPHA, ANYC, BSLASH, ANYC, XOR, ALPHA,
24 ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
25 ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
26 ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
27 ALPHA, ALPHA, ALPHA, ANYC, OR, ANYC, COMPL, ANYC /*BUG 2*/
28 };
29
30 /* symhash - compute hash value for symbol*/
31 /* Sums the symbols characters and takes that modulus the hash table*/
32 /* size.*/
33 symhash(sym) /* returns hash value for symbol*/
34 char *sym; /* pointer to symbol*/
35 {
36 register char *p;
37 register int hashval, i;
38
39 for( p = sym, i = SSIZE, hashval = 0; *p != '\0' && i > 0; i-- )
40 hashval =+ *p++;
41 return( hashval % HSIZE );
42 }
43
44 /* symequal - check for symbol equality*/
45 /* Does comparison between two symbols.*/
46 symequal(sym1,sym2) /* returns 1 if equal, 0 otherwise*/
47 char *sym1; /* pointer to first symbol*/
48 char *sym2; /* pointer to second symbol*/
49 {
50 register char *p, *q;
51 register int i;
52
53 q = sym2;
54 i = SSIZE;
55 for( p = sym1; *p == *q++; )
56 if( *p++ == '\0' || --i == 0 )
57 return(1);
58 return(0);
59 }
1File: LEX.C Page 2
60
61 /* symcopy - symbol copy*/
62 /* Copies one symbol to another.*/
63 symcopy(sym1,sym2) /* returns - none*/
64 char *sym1; /* pointer to symbol to copy*/
65 char *sym2; /* pointer to area to copy to*/
66 {
67 register char *p, *q;
68 register int i;
69
70 for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
71 if( *p )
72 *q++ = *p++;
73 else
74 *q++ = '\0';
75 }
76
77 /* error - output error message*/
78 /* Outputs line number and error message and keeps track of errors.*/
79 error(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
80 char *s; /* printf string*/
81 int x1, x2, x3, x4, x5, x6; /* printf args*/
82 {
83 if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
84 printf("# %d: ",lineno);
85 else
86 printf("%s : # %d: ",(filep)->ifile,(filep)->lineno);
87 printf(s,x1,x2,x3,x4,x5,x6);
88 putchar('\n');
89 mfail++;
90 }
91
92 /* putback - puts back a single character*/
93 /* Checks for push back buffer overflow.*/
94 putback(c)
95 int c;
96 {
97 if( pbp >= &pbbuf[PBSIZE] ) {
98 error("too many characters pushed back");
99 cexit();
100 }
101 *pbp++ = c;
102 }
103
104 /* pbtok - push back a token*/
105 /* Reverses token as its pushing it back.*/
106 pbtok(s)
107 char *s;
108 {
109 register char *p;
110
111 for( p = s + strlen(s); p > s ; )
112 putback(*--p);
113 }
114
115 /* ngetch - get a (possibly) pushed back character*/
116 /* This handles the include file stack and incrementing the line*/
117 /* number for the lowest level file.*/
118 ngetch() /* returns character or EOF*/
1File: LEX.C Page 3
119 {
120 register int c, i;
121 register char *p, *q;
122
123 if( pbp > &pbbuf[0] )
124 return(*--pbp);
125 pbflag = 0;
126 while( (c=getc(&(filep->inbuf))) < 0 ) {
127 if( filep == &filestack[0] )
128 return(EOF);
129 close(filep->inbuf.fd);
130 filep--;
131 if( filep == &filestack[0] ) { /*need line for #include...*/
132 putc('\n',&outbuf);
133 lineno++;
134 }
135 }
136 return( c );
137 }
138
139 /* getsp - get symbol pointer*/
140 /* Calculates the symbol table pointer for a given symbol, if symbol*/
141 /* is not defined, will point to appropriate place to insert symbol.*/
142 struct symbol *getsp(name)
143 char *name;
144 {
145 register int wrap;
146 register struct symbol *sp, *asp;
147
148 wrap = 0;
149 asp = 0;
150 for( sp = &symtab[symhash(name)]; sp->s_def != null; ) {
151 if( symequal(sp->s_name,name) )
152 return(sp);
153 if( !asp && sp->s_def == null )
154 asp = sp;
155 if( ++sp >= &symtab[HSIZE] ) {
156 if( wrap++ ) {
157 error("symbol table overflow");
158 cexit();
159 }
160 sp = &symtab[0];
161 }
162 }
163 return( asp ? asp : sp );
164 }
165
166 /* lookup - looks up a symbol to see if it is defined*/
167 /* Returns pointer to definition if found.*/
168 char *lookup(name) /* returns 0 or ptr to symbol*/
169 char *name; /* symbol name*/
170 {
171 register struct symbol *sp;
172
173 sp = getsp(name);
174 if( sp->s_def == 0 || sp->s_def == null )
175 return(0);
176 return(sp);
177 }
1File: LEX.C Page 4
178
179 /* gettok - gets next token from input*/
180 /* Collects character string in token and handles special tokens for*/
181 /* the expression evaluator.*/
182 gettok(token) /* returns token type*/
183 char *token;
184 {
185 register char *p, c;
186 register int type, count, t, l;
187
188 p = token;
189 c = ngetch();
190 *p++ = c;
191 switch( type = ctype[c] ) {
192
193 case SQUOTE:
194 case DQUOTE:
195 getstr(token,TOKSIZE,c);
196 return(type);
197
198 case DIGIT:
199 case ALPHA:
200 for( ; p < &token[TOKSIZE]; p++ ) {
201 *p = ngetch();
202 if( (t=ctype[*p]) != ALPHA && t != DIGIT )
203 break;
204 }
205 putback(*p);
206 break;
207
208 case NOT:
209 if( peekis('=') ) {
210 type = NEQUAL;
211 *p++ = '=';
212 }
213 break;
214
215 case GREAT:
216 if( peekis('>') ) {
217 type = RSHIFT;
218 *p++ = '>';
219 }
220 else if( peekis('=') ) {
221 type = GREQUAL;
222 *p++ = '=';
223 }
224 break;
225
226 case LESS:
227 if( peekis('<') ) {
228 type = LSHIFT;
229 *p++ = '<';
230 }
231 else if( peekis('=') ) {
232 type = LSEQUAL;
233 *p++ = '=';
234 }
235 break;
236
1File: LEX.C Page 5
237 case EQUAL:
238 if( peekis('=') )
239 *p++ = '=';
240 else
241 type = ANYC;
242 break;
243
244 case DIV:
245 if( peekis('*') ) {
246 l = lineno;
247 while( (c=ngetch()) != EOF )
248 if( c == '\n' ) {
249 if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
250 lineno++;
251 putc('\n',&outbuf);
252 }
253 }
254 else if( c == '*' && peekis('/') )
255 break;
256 if( c == EOF ) {
257 lineno = l;
258 error("no */ before EOF");
259 }
260 type = WHITE;
261 token[0] = ' ';
262 }
263 else if( peekis('/') ) {
264 while( (c=ngetch()) != EOF && c != '\n' )
265 ;
266 type = NEWL;
267 token[0] = '\n';
268 }
269 break;
270
271 case BADC:
272 error("bad character 0%o",c);
273 break;
274
275 }
276 *p = '\0';
277 return(type);
278 }
279
280 /* getstr - get a quoted (single or double) character string*/
281 /* Gets specified number of characters, handling escapes.*/
282 getstr(str,nchars,endc) /* returns - none*/
283 char *str; /* pointer to string buffer*/
284 int nchars; /* max number of characters*/
285 char endc; /* ending string character*/
286 {
287 register char *p;
288 register int i;
289 register int c;
290 register int j;
291
292 p = str;
293 *p++ = endc;
294 for( i = nchars-2; (c=ngetch()) != endc; ) {
295 if( c == EOF || c == '\n' ) {
1File: LEX.C Page 6
296 error("string cannot cross line");
297 break;
298 }
299 if( --i > 0 ) /*BUG 1*/
300 *p++ = c;
301 else if( !i )
302 error("string too long");
303 if( c == '\\' ) {
304 c = ngetch();
305 if( --i > 0 ) /*BUG 1*/
306 *p++ = c;
307 else if( !i )
308 error("string too long");
309 }
310 }
311 *p++ = endc;
312 *p = '\0';
313 }
314
315 /* peekis - peeks at next character for specific character*/
316 /* Gets next (possibly pushed back) character, if it matches*/
317 /* the given character 1 is returned, otherwise the character*/
318 /* is put back.*/
319 peekis(tc) /* returns 1 if match, 0 otherwise*/
320 int tc; /* test character*/
321 {
322 register int c;
323
324 if( (c=ngetch()) == tc )
325 return(1);
326 putback(c);
327 return(0);
328 }

View File

@@ -0,0 +1,4 @@
$1lo68 -f $1 -r -o cp68.rel -unofloat 0$1s.o cexpr.o lex.o macro.o main.o util.o 0$1lib6.a 0$1clib
era *.o
user 12!make $1

View File

@@ -0,0 +1,27 @@
$ num
CEXPR.C
CEXPR.lis
$ num
INIT.C
INIT.lis
$ num
LEX.C
LEX.lis
$ num
MACRO.C
MACRO.lis
$ num
MAIN.C
MAIN.lis
$ num
UTIL.C
UTIL.lis
$ num
ICODE.H
ICODE.lst
$ num
MACHINE.H
MACHINE.lst
$ num
PREPROC.H
PREPROC.lst

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
#define PDP11 1 /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
#define UNIX 1 /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,11 @@
1File: MACHINE.H Page 1
1 /*
2 * Use this file to determine what kind of machine you want the
3 * Alcyon stuff to run on ....
4 */
5 /*#define MC68000 1*/ /* 68000 version */
6 #define VAX 1 /* VAX Version */
7 /*#define PDP11 1*/ /* PDP-11 Version*/
8 /*#define CPM 1*/ /* CP/M Operating System*/
9 /*#define UNIX 1*/ /* UNIX Operating System*/
10 #define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,673 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define CSTKSIZE 20
#define FILESEP '/'
#define NINCL 10
#ifdef UNIX
char *stdincl "/usr/include/"; /*standard include directory*/
#endif
#ifdef VMS
char *stdincl "lib:";
#endif
#ifdef CPM
char *stdincl "";
#endif
int clabel 1000;
int nlabel 1001;
int nincl;
char *incl[10];
char tmp[6];
struct builtin {
char *b_name;
int b_type;
} btab[] {
"define", DEFINE,
"include", INCLUDE,
"undef", UNDEF,
"ifdef", IFDEF,
"ifndef", IFNDEF,
"else", ELSE,
"endif", ENDIF,
"if", IF,
0,
};
char *getinclude();
char cstack[CSTKSIZE];
char *cstkptr, inclname[TOKSIZE];
/* domacro - do macro processing*/
/* Does the macro pre-processing on the input file and leaves the*/
/* result on the output file.*/
domacro(infile,outfile,nd) /* returns 1 if ok, 0 otherwise*/
char *infile; /* input file name*/
char *outfile; /* output file name*/
int nd; /* number of defines*/
{
register struct builtin *bp;
register char *l;
register struct symbol *sp;
register int x, nonewline; /* handle empty new lines with SOH */
register char *p;
filep = &filestack[0];
if( fopen(infile,&(filep->inbuf),0) < 0 ) { /* 3rd arg for versados */
error("can't open source file %s\n",infile);
return(0);
}
if( fcreat(outfile,&outbuf,0) < 0 ) { /* 3rd arg for versados */
error("can't creat %s\n",outfile);
return(0);
}
for (sp= &symtab[0]; sp<= &symtab[HSIZE-1]; sp++) /*3.4*/
sp->s_def = null; /* clear out symbol table */
if( !defap ) {
defp = defap = sbrk(1024);
defmax = defcount = 1024;
}
else { /* multiple files, define area already exists */
defcount = defmax;
for (x = defmax, defp = defap; x>0; x--)
*defp++ = 0;
defp = defap;
}
lineno = 1;
nonewline = defused = mfail = 0;
pbp = &pbbuf[0];
cstkptr = &cstack[0];
install("Newlabel",NEWLABEL);
install("Label",LABEL);
while( --nd >= 0 )
dinstall(defs[nd].ptr,defs[nd].value);
while( getline(infile) ) {
l = line;
if( filep == &filestack[0] && pbp == &pbbuf[0] )
lineno++;
else if ( !pflag && !asflag ) { /*[vlh] add fname & line#*/
if (*l) {
putc(SOH,&outbuf);
for (p = (filep)->ifile; *p; p++)
putc(*p,&outbuf);
putc(SOH,&outbuf);
itoa((filep)->lineno,tmp,5);
for (p = tmp; *p==' '; ) p++;
for ( ; *p; p++)
putc(*p,&outbuf);
putc(' ',&outbuf);
if (!(*l)) putc(' ',&outbuf);
}
else nonewline++;
(filep)->lineno++;
}
while( *l )
putc(*l++,&outbuf);
if (!nonewline) putc('\n',&outbuf);
else nonewline = 0;
}
if( cstkptr != &cstack[0] )
error("unmatched conditional");
if( defused > defmax )
defmax = defused;
v6flush(&outbuf);
close(outbuf.fd);
close(filep->inbuf.fd);
return(mfail==0);
}
install(name,def)
char *name;
int def;
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(def);
putd('\0');
}
dinstall(name,def) /* returns - none*/
char *name; /* macro name*/
char *def; /* pointer to definition*/
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(NOARGS);
if (def) /* [vlh] character strings... */
while(*def) putd(*def++);
else putd('1'); /* [vlh] default define value */
putd('\0');
}
/* kwlook - look up the macro built-in names*/
/* Searches thru the built-in table for the name.*/
kwlook(name) /* returns keyword index or 0*/
char *name; /* keyword name to lookup*/
{
register struct builtin *bp;
for( bp = &btab[0]; bp->b_name; bp++ )
if( strcmp(bp->b_name,name) == 0 )
return(bp->b_type);
return(0);
}
/*
* getline - get input line handling macro statements
* Checks for a preprocessor statement on the line and if there
* is one there, it processes it. Note that most of the work is
* in determining whether we need to skip the current line or not.
* This is all handled with the condition stack and the skip variable.
* The skip variable is non-zero if any condition on the condition
* stack is SKIP.
*/
getline(infile) /* returns 0 for EOF, 1 otherwise*/
char *infile; /* [vlh] for quoted include files */
{
char token[TOKSIZE];
register int type, i;
register char *p;
initl();
if( (type=gettok(token)) == EOF )
return(0);
if( type == POUND ) {
if( (type=getntok(token)) == NEWL )
return(1);
switch( kwlook(token) ) {
case IFDEF:
if( getntok(token) == ALPHA && lookup(token) )
push(NOSKIP);
else {
push(SKIP);
skip++;
}
break;
case IFNDEF:
if( getntok(token) == ALPHA && lookup(token) ) {
push(SKIP);
skip++;
}
else
push(NOSKIP);
break;
case ENDIF:
if( (i=pop()) == SKIP )
skip--;
else if( i != NOSKIP )
error("invalid #endif");
break;
case ELSE:
if( (i=pop()) == SKIP ) {
skip--;
push(NOSKIP);
}
else if( i == NOSKIP ) {
skip++;
push(SKIP);
}
else
error("invalid #else");
break;
case DEFINE:
if( !skip ) /*if in skip, don't do define*/
dodefine();
break;
case UNDEF:
if( !skip ) { /*if in skip, don't undef*/
if( (type=getntok(token)) == ALPHA )
undefine(token);
}
break;
case INCLUDE:
if( !skip ) /*if in skip, don't do include*/
doinclude(infile);
break;
case IF:
if( cexpr() ) /*evaluate constant expression*/
push(NOSKIP); /*non-zero, so don't skip*/
else {
push(SKIP);
skip++;
}
break;
default:
error("invalid preprocessor command");
break;
}
eatup();
}
else if( type == NEWL )
;
else if( skip )
eatup();
else {
for( ; type != NEWL && type != EOF ; type = gettok(token) ) {
if( type == ALPHA && (p=lookup(token)) )
expand(p);
else {
for( p = token; *p ; )
putl(*p++);
}
}
}
putl('\0');
return(1);
}
/* eatup - eat up the rest of the input line until a newline or EOF*/
/* Does gettok calls.*/
eatup() /* returns - none*/
{
register int type;
char etoken[TOKSIZE];
while( (type=gettok(etoken)) != NEWL && type != EOF )
;
}
/* putl - put a character to the current output line*/
/* Checks for line overflow.*/
putl(c) /* returns - none*/
int c; /* character to put on line*/
{
if( linep < &line[LINESIZE] )
*linep++ = c;
else if ( !loverflow ) {
loverflow++;
error("line overflow");
}
}
/* initl - initialize current line*/
/* Sets the line pointer and the line overflow flag.*/
initl() /* returns - none*/
{
*(linep= &line[0]) = '\0';
loverflow = 0;
}
/* putd - put a character to the define buffer*/
/* Does dynamic allocation for define buffer*/
putd(c) /* returns - none*/
int c; /* character to put in buffer*/
{
if( !defcount ) {
if( sbrk(DEFSIZE) == -1 ) {
error("define table overflow");
cexit();
}
defcount = DEFSIZE;
}
defused++;
defcount--;
*defp++ = c;
}
/* undefine - does undef command*/
/* Sets the symbols definition to the null pointer*/
undefine(name) /* returns - none*/
char *name; /* pointer to name to undef*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def )
sp->s_def = null;
}
/* dodefine - do #define processing*/
/* Checks the define name, collects formal arguements and saves*/
/* macro definition, substituting for formal arguments as it goes.*/
dodefine() /* returns - none*/
{
char token[TOKSIZE], *args[MAXARGS], argbuf[ARGBSIZE];
register char *abp, *p;
register int type, nargs, i;
register struct symbol *sp;
if( (type=getntok(token)) != ALPHA ) {
error("bad define name: %s",token);
return;
}
sp = getsp(token);
symcopy(token,sp->s_name);
sp->s_def = defp;
nargs = 0;
abp = argbuf;
if( (type=gettok(token)) == LPAREN ) {
for( ; (type=getfarg(token)) != RPAREN; nargs++ ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
break;
}
args[nargs] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
break;
}
}
}
putd(nargs);
}
else {
pbtok(token);
putd(NOARGS);
}
type = getntok(token); /*get next non-white token*/
for( ; type != NEWL && type != EOF; type = gettok(token) ) {
if( type == ALPHA ) {
for( i = 0; i < nargs; i++ ) {
if( strcmp(args[i],token) == 0 )
break;
}
if( i < nargs ) { /*sub ARG marker for formal arg*/
putd(i+1);
putd(ARG);
continue;
}
}
else if( type == BSLASH ) {
if( (i=ngetch()) == '\n' ) { /*multi-line macro?*/
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
putc('\n',&outbuf);
}
}
putd(i);
continue;
}
for( p = token; *p ; )
putd(*p++);
}
pbtok(token);
putd('\0');
}
/* expand - expands the macro definition*/
/* Checks for define recursion and #define x x problems, collects*/
/* the actual arguments using getaarg, and then expands the macro*/
/* by pushing it onto the push back buffer, substituting arguments*/
/* as it goes.*/
expand(sp) /* returns - none*/
struct symbol *sp; /* pointer to macro to expand*/
{
char argbuf[ARGBSIZE], *args[MAXARGS], token[TOKSIZE];
register char *p, *abp, *mdef;
register int i, j, nargs, type;
if( pbflag++ > 100 ) {
error("define recursion");
return;
}
if( strcmp(sp->s_name,mdef=sp->s_def) == 0 ) { /*handle #define x x*/
while( *mdef )
putl(*mdef++);
return;
}
nargs = 0;
if( *mdef == NOARGS ) /*suppress grabbing of args*/
;
else if( gettok(token) != LPAREN )
pbtok(token);
else {
abp = &argbuf[0];
while( (type=getaarg(token)) != EOF ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
return;
}
args[nargs++] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
return;
}
}
if( type == RPAREN )
break;
}
}
if( *mdef == NEWLABEL ) {
clabel = nlabel;
if( !nargs )
nlabel++;
else
nlabel =+ atoi(args[0]);
}
else if( *mdef == LABEL ) {
if( !nargs )
i = clabel;
else
i = clabel + atoi(args[0]);
pbnum(i);
pbtok("_L");
}
else {
mdef++; /*skip no. of args*/
for( p = mdef + strlen(mdef) - 1; p >= mdef; p-- ) {
if( *p == ARG ) {
if( (j= *--p) <= nargs )
pbtok(args[j-1]);
}
else
putback(*p);
}
}
}
/* getfarg - get macro formal parameters*/
/* Skips blanks and handles "," and ")".*/
getfarg(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
if( (type=getntok(token)) == RPAREN || type == ALPHA )
return(type);
if( type != COMMA || (type=getntok(token)) != ALPHA )
error("bad argument:%s",token);
return(type);
}
/* getntok - get next token, suppressing white space*/
/* Merely gettok's until non-white space is there*/
getntok(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
while( (type=gettok(token)) == WHITE )
;
return(type);
}
/* getaarg - get macro actual argument*/
/* This handles the collecting of the macro's call arguments.*/
/* Note that you may have parenthesis as part of the macro argument,*/
/* hence you need to keep track of them.*/
getaarg(argp) /* returns token type*/
char *argp; /* argument returned*/
{
int type, plevel, i;
register char *p, *ap;
char token[TOKSIZE];
ap = argp;
*ap = '\0';
plevel = 0;
i = TOKSIZE;
while( ((type=gettok(token)) != COMMA && type != RPAREN) || plevel ) {
for( p = token; *ap = *p++; ap++ )
if( --i <= 0 ) {
error("macro argument too long");
return(EOF);
}
if( type == LPAREN )
plevel++;
else if( type == RPAREN )
plevel--;
else if( type == EOF ) {
error("unexpected EOF");
cexit();
}
}
if( ap == argp )
type = EOF;
return(type);
}
/* push - push a #ifdef condition value on condition stack*/
/* Checks for stack overflow.*/
push(val) /* returns - none*/
int val; /* value to push*/
{
if( cstkptr >= &cstack[CSTKSIZE] ) {
error("condition stack overflow");
cexit();
}
*cstkptr++ = val;
}
/* pop - pop the #ifdef, etc. condition stack*/
/* Checks for stack undeflow.*/
pop() /* returns - top of condition stack*/
{
if( cstkptr <= &cstack[0] )
return(-1);
return( *--cstkptr );
}
/* doinclude - handle #include command*/
/* Checks for file name or library file name and pushes file on*/
/* include file stack.*/
doinclude(infile) /* returns - none*/
char *infile; /* [vlh] for quoted include files */
{
register int type, fd;
char token[TOKSIZE], fname[TOKSIZE];
register char *p, *q, c, *ptr1, *ptr2;
int i, j;
p = fname;
if( (type=getntok(token)) == SQUOTE || type == DQUOTE ) {
for( c = token[0], q = &token[1]; *q != c; )
*p++ = *q++;
*p = '\0';
p = getinclude(fname,infile);
}
else if( type != LESS ) {
error("bad include file");
return;
}
else {
while( (type=gettok(token))!=GREAT && type!=NEWL && type!=EOF )
for( q = token; *p = *q++; p++ )
;
if( type != GREAT ) {
error("bad include file name");
pbtok(token);
return;
}
p = getinclude(fname,0L);
}
eatup(); /*need here...*/
filep++;
if( filep >= &filestack[FSTACK] )
error("includes nested too deeply");
else {
if( fopen(p,&(filep->inbuf),0) < 0 )/* 3rd arg for versados */
error("can't open include file %s\n",p);
else {
filep->ifd = fd;
filep->lineno = 0; /* [vlh] */
doifile(p);
}
}
putback('\n'); /*for eatup in domacro*/
}
doifile(p) /* [vlh] */
char *p;
{
register char *iptr;
register int ndx;
while ((ndx = index(p,FILESEP)) >= 0) p =+ ndx+1;
for( iptr = filep->ifile; *p; ) *iptr++ = *p++;
*iptr = 0;
}
/* getinclude - get include file full pathname */
char *
getinclude(fname,parent) /* [vlh] */
char *fname;
char *parent; /* search parent-file home directory ? */
{
register char *q, *t;
register int i, fd, ndx;
if (parent) { /* include filename surrounded by quotes */
q = (filep == &filestack[0]) ? parent : (filep)->ifile;
t = &inclname;
while ((ndx = index(q,FILESEP)) >= 0) {
ndx++;
while (ndx--) *t++ = *q++;
}
for (q=fname; *t++ = *q++; );
*t = 0;
if ((fd = open(inclname,0)) >= 0) { /* found it */
close(fd);
return(&inclname);
}
}
for (i=0; i<nincl; i++) {
for(t=inclname, q=incl[i]; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
if ((fd = open(inclname,0)) >= 0) {
close(fd);
return(&inclname);
}
}
for(t=inclname, q=stdincl; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
return(&inclname);
}
pbnum(num) /* returns - none*/
int num;
{
register int digit;
do {
digit = num % 10;
num =/ 10;
putback(digit+'0');
} while( num > 0 );
}

View File

@@ -0,0 +1,685 @@
1File: MACRO.C Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7
8 #include "preproc.h"
9
10 #define CSTKSIZE 20
11 #define FILESEP '/'
12 #define NINCL 10
13
14 #ifdef UNIX
15 char *stdincl "/usr/include/"; /*standard include directory*/
16 #endif
17 #ifdef VMS
18 char *stdincl "lib:";
19 #endif
20 #ifdef CPM
21 char *stdincl "";
22 #endif
23
24 int clabel 1000;
25 int nlabel 1001;
26 int nincl;
27 char *incl[10];
28 char tmp[6];
29
30 struct builtin {
31 char *b_name;
32 int b_type;
33 } btab[] {
34 "define", DEFINE,
35 "include", INCLUDE,
36 "undef", UNDEF,
37 "ifdef", IFDEF,
38 "ifndef", IFNDEF,
39 "else", ELSE,
40 "endif", ENDIF,
41 "if", IF,
42 0,
43 };
44
45 char *getinclude();
46 char cstack[CSTKSIZE];
47 char *cstkptr, inclname[TOKSIZE];
48
49 /* domacro - do macro processing*/
50 /* Does the macro pre-processing on the input file and leaves the*/
51 /* result on the output file.*/
52 domacro(infile,outfile,nd) /* returns 1 if ok, 0 otherwise*/
53 char *infile; /* input file name*/
54 char *outfile; /* output file name*/
55 int nd; /* number of defines*/
56 {
57 register struct builtin *bp;
58 register char *l;
59 register struct symbol *sp;
1File: MACRO.C Page 2
60 register int x, nonewline; /* handle empty new lines with SOH */
61 register char *p;
62 filep = &filestack[0];
63
64 if( fopen(infile,&(filep->inbuf),0) < 0 ) { /* 3rd arg for versados */
65 error("can't open source file %s\n",infile);
66 return(0);
67 }
68 if( fcreat(outfile,&outbuf,0) < 0 ) { /* 3rd arg for versados */
69 error("can't creat %s\n",outfile);
70 return(0);
71 }
72 for (sp= &symtab[0]; sp<= &symtab[HSIZE-1]; sp++) /*3.4*/
73 sp->s_def = null; /* clear out symbol table */
74 if( !defap ) {
75 defp = defap = sbrk(1024);
76 defmax = defcount = 1024;
77 }
78 else { /* multiple files, define area already exists */
79 defcount = defmax;
80 for (x = defmax, defp = defap; x>0; x--)
81 *defp++ = 0;
82 defp = defap;
83 }
84 lineno = 1;
85 nonewline = defused = mfail = 0;
86 pbp = &pbbuf[0];
87 cstkptr = &cstack[0];
88 install("Newlabel",NEWLABEL);
89 install("Label",LABEL);
90 while( --nd >= 0 )
91 dinstall(defs[nd].ptr,defs[nd].value);
92 while( getline(infile) ) {
93 l = line;
94 if( filep == &filestack[0] && pbp == &pbbuf[0] )
95 lineno++;
96 else if ( !pflag && !asflag ) { /*[vlh] add fname & line#*/
97 if (*l) {
98 putc(SOH,&outbuf);
99 for (p = (filep)->ifile; *p; p++)
100 putc(*p,&outbuf);
101 putc(SOH,&outbuf);
102 itoa((filep)->lineno,tmp,5);
103 for (p = tmp; *p==' '; ) p++;
104 for ( ; *p; p++)
105 putc(*p,&outbuf);
106 putc(' ',&outbuf);
107 if (!(*l)) putc(' ',&outbuf);
108 }
109 else nonewline++;
110 (filep)->lineno++;
111 }
112 while( *l )
113 putc(*l++,&outbuf);
114 if (!nonewline) putc('\n',&outbuf);
115 else nonewline = 0;
116 }
117 if( cstkptr != &cstack[0] )
118 error("unmatched conditional");
1File: MACRO.C Page 3
119 if( defused > defmax )
120 defmax = defused;
121 v6flush(&outbuf);
122 close(outbuf.fd);
123 close(filep->inbuf.fd);
124 return(mfail==0);
125 }
126
127 install(name,def)
128 char *name;
129 int def;
130 {
131 register struct symbol *sp;
132
133 sp = getsp(name);
134 symcopy(name,sp->s_name);
135 sp->s_def = defp;
136 putd(def);
137 putd('\0');
138 }
139
140 dinstall(name,def) /* returns - none*/
141 char *name; /* macro name*/
142 char *def; /* pointer to definition*/
143 {
144 register struct symbol *sp;
145
146 sp = getsp(name);
147 symcopy(name,sp->s_name);
148 sp->s_def = defp;
149 putd(NOARGS);
150 if (def) /* [vlh] character strings... */
151 while(*def) putd(*def++);
152 else putd('1'); /* [vlh] default define value */
153 putd('\0');
154 }
155
156 /* kwlook - look up the macro built-in names*/
157 /* Searches thru the built-in table for the name.*/
158 kwlook(name) /* returns keyword index or 0*/
159 char *name; /* keyword name to lookup*/
160 {
161 register struct builtin *bp;
162
163 for( bp = &btab[0]; bp->b_name; bp++ )
164 if( strcmp(bp->b_name,name) == 0 )
165 return(bp->b_type);
166 return(0);
167 }
168
169 /*
170 * getline - get input line handling macro statements
171 * Checks for a preprocessor statement on the line and if there
172 * is one there, it processes it. Note that most of the work is
173 * in determining whether we need to skip the current line or not.
174 * This is all handled with the condition stack and the skip variable.
175 * The skip variable is non-zero if any condition on the condition
176 * stack is SKIP.
177 */
1File: MACRO.C Page 4
178 getline(infile) /* returns 0 for EOF, 1 otherwise*/
179 char *infile; /* [vlh] for quoted include files */
180 {
181 char token[TOKSIZE];
182 register int type, i;
183 register char *p;
184
185 initl();
186 if( (type=gettok(token)) == EOF )
187 return(0);
188 if( type == POUND ) {
189 if( (type=getntok(token)) == NEWL )
190 return(1);
191 switch( kwlook(token) ) {
192
193 case IFDEF:
194 if( getntok(token) == ALPHA && lookup(token) )
195 push(NOSKIP);
196 else {
197 push(SKIP);
198 skip++;
199 }
200 break;
201
202 case IFNDEF:
203 if( getntok(token) == ALPHA && lookup(token) ) {
204 push(SKIP);
205 skip++;
206 }
207 else
208 push(NOSKIP);
209 break;
210
211 case ENDIF:
212 if( (i=pop()) == SKIP )
213 skip--;
214 else if( i != NOSKIP )
215 error("invalid #endif");
216 break;
217
218 case ELSE:
219 if( (i=pop()) == SKIP ) {
220 skip--;
221 push(NOSKIP);
222 }
223 else if( i == NOSKIP ) {
224 skip++;
225 push(SKIP);
226 }
227 else
228 error("invalid #else");
229 break;
230
231 case DEFINE:
232 if( !skip ) /*if in skip, don't do define*/
233 dodefine();
234 break;
235
236 case UNDEF:
1File: MACRO.C Page 5
237 if( !skip ) { /*if in skip, don't undef*/
238 if( (type=getntok(token)) == ALPHA )
239 undefine(token);
240 }
241 break;
242
243 case INCLUDE:
244 if( !skip ) /*if in skip, don't do include*/
245 doinclude(infile);
246 break;
247
248 case IF:
249 if( cexpr() ) /*evaluate constant expression*/
250 push(NOSKIP); /*non-zero, so don't skip*/
251 else {
252 push(SKIP);
253 skip++;
254 }
255 break;
256
257 default:
258 error("invalid preprocessor command");
259 break;
260 }
261 eatup();
262 }
263 else if( type == NEWL )
264 ;
265 else if( skip )
266 eatup();
267 else {
268 for( ; type != NEWL && type != EOF ; type = gettok(token) ) {
269 if( type == ALPHA && (p=lookup(token)) )
270 expand(p);
271 else {
272 for( p = token; *p ; )
273 putl(*p++);
274 }
275 }
276 }
277 putl('\0');
278 return(1);
279 }
280
281 /* eatup - eat up the rest of the input line until a newline or EOF*/
282 /* Does gettok calls.*/
283 eatup() /* returns - none*/
284 {
285 register int type;
286 char etoken[TOKSIZE];
287
288 while( (type=gettok(etoken)) != NEWL && type != EOF )
289 ;
290 }
291
292 /* putl - put a character to the current output line*/
293 /* Checks for line overflow.*/
294 putl(c) /* returns - none*/
295 int c; /* character to put on line*/
1File: MACRO.C Page 6
296 {
297 if( linep < &line[LINESIZE] )
298 *linep++ = c;
299 else if ( !loverflow ) {
300 loverflow++;
301 error("line overflow");
302 }
303 }
304
305 /* initl - initialize current line*/
306 /* Sets the line pointer and the line overflow flag.*/
307 initl() /* returns - none*/
308 {
309 *(linep= &line[0]) = '\0';
310 loverflow = 0;
311 }
312
313 /* putd - put a character to the define buffer*/
314 /* Does dynamic allocation for define buffer*/
315 putd(c) /* returns - none*/
316 int c; /* character to put in buffer*/
317 {
318 if( !defcount ) {
319 if( sbrk(DEFSIZE) == -1 ) {
320 error("define table overflow");
321 cexit();
322 }
323 defcount = DEFSIZE;
324 }
325 defused++;
326 defcount--;
327 *defp++ = c;
328 }
329
330 /* undefine - does undef command*/
331 /* Sets the symbols definition to the null pointer*/
332 undefine(name) /* returns - none*/
333 char *name; /* pointer to name to undef*/
334 {
335 register struct symbol *sp;
336
337 sp = getsp(name);
338 if( sp->s_def )
339 sp->s_def = null;
340 }
341
342 /* dodefine - do #define processing*/
343 /* Checks the define name, collects formal arguements and saves*/
344 /* macro definition, substituting for formal arguments as it goes.*/
345 dodefine() /* returns - none*/
346 {
347 char token[TOKSIZE], *args[MAXARGS], argbuf[ARGBSIZE];
348 register char *abp, *p;
349 register int type, nargs, i;
350 register struct symbol *sp;
351
352 if( (type=getntok(token)) != ALPHA ) {
353 error("bad define name: %s",token);
354 return;
1File: MACRO.C Page 7
355 }
356 sp = getsp(token);
357 symcopy(token,sp->s_name);
358 sp->s_def = defp;
359 nargs = 0;
360 abp = argbuf;
361 if( (type=gettok(token)) == LPAREN ) {
362 for( ; (type=getfarg(token)) != RPAREN; nargs++ ) {
363 if( nargs >= MAXARGS ) {
364 error("too many arguments");
365 break;
366 }
367 args[nargs] = abp;
368 for( p = token; *abp++ = *p++; ) {
369 if( abp >= &argbuf[ARGBSIZE] ) {
370 error("argument buffer overflow");
371 break;
372 }
373 }
374 }
375 putd(nargs);
376 }
377 else {
378 pbtok(token);
379 putd(NOARGS);
380 }
381 type = getntok(token); /*get next non-white token*/
382 for( ; type != NEWL && type != EOF; type = gettok(token) ) {
383 if( type == ALPHA ) {
384 for( i = 0; i < nargs; i++ ) {
385 if( strcmp(args[i],token) == 0 )
386 break;
387 }
388 if( i < nargs ) { /*sub ARG marker for formal arg*/
389 putd(i+1);
390 putd(ARG);
391 continue;
392 }
393 }
394 else if( type == BSLASH ) {
395 if( (i=ngetch()) == '\n' ) { /*multi-line macro?*/
396 if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
397 lineno++;
398 putc('\n',&outbuf);
399 }
400 }
401 putd(i);
402 continue;
403 }
404 for( p = token; *p ; )
405 putd(*p++);
406 }
407 pbtok(token);
408 putd('\0');
409 }
410
411 /* expand - expands the macro definition*/
412 /* Checks for define recursion and #define x x problems, collects*/
413 /* the actual arguments using getaarg, and then expands the macro*/
1File: MACRO.C Page 8
414 /* by pushing it onto the push back buffer, substituting arguments*/
415 /* as it goes.*/
416 expand(sp) /* returns - none*/
417 struct symbol *sp; /* pointer to macro to expand*/
418 {
419 char argbuf[ARGBSIZE], *args[MAXARGS], token[TOKSIZE];
420 register char *p, *abp, *mdef;
421 register int i, j, nargs, type;
422
423 if( pbflag++ > 100 ) {
424 error("define recursion");
425 return;
426 }
427 if( strcmp(sp->s_name,mdef=sp->s_def) == 0 ) { /*handle #define x x*/
428 while( *mdef )
429 putl(*mdef++);
430 return;
431 }
432 nargs = 0;
433 if( *mdef == NOARGS ) /*suppress grabbing of args*/
434 ;
435 else if( gettok(token) != LPAREN )
436 pbtok(token);
437 else {
438 abp = &argbuf[0];
439 while( (type=getaarg(token)) != EOF ) {
440 if( nargs >= MAXARGS ) {
441 error("too many arguments");
442 return;
443 }
444 args[nargs++] = abp;
445 for( p = token; *abp++ = *p++; ) {
446 if( abp >= &argbuf[ARGBSIZE] ) {
447 error("argument buffer overflow");
448 return;
449 }
450 }
451 if( type == RPAREN )
452 break;
453 }
454 }
455 if( *mdef == NEWLABEL ) {
456 clabel = nlabel;
457 if( !nargs )
458 nlabel++;
459 else
460 nlabel =+ atoi(args[0]);
461 }
462 else if( *mdef == LABEL ) {
463 if( !nargs )
464 i = clabel;
465 else
466 i = clabel + atoi(args[0]);
467 pbnum(i);
468 pbtok("_L");
469 }
470 else {
471 mdef++; /*skip no. of args*/
472 for( p = mdef + strlen(mdef) - 1; p >= mdef; p-- ) {
1File: MACRO.C Page 9
473 if( *p == ARG ) {
474 if( (j= *--p) <= nargs )
475 pbtok(args[j-1]);
476 }
477 else
478 putback(*p);
479 }
480 }
481 }
482
483 /* getfarg - get macro formal parameters*/
484 /* Skips blanks and handles "," and ")".*/
485 getfarg(token) /* returns token type*/
486 char *token; /* token returned*/
487 {
488 register int type;
489
490 if( (type=getntok(token)) == RPAREN || type == ALPHA )
491 return(type);
492 if( type != COMMA || (type=getntok(token)) != ALPHA )
493 error("bad argument:%s",token);
494 return(type);
495 }
496
497 /* getntok - get next token, suppressing white space*/
498 /* Merely gettok's until non-white space is there*/
499 getntok(token) /* returns token type*/
500 char *token; /* token returned*/
501 {
502 register int type;
503
504 while( (type=gettok(token)) == WHITE )
505 ;
506 return(type);
507 }
508
509 /* getaarg - get macro actual argument*/
510 /* This handles the collecting of the macro's call arguments.*/
511 /* Note that you may have parenthesis as part of the macro argument,*/
512 /* hence you need to keep track of them.*/
513 getaarg(argp) /* returns token type*/
514 char *argp; /* argument returned*/
515 {
516 int type, plevel, i;
517 register char *p, *ap;
518 char token[TOKSIZE];
519
520 ap = argp;
521 *ap = '\0';
522 plevel = 0;
523 i = TOKSIZE;
524 while( ((type=gettok(token)) != COMMA && type != RPAREN) || plevel ) {
525 for( p = token; *ap = *p++; ap++ )
526 if( --i <= 0 ) {
527 error("macro argument too long");
528 return(EOF);
529 }
530 if( type == LPAREN )
531 plevel++;
1File: MACRO.C Page 10
532 else if( type == RPAREN )
533 plevel--;
534 else if( type == EOF ) {
535 error("unexpected EOF");
536 cexit();
537 }
538 }
539 if( ap == argp )
540 type = EOF;
541 return(type);
542 }
543
544 /* push - push a #ifdef condition value on condition stack*/
545 /* Checks for stack overflow.*/
546 push(val) /* returns - none*/
547 int val; /* value to push*/
548 {
549 if( cstkptr >= &cstack[CSTKSIZE] ) {
550 error("condition stack overflow");
551 cexit();
552 }
553 *cstkptr++ = val;
554 }
555
556 /* pop - pop the #ifdef, etc. condition stack*/
557 /* Checks for stack undeflow.*/
558 pop() /* returns - top of condition stack*/
559 {
560 if( cstkptr <= &cstack[0] )
561 return(-1);
562 return( *--cstkptr );
563 }
564
565 /* doinclude - handle #include command*/
566 /* Checks for file name or library file name and pushes file on*/
567 /* include file stack.*/
568 doinclude(infile) /* returns - none*/
569 char *infile; /* [vlh] for quoted include files */
570 {
571 register int type, fd;
572 char token[TOKSIZE], fname[TOKSIZE];
573 register char *p, *q, c, *ptr1, *ptr2;
574 int i, j;
575
576 p = fname;
577 if( (type=getntok(token)) == SQUOTE || type == DQUOTE ) {
578 for( c = token[0], q = &token[1]; *q != c; )
579 *p++ = *q++;
580 *p = '\0';
581 p = getinclude(fname,infile);
582 }
583 else if( type != LESS ) {
584 error("bad include file");
585 return;
586 }
587 else {
588 while( (type=gettok(token))!=GREAT && type!=NEWL && type!=EOF )
589 for( q = token; *p = *q++; p++ )
590 ;
1File: MACRO.C Page 11
591 if( type != GREAT ) {
592 error("bad include file name");
593 pbtok(token);
594 return;
595 }
596 p = getinclude(fname,0L);
597 }
598 eatup(); /*need here...*/
599 filep++;
600 if( filep >= &filestack[FSTACK] )
601 error("includes nested too deeply");
602 else {
603 if( fopen(p,&(filep->inbuf),0) < 0 )/* 3rd arg for versados */
604 error("can't open include file %s\n",p);
605 else {
606 filep->ifd = fd;
607 filep->lineno = 0; /* [vlh] */
608 doifile(p);
609 }
610 }
611 putback('\n'); /*for eatup in domacro*/
612 }
613
614 doifile(p) /* [vlh] */
615 char *p;
616 {
617 register char *iptr;
618 register int ndx;
619
620 while ((ndx = index(p,FILESEP)) >= 0) p =+ ndx+1;
621 for( iptr = filep->ifile; *p; ) *iptr++ = *p++;
622 *iptr = 0;
623 }
624
625 /* getinclude - get include file full pathname */
626 char *
627 getinclude(fname,parent) /* [vlh] */
628 char *fname;
629 char *parent; /* search parent-file home directory ? */
630 {
631 register char *q, *t;
632 register int i, fd, ndx;
633
634 if (parent) { /* include filename surrounded by quotes */
635 q = (filep == &filestack[0]) ? parent : (filep)->ifile;
636 t = &inclname;
637 while ((ndx = index(q,FILESEP)) >= 0) {
638 ndx++;
639 while (ndx--) *t++ = *q++;
640 }
641 for (q=fname; *t++ = *q++; );
642 *t = 0;
643 if ((fd = open(inclname,0)) >= 0) { /* found it */
644 close(fd);
645 return(&inclname);
646 }
647 }
648 for (i=0; i<nincl; i++) {
649 for(t=inclname, q=incl[i]; *t++ = *q++; ) ;
1File: MACRO.C Page 12
650 for(q=fname, --t; *t++ = *q++; ) ;
651 *t = 0;
652 if ((fd = open(inclname,0)) >= 0) {
653 close(fd);
654 return(&inclname);
655 }
656 }
657 for(t=inclname, q=stdincl; *t++ = *q++; ) ;
658 for(q=fname, --t; *t++ = *q++; ) ;
659 *t = 0;
660 return(&inclname);
661 }
662
663 pbnum(num) /* returns - none*/
664 int num;
665 {
666 register int digit;
667
668 do {
669 digit = num % 10;
670 num =/ 10;
671 putback(digit+'0');
672 } while( num > 0 );
673 }

View File

@@ -0,0 +1,141 @@
#
/*
Copyright 1981
Alcyon Corporation
8474 Commerce Av.
San Diego, Ca. 92121
*/
#include "preproc.h"
int status = 0;
char *stdincl; /* Include prefix for macro processor */
/* cexit - exit from C compiler driver*/
/* This deletes any existing temps and exits with the error status.*/
cexit() /* returns - none*/
{
exit(status);
}
/* main - main routine for C68 Compiler system*/
/* Handles the C68 arguments. For each C file given, the macro*/
/* pre-processor is called, then the parser, code generator and*/
/* assember are fexec'd. The loader arguments are collected and*/
/* the loader is fexec'd.*/
main(argc,argv)
int argc;
char **argv;
{
if(argc < 3)
usage();
if (*argv[1] == '-')
{
if(argc != 5 || argv[1][1] != 'i')
usage();
stdincl = argv[2];
domacro(argv[3],argv[4],0,0L);
cexit();
}
if(argc != 3)
usage();
domacro(argv[1],argv[2],0,0L);
cexit();
}
usage()
{
error("usage: c68 [-i x:] inputfile outputfile\n");
exit();
}
/* strcmp - string comparison*/
/* Compares two strings for equality, less or greater.*/
strcmp(s,t) /* returns 0 for equality,*/
/* neg for < and pos for >.*/
char *s; /* first string*/
char *t; /* second string*/
{
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return(0);
return( *s - *t );
}
/* strlen - string length*/
/* Computes number of bytes in string.*/
strlen(s) /* returns string length*/
char *s; /* string to compute length*/
{
register int n;
for( n = 0; *s++ != '\0'; )
n++;
return(n);
}
/* itoa - integer to ASCII conversion*/
/* Converts integer to ASCII string, handles '-'.*/
itoa(n,s,w) /* returns - none*/
int n; /* number to convert*/
char *s; /* resulting string*/
int w; /* minimum width of string*/
{
register int sign, i;
char temp[6];
if( (sign=n) < 0 )
n = -n;
i = 0;
do {
temp[i++] = n % 10 + '0';
} while( (n =/ 10) > 0 );
if( sign < 0 )
temp[i++] = '-';
while( --w >= i ) /*pad on left with blanks*/
*s++ = ' ';
while( --i >= 0 ) /*move chars reversed*/
*s++ = temp[i];
*s = '\0';
}
/* strend - set string end*/
/* This is used to compare the endings of file names for ".c", etc.*/
strend(s,t) /* returns 1 if match, 0 otherwise*/
char *s; /* string to compare*/
char *t; /* string ending*/
{
int ls, lt;
if( (ls=strlen(s)) < (lt=strlen(t)) )
return(0);
if( strcmp(&s[ls-lt],t) == 0 )
return(1);
return(0);
}
/* index - find the index of a character in a string*/
/* This is identical to Software Tools index.*/
index(str,chr) /* returns index of c in str or -1*/
char *str; /* pointer to string to search*/
char chr; /* character to search for*/
{
register char *s;
register int i;
for( s = str, i = 0; *s != '\0'; i++ )
if( *s++ == chr )
return(i);
return(-1);
}
v6flush(v6buf)
struct iobuf *v6buf;
{
register i;
i = BLEN - v6buf->nunused;
v6buf->nunused = BLEN;
v6buf->xfree = &(v6buf->buff[0]);
if(write(v6buf->fildes,v6buf->xfree,i) != i)
return(-1);
return(0);
}

View File

@@ -0,0 +1,144 @@
1File: MAIN.C Page 1
1 #
2 /*
3 Copyright 1981
4 Alcyon Corporation
5 8474 Commerce Av.
6 San Diego, Ca. 92121
7 */
8 #include "preproc.h"
9 int status = 0;
10 char *stdincl; /* Include prefix for macro processor */
11 /* cexit - exit from C compiler driver*/
12 /* This deletes any existing temps and exits with the error status.*/
13 cexit() /* returns - none*/
14 {
15
16 exit(status);
17 }
18
19 /* main - main routine for C68 Compiler system*/
20 /* Handles the C68 arguments. For each C file given, the macro*/
21 /* pre-processor is called, then the parser, code generator and*/
22 /* assember are fexec'd. The loader arguments are collected and*/
23 /* the loader is fexec'd.*/
24 main(argc,argv)
25 int argc;
26 char **argv;
27 {
28
29 if(argc < 3)
30 usage();
31
32 if (*argv[1] == '-')
33 {
34 if(argc != 5 || argv[1][1] != 'i')
35 usage();
36
37 stdincl = argv[2];
38 domacro(argv[3],argv[4],0,0L);
39 cexit();
40 }
41 if(argc != 3)
42 usage();
43 domacro(argv[1],argv[2],0,0L);
44 cexit();
45 }
46 usage()
47 {
48 error("usage: c68 [-i x:] inputfile outputfile\n");
49 exit();
50 }
51
52 /* strcmp - string comparison*/
53 /* Compares two strings for equality, less or greater.*/
54 strcmp(s,t) /* returns 0 for equality,*/
55 /* neg for < and pos for >.*/
56 char *s; /* first string*/
57 char *t; /* second string*/
58 {
59 for( ; *s == *t; s++, t++ )
1File: MAIN.C Page 2
60 if( *s == '\0' )
61 return(0);
62 return( *s - *t );
63 }
64
65 /* strlen - string length*/
66 /* Computes number of bytes in string.*/
67 strlen(s) /* returns string length*/
68 char *s; /* string to compute length*/
69 {
70 register int n;
71
72 for( n = 0; *s++ != '\0'; )
73 n++;
74 return(n);
75 }
76
77 /* itoa - integer to ASCII conversion*/
78 /* Converts integer to ASCII string, handles '-'.*/
79 itoa(n,s,w) /* returns - none*/
80 int n; /* number to convert*/
81 char *s; /* resulting string*/
82 int w; /* minimum width of string*/
83 {
84 register int sign, i;
85 char temp[6];
86
87 if( (sign=n) < 0 )
88 n = -n;
89 i = 0;
90 do {
91 temp[i++] = n % 10 + '0';
92 } while( (n =/ 10) > 0 );
93 if( sign < 0 )
94 temp[i++] = '-';
95 while( --w >= i ) /*pad on left with blanks*/
96 *s++ = ' ';
97 while( --i >= 0 ) /*move chars reversed*/
98 *s++ = temp[i];
99 *s = '\0';
100 }
101
102 /* strend - set string end*/
103 /* This is used to compare the endings of file names for ".c", etc.*/
104 strend(s,t) /* returns 1 if match, 0 otherwise*/
105 char *s; /* string to compare*/
106 char *t; /* string ending*/
107 {
108 int ls, lt;
109
110 if( (ls=strlen(s)) < (lt=strlen(t)) )
111 return(0);
112 if( strcmp(&s[ls-lt],t) == 0 )
113 return(1);
114 return(0);
115 }
116 /* index - find the index of a character in a string*/
117 /* This is identical to Software Tools index.*/
118 index(str,chr) /* returns index of c in str or -1*/
1File: MAIN.C Page 3
119 char *str; /* pointer to string to search*/
120 char chr; /* character to search for*/
121 {
122 register char *s;
123 register int i;
124
125 for( s = str, i = 0; *s != '\0'; i++ )
126 if( *s++ == chr )
127 return(i);
128 return(-1);
129 }
130 v6flush(v6buf)
131 struct iobuf *v6buf;
132 {
133 register i;
134
135 i = BLEN - v6buf->nunused;
136 v6buf->nunused = BLEN;
137 v6buf->xfree = &(v6buf->buff[0]);
138 if(write(v6buf->fildes,v6buf->xfree,i) != i)
139 return(-1);
140 return(0);
141 }

View File

@@ -0,0 +1,49 @@
$1stat machine.h=rw
$1pip machine.h=machine.68k
$1cp68 -i 0$1 CEXPR.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CEXPR.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u CEXPR.s
era CEXPR.s
$1cp68 -i 0$1 LEX.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic LEX.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u LEX.s
era LEX.s
$1cp68 -i 0$1 MACRO.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic MACRO.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MACRO.s
era MACRO.s
$1cp68 -i 0$1 MAIN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic MAIN.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MAIN.s
era MAIN.s
$1cp68 -i 0$1 UTIL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic UTIL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u UTIL.s
era UTIL.s
link $1

View File

@@ -0,0 +1,150 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include <stdio.h>
#include <klib.h>
#include "icode.h"
#include "machine.h"
/*cexpr operators*/
#define EOF 0
#define SUB 1
#define ADD 2
#define NOT 3
#define NEG 4
#define LPAREN 5
#define RPAREN 6
#define QMARK 7
#define COLON 8
#define OR 9
#define AND 10
#define XOR 11
#define EQUAL 12
#define NEQUAL 13
#define LESS 14
#define LSEQUAL 15
#define GREAT 16
#define GREQUAL 17
#define LSHIFT 18
#define RSHIFT 19
#define MULT 20
#define DIV 21
#define MOD 22
#define COMPL 23
#define CONST 24
#define LASTOP COMPL /*up to here used by cexpr*/
#define SQUOTE 25
#define DQUOTE 26
#define ANYC 27
#define BADC 28
#define COMMA 29
#define NEWL 30
#define POUND 31
#define ALPHA 32
#define DIGIT 33
#define BSLASH 34
#define WHITE 35
#define BUFSIZE 512
#define LINESIZE 512
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define DEFINE 1
#define UNDEF 2
#define INCLUDE 3
#define IFDEF 4
#define IFNDEF 5
#define ELSE 6
#define ENDIF 7
#define IF 8
#define SKIP 0
#define NOSKIP 1
#define SOH '\01'
#define SSIZE 8
#define HSIZE 517 /* 3.4 made prime */
#define FSTACK 10
#define TRUE 1
#define FALSE 0
#define NDEFS 20
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE];
/*buffered I/O structure*/
struct ibuf {
int fd;
int nc;
char *bp;
char buffer[BUFSIZE];
} outbuf;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS];
struct stackstruc { /* [vlh] */
int ifd;
char ifile[13];
int lineno;
struct ibuf inbuf;
} filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
#ifdef VERSADOS
#define NONEST 1
#define NOFORKS 1
#endif
#ifdef VMS
#define NONEST 1
#endif
#ifdef NONEST
struct ibuf holdbuf; /* alternate buffer, hold main file info */
#endif
#endif
int mfail; /*macro error flag*/
int skip; /*skipping current line*/
char *defap; /*pointer to available define area*/
char *defp; /*pointer to next avail define byte*/
int defcount; /*bytes left in define area*/
int defused; /*number of bytes used in define area*/
int defmax; /*maximum define area used*/
int pflag;
int asflag;
/*line to output after macro substitution*/
char line[LINESIZE+2]; /*line buffer*/
char *linep; /*current line pointer*/
int loverflow; /*line overflow flag*/
int lineno;
/*push back buffer*/
char pbbuf[PBSIZE]; /*push back buffer*/
char *pbp; /*push back pointer*/
int pbflag; /*checks for recursive definition*/
char null[]; /*used for undef'd symbols*/
char *lookup();
#ifdef BULLSHIT
char *maketemp();
char *setend();
char *makecopy();
#endif
char *sbrk();
struct symbol *getsp();

View File

@@ -0,0 +1,153 @@
1File: PREPROC.H Page 1
1 /*
2 Copyright 1982
3 Alcyon Corporation
4 8716 Production Ave.
5 San Diego, Ca. 92121
6 */
7 #include <stdio.h>
8 #include <klib.h>
9 #include "icode.h"
10 #include "machine.h"
11 /*cexpr operators*/
12 #define EOF 0
13 #define SUB 1
14 #define ADD 2
15 #define NOT 3
16 #define NEG 4
17 #define LPAREN 5
18 #define RPAREN 6
19 #define QMARK 7
20 #define COLON 8
21 #define OR 9
22 #define AND 10
23 #define XOR 11
24 #define EQUAL 12
25 #define NEQUAL 13
26 #define LESS 14
27 #define LSEQUAL 15
28 #define GREAT 16
29 #define GREQUAL 17
30 #define LSHIFT 18
31 #define RSHIFT 19
32 #define MULT 20
33 #define DIV 21
34 #define MOD 22
35 #define COMPL 23
36 #define CONST 24
37 #define LASTOP COMPL /*up to here used by cexpr*/
38 #define SQUOTE 25
39 #define DQUOTE 26
40 #define ANYC 27
41 #define BADC 28
42 #define COMMA 29
43 #define NEWL 30
44 #define POUND 31
45 #define ALPHA 32
46 #define DIGIT 33
47 #define BSLASH 34
48 #define WHITE 35
49 #define BUFSIZE 512
50 #define LINESIZE 512
51 #define ARG -1
52 #define NEWLABEL -2
53 #define LABEL -3
54 #define NOARGS -4
55 #define MAXARGS 60
56 #define ARGBSIZE 1000
57 #define TOKSIZE 300 /*BUG 4/20/82 was 128*/
58 #define DEFSIZE 1024
59 #define PBSIZE 1000
1File: PREPROC.H Page 2
60 #define DEFINE 1
61 #define UNDEF 2
62 #define INCLUDE 3
63 #define IFDEF 4
64 #define IFNDEF 5
65 #define ELSE 6
66 #define ENDIF 7
67 #define IF 8
68 #define SKIP 0
69 #define NOSKIP 1
70 #define SOH '\01'
71 #define SSIZE 8
72 #define HSIZE 517 /* 3.4 made prime */
73 #define FSTACK 10
74
75 #define TRUE 1
76 #define FALSE 0
77 #define NDEFS 20
78
79 struct symbol {
80 char s_name[SSIZE];
81 char *s_def;
82 } symtab[HSIZE];
83
84 /*buffered I/O structure*/
85 struct ibuf {
86 int fd;
87 int nc;
88 char *bp;
89 char buffer[BUFSIZE];
90 } outbuf;
91
92 /* command line define structure */
93 struct defstruc {
94 char *ptr;
95 char *value;
96 } defs[NDEFS];
97
98 struct stackstruc { /* [vlh] */
99 int ifd;
100 char ifile[13];
101 int lineno;
102 struct ibuf inbuf;
103 } filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
104
105 #ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
106 #ifdef VERSADOS
107 #define NONEST 1
108 #define NOFORKS 1
109 #endif
110
111 #ifdef VMS
112 #define NONEST 1
113 #endif
114
115 #ifdef NONEST
116 struct ibuf holdbuf; /* alternate buffer, hold main file info */
117 #endif
118 #endif
1File: PREPROC.H Page 3
119
120 int mfail; /*macro error flag*/
121 int skip; /*skipping current line*/
122 char *defap; /*pointer to available define area*/
123 char *defp; /*pointer to next avail define byte*/
124 int defcount; /*bytes left in define area*/
125 int defused; /*number of bytes used in define area*/
126 int defmax; /*maximum define area used*/
127 int pflag;
128 int asflag;
129
130 /*line to output after macro substitution*/
131 char line[LINESIZE+2]; /*line buffer*/
132 char *linep; /*current line pointer*/
133 int loverflow; /*line overflow flag*/
134 int lineno;
135
136 /*push back buffer*/
137 char pbbuf[PBSIZE]; /*push back buffer*/
138 char *pbp; /*push back pointer*/
139 int pbflag; /*checks for recursive definition*/
140
141 char null[]; /*used for undef'd symbols*/
142
143 char *lookup();
144 #ifdef BULLSHIT
145 char *maketemp();
146 char *setend();
147 char *makecopy();
148 #endif
149 char *sbrk();
150 struct symbol *getsp();

View File

@@ -0,0 +1,12 @@
e:send MACHINE.H
e:send CEXPR.C
e:send LEX.C
e:send MACRO.C
e:send MAIN.C
e:send UTIL.C
e:send ICODE.H
e:send PREPROC.H
e:send LINK.SUB
e:send MAKE.SUB
e:send MACHINE.68K
e:send SEND11.SUB

View File

@@ -0,0 +1,16 @@
atoi(as)
char *as;
{
register int n, sign;
register char *s;
s = as;
while( *s==' ' || *s=='\n' || *s == '\t')
s++;
sign = 1;
if( *s == '+' || *s == '-' )
sign = (*s++=='+') ? 1 : -1;
for( n = 0; *s >= '0' && *s <= '9'; s++ )
n = (n * 10) + (*s - '0');
return( sign * n );
}

View File

@@ -0,0 +1,17 @@
1File: UTIL.C Page 1
1 atoi(as)
2 char *as;
3 {
4 register int n, sign;
5 register char *s;
6
7 s = as;
8 while( *s==' ' || *s=='\n' || *s == '\t')
9 s++;
10 sign = 1;
11 if( *s == '+' || *s == '-' )
12 sign = (*s++=='+') ? 1 : -1;
13 for( n = 0; *s >= '0' && *s <= '9'; s++ )
14 n = (n * 10) + (*s - '0');
15 return( sign * n );
16 }

View File

@@ -0,0 +1,14 @@
$ preproc
$ set noon
$ !
$ ! Build file for VMS version of CP68
$ !
$ copy machine.vax machine.h
$ pur machine.h
$ cx CEXPR
$ cx INIT
$ cx LEX
$ cx MACRO
$ cx MAIN
$ cx UTIL
$ clink cexpr,init,lex,macro,main,util,lib:klib/lib cp68

View File

@@ -0,0 +1,19 @@
$ set noon
$ vsend CEXPR.C
$ vsend ICODE.H
$ vsend INIT.C
$ vsend LEX.C
$ vsend LINK.SUB
$ vsend LIST.COM
$ vsend MACHINE.11
$ vsend MACHINE.68K
$ vsend MACHINE.H
$ vsend MACHINE.VAX
$ vsend MACRO.C
$ vsend MAIN.C
$ vsend MAKE.SUB
$ vsend PREPROC.H
$ vsend SEND11.SUB
$ vsend UTIL.C
$ vsend VMAKE.COM
$ vsend done

View File

@@ -0,0 +1,23 @@
Directory DRB0:[STEVE.CPM68K.V102.CP68]
CEXPR.C;1
ICODE.H;1
INIT.C;15
LEX.C;1
LINK.SUB;1
LIST.COM;2
MACHINE.11;1
MACHINE.68K;2
MACHINE.H;9
MACHINE.VAX;1
MACRO.C;1
MAIN.C;1
MAKE.SUB;2
PREPROC.H;1
SEND11.SUB;1
UTIL.C;1
VMAKE.COM;4
VSEND.COM;1
Total of 18 files.

View File

@@ -0,0 +1,9 @@
$ xer CEXPR.LIS
$ xer INIT.LIS
$ xer LEX.LIS
$ xer MACRO.LIS
$ xer MAIN.LIS
$ xer UTIL.LIS
$ xer ICODE.LST
$ xer MACHINE.LST
$ xer PREPROC.LST

View File

@@ -0,0 +1,14 @@
Directory DRB0:[STEVE.CPM68K.V102.CP68]
CEXPR.LIS;1
INIT.LIS;1
LEX.LIS;1
MACRO.LIS;1
MAIN.LIS;1
UTIL.LIS;1
ICODE.LST;1
MACHINE.LST;1
PREPROC.LST;1
Total of 9 files.