cc2.h (6688B)
1 #define ASLABEL 0 2 3 #ifdef NDEBUG 4 #define PRCFG(msg) 5 #define PRTREE(msg) 6 #else 7 #define PRCFG(msg) (enadebug ? prcfg(msg) : NULL) 8 #define PRTREE(msg) (enadebug ? prforest(msg) : NULL) 9 #endif 10 11 enum iflags { 12 BBENTRY = 1, /* basic block entry */ 13 BBEXIT = 2, /* basic block exit */ 14 }; 15 16 enum tflags { 17 SIGNF = 1 << 0, /* Signed type */ 18 INTF = 1 << 1, /* integer type */ 19 FLOATF = 1 << 2, /* float type */ 20 STRF = 1 << 3, /* string */ 21 AGGRF = 1 << 4, /* aggregate */ 22 FUNF = 1 << 5, /* function */ 23 PARF = 1 << 6, /* parameter */ 24 INITF = 1 << 7, /* initializer flag */ 25 ELLIPS = 1 << 8, /* vararg function */ 26 ARRF = 1 << 9, /* array flag */ 27 PTRF = 1 << 10, /* pointer flag */ 28 }; 29 30 enum sclass { 31 SAUTO = 'A', 32 SREG = 'R', 33 SLABEL = 'L', 34 SINDEX = 'I', 35 STMP = 'N', 36 SGLOB = 'G', 37 SEXTRN = 'X', 38 SPRIV = 'Y', 39 SLOCAL = 'T', 40 SMEMB = 'M', 41 SCONST = '#', 42 STRING = '"', 43 SNONE = 0 /* cc2 relies on SNONE being 0 in nextpc() */ 44 }; 45 46 enum types { 47 ELLIPSIS = 'E', 48 INT8 = 'C', 49 INT16 = 'I', 50 INT32 = 'W', 51 INT64 = 'Q', 52 UINT8 = 'K', 53 UINT16 = 'N', 54 UINT32 = 'Z', 55 UINT64 = 'O', 56 POINTER = 'P', 57 FUNCTION = 'F', 58 VECTOR = 'V', 59 UNION = 'U', 60 STRUCT = 'S', 61 BOOL = 'B', 62 FLOAT = 'J', 63 DOUBLE = 'D', 64 LDOUBLE = 'H', 65 VOID = '0' 66 }; 67 68 enum op { 69 /* kind of operand */ 70 /* operands */ 71 OMEM = 'M', 72 OINDEX = 'I', 73 OTMP = 'N', 74 OAUTO = 'A', 75 OREG = 'R', 76 OMREG = 'G', 77 OCONST = '#', 78 OSTRING = '"', 79 OLOAD = 'D', 80 OLABEL = 'L', 81 OADD = '+', 82 OSUB = '-', 83 OMUL = '*', 84 OMOD = '%', 85 ODIV = '/', 86 OSHL = 'l', 87 OSHR = 'r', 88 OLT = '<', 89 OGT = '>', 90 OLE = '[', 91 OGE = ']', 92 OEQ = '=', 93 ONE = '!', 94 OBAND = '&', 95 OBOR = '|', 96 OBXOR = '^', 97 OCPL = '~', 98 OASSIG = ':', 99 OSNEG = '_', 100 OCALL = 'c', 101 OCALLE = 'z', 102 OPAR = 'p', 103 OFIELD = '.', 104 OCOMMA = ',', 105 OASK = '?', 106 OCOLON = ' ', 107 OADDR = '\'', 108 OAND = 'a', 109 OOR = 'o', 110 ONEG = 'n', 111 OPTR = '@', 112 OCAST = 'g', 113 OINC = 'i', 114 ODEC = 'd', 115 OBUILTIN = 'm', 116 /*statements */ 117 ONOP = 'q', 118 OJMP = 'j', 119 OBRANCH = 'y', 120 ORET = 'h', 121 OBLOOP = 'b', 122 OELOOP = 'e', 123 OCASE = 'v', 124 ODEFAULT = 'f', 125 OBSWITCH = 's', 126 OESWITCH = 't', 127 OBFUN = 'x', 128 OEFUN = 'k', 129 }; 130 131 enum builtins { 132 BVA_START = 's', 133 BVA_END = 'e', 134 BVA_ARG = 'a', 135 BVA_COPY = 'c', 136 }; 137 138 enum nerrors { 139 EEOFFUN, /* EOF while parsing function */ 140 ENLABEL, /* label without statement */ 141 EIDOVER, /* identifier overflow */ 142 EOUTPAR, /* out pf params */ 143 ESYNTAX, /* syntax error */ 144 ESTACKA, /* stack unaligned */ 145 ESTACKO, /* stack overflow */ 146 ESTACKU, /* stack underflow */ 147 ELNLINE, /* line too long */ 148 ELNBLNE, /* line without new line */ 149 EFERROR, /* error reading from file:%s */ 150 EBADID, /* incorrect symbol id */ 151 EWTACKO, /* switch stack overflow */ 152 EWTACKU, /* switch stack underflow */ 153 ENOSWTC, /* Out of switch statement */ 154 EBBUILT, /* Unknown builtin */ 155 EOVERFL, /* Numerical overflow */ 156 EBAFFUN, /* Function body not finished */ 157 ENUMERR 158 }; 159 160 typedef struct node Node; 161 typedef struct type Type; 162 typedef struct symbol Symbol; 163 typedef struct addr Addr; 164 typedef struct inst Inst; 165 typedef struct block Block; 166 typedef struct swtch Swtch; 167 typedef struct mach Mach; 168 169 struct mach { 170 int swtchif; 171 }; 172 173 struct swtch { 174 int nr; 175 TINT min, max; 176 Node *bswtch; 177 Node *eswtch; 178 Node **cases; 179 Node *defnode; 180 181 Swtch *next; 182 }; 183 184 struct type { 185 unsigned long size; 186 unsigned align; 187 unsigned short id; 188 unsigned short flags; 189 }; 190 191 struct symbol { 192 Type type; 193 Type rtype; 194 unsigned short id; 195 unsigned short numid; 196 int refcnt; 197 char *name; 198 char kind; 199 union { 200 long off; 201 Node *stmt; 202 Inst *inst; 203 } u; 204 Symbol *next, *prev; 205 Symbol *h_next; 206 }; 207 208 struct node { 209 char op; 210 Type type; 211 int complex; 212 int address; 213 unsigned flags; 214 union { 215 TUINT i; 216 TFLOAT f; 217 char *s; 218 Symbol *sym; 219 Swtch *swtch; 220 int reg; 221 int subop; 222 long off; 223 } u; 224 Symbol *label; 225 Block *bb; 226 Node *left, *right; 227 Node *next, *prev; 228 }; 229 230 struct block { 231 int id; 232 int printed, visited; 233 Node *entryp, *exitp; 234 Block *true, *false; 235 Swtch *swtch; 236 Block *next; 237 }; 238 239 struct addr { 240 char kind; 241 union { 242 int reg; 243 TUINT i; 244 Symbol *sym; 245 long off; 246 } u; 247 }; 248 249 struct inst { 250 unsigned char op; 251 unsigned char flags; 252 Symbol *label; 253 Inst *next, *prev; 254 Addr from1, from2, to; 255 }; 256 257 /* main.c */ 258 extern void error(unsigned nerror, ...); 259 260 /* parse.c */ 261 extern void parse(void); 262 263 /* cgen.c */ 264 extern void genaddr(void); 265 extern void genasm(void); 266 extern Node *tsethi(Node *); 267 268 /* peep.c */ 269 extern void peephole(void); 270 271 /* code.c */ 272 extern void data(Node *np); 273 extern void writeout(void), endinit(void); 274 extern void code(int op, Node *to, Node *from1, Node *from2); 275 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *); 276 extern void setlabel(Symbol *); 277 extern Node *label2node(Node *np, Symbol *sym); 278 extern Node *constnode(Node *np, TUINT n, Type *tp); 279 extern Node *tmpnode(Type *, Symbol *); 280 extern Node *idxnode(Node *, long); 281 extern void delcode(void); 282 extern Symbol *newlabel(void); 283 extern void pprint(char *s); 284 extern void deftype(Type *); 285 extern Node *labelstmt(Node *, Symbol *); 286 287 /* node.c */ 288 extern void newfun(Symbol *, Node *); 289 extern void apply(Node *(*fun)(Node *)); 290 extern void cleannodes(void); 291 extern void delnode(Node *np); 292 extern void deltree(Node *np); 293 extern void prtree(Node *np), prforest(char *msg); 294 extern Node *node(int op); 295 extern Node *addstmt(Node *); 296 extern Node *delstmt(Node *); 297 extern Node *insstmt(Node *, Node *); 298 extern Node *prestmt(Node *); 299 extern void delrange(Node *, Node *); 300 extern Node *unlinkstmt(Node *); 301 302 /* symbol.c */ 303 #define TMPSYM 0 304 extern Symbol *getsym(unsigned id); 305 extern void popctx(void); 306 extern void pushctx(void); 307 extern void freesym(Symbol *sym); 308 309 /* cfg.c */ 310 extern void gencfg(void); 311 extern void cleancfg(void); 312 extern Node *sethi(Node *); 313 314 /* swtch.c */ 315 extern void cleanswtch(void); 316 extern Swtch *newswtch(Swtch *); 317 extern Node *swtch(Node *); 318 extern Node *swtchdefault(Swtch *); 319 320 /* globals */ 321 extern Symbol *curfun; 322 extern Symbol *locals; 323 extern Inst *pc, *prog; 324 extern Node *laststmt; 325 extern Mach mach; 326 327 /* target */ 328 extern Type int8type, int16type, int32type, int64type, 329 uint8type, uint16type, uint32type, uint64type, 330 float32type, float64type, float80type, 331 booltype, 332 ptrtype, 333 voidtype, 334 arg_type;