p = code;
if(p[1] == 'i')
p += 2;
regalloc(&nod1, n, nn);
cgen(l, &nod1);
if(v < 0)
gopcode(OSUB, &nod1, nodconst(0), &nod1);
regalloc(&nod2, n, Z);
loop:
switch(*p) {
case 0:
regfree(&nod2);
gopcode(OAS, &nod1, Z, nn);
regfree(&nod1);
return 1;
case '+':
o = OADD;
goto addsub;
case '-':
o = OSUB;
addsub: /* number is r,n,l */
v = p[1] - '0';
r = &nod1;
if(v&4)
r = &nod2;
n = &nod1;
if(v&2)
n = &nod2;
l = &nod1;
if(v&1)
l = &nod2;
gopcode(o, l, n, r);
break;
default: /* op is shiftcount, number is r,l */
v = p[1] - '0';
r = &nod1;
if(v&2)
r = &nod2;
l = &nod1;
if(v&1)
l = &nod2;
v = *p - 'a';
if(v < 0 || v >= 32) {
diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
break;
}
gopcode(OASHL, nodconst(v), l, r);
break;
}
p += 2;
goto loop;
}
void
sextern(Sym *s, Node *a, long o, long w)
{
long e, lw;
char*
zaddr(char *bp, Adr *a, int s)
{
long l;
Ieee e;
bp[0] = a->type;
bp[1] = a->reg;
bp[2] = s;
bp[3] = a->name;
bp += 4;
switch(a->type) {
default:
diag(Z, "unknown type %d in zaddr", a->type);
case D_NONE:
case D_REG:
case D_FREG:
case D_MREG:
case D_FCREG:
case D_LO:
case D_HI:
break;
case D_OREG:
case D_CONST:
case D_BRANCH:
l = a->offset;
bp[0] = l;
bp[1] = l>>8;
bp[2] = l>>16;
bp[3] = l>>24;
bp += 4;
break;
case D_SCONST:
memmove(bp, a->sval, NSNAME);
bp += NSNAME;
break;
case D_FCONST:
ieeedtod(&e, a->dval);
l = e.l;
bp[0] = l;
bp[1] = l>>8;
bp[2] = l>>16;
bp[3] = l>>24;
bp += 4;
l = e.h;
bp[0] = l;
bp[1] = l>>8;
bp[2] = l>>16;
bp[3] = l>>24;
bp += 4;
break;
}
return bp;
}
long
align(long i, Type *t, int op)
{
long o;
Type *v;
int w;
o = i;
w = 1;
switch(op) {
default:
diag(Z, "unknown align opcode %d", op);
break;
case Asu2: /* padding at end of a struct */
w = SZ_LONG;
if(packflg)
w = packflg;
break;
case Ael1: /* initial allign of struct element */
for(v=t; v->etype==TARRAY; v=v->link)
;
w = ewidth[v->etype];
if(w <= 0 || w >= SZ_LONG)
w = SZ_LONG;
if(packflg)
w = packflg;
break;
case Ael2: /* width of a struct element */
o += t->width;
break;
case Aarg0: /* initial passbyptr argument in arg list */
if(typesuv[t->etype]) {
o = align(o, types[TIND], Aarg1);
o = align(o, types[TIND], Aarg2);
}
break;
case Aarg1: /* initial allign of parameter */
w = ewidth[t->etype];
if(w <= 0 || w >= SZ_LONG) {
w = SZ_LONG;
break;
}
if(thechar == 'v')
o += SZ_LONG - w; /* big endian adjustment */
w = 1;
break;
case Aarg2: /* width of a parameter */
o += t->width;
w = SZ_LONG;
break;
case Aaut3: /* total allign of automatic */
o = align(o, t, Ael1);
o = align(o, t, Ael2);
w = SZ_LONG;
break;
}
o = round(o, w);
if(debug['A'])
print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
return o;
}
long
maxround(long max, long v)
{
v += SZ_LONG-1;
if(v > max)
max = round(v, SZ_LONG);
return max;
}