summaryrefslogtreecommitdiff
path: root/src/cmd/5c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/cmd/5c
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-upstream/2011.01.12.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/cmd/5c')
-rw-r--r--src/cmd/5c/Makefile21
-rw-r--r--src/cmd/5c/list.c16
-rw-r--r--src/cmd/5c/mul.c4
-rw-r--r--src/cmd/5c/peep.c2
-rw-r--r--src/cmd/5c/reg.c10
-rw-r--r--src/cmd/5c/swt.c42
-rw-r--r--src/cmd/5c/txt.c61
7 files changed, 92 insertions, 64 deletions
diff --git a/src/cmd/5c/Makefile b/src/cmd/5c/Makefile
index b534206f3..70b614e8a 100644
--- a/src/cmd/5c/Makefile
+++ b/src/cmd/5c/Makefile
@@ -2,10 +2,10 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-include ../../Make.conf
+include ../../Make.inc
+O:=$(HOST_O)
-TARG=\
- 5c\
+TARG=5c
HFILES=\
gc.h\
@@ -26,18 +26,9 @@ OFILES=\
../5l/enam.$O\
LIB=\
- ../cc/cc.a$O
+ ../cc/cc.a\
-$(TARG): $(OFILES) $(LIB)
- $(LD) -o $(TARG) -L"$(GOROOT)"/lib $(OFILES) $(LIB) -lbio -l9
-
-$(OFILES): $(HFILES)
-
-clean:
- rm -f *.$O $(TARG) *.5 enam.c 5.out a.out
-
-install: $(TARG)
- cp $(TARG) "$(GOBIN)"/$(TARG)
+include ../../Make.ccmd
%.$O: ../cc/%.c
- $(CC) $(CFLAGS) -c -I. -o $@ ../cc/$*.c
+ $(HOST_CC) $(HOST_CFLAGS) -c -I. -o $@ ../cc/$*.c
diff --git a/src/cmd/5c/list.c b/src/cmd/5c/list.c
index c792c130d..ab0fae83c 100644
--- a/src/cmd/5c/list.c
+++ b/src/cmd/5c/list.c
@@ -59,7 +59,7 @@ Bconv(Fmt *fp)
if(str[0])
strcat(str, " ");
if(var[i].sym == S) {
- sprint(ss, "$%ld", var[i].offset);
+ sprint(ss, "$%d", var[i].offset);
s = ss;
} else
s = var[i].sym->name;
@@ -204,7 +204,7 @@ Dconv(Fmt *fp)
break;
case D_BRANCH:
- sprint(str, "%ld(PC)", a->offset-pc);
+ sprint(str, "%d(PC)", a->offset-pc);
break;
case D_FCONST:
@@ -307,7 +307,7 @@ Nconv(Fmt *fp)
a = va_arg(fp->args, Adr*);
s = a->sym;
if(s == S) {
- sprint(str, "%ld", a->offset);
+ sprint(str, "%d", a->offset);
goto out;
}
switch(a->name) {
@@ -316,23 +316,23 @@ Nconv(Fmt *fp)
break;
case D_NONE:
- sprint(str, "%ld", a->offset);
+ sprint(str, "%d", a->offset);
break;
case D_EXTERN:
- sprint(str, "%s+%ld(SB)", s->name, a->offset);
+ sprint(str, "%s+%d(SB)", s->name, a->offset);
break;
case D_STATIC:
- sprint(str, "%s<>+%ld(SB)", s->name, a->offset);
+ sprint(str, "%s<>+%d(SB)", s->name, a->offset);
break;
case D_AUTO:
- sprint(str, "%s-%ld(SP)", s->name, -a->offset);
+ sprint(str, "%s-%d(SP)", s->name, -a->offset);
break;
case D_PARAM:
- sprint(str, "%s+%ld(FP)", s->name, a->offset);
+ sprint(str, "%s+%d(FP)", s->name, a->offset);
break;
}
out:
diff --git a/src/cmd/5c/mul.c b/src/cmd/5c/mul.c
index 121f67d5b..ff50c4845 100644
--- a/src/cmd/5c/mul.c
+++ b/src/cmd/5c/mul.c
@@ -115,7 +115,7 @@ mulcon0(int32 v)
if(docode(hintab[g].hint, m->code, 1, 0))
return m;
- print("multiply table failure %ld\n", v);
+ print("multiply table failure %d\n", v);
m->code[0] = 0;
return 0;
@@ -132,7 +132,7 @@ no:
if(gen1(g)) {
if(docode(hint, m->code, 1, 0))
return m;
- print("multiply table failure %ld\n", v);
+ print("multiply table failure %d\n", v);
break;
}
}
diff --git a/src/cmd/5c/peep.c b/src/cmd/5c/peep.c
index 4959d414d..8945ee732 100644
--- a/src/cmd/5c/peep.c
+++ b/src/cmd/5c/peep.c
@@ -1324,8 +1324,6 @@ predicable(Prog *p)
|| p->as == ASIGNAME
|| p->as == ATEXT
|| p->as == AWORD
- || p->as == ADYNT
- || p->as == AINIT
|| p->as == ABCASE
|| p->as == ACASE)
return 0;
diff --git a/src/cmd/5c/reg.c b/src/cmd/5c/reg.c
index f2d38d519..8c9794418 100644
--- a/src/cmd/5c/reg.c
+++ b/src/cmd/5c/reg.c
@@ -309,7 +309,7 @@ loop2:
if(debug['R'] && debug['v']) {
print("\nprop structure:\n");
for(r = firstr; r != R; r = r->link) {
- print("%ld:%P", r->loop, r->prog);
+ print("%d:%P", r->loop, r->prog);
for(z=0; z<BITS; z++)
bit.b[z] = r->set.b[z] |
r->refahead.b[z] | r->calahead.b[z] |
@@ -955,7 +955,7 @@ paint1(Reg *r, int bn)
if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb) {
change -= CLOAD * r->loop;
if(debug['R'] && debug['v'])
- print("%ld%P\tld %B $%d\n", r->loop,
+ print("%d%P\td %B $%d\n", r->loop,
r->prog, blsh(bn), change);
}
for(;;) {
@@ -965,21 +965,21 @@ paint1(Reg *r, int bn)
if(r->use1.b[z] & bb) {
change += CREF * r->loop;
if(debug['R'] && debug['v'])
- print("%ld%P\tu1 %B $%d\n", r->loop,
+ print("%d%P\tu1 %B $%d\n", r->loop,
p, blsh(bn), change);
}
if((r->use2.b[z]|r->set.b[z]) & bb) {
change += CREF * r->loop;
if(debug['R'] && debug['v'])
- print("%ld%P\tu2 %B $%d\n", r->loop,
+ print("%d%P\tu2 %B $%d\n", r->loop,
p, blsh(bn), change);
}
if(STORE(r) & r->regdiff.b[z] & bb) {
change -= CLOAD * r->loop;
if(debug['R'] && debug['v'])
- print("%ld%P\tst %B $%d\n", r->loop,
+ print("%d%P\tst %B $%d\n", r->loop,
p, blsh(bn), change);
}
diff --git a/src/cmd/5c/swt.c b/src/cmd/5c/swt.c
index cefbf53d9..43eb73c94 100644
--- a/src/cmd/5c/swt.c
+++ b/src/cmd/5c/swt.c
@@ -47,7 +47,7 @@ swit1(C1 *q, int nc, int32 def, Node *n)
if(nc < 5) {
for(i=0; i<nc; i++) {
if(debug['W'])
- print("case = %.8lux\n", q->val);
+ print("case = %.8ux\n", q->val);
gopcode(OEQ, nodconst(q->val), n, Z);
patch(p, q->label);
q++;
@@ -60,7 +60,7 @@ swit1(C1 *q, int nc, int32 def, Node *n)
i = nc / 2;
r = q+i;
if(debug['W'])
- print("case > %.8lux\n", r->val);
+ print("case > %.8ux\n", r->val);
gopcode(OGT, nodconst(r->val), n, Z);
sp = p;
gopcode(OEQ, nodconst(r->val), n, Z); /* just gen the B.EQ */
@@ -68,7 +68,7 @@ swit1(C1 *q, int nc, int32 def, Node *n)
swit1(q, i, def, n);
if(debug['W'])
- print("case < %.8lux\n", r->val);
+ print("case < %.8ux\n", r->val);
patch(sp, pc);
swit1(r+1, nc-i-1, def, n);
return;
@@ -81,7 +81,7 @@ direct:
patch(p, def);
for(i=0; i<nc; i++) {
if(debug['W'])
- print("case = %.8lux\n", q->val);
+ print("case = %.8ux\n", q->val);
while(q->val != v) {
nextpc();
p->as = ABCASE;
@@ -227,7 +227,7 @@ mulcon(Node *n, Node *nn)
return 0;
}
if(debug['M'] && debug['v'])
- print("%L multiply: %ld\n", n->lineno, v);
+ print("%L multiply: %d\n", n->lineno, v);
memmove(code, m->code, sizeof(m->code));
code[sizeof(m->code)] = 0;
@@ -606,7 +606,7 @@ zaddr(char *bp, Adr *a, int s)
}
int32
-align(int32 i, Type *t, int op)
+align(int32 i, Type *t, int op, int32 *maxalign)
{
int32 o;
Type *v;
@@ -620,7 +620,9 @@ align(int32 i, Type *t, int op)
break;
case Asu2: /* padding at end of a struct */
- w = SZ_LONG;
+ w = *maxalign;
+ if(w < 1)
+ w = 1;
if(packflg)
w = packflg;
break;
@@ -628,10 +630,16 @@ align(int32 i, Type *t, int op)
case Ael1: /* initial align 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)
+ if(v->etype == TSTRUCT || v->etype == TUNION)
+ w = v->align;
+ else {
+ w = ewidth[v->etype];
+ if(w == 8)
+ w = 4;
+ }
+ if(w < 1 || w > SZ_LONG)
+ fatal(Z, "align");
+ if(packflg)
w = packflg;
break;
@@ -641,8 +649,8 @@ align(int32 i, Type *t, int op)
case Aarg0: /* initial passbyptr argument in arg list */
if(typesuv[t->etype]) {
- o = align(o, types[TIND], Aarg1);
- o = align(o, types[TIND], Aarg2);
+ o = align(o, types[TIND], Aarg1, nil);
+ o = align(o, types[TIND], Aarg2, nil);
}
break;
@@ -661,14 +669,16 @@ align(int32 i, Type *t, int op)
break;
case Aaut3: /* total align of automatic */
- o = align(o, t, Ael2);
- o = align(o, t, Ael1);
+ o = align(o, t, Ael2, nil);
+ o = align(o, t, Ael1, nil);
w = SZ_LONG; /* because of a pun in cc/dcl.c:contig() */
break;
}
o = xround(o, w);
+ if(maxalign != nil && *maxalign < w)
+ *maxalign = w;
if(debug['A'])
- print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
+ print("align %s %d %T = %d\n", bnames[op], i, t, o);
return o;
}
diff --git a/src/cmd/5c/txt.c b/src/cmd/5c/txt.c
index 9dac0312f..0f17cea89 100644
--- a/src/cmd/5c/txt.c
+++ b/src/cmd/5c/txt.c
@@ -388,7 +388,7 @@ err:
void
regsalloc(Node *n, Node *nn)
{
- cursafe = align(cursafe, nn->type, Aaut3);
+ cursafe = align(cursafe, nn->type, Aaut3, nil);
maxargsafe = maxround(maxargsafe, cursafe+curarg);
*n = *nodsafe;
n->xoffset = -(stkoff + cursafe);
@@ -402,22 +402,22 @@ regaalloc1(Node *n, Node *nn)
{
nodreg(n, nn, REGARG);
reg[REGARG]++;
- curarg = align(curarg, nn->type, Aarg1);
- curarg = align(curarg, nn->type, Aarg2);
+ curarg = align(curarg, nn->type, Aarg1, nil);
+ curarg = align(curarg, nn->type, Aarg2, nil);
maxargsafe = maxround(maxargsafe, cursafe+curarg);
}
void
regaalloc(Node *n, Node *nn)
{
- curarg = align(curarg, nn->type, Aarg1);
+ curarg = align(curarg, nn->type, Aarg1, nil);
*n = *nn;
n->op = OINDREG;
n->reg = REGSP;
n->xoffset = curarg + SZ_LONG;
n->complex = 0;
n->addable = 20;
- curarg = align(curarg, nn->type, Aarg2);
+ curarg = align(curarg, nn->type, Aarg2, nil);
maxargsafe = maxround(maxargsafe, cursafe+curarg);
}
@@ -580,7 +580,8 @@ void
gmove(Node *f, Node *t)
{
int ft, tt, a;
- Node nod;
+ Node nod, nod1;
+ Prog *p1;
ft = f->type->etype;
tt = t->type->etype;
@@ -709,21 +710,53 @@ gmove(Node *f, Node *t)
}
break;
case TUINT:
- case TINT:
case TULONG:
+ if(tt == TFLOAT || tt == TDOUBLE) {
+ // ugly and probably longer than necessary,
+ // but vfp has a single instruction for this,
+ // so hopefully it won't last long.
+ //
+ // tmp = f
+ // tmp1 = tmp & 0x80000000
+ // tmp ^= tmp1
+ // t = float(int32(tmp))
+ // if(tmp1)
+ // t += 2147483648.
+ //
+ regalloc(&nod, f, Z);
+ regalloc(&nod1, f, Z);
+ gins(AMOVW, f, &nod);
+ gins(AMOVW, &nod, &nod1);
+ gins(AAND, nodconst(0x80000000), &nod1);
+ gins(AEOR, &nod1, &nod);
+ if(tt == TFLOAT)
+ gins(AMOVWF, &nod, t);
+ else
+ gins(AMOVWD, &nod, t);
+ gins(ACMP, nodconst(0), Z);
+ raddr(&nod1, p);
+ gins(ABEQ, Z, Z);
+ regfree(&nod);
+ regfree(&nod1);
+ p1 = p;
+ regalloc(&nod, t, Z);
+ gins(AMOVF, nodfconst(2147483648.), &nod);
+ gins(AADDF, &nod, t);
+ regfree(&nod);
+ patch(p1, pc);
+ return;
+ }
+ // fall through
+
+ case TINT:
case TLONG:
case TIND:
switch(tt) {
case TDOUBLE:
- case TVLONG:
gins(AMOVWD, f, t);
- if(ft == TULONG) {
- }
return;
case TFLOAT:
gins(AMOVWF, f, t);
- if(ft == TULONG) {
- }
return;
case TINT:
case TUINT:
@@ -741,7 +774,6 @@ gmove(Node *f, Node *t)
case TSHORT:
switch(tt) {
case TDOUBLE:
- case TVLONG:
regalloc(&nod, f, Z);
gins(AMOVH, f, &nod);
gins(AMOVWD, &nod, t);
@@ -771,7 +803,6 @@ gmove(Node *f, Node *t)
case TUSHORT:
switch(tt) {
case TDOUBLE:
- case TVLONG:
regalloc(&nod, f, Z);
gins(AMOVHU, f, &nod);
gins(AMOVWD, &nod, t);
@@ -801,7 +832,6 @@ gmove(Node *f, Node *t)
case TCHAR:
switch(tt) {
case TDOUBLE:
- case TVLONG:
regalloc(&nod, f, Z);
gins(AMOVB, f, &nod);
gins(AMOVWD, &nod, t);
@@ -831,7 +861,6 @@ gmove(Node *f, Node *t)
case TUCHAR:
switch(tt) {
case TDOUBLE:
- case TVLONG:
regalloc(&nod, f, Z);
gins(AMOVBU, f, &nod);
gins(AMOVWD, &nod, t);