1 #include "../cc/cc.h" 2 #include "../kc/k.out.h" 3 4 /* 5 * kc/sparc 6 * Sun sparc 7 */ 8 #define SZ_CHAR 1 9 #define SZ_SHORT 2 10 #define SZ_INT 4 11 #define SZ_LONG 4 12 #define SZ_VLONG 8 13 #define SZ_IND 4 14 #define SZ_FLOAT 4 15 #define SZ_DOUBLE 8 16 #define FNX 100 17 18 typedef struct Adr Adr; 19 typedef struct Prog Prog; 20 typedef struct Case Case; 21 typedef struct C1 C1; 22 typedef struct Multab Multab; 23 typedef struct Hintab Hintab; 24 typedef struct Var Var; 25 typedef struct Reg Reg; 26 typedef struct Rgn Rgn; 27 28 struct Adr 29 { 30 long offset; 31 double dval; 32 char sval[NSNAME]; 33 34 Sym* sym; 35 char type; 36 char reg; 37 char name; 38 char etype; 39 }; 40 #define A ((Adr*)0) 41 42 #define INDEXED 9 43 struct Prog 44 { 45 Adr from; 46 Adr to; 47 Prog* link; 48 long lineno; 49 short as; 50 char reg; 51 }; 52 #define P ((Prog*)0) 53 54 struct Case 55 { 56 Case* link; 57 vlong val; 58 long label; 59 char def; 60 char isv; 61 }; 62 #define C ((Case*)0) 63 64 struct C1 65 { 66 vlong val; 67 long label; 68 }; 69 70 struct Multab 71 { 72 long val; 73 char code[20]; 74 }; 75 76 struct Hintab 77 { 78 ushort val; 79 char hint[10]; 80 }; 81 82 struct Var 83 { 84 long offset; 85 Sym* sym; 86 char name; 87 char etype; 88 }; 89 90 struct Reg 91 { 92 long pc; 93 long rpo; /* reverse post ordering */ 94 95 Bits set; 96 Bits use1; 97 Bits use2; 98 99 Bits refbehind; 100 Bits refahead; 101 Bits calbehind; 102 Bits calahead; 103 Bits regdiff; 104 Bits act; 105 106 long regu; 107 long loop; /* could be shorter */ 108 109 Reg* log5; 110 long active; 111 112 Reg* p1; 113 Reg* p2; 114 Reg* p2link; 115 Reg* s1; 116 Reg* s2; 117 Reg* link; 118 Prog* prog; 119 }; 120 #define R ((Reg*)0) 121 122 #define NRGN 600 123 struct Rgn 124 { 125 Reg* enter; 126 short cost; 127 short varno; 128 short regno; 129 }; 130 131 EXTERN long breakpc; 132 EXTERN long nbreak; 133 EXTERN Case* cases; 134 EXTERN Node constnode; 135 EXTERN Node fconstnode; 136 EXTERN long continpc; 137 EXTERN long curarg; 138 EXTERN long cursafe; 139 EXTERN Prog* firstp; 140 EXTERN Prog* lastp; 141 EXTERN int hintabsize; 142 EXTERN long maxargsafe; 143 EXTERN Multab multab[20]; 144 EXTERN int mnstring; 145 EXTERN Node* nodrat; 146 EXTERN Node* nodret; 147 EXTERN Node* nodsafe; 148 EXTERN long nrathole; 149 EXTERN long nstring; 150 EXTERN Prog* p; 151 EXTERN long pc; 152 EXTERN Node regnode; 153 EXTERN char string[NSNAME]; 154 EXTERN Sym* symrathole; 155 EXTERN Node znode; 156 EXTERN Prog zprog; 157 EXTERN char reg[NREG+NREG]; 158 EXTERN long exregoffset; 159 EXTERN long exfregoffset; 160 161 #define BLOAD(r) band(bnot(r->refbehind), r->refahead) 162 #define BSTORE(r) band(bnot(r->calbehind), r->calahead) 163 #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) 164 #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z]) 165 166 #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32)) 167 168 #define CLOAD 5 169 #define CREF 5 170 #define CINF 1000 171 #define LOOP 3 172 173 EXTERN Rgn region[NRGN]; 174 EXTERN Rgn* rgp; 175 EXTERN int nregion; 176 EXTERN int nvar; 177 178 EXTERN Bits externs; 179 EXTERN Bits params; 180 EXTERN Bits consts; 181 EXTERN Bits addrs; 182 183 EXTERN long regbits; 184 EXTERN long exregbits; 185 186 EXTERN int change; 187 EXTERN int suppress; 188 189 EXTERN Reg* firstr; 190 EXTERN Reg* lastr; 191 EXTERN Reg zreg; 192 EXTERN Reg* freer; 193 EXTERN Var var[NVAR]; 194 EXTERN long* idom; 195 EXTERN Reg** rpo2r; 196 EXTERN long maxnr; 197 198 extern char* anames[]; 199 extern Hintab hintab[]; 200 201 /* 202 * sgen.c 203 */ 204 void codgen(Node*, Node*); 205 void gen(Node*); 206 void usedset(Node*, int); 207 void noretval(int); 208 void xcom(Node*); 209 int bcomplex(Node*, Node*); 210 211 /* 212 * cgen.c 213 */ 214 void cgen(Node*, Node*); 215 void reglcgen(Node*, Node*, Node*); 216 void lcgen(Node*, Node*); 217 void bcgen(Node*, int); 218 void boolgen(Node*, int, Node*); 219 void sugen(Node*, Node*, long); 220 void layout(Node*, Node*, int, int, Node*); 221 222 /* 223 * txt.c 224 */ 225 void ginit(void); 226 void gclean(void); 227 void nextpc(void); 228 void gargs(Node*, Node*, Node*); 229 void garg1(Node*, Node*, Node*, int, Node**); 230 Node* nodconst(long); 231 Node* nod32const(vlong); 232 Node* nodfconst(double); 233 void nodreg(Node*, Node*, int); 234 void regret(Node*, Node*); 235 void regalloc(Node*, Node*, Node*); 236 void regfree(Node*); 237 void regialloc(Node*, Node*, Node*); 238 void regsalloc(Node*, Node*); 239 void regaalloc1(Node*, Node*); 240 void regaalloc(Node*, Node*); 241 void regind(Node*, Node*); 242 void gprep(Node*, Node*); 243 void raddr(Node*, Prog*); 244 void naddr(Node*, Adr*); 245 void gmove(Node*, Node*); 246 void gins(int a, Node*, Node*); 247 void gopcode(int, Node*, Node*, Node*); 248 int samaddr(Node*, Node*); 249 void gbranch(int); 250 void patch(Prog*, long); 251 int sconst(Node*); 252 int sval(long); 253 void gpseudo(int, Sym*, Node*); 254 255 /* 256 * swt.c 257 */ 258 int swcmp(const void*, const void*); 259 void doswit(Node*); 260 void swit1(C1*, int, long, Node*); 261 void swit2(C1*, int, long, Node*, Node*); 262 void casf(void); 263 void bitload(Node*, Node*, Node*, Node*, Node*); 264 void bitstore(Node*, Node*, Node*, Node*, Node*); 265 long outstring(char*, long); 266 int mulcon(Node*, Node*); 267 Multab* mulcon0(Node*, long); 268 int mulcon1(Node*, long, Node*); 269 void nullwarn(Node*, Node*); 270 void gextern(Sym*, Node*, long, long); 271 void outcode(void); 272 void ieeedtod(Ieee*, double); 273 274 /* 275 * list 276 */ 277 void listinit(void); 278 int Pconv(Fmt*); 279 int Aconv(Fmt*); 280 int Dconv(Fmt*); 281 int Sconv(Fmt*); 282 int Nconv(Fmt*); 283 int Bconv(Fmt*); 284 285 /* 286 * reg.c 287 */ 288 Reg* rega(void); 289 int rcmp(const void*, const void*); 290 void regopt(Prog*); 291 void addmove(Reg*, int, int, int); 292 Bits mkvar(Adr*, int); 293 void prop(Reg*, Bits, Bits); 294 void loopit(Reg*, long); 295 void synch(Reg*, Bits); 296 ulong allreg(ulong, Rgn*); 297 void paint1(Reg*, int); 298 ulong paint2(Reg*, int); 299 void paint3(Reg*, int, long, int); 300 void addreg(Adr*, int); 301 302 /* 303 * peep.c 304 */ 305 void peep(void); 306 void excise(Reg*); 307 Reg* uniqp(Reg*); 308 Reg* uniqs(Reg*); 309 int regtyp(Adr*); 310 int regzer(Adr*); 311 int anyvar(Adr*); 312 int subprop(Reg*); 313 int copyprop(Reg*); 314 int copy1(Adr*, Adr*, Reg*, int); 315 int copyu(Prog*, Adr*, Adr*); 316 317 int copyas(Adr*, Adr*); 318 int copyau(Adr*, Adr*); 319 int copyau1(Prog*, Adr*); 320 int copysub(Adr*, Adr*, Adr*, int); 321 int copysub1(Prog*, Adr*, Adr*, int); 322 323 long RtoB(int); 324 long FtoB(int); 325 int BtoR(long); 326 int BtoF(long); 327 328 /* 329 * com64.c 330 */ 331 int com64(Node*); 332 void com64init(void); 333 void bool64(Node*); 334 335 #pragma varargck type "A" int 336 #pragma varargck type "B" Bits 337 #pragma varargck type "D" Adr* 338 #pragma varargck type "N" Adr* 339 #pragma varargck type "P" Prog* 340 #pragma varargck type "S" char* 341