1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 #include "../qc/q.out.h" 5 6 #ifndef EXTERN 7 #define EXTERN extern 8 #endif 9 10 typedef struct Sym Sym; 11 typedef struct Gen Gen; 12 typedef struct Io Io; 13 typedef struct Hist Hist; 14 15 #define MAXALIGN 7 16 #define FPCHIP 1 17 #define NSYMB 8192 18 #define BUFSIZ 8192 19 #define HISTSZ 20 20 #define NINCLUDE 10 21 #define NHUNK 10000 22 #define EOF (-1) 23 #define IGN (-2) 24 #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff) 25 #define NHASH 503 26 #define STRINGSZ 200 27 #define NMACRO 10 28 29 #define ALLOC(lhs, type)\ 30 while(nhunk < sizeof(type))\ 31 gethunk();\ 32 lhs = (type*)hunk;\ 33 nhunk -= sizeof(type);\ 34 hunk += sizeof(type); 35 36 #define ALLOCN(lhs, len, n)\ 37 if(lhs+len != hunk || nhunk < n) {\ 38 while(nhunk <= len)\ 39 gethunk();\ 40 memmove(hunk, lhs, len);\ 41 lhs = hunk;\ 42 hunk += len;\ 43 nhunk -= len;\ 44 }\ 45 hunk += n;\ 46 nhunk -= n; 47 48 struct Sym 49 { 50 Sym* link; 51 char* macro; 52 long value; 53 ushort type; 54 char *name; 55 char sym; 56 }; 57 #define S ((Sym*)0) 58 59 struct 60 { 61 char* p; 62 int c; 63 } fi; 64 65 struct Io 66 { 67 Io* link; 68 char b[BUFSIZ]; 69 char* p; 70 short c; 71 short f; 72 }; 73 #define I ((Io*)0) 74 75 struct 76 { 77 Sym* sym; 78 short type; 79 } h[NSYM]; 80 81 struct Gen 82 { 83 Sym* sym; 84 long offset; 85 short type; 86 short reg; 87 short xreg; 88 short name; 89 ushort mask; 90 double dval; 91 char sval[8]; 92 }; 93 94 struct Hist 95 { 96 Hist* link; 97 char* name; 98 long line; 99 long offset; 100 }; 101 #define H ((Hist*)0) 102 103 enum 104 { 105 CLAST, 106 CMACARG, 107 CMACRO, 108 CPREPROC 109 }; 110 111 EXTERN char debug[256]; 112 EXTERN Sym* hash[NHASH]; 113 EXTERN char* Dlist[30]; 114 EXTERN int nDlist; 115 EXTERN Hist* ehist; 116 EXTERN int newflag; 117 EXTERN Hist* hist; 118 EXTERN char* hunk; 119 EXTERN char* include[NINCLUDE]; 120 EXTERN Io* iofree; 121 EXTERN Io* ionext; 122 EXTERN Io* iostack; 123 EXTERN long lineno; 124 EXTERN int nerrors; 125 EXTERN long nhunk; 126 EXTERN int nosched; 127 EXTERN int ninclude; 128 EXTERN Gen nullgen; 129 EXTERN char* outfile; 130 EXTERN int pass; 131 EXTERN char* pathname; 132 EXTERN long pc; 133 EXTERN int peekc; 134 EXTERN int sym; 135 EXTERN char symb[NSYMB]; 136 EXTERN int thechar; 137 EXTERN char* thestring; 138 EXTERN long thunk; 139 EXTERN Biobuf obuf; 140 141 void errorexit(void); 142 void pushio(void); 143 void newio(void); 144 void newfile(char*, int); 145 Sym* slookup(char*); 146 Sym* lookup(void); 147 void syminit(Sym*); 148 long yylex(void); 149 int getc(void); 150 int getnsc(void); 151 void unget(int); 152 int escchar(int); 153 void cinit(void); 154 void pinit(char*); 155 void cclean(void); 156 void outcode(int, Gen*, int, Gen*); 157 void outgcode(int, Gen*, int, Gen*, Gen*); 158 void zname(char*, int, int); 159 void zaddr(Gen*, int); 160 void ieeedtod(Ieee*, double); 161 int filbuf(void); 162 Sym* getsym(void); 163 void domacro(void); 164 void macund(void); 165 void macdef(void); 166 void macexpand(Sym*, char*); 167 void macinc(void); 168 void macprag(void); 169 void maclin(void); 170 void macif(int); 171 void macend(void); 172 void dodefine(char*); 173 void prfile(long); 174 void outhist(void); 175 void linehist(char*, int); 176 void gethunk(void); 177 void yyerror(char*, ...); 178 int yyparse(void); 179 void setinclude(char*); 180 int assemble(char*); 181 182 /* 183 * system-dependent stuff from ../cc/compat.c 184 */ 185 enum /* keep in synch with ../cc/cc.h */ 186 { 187 Plan9 = 1<<0, 188 Unix = 1<<1, 189 Windows = 1<<2 190 }; 191 int mywait(int*); 192 int mycreat(char*, int); 193 int systemtype(int); 194 int pathchar(void); 195 char* mygetwd(char*, int); 196 int myexec(char*, char*[]); 197 int mydup(int, int); 198 int myfork(void); 199 int mypipe(int*); 200 void* mysbrk(ulong); 201