cc2.h (5102B)
1 enum iflags { 2 BBENTRY = 1, /* basic block entry */ 3 }; 4 5 enum tflags { 6 SIGNF = 1 << 0, /* Signed type */ 7 INTF = 1 << 1, /* integer type */ 8 FLOATF = 1 << 2, /* float type */ 9 STRF = 1 << 3, /* string */ 10 AGGRF = 1 << 4, /* aggregate */ 11 FUNF = 1 << 5, /* function */ 12 PARF = 1 << 6, /* parameter */ 13 INITF = 1 << 7, /* initializer flag */ 14 ELLIPS = 1 << 8, /* vararg function */ 15 }; 16 17 enum sclass { 18 SAUTO = 'A', 19 SREG = 'R', 20 SLABEL = 'L', 21 SINDEX = 'I', 22 STMP = 'N', 23 SGLOB = 'G', 24 SEXTRN = 'X', 25 SPRIV = 'Y', 26 SLOCAL = 'T', 27 SMEMB = 'M', 28 SCONST = '#', 29 STRING = '"', 30 SNONE = 0 /* cc2 relies on SNONE being 0 in nextpc() */ 31 }; 32 33 enum types { 34 ELLIPSIS = 'E', 35 INT8 = 'C', 36 INT16 = 'I', 37 INT32 = 'W', 38 INT64 = 'Q', 39 UINT8 = 'K', 40 UINT16 = 'N', 41 UINT32 = 'Z', 42 UINT64 = 'O', 43 POINTER = 'P', 44 FUNCTION = 'F', 45 VECTOR = 'V', 46 UNION = 'U', 47 STRUCT = 'S', 48 BOOL = 'B', 49 FLOAT = 'J', 50 DOUBLE = 'D', 51 LDOUBLE = 'H', 52 VOID = '0' 53 }; 54 55 enum op { 56 /* kind of operand */ 57 /* operands */ 58 OMEM = 'M', 59 OTMP = 'N', 60 OAUTO = 'A', 61 OREG = 'R', 62 OCONST = '#', 63 OSTRING = '"', 64 OLOAD = 'D', 65 OLABEL = 'L', 66 OADD = '+', 67 OSUB = '-', 68 OMUL = '*', 69 OMOD = '%', 70 ODIV = '/', 71 OSHL = 'l', 72 OSHR = 'r', 73 OLT = '<', 74 OGT = '>', 75 OLE = '[', 76 OGE = ']', 77 OEQ = '=', 78 ONE = '!', 79 OBAND = '&', 80 OBOR = '|', 81 OBXOR = '^', 82 OCPL = '~', 83 OASSIG = ':', 84 OSNEG = '_', 85 OCALL = 'c', 86 OCALLE = 'z', 87 OPAR = 'p', 88 OFIELD = '.', 89 OCOMMA = ',', 90 OASK = '?', 91 OCOLON = ' ', 92 OADDR = '\'', 93 OAND = 'a', 94 OOR = 'o', 95 ONEG = 'n', 96 OPTR = '@', 97 OCAST = 'g', 98 OINC = 'i', 99 ODEC = 'd', 100 OBUILTIN = 'm', 101 /*statements */ 102 ONOP = 'q', 103 OJMP = 'j', 104 OBRANCH = 'y', 105 ORET = 'h', 106 OBLOOP = 'b', 107 OELOOP = 'e', 108 OCASE = 'v', 109 ODEFAULT = 'f', 110 OBSWITCH = 's', 111 OESWITCH = 't', 112 OBFUN = 'x', 113 OEFUN = 'k', 114 }; 115 116 enum builtins { 117 BVA_START = 's', 118 BVA_END = 'e', 119 BVA_ARG = 'a', 120 BVA_COPY = 'c', 121 }; 122 123 enum nerrors { 124 EEOFFUN, /* EOF while parsing function */ 125 ENLABEL, /* label without statement */ 126 EIDOVER, /* identifier overflow */ 127 EOUTPAR, /* out pf params */ 128 ESYNTAX, /* syntax error */ 129 ESTACKA, /* stack unaligned */ 130 ESTACKO, /* stack overflow */ 131 ESTACKU, /* stack underflow */ 132 ELNLINE, /* line too long */ 133 ELNBLNE, /* line without new line */ 134 EFERROR, /* error reading from file:%s */ 135 EBADID, /* incorrect symbol id */ 136 EWTACKO, /* switch stack overflow */ 137 EWTACKU, /* switch stack underflow */ 138 ENOSWTC, /* Out of switch statement */ 139 EBBUILT, /* Unknown builtin */ 140 ENUMERR 141 }; 142 143 typedef struct node Node; 144 typedef struct type Type; 145 typedef struct symbol Symbol; 146 typedef struct addr Addr; 147 typedef struct inst Inst; 148 149 struct type { 150 unsigned long size; 151 unsigned long align; 152 short flags; 153 }; 154 155 struct symbol { 156 Type type; 157 Type rtype; 158 unsigned short id; 159 unsigned short numid; 160 char *name; 161 char kind; 162 union { 163 unsigned long off; 164 Node *stmt; 165 Inst *inst; 166 } u; 167 Symbol *next; 168 Symbol *h_next; 169 }; 170 171 struct node { 172 char op; 173 Type type; 174 char complex; 175 char address; 176 unsigned char flags; 177 union { 178 TUINT i; 179 TFLOAT f; 180 char reg; 181 char *s; 182 Symbol *sym; 183 char subop; 184 } u; 185 Symbol *label; 186 Node *left, *right; 187 Node *next, *prev; 188 }; 189 190 struct addr { 191 char kind; 192 union { 193 char reg; 194 TUINT i; 195 Symbol *sym; 196 } u; 197 }; 198 199 struct inst { 200 unsigned char op; 201 unsigned char flags; 202 Symbol *label; 203 Inst *next, *prev; 204 Addr from1, from2, to; 205 }; 206 207 /* main.c */ 208 extern void error(unsigned nerror, ...); 209 210 /* parse.c */ 211 extern void parse(void); 212 213 /* optm.c */ 214 extern Node *optm_dep(Node *np), *optm_ind(Node *np); 215 216 /* cgen.c */ 217 extern Node *sethi(Node *np); 218 extern Node *cgen(Node *np); 219 220 /* peep.c */ 221 extern void peephole(void); 222 223 /* code.c */ 224 extern void data(Node *np); 225 extern void writeout(void), endinit(void), newfun(void); 226 extern void code(int op, Node *to, Node *from1, Node *from2); 227 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *); 228 extern void setlabel(Symbol *sym), getbblocks(void); 229 extern Node *label2node(Node *np, Symbol *sym); 230 extern Node *constnode(Node *np, TUINT n, Type *tp); 231 extern Symbol *newlabel(void); 232 233 /* node.c */ 234 #define SETCUR 1 235 #define KEEPCUR 0 236 extern void apply(Node *(*fun)(Node *)); 237 extern void cleannodes(void); 238 extern void delnode(Node *np); 239 extern void deltree(Node *np); 240 extern void prtree(Node *np), prforest(char *msg); 241 extern Node *node(int op); 242 extern Node *addstmt(Node *np, int flags); 243 extern Node *delstmt(void); 244 extern Node *nextstmt(void); 245 246 /* symbol.c */ 247 #define TMPSYM 0 248 extern Symbol *getsym(unsigned id); 249 extern void popctx(void); 250 extern void pushctx(void); 251 extern void freesym(Symbol *sym); 252 253 /* globals */ 254 extern Symbol *curfun; 255 extern Symbol *locals; 256 extern Inst *pc, *prog;