4 swit1(C1 *q, int nc, long def, Node *n)
13 print("case = %.8llux\n", q->val);
25 print("case > %.8llux\n", r->val);
34 print("case < %.8llux\n", r->val);
36 swit1(r+1, nc-i-1, def, n);
40 bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
47 * n1 gets adjusted/masked value
48 * n2 gets address of cell
49 * n3 gets contents of cell
62 if(b->type->shift == 0 && typeu[b->type->etype]) {
63 v = ~0 + (1L << b->type->nbits);
64 gopcode(OAND, tfield, nodconst(v), n1);
66 sh = 32 - b->type->shift - b->type->nbits;
68 gopcode(OASHL, tfield, nodconst(sh), n1);
71 if(typeu[b->type->etype])
72 gopcode(OLSHR, tfield, nodconst(sh), n1);
74 gopcode(OASHR, tfield, nodconst(sh), n1);
79 bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
85 regalloc(&nod, b->left, Z);
86 v = ~0 + (1L << b->type->nbits);
87 gopcode(OAND, types[TLONG], nodconst(v), n1);
93 gopcode(OASHL, types[TLONG], nodconst(sh), &nod);
95 gopcode(OAND, types[TLONG], nodconst(~v), n3);
96 gopcode(OOR, types[TLONG], n3, &nod);
106 outstring(char *s, long n)
114 string[mnstring] = *s++;
117 if(mnstring >= NSNAME) {
118 gpseudo(ADATA, symstring, nodconst(0L));
119 p->from.offset += nstring - NSNAME;
120 p->from.scale = NSNAME;
121 p->to.type = D_SCONST;
122 memmove(p->to.sval, string, NSNAME);
131 sextern(Sym *s, Node *a, long o, long w)
135 for(e=0; e<w; e+=NSNAME) {
139 gpseudo(ADATA, s, nodconst(0L));
140 p->from.offset += o+e;
142 p->to.type = D_SCONST;
143 memmove(p->to.sval, a->cstring+e, lw);
148 gextern(Sym *s, Node *a, long o, long w)
150 if(0 && a->op == OCONST && typev[a->type->etype]) {
151 gpseudo(ADATA, s, lo64(a));
154 gpseudo(ADATA, s, hi64(a));
155 p->from.offset += o + 4;
159 gpseudo(ADATA, s, a);
164 p->to.index = p->to.type;
173 void zname(Biobuf*, Sym*, int);
174 void zaddr(Biobuf*, Adr*, int);
175 void outhist(Biobuf*);
180 struct { Sym *sym; short type; } h[NSYM];
183 int f, sf, st, t, sym;
187 for(p = firstp; p != P; p = p->link)
188 if(p->as != ADATA && p->as != AGLOBL)
190 for(p = firstp; p != P; p = p->link) {
192 if(p->as != ADATA && p->as != AGLOBL)
196 f = open(outfile, OWRITE);
198 diag(Z, "cannot open %s", outfile);
201 Binit(&b, f, OWRITE);
204 for(sym=0; sym<NSYM; sym++) {
209 for(p = firstp; p != P; p = p->link) {
215 if(sf < 0 || sf >= NSYM)
237 if(st < 0 || st >= NSYM)
259 Bputc(&b, p->lineno);
260 Bputc(&b, p->lineno>>8);
261 Bputc(&b, p->lineno>>16);
262 Bputc(&b, p->lineno>>24);
263 zaddr(&b, &p->from, sf);
264 zaddr(&b, &p->to, st);
283 for(h = hist; h != H; h = h->link) {
286 /* on windows skip drive specifier in pathname */
287 if(systemtype(Windows) && p && p[1] == ':'){
291 if(p && p[0] != c && h->offset == 0 && pathname){
292 /* on windows skip drive specifier in pathname */
293 if(systemtype(Windows) && pathname[1] == ':') {
297 } else if(pathname[0] == c){
307 n = 1; /* leading "/" */
308 *p = '/'; /* don't emit "\" on windows */
331 pg.to.type = zprog.to.type;
332 pg.to.offset = h->offset;
334 pg.to.type = D_CONST;
339 Bputc(b, pg.lineno>>8);
340 Bputc(b, pg.lineno>>16);
341 Bputc(b, pg.lineno>>24);
342 zaddr(b, &pg.from, 0);
348 zname(Biobuf *b, Sym *s, int t)
353 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
356 Bputc(b, ASIGNAME>>8);
364 Bputc(b, ANAME); /* as */
365 Bputc(b, ANAME>>8); /* as */
367 Bputc(b, t); /* type */
368 Bputc(b, s->sym); /* sym */
378 zaddr(Biobuf *b, Adr *a, int s)
386 if(a->index != D_NONE || a->scale != 0)
398 if((vlong)l != a->offset)
411 if(t & T_INDEX) { /* implies index, scale */
415 if(t & T_OFFSET) { /* implies offset */
429 if(t & T_SYM) /* implies sym */
432 ieeedtod(&e, a->dval);
447 for(i=0; i<NSNAME; i++) {
458 align(long i, Type *t, int op)
468 diag(Z, "unknown align opcode %d", op);
471 case Asu2: /* padding at end of a struct */
477 case Ael1: /* initial align of struct element */
478 for(v=t; v->etype==TARRAY; v=v->link)
480 w = ewidth[v->etype];
481 if(w <= 0 || w >= SZ_VLONG)
487 case Ael2: /* width of a struct element */
491 case Aarg0: /* initial passbyptr argument in arg list */
492 if(typesu[t->etype]) {
493 o = align(o, types[TIND], Aarg1);
494 o = align(o, types[TIND], Aarg2);
498 case Aarg1: /* initial align of parameter */
499 w = ewidth[t->etype];
500 if(w <= 0 || w >= SZ_VLONG) {
504 w = 1; /* little endian no adjustment */
507 case Aarg2: /* width of a parameter */
512 case Aaut3: /* total allign of automatic */
513 o = align(o, t, Ael1);
514 o = align(o, t, Ael2);
519 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
524 maxround(long max, long v)
528 max = round(v, SZ_VLONG);