github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/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 Case Case; 50 typedef struct C1 C1; 51 typedef struct Reg Reg; 52 typedef struct Rgn Rgn; 53 typedef struct Renv Renv; 54 55 EXTERN struct 56 { 57 Node* regtree; 58 Node* basetree; 59 short scale; 60 short reg; 61 short ptr; 62 } idx; 63 64 #define A ((Addr*)0) 65 66 #define INDEXED 9 67 68 #define P ((Prog*)0) 69 70 struct Case 71 { 72 Case* link; 73 int32 val; 74 int32 label; 75 char def; 76 char isv; 77 }; 78 #define C ((Case*)0) 79 80 struct C1 81 { 82 int32 val; 83 int32 label; 84 }; 85 86 struct Reg 87 { 88 int32 pc; 89 int32 rpo; /* reverse post ordering */ 90 91 Bits set; 92 Bits use1; 93 Bits use2; 94 95 Bits refbehind; 96 Bits refahead; 97 Bits calbehind; 98 Bits calahead; 99 Bits regdiff; 100 Bits act; 101 102 int32 regu; 103 int32 loop; /* could be shorter */ 104 105 Reg* log5; 106 int32 active; 107 108 Reg* p1; 109 Reg* p2; 110 Reg* p2link; 111 Reg* s1; 112 Reg* s2; 113 Reg* link; 114 Prog* prog; 115 }; 116 #define R ((Reg*)0) 117 118 struct Renv 119 { 120 int safe; 121 Node base; 122 Node* saved; 123 Node* scope; 124 }; 125 126 #define NRGN 600 127 struct Rgn 128 { 129 Reg* enter; 130 short cost; 131 short varno; 132 short regno; 133 }; 134 135 EXTERN int32 breakpc; 136 EXTERN int32 nbreak; 137 EXTERN Case* cases; 138 EXTERN Node constnode; 139 EXTERN Node fconstnode; 140 EXTERN int32 continpc; 141 EXTERN int32 curarg; 142 EXTERN int32 cursafe; 143 EXTERN Prog* lastp; 144 EXTERN int32 maxargsafe; 145 EXTERN int mnstring; 146 EXTERN int retok; 147 EXTERN Node* nodrat; 148 EXTERN Node* nodret; 149 EXTERN Node* nodsafe; 150 EXTERN int32 nrathole; 151 EXTERN int32 nstring; 152 EXTERN Prog* p; 153 EXTERN int32 pc; 154 EXTERN Node regnode; 155 EXTERN Node fregnode0; 156 EXTERN Node fregnode1; 157 EXTERN char string[NSNAME]; 158 EXTERN Sym* symrathole; 159 EXTERN Node znode; 160 EXTERN Prog zprog; 161 EXTERN int reg[D_NONE]; 162 EXTERN int32 exregoffset; 163 EXTERN int32 exfregoffset; 164 165 #define BLOAD(r) band(bnot(r->refbehind), r->refahead) 166 #define BSTORE(r) band(bnot(r->calbehind), r->calahead) 167 #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) 168 #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z]) 169 170 #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32)) 171 172 #define CLOAD 5 173 #define CREF 5 174 #define CINF 1000 175 #define LOOP 3 176 177 EXTERN Rgn region[NRGN]; 178 EXTERN Rgn* rgp; 179 EXTERN int nregion; 180 EXTERN int nvar; 181 182 EXTERN Bits externs; 183 EXTERN Bits params; 184 EXTERN Bits consts; 185 EXTERN Bits addrs; 186 187 EXTERN int32 regbits; 188 EXTERN int32 exregbits; 189 190 EXTERN int change; 191 EXTERN int suppress; 192 193 EXTERN Reg* firstr; 194 EXTERN Reg* lastr; 195 EXTERN Reg zreg; 196 EXTERN Reg* freer; 197 EXTERN int32* idom; 198 EXTERN Reg** rpo2r; 199 EXTERN int32 maxnr; 200 201 extern char* anames[]; 202 203 /* 204 * sgen.c 205 */ 206 void codgen(Node*, Node*); 207 void gen(Node*); 208 void noretval(int); 209 void usedset(Node*, int); 210 void xcom(Node*); 211 void indx(Node*); 212 int bcomplex(Node*, Node*); 213 Prog* gtext(Sym*, int32); 214 vlong argsize(void); 215 216 /* 217 * cgen.c 218 */ 219 void zeroregm(Node*); 220 void cgen(Node*, Node*); 221 void reglcgen(Node*, Node*, Node*); 222 void lcgen(Node*, Node*); 223 void bcgen(Node*, int); 224 void boolgen(Node*, int, Node*); 225 void sugen(Node*, Node*, int32); 226 int needreg(Node*, int); 227 228 /* 229 * cgen64.c 230 */ 231 int vaddr(Node*, int); 232 void loadpair(Node*, Node*); 233 int cgen64(Node*, Node*); 234 void testv(Node*, int); 235 236 /* 237 * txt.c 238 */ 239 void ginit(void); 240 void gclean(void); 241 void nextpc(void); 242 void gargs(Node*, Node*, Node*); 243 void garg1(Node*, Node*, Node*, int, Node**); 244 Node* nodconst(int32); 245 Node* nodfconst(double); 246 int nodreg(Node*, Node*, int); 247 int isreg(Node*, int); 248 void regret(Node*, Node*); 249 void regalloc(Node*, Node*, Node*); 250 void regfree(Node*); 251 void regialloc(Node*, Node*, Node*); 252 void regsalloc(Node*, Node*); 253 void regaalloc1(Node*, Node*); 254 void regaalloc(Node*, Node*); 255 void regind(Node*, Node*); 256 void gprep(Node*, Node*); 257 void naddr(Node*, Addr*); 258 void gmove(Node*, Node*); 259 void gins(int a, Node*, Node*); 260 void fgopcode(int, Node*, Node*, int, int); 261 void gopcode(int, Type*, Node*, Node*); 262 int samaddr(Node*, Node*); 263 void gbranch(int); 264 void patch(Prog*, int32); 265 int sconst(Node*); 266 void gpseudo(int, Sym*, Node*); 267 void gprefetch(Node*); 268 void gpcdata(int, int); 269 270 /* 271 * swt.c 272 */ 273 int swcmp(const void*, const void*); 274 void doswit(Node*); 275 void swit1(C1*, int, int32, Node*); 276 void swit2(C1*, int, int32, Node*); 277 void newcase(void); 278 void bitload(Node*, Node*, Node*, Node*, Node*); 279 void bitstore(Node*, Node*, Node*, Node*, Node*); 280 int32 outstring(char*, int32); 281 void nullwarn(Node*, Node*); 282 void sextern(Sym*, Node*, int32, int32); 283 void gextern(Sym*, Node*, int32, int32); 284 void outcode(void); 285 286 /* 287 * list 288 */ 289 void listinit(void); 290 291 /* 292 * reg.c 293 */ 294 Reg* rega(void); 295 int rcmp(const void*, const void*); 296 void regopt(Prog*); 297 void addmove(Reg*, int, int, int); 298 Bits mkvar(Reg*, Addr*); 299 void prop(Reg*, Bits, Bits); 300 void loopit(Reg*, int32); 301 void synch(Reg*, Bits); 302 uint32 allreg(uint32, Rgn*); 303 void paint1(Reg*, int); 304 uint32 paint2(Reg*, int); 305 void paint3(Reg*, int, int32, int); 306 void addreg(Addr*, int); 307 308 /* 309 * peep.c 310 */ 311 void peep(void); 312 void excise(Reg*); 313 Reg* uniqp(Reg*); 314 Reg* uniqs(Reg*); 315 int regtyp(Addr*); 316 int anyvar(Addr*); 317 int subprop(Reg*); 318 int copyprop(Reg*); 319 int copy1(Addr*, Addr*, Reg*, int); 320 int copyu(Prog*, Addr*, Addr*); 321 322 int copyas(Addr*, Addr*); 323 int copyau(Addr*, Addr*); 324 int copysub(Addr*, Addr*, Addr*, int); 325 int copysub1(Prog*, Addr*, Addr*, int); 326 327 int32 RtoB(int); 328 int32 FtoB(int); 329 int BtoR(int32); 330 int BtoF(int32); 331 332 #define D_HI D_NONE 333 #define D_LO D_NONE 334 335 /* 336 * bound 337 */ 338 void comtarg(void); 339 340 /* 341 * com64 342 */ 343 int cond(int); 344 int com64(Node*); 345 void com64init(void); 346 void bool64(Node*); 347 int32 lo64v(Node*); 348 int32 hi64v(Node*); 349 Node* lo64(Node*); 350 Node* hi64(Node*); 351 352 /* 353 * div/mul 354 */ 355 void sdivgen(Node*, Node*, Node*, Node*); 356 void udivgen(Node*, Node*, Node*, Node*); 357 void sdiv2(int32, int, Node*, Node*); 358 void smod2(int32, int, Node*, Node*); 359 void mulgen(Type*, Node*, Node*); 360 void genmuladd(Node*, Node*, int, Node*); 361 void shiftit(Type*, Node*, Node*); 362 363 /* wrecklessly steal a field */ 364 365 #define rplink label