github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/cmd/8c/gc.h (about) 1 // Inferno utils/8c/gc.h 2 // http://code.google.com/p/inferno-os/source/browse/utils/8c/gc.h 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 6 // Portions Copyright © 1997-1999 Vita Nuova Limited 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright © 2004,2006 Bruce Ellis 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright © 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 #include <u.h> 32 #include "../cc/cc.h" 33 #include "../8l/8.out.h" 34 35 /* 36 * 8c/386 37 * Intel 386 38 */ 39 #define SZ_CHAR 1 40 #define SZ_SHORT 2 41 #define SZ_INT 4 42 #define SZ_LONG 4 43 #define SZ_IND 4 44 #define SZ_FLOAT 4 45 #define SZ_VLONG 8 46 #define SZ_DOUBLE 8 47 #define FNX 100 48 49 typedef struct Adr Adr; 50 typedef struct Prog Prog; 51 typedef struct Case Case; 52 typedef struct C1 C1; 53 typedef struct Var Var; 54 typedef struct Reg Reg; 55 typedef struct Rgn Rgn; 56 typedef struct Renv Renv; 57 58 EXTERN struct 59 { 60 Node* regtree; 61 Node* basetree; 62 short scale; 63 short reg; 64 short ptr; 65 } idx; 66 67 struct Adr 68 { 69 int32 offset; 70 int32 offset2; 71 double dval; 72 char sval[NSNAME]; 73 74 Sym* sym; 75 uchar type; 76 uchar index; 77 uchar etype; 78 uchar scale; /* doubles as width in DATA op */ 79 }; 80 #define A ((Adr*)0) 81 82 #define INDEXED 9 83 struct Prog 84 { 85 Adr from; 86 Adr to; 87 Prog* link; 88 int32 lineno; 89 short as; 90 }; 91 #define P ((Prog*)0) 92 93 struct Case 94 { 95 Case* link; 96 int32 val; 97 int32 label; 98 char def; 99 char isv; 100 }; 101 #define C ((Case*)0) 102 103 struct C1 104 { 105 int32 val; 106 int32 label; 107 }; 108 109 struct Var 110 { 111 int32 offset; 112 Sym* sym; 113 char name; 114 char etype; 115 }; 116 117 struct Reg 118 { 119 int32 pc; 120 int32 rpo; /* reverse post ordering */ 121 122 Bits set; 123 Bits use1; 124 Bits use2; 125 126 Bits refbehind; 127 Bits refahead; 128 Bits calbehind; 129 Bits calahead; 130 Bits regdiff; 131 Bits act; 132 133 int32 regu; 134 int32 loop; /* could be shorter */ 135 136 Reg* log5; 137 int32 active; 138 139 Reg* p1; 140 Reg* p2; 141 Reg* p2link; 142 Reg* s1; 143 Reg* s2; 144 Reg* link; 145 Prog* prog; 146 }; 147 #define R ((Reg*)0) 148 149 struct Renv 150 { 151 int safe; 152 Node base; 153 Node* saved; 154 Node* scope; 155 }; 156 157 #define NRGN 600 158 struct Rgn 159 { 160 Reg* enter; 161 short cost; 162 short varno; 163 short regno; 164 }; 165 166 EXTERN int32 breakpc; 167 EXTERN int32 nbreak; 168 EXTERN Case* cases; 169 EXTERN Node constnode; 170 EXTERN Node fconstnode; 171 EXTERN int32 continpc; 172 EXTERN int32 curarg; 173 EXTERN int32 cursafe; 174 EXTERN Prog* firstp; 175 EXTERN Prog* lastp; 176 EXTERN int32 maxargsafe; 177 EXTERN int mnstring; 178 EXTERN int retok; 179 EXTERN Node* nodrat; 180 EXTERN Node* nodret; 181 EXTERN Node* nodsafe; 182 EXTERN int32 nrathole; 183 EXTERN int32 nstring; 184 EXTERN Prog* p; 185 EXTERN int32 pc; 186 EXTERN Node regnode; 187 EXTERN Node fregnode0; 188 EXTERN Node fregnode1; 189 EXTERN char string[NSNAME]; 190 EXTERN Sym* symrathole; 191 EXTERN Node znode; 192 EXTERN Prog zprog; 193 EXTERN int reg[D_NONE]; 194 EXTERN int32 exregoffset; 195 EXTERN int32 exfregoffset; 196 197 #define BLOAD(r) band(bnot(r->refbehind), r->refahead) 198 #define BSTORE(r) band(bnot(r->calbehind), r->calahead) 199 #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) 200 #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z]) 201 202 #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32)) 203 204 #define CLOAD 5 205 #define CREF 5 206 #define CINF 1000 207 #define LOOP 3 208 209 EXTERN Rgn region[NRGN]; 210 EXTERN Rgn* rgp; 211 EXTERN int nregion; 212 EXTERN int nvar; 213 214 EXTERN Bits externs; 215 EXTERN Bits params; 216 EXTERN Bits consts; 217 EXTERN Bits addrs; 218 219 EXTERN int32 regbits; 220 EXTERN int32 exregbits; 221 222 EXTERN int change; 223 EXTERN int suppress; 224 225 EXTERN Reg* firstr; 226 EXTERN Reg* lastr; 227 EXTERN Reg zreg; 228 EXTERN Reg* freer; 229 EXTERN Var var[NVAR]; 230 EXTERN int32* idom; 231 EXTERN Reg** rpo2r; 232 EXTERN int32 maxnr; 233 234 extern char* anames[]; 235 236 /* 237 * sgen.c 238 */ 239 void codgen(Node*, Node*); 240 void gen(Node*); 241 void noretval(int); 242 void usedset(Node*, int); 243 void xcom(Node*); 244 void indx(Node*); 245 int bcomplex(Node*, Node*); 246 Prog* gtext(Sym*, int32); 247 vlong argsize(void); 248 249 /* 250 * cgen.c 251 */ 252 void zeroregm(Node*); 253 void cgen(Node*, Node*); 254 void reglcgen(Node*, Node*, Node*); 255 void lcgen(Node*, Node*); 256 void bcgen(Node*, int); 257 void boolgen(Node*, int, Node*); 258 void sugen(Node*, Node*, int32); 259 int needreg(Node*, int); 260 261 /* 262 * cgen64.c 263 */ 264 int vaddr(Node*, int); 265 void loadpair(Node*, Node*); 266 int cgen64(Node*, Node*); 267 void testv(Node*, int); 268 269 /* 270 * txt.c 271 */ 272 void ginit(void); 273 void gclean(void); 274 void nextpc(void); 275 void gargs(Node*, Node*, Node*); 276 void garg1(Node*, Node*, Node*, int, Node**); 277 Node* nodconst(int32); 278 Node* nodfconst(double); 279 int nodreg(Node*, Node*, int); 280 int isreg(Node*, int); 281 void regret(Node*, Node*); 282 void regalloc(Node*, Node*, Node*); 283 void regfree(Node*); 284 void regialloc(Node*, Node*, Node*); 285 void regsalloc(Node*, Node*); 286 void regaalloc1(Node*, Node*); 287 void regaalloc(Node*, Node*); 288 void regind(Node*, Node*); 289 void gprep(Node*, Node*); 290 void naddr(Node*, Adr*); 291 void gmove(Node*, Node*); 292 void gins(int a, Node*, Node*); 293 void fgopcode(int, Node*, Node*, int, int); 294 void gopcode(int, Type*, Node*, Node*); 295 int samaddr(Node*, Node*); 296 void gbranch(int); 297 void patch(Prog*, int32); 298 int sconst(Node*); 299 void gpseudo(int, Sym*, Node*); 300 void gprefetch(Node*); 301 void gpcdata(int, int); 302 303 /* 304 * swt.c 305 */ 306 int swcmp(const void*, const void*); 307 void doswit(Node*); 308 void swit1(C1*, int, int32, Node*); 309 void swit2(C1*, int, int32, Node*); 310 void newcase(void); 311 void bitload(Node*, Node*, Node*, Node*, Node*); 312 void bitstore(Node*, Node*, Node*, Node*, Node*); 313 int32 outstring(char*, int32); 314 void nullwarn(Node*, Node*); 315 void sextern(Sym*, Node*, int32, int32); 316 void gextern(Sym*, Node*, int32, int32); 317 void outcode(void); 318 void ieeedtod(Ieee*, double); 319 320 /* 321 * list 322 */ 323 void listinit(void); 324 int Pconv(Fmt*); 325 int Aconv(Fmt*); 326 int Dconv(Fmt*); 327 int Sconv(Fmt*); 328 int Rconv(Fmt*); 329 int Xconv(Fmt*); 330 int Bconv(Fmt*); 331 332 /* 333 * reg.c 334 */ 335 Reg* rega(void); 336 int rcmp(const void*, const void*); 337 void regopt(Prog*); 338 void addmove(Reg*, int, int, int); 339 Bits mkvar(Reg*, Adr*); 340 void prop(Reg*, Bits, Bits); 341 void loopit(Reg*, int32); 342 void synch(Reg*, Bits); 343 uint32 allreg(uint32, Rgn*); 344 void paint1(Reg*, int); 345 uint32 paint2(Reg*, int); 346 void paint3(Reg*, int, int32, int); 347 void addreg(Adr*, int); 348 349 /* 350 * peep.c 351 */ 352 void peep(void); 353 void excise(Reg*); 354 Reg* uniqp(Reg*); 355 Reg* uniqs(Reg*); 356 int regtyp(Adr*); 357 int anyvar(Adr*); 358 int subprop(Reg*); 359 int copyprop(Reg*); 360 int copy1(Adr*, Adr*, Reg*, int); 361 int copyu(Prog*, Adr*, Adr*); 362 363 int copyas(Adr*, Adr*); 364 int copyau(Adr*, Adr*); 365 int copysub(Adr*, Adr*, Adr*, int); 366 int copysub1(Prog*, Adr*, Adr*, int); 367 368 int32 RtoB(int); 369 int32 FtoB(int); 370 int BtoR(int32); 371 int BtoF(int32); 372 373 #define D_HI D_NONE 374 #define D_LO D_NONE 375 376 /* 377 * bound 378 */ 379 void comtarg(void); 380 381 /* 382 * com64 383 */ 384 int cond(int); 385 int com64(Node*); 386 void com64init(void); 387 void bool64(Node*); 388 int32 lo64v(Node*); 389 int32 hi64v(Node*); 390 Node* lo64(Node*); 391 Node* hi64(Node*); 392 393 /* 394 * div/mul 395 */ 396 void sdivgen(Node*, Node*, Node*, Node*); 397 void udivgen(Node*, Node*, Node*, Node*); 398 void sdiv2(int32, int, Node*, Node*); 399 void smod2(int32, int, Node*, Node*); 400 void mulgen(Type*, Node*, Node*); 401 void genmuladd(Node*, Node*, int, Node*); 402 void shiftit(Type*, Node*, Node*); 403 404 #pragma varargck type "A" int 405 #pragma varargck type "B" Bits 406 #pragma varargck type "D" Adr* 407 #pragma varargck type "lD" Adr* 408 #pragma varargck type "P" Prog* 409 #pragma varargck type "R" int 410 #pragma varargck type "S" char* 411 412 /* wrecklessly steal a field */ 413 414 #define rplink label