|
|
1.1 ! root 1: /* ! 2: * C compiler-- first pass header ! 3: */ ! 4: ! 5: #include <stdio.h> ! 6: ! 7: /* ! 8: * parameters ! 9: */ ! 10: ! 11: #define LTYPE long /* change to int if no long consts */ ! 12: #define MAXINT 077777 /* Largest positive short integer */ ! 13: #define MAXUINT 0177777 /* largest unsigned integer */ ! 14: #define NCPS 8 /* # chars per symbol */ ! 15: #define HSHSIZ 300 /* # entries in hash table for names */ ! 16: #define CMSIZ 40 /* size of expression stack */ ! 17: #define SSIZE 40 /* size of other expression stack */ ! 18: #define SWSIZ 300 /* size of switch table */ ! 19: #define NMEMS 128 /* Number of members in a structure */ ! 20: #define NBPW 16 /* bits per word, object machine */ ! 21: #define NBPC 8 /* bits per character, object machine */ ! 22: #define NCPW 2 /* chars per word, object machine */ ! 23: #define LNCPW 2 /* chars per word, compiler's machine */ ! 24: #define LNBPW 16 /* bits per word, compiler's machine */ ! 25: #define STAUTO (-6) /* offset of first auto variable */ ! 26: #define STARG 4 /* offset of first argument */ ! 27: #define DCLSLOP 512 /* Amount trees lie above declaration stuff */ ! 28: ! 29: ! 30: /* ! 31: * # bytes in primitive types ! 32: */ ! 33: #define SZCHAR 1 ! 34: #define SZINT 2 ! 35: #define SZPTR 2 ! 36: #define SZFLOAT 4 ! 37: #define SZLONG 4 ! 38: #define SZDOUB 8 ! 39: ! 40: /* ! 41: * Structure of namelist ! 42: */ ! 43: struct nmlist { ! 44: char hclass; /* storage class */ ! 45: char hflag; /* various flags */ ! 46: int htype; /* type */ ! 47: int *hsubsp; /* subscript list */ ! 48: union str *hstrp; /* structure description */ ! 49: int hoffset; /* post-allocation location */ ! 50: struct nmlist *nextnm; /* next name in chain */ ! 51: union str *sparent; /* Structure of which this is member */ ! 52: char hblklev; /* Block level of definition */ ! 53: char name[NCPS]; /* ASCII name */ ! 54: }; ! 55: ! 56: /* ! 57: * format of a structure description ! 58: * Same gadget is also used for fields, ! 59: * which can't be structures also. ! 60: * Finally, it is used for parameter collection. ! 61: */ ! 62: union str { ! 63: struct SS { ! 64: int ssize; /* structure size */ ! 65: struct nmlist **memlist; /* member list */ ! 66: } S; ! 67: struct FS { ! 68: int flen; /* field width in bits */ ! 69: int bitoffs; /* shift count */ ! 70: } F; ! 71: struct nmlist P; ! 72: }; ! 73: ! 74: /* ! 75: * Structure of tree nodes for operators ! 76: */ ! 77: struct tnode { ! 78: int op; /* operator */ ! 79: int type; /* data type */ ! 80: int *subsp; /* subscript list (for arrays) */ ! 81: union str *strp; /* structure description for structs */ ! 82: union tree *tr1; /* left operand */ ! 83: union tree *tr2; /* right operand */ ! 84: }; ! 85: ! 86: /* ! 87: * Tree node for constants ! 88: */ ! 89: struct cnode { ! 90: int op; ! 91: int type; ! 92: int *subsp; ! 93: union str *strp; ! 94: int value; ! 95: }; ! 96: ! 97: /* ! 98: * Tree node for long constants ! 99: */ ! 100: struct lnode { ! 101: int op; ! 102: int type; ! 103: int *subsp; ! 104: union str *strp; ! 105: long lvalue; ! 106: }; ! 107: ! 108: /* ! 109: * tree node for floating ! 110: * constants ! 111: */ ! 112: struct fnode { ! 113: int op; ! 114: int type; ! 115: int *subsp; ! 116: union str *strp; ! 117: char *cstr; ! 118: }; ! 119: ! 120: /* ! 121: * All possibilities for tree nodes ! 122: */ ! 123: union tree { ! 124: struct tnode t; ! 125: struct cnode c; ! 126: struct lnode l; ! 127: struct fnode f; ! 128: struct nmlist n; ! 129: struct FS fld; ! 130: }; ! 131: ! 132: ! 133: /* ! 134: * Place used to keep dimensions ! 135: * during declarations ! 136: */ ! 137: struct tdim { ! 138: int rank; ! 139: int dimens[5]; ! 140: }; ! 141: ! 142: /* ! 143: * Table for recording switches. ! 144: */ ! 145: struct swtab { ! 146: int swlab; ! 147: int swval; ! 148: }; ! 149: ! 150: #define TNULL (union tree *)NULL ! 151: ! 152: char cvtab[4][4]; ! 153: char filename[64]; ! 154: int opdope[]; ! 155: char ctab[]; ! 156: char symbuf[NCPS+2]; ! 157: struct nmlist *hshtab[HSHSIZ]; ! 158: int kwhash[(HSHSIZ+LNBPW-1)/LNBPW]; ! 159: union tree **cp; ! 160: int isn; ! 161: struct swtab swtab[SWSIZ]; ! 162: int unscflg; ! 163: struct swtab *swp; ! 164: int contlab; ! 165: int brklab; ! 166: int retlab; ! 167: int deflab; ! 168: unsigned autolen; /* make these int if necessary */ ! 169: unsigned maxauto; /* ... will only cause trouble rarely */ ! 170: int peeksym; ! 171: int peekc; ! 172: int eof; ! 173: int line; ! 174: char *locbase; ! 175: char *treebase; ! 176: char *treebot; ! 177: char *coremax; ! 178: struct nmlist *defsym; ! 179: struct nmlist *funcsym; ! 180: int proflg; ! 181: struct nmlist *csym; ! 182: int cval; ! 183: LTYPE lcval; ! 184: int nchstr; ! 185: int nerror; ! 186: struct nmlist *paraml; ! 187: struct nmlist *parame; ! 188: int strflg; ! 189: int mosflg; ! 190: int initflg; ! 191: char sbuf[BUFSIZ]; ! 192: FILE *sbufp; ! 193: int regvar; ! 194: int bitoffs; ! 195: struct tnode funcblk; ! 196: char cvntab[]; ! 197: char numbuf[64]; ! 198: struct nmlist **memlist; ! 199: union str *sparent; ! 200: int nmems; ! 201: struct nmlist structhole; ! 202: int blklev; ! 203: int mossym; ! 204: ! 205: /* ! 206: operators ! 207: */ ! 208: #define EOFC 0 ! 209: #define SEMI 1 ! 210: #define LBRACE 2 ! 211: #define RBRACE 3 ! 212: #define LBRACK 4 ! 213: #define RBRACK 5 ! 214: #define LPARN 6 ! 215: #define RPARN 7 ! 216: #define COLON 8 ! 217: #define COMMA 9 ! 218: #define FSEL 10 ! 219: #define CAST 11 ! 220: #define ETYPE 12 ! 221: ! 222: #define KEYW 19 ! 223: #define NAME 20 ! 224: #define CON 21 ! 225: #define STRING 22 ! 226: #define FCON 23 ! 227: #define SFCON 24 ! 228: #define LCON 25 ! 229: #define SLCON 26 ! 230: #define NULLOP 29 ! 231: #define XNULLOP 218 /* interface version */ ! 232: ! 233: #define SIZEOF 91 ! 234: #define INCBEF 30 ! 235: #define DECBEF 31 ! 236: #define INCAFT 32 ! 237: #define DECAFT 33 ! 238: #define EXCLA 34 ! 239: #define AMPER 35 ! 240: #define STAR 36 ! 241: #define NEG 37 ! 242: #define COMPL 38 ! 243: ! 244: #define DOT 39 ! 245: #define PLUS 40 ! 246: #define MINUS 41 ! 247: #define TIMES 42 ! 248: #define DIVIDE 43 ! 249: #define MOD 44 ! 250: #define RSHIFT 45 ! 251: #define LSHIFT 46 ! 252: #define AND 47 ! 253: #define OR 48 ! 254: #define EXOR 49 ! 255: #define ARROW 50 ! 256: #define ITOF 51 ! 257: #define FTOI 52 ! 258: #define LOGAND 53 ! 259: #define LOGOR 54 ! 260: #define FTOL 56 ! 261: #define LTOF 57 ! 262: #define ITOL 58 ! 263: #define LTOI 59 ! 264: #define ITOP 13 ! 265: #define PTOI 14 ! 266: #define LTOP 15 ! 267: ! 268: #define EQUAL 60 ! 269: #define NEQUAL 61 ! 270: #define LESSEQ 62 ! 271: #define LESS 63 ! 272: #define GREATEQ 64 ! 273: #define GREAT 65 ! 274: #define LESSEQP 66 ! 275: #define LESSP 67 ! 276: #define GREATQP 68 ! 277: #define GREATP 69 ! 278: ! 279: #define ASPLUS 70 ! 280: #define ASMINUS 71 ! 281: #define ASTIMES 72 ! 282: #define ASDIV 73 ! 283: #define ASMOD 74 ! 284: #define ASRSH 75 ! 285: #define ASLSH 76 ! 286: #define ASSAND 77 ! 287: #define ASOR 78 ! 288: #define ASXOR 79 ! 289: #define ASSIGN 80 ! 290: ! 291: #define QUEST 90 ! 292: #define MAX 93 ! 293: #define MAXP 94 ! 294: #define MIN 95 ! 295: #define MINP 96 ! 296: #define SEQNC 97 ! 297: #define CALL 100 ! 298: #define MCALL 101 ! 299: #define JUMP 102 ! 300: #define CBRANCH 103 ! 301: #define INIT 104 ! 302: #define SETREG 105 ! 303: #define RFORCE 110 ! 304: #define BRANCH 111 ! 305: #define LABEL 112 ! 306: #define NLABEL 113 ! 307: #define RLABEL 114 ! 308: #define STRASG 115 ! 309: #define ITOC 109 ! 310: #define SEOF 200 /* stack EOF marker in expr compilation */ ! 311: ! 312: /* ! 313: types ! 314: */ ! 315: #define INT 0 ! 316: #define CHAR 1 ! 317: #define FLOAT 2 ! 318: #define DOUBLE 3 ! 319: #define STRUCT 4 ! 320: #define LONG 6 ! 321: #define UNSIGN 7 ! 322: #define UNCHAR 8 ! 323: #define UNLONG 9 ! 324: #define VOID 10 ! 325: #define UNION 8 /* adjusted later to struct */ ! 326: ! 327: #define ALIGN 01 ! 328: #define TYPE 017 ! 329: #define BIGTYPE 060000 ! 330: #define TYLEN 2 ! 331: #define XTYPE (03<<4) ! 332: #define PTR 020 ! 333: #define FUNC 040 ! 334: #define ARRAY 060 ! 335: ! 336: /* ! 337: storage classes ! 338: */ ! 339: #define KEYWC 1 ! 340: #define TYPEDEF 9 ! 341: #define MOS 10 ! 342: #define AUTO 11 ! 343: #define EXTERN 12 ! 344: #define STATIC 13 ! 345: #define REG 14 ! 346: #define STRTAG 15 ! 347: #define ARG 16 ! 348: #define ARG1 17 ! 349: #define AREG 18 ! 350: #define DEFXTRN 20 ! 351: #define MOU 21 ! 352: #define ENUMTAG 22 ! 353: #define ENUMCON 24 ! 354: ! 355: /* ! 356: keywords ! 357: */ ! 358: #define GOTO 20 ! 359: #define RETURN 21 ! 360: #define IF 22 ! 361: #define WHILE 23 ! 362: #define ELSE 24 ! 363: #define SWITCH 25 ! 364: #define CASE 26 ! 365: #define BREAK 27 ! 366: #define CONTIN 28 ! 367: #define DO 29 ! 368: #define DEFAULT 30 ! 369: #define FOR 31 ! 370: #define ENUM 32 ! 371: ! 372: /* ! 373: characters ! 374: */ ! 375: #define BSLASH 117 ! 376: #define SHARP 118 ! 377: #define INSERT 119 ! 378: #define PERIOD 120 ! 379: #define SQUOTE 121 ! 380: #define DQUOTE 122 ! 381: #define LETTER 123 ! 382: #define DIGIT 124 ! 383: #define NEWLN 125 ! 384: #define SPACE 126 ! 385: #define UNKN 127 ! 386: ! 387: /* ! 388: * Special operators in intermediate code ! 389: */ ! 390: #define BDATA 200 ! 391: #define WDATA 201 ! 392: #define PROG 202 ! 393: #define DATA 203 ! 394: #define BSS 204 ! 395: #define CSPACE 205 ! 396: #define SSPACE 206 ! 397: #define SYMDEF 207 ! 398: #define SAVE 208 ! 399: #define RETRN 209 ! 400: #define EVEN 210 ! 401: #define PROFIL 212 ! 402: #define SWIT 213 ! 403: #define EXPR 214 ! 404: #define SNAME 215 ! 405: #define RNAME 216 ! 406: #define ANAME 217 ! 407: #define SETSTK 219 ! 408: #define SINIT 220 ! 409: ! 410: /* ! 411: Flag bits ! 412: */ ! 413: ! 414: #define BINARY 01 ! 415: #define LVALUE 02 ! 416: #define RELAT 04 ! 417: #define ASSGOP 010 ! 418: #define LWORD 020 ! 419: #define RWORD 040 ! 420: #define COMMUTE 0100 ! 421: #define RASSOC 0200 ! 422: #define LEAF 0400 ! 423: #define PCVOK 040000 ! 424: ! 425: /* ! 426: * Conversion codes ! 427: */ ! 428: #define ITF 1 ! 429: #define ITL 2 ! 430: #define LTF 3 ! 431: #define ITP 4 ! 432: #define PTI 5 ! 433: #define FTI 6 ! 434: #define LTI 7 ! 435: #define FTL 8 ! 436: #define LTP 9 ! 437: #define ITC 10 ! 438: #define XX 15 ! 439: ! 440: /* ! 441: * symbol table flags ! 442: */ ! 443: ! 444: #define FMOS 01 ! 445: #define FTAG 02 ! 446: #define FENUM 03 ! 447: #define FUNION 04 ! 448: #define FKIND 07 ! 449: #define FFIELD 020 ! 450: #define FINIT 040 ! 451: #define FLABL 0100 ! 452: ! 453: /* ! 454: * functions ! 455: */ ! 456: char *sbrk(); ! 457: union tree *tree(); ! 458: char *copnum(); ! 459: union tree *convert(); ! 460: union tree *chkfun(); ! 461: union tree *disarray(); ! 462: union tree *block(); ! 463: union tree *cblock(); ! 464: union tree *fblock(); ! 465: char *Dblock(); ! 466: char *Tblock(); ! 467: char *starttree(); ! 468: union tree *pexpr(); ! 469: union str *strdec(); ! 470: union tree *xprtype(); ! 471: struct nmlist *pushdecl(); ! 472: unsigned hash(); ! 473: union tree *structident(); ! 474: struct nmlist *gentemp(); ! 475: union tree *nblock();
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.