Commit 2acbc371 authored by Russ Cox's avatar Russ Cox

various 6g cleanup:

* give genwrapper and genembedtramp the same signature.
* move duint8, duint16, duint32, duint64, duintptr into gc.
* tidy genwrapper.
* bug involving struct field symbols in signature list.
  (hash-order dependent so hard to trigger)
* new Type print format %#-T like %#T but omits
  names on function arguments.

R=ken
OCL=31237
CL=31237
parent 74b546ae
...@@ -510,25 +510,7 @@ duintxx(Sym *s, int off, uint64 v, int wid) ...@@ -510,25 +510,7 @@ duintxx(Sym *s, int off, uint64 v, int wid)
} }
int int
duint32(Sym *s, int off, uint32 v) dsymptr(Sym *s, int off, Sym *x, int xoff)
{
return duintxx(s, off, v, 4);
}
int
duint16(Sym *s, int off, uint32 v)
{
return duintxx(s, off, v, 2);
}
int
duintptr(Sym *s, int off, uint32 v)
{
return duintxx(s, off, v, 8);
}
int
dsymptr(Sym *s, int off, Sym *x)
{ {
Prog *p; Prog *p;
...@@ -543,48 +525,46 @@ dsymptr(Sym *s, int off, Sym *x) ...@@ -543,48 +525,46 @@ dsymptr(Sym *s, int off, Sym *x)
p->to.type = D_ADDR; p->to.type = D_ADDR;
p->to.index = D_EXTERN; p->to.index = D_EXTERN;
p->to.sym = x; p->to.sym = x;
p->to.offset = 0; p->to.offset = xoff;
off += widthptr; off += widthptr;
return off; return off;
} }
void void
genembedtramp(Type *t, Sig *b) genembedtramp(Type *rcvr, Type *method, Sym *newnam)
{ {
Sym *e; Sym *e;
int c, d, o, loaded; int c, d, o, mov, add, loaded;
Prog *p; Prog *p;
Type *f; Type *f;
e = lookup(b->name); if(debug['r'])
print("genembedtramp %T %T %S\n", rcvr, method, newnam);
e = method->sym;
for(d=0; d<nelem(dotlist); d++) { for(d=0; d<nelem(dotlist); d++) {
c = adddot1(e, t, d, nil); c = adddot1(e, rcvr, d, nil);
if(c == 1) if(c == 1)
goto out; goto out;
} }
fatal("genembedtramp %T.%s", t, b->name); fatal("genembedtramp %T.%S", rcvr, method->sym);
out: out:
// print("genembedtramp %d\n", d); newplist()->name = newname(newnam);
// print(" t = %lT\n", t);
// print(" name = %s\n", b->name);
// print(" sym = %S\n", b->sym);
// print(" hash = 0x%ux\n", b->hash);
newplist()->name = newname(b->sym);
//TEXT main·S_test2(SB),7,$0 //TEXT main·S_test2(SB),7,$0
p = pc; p = pc;
gins(ATEXT, N, N); gins(ATEXT, N, N);
p->from.type = D_EXTERN; p->from.type = D_EXTERN;
p->from.sym = b->sym; p->from.sym = newnam;
p->to.type = D_CONST; p->to.type = D_CONST;
p->to.offset = 0; p->to.offset = 0;
p->from.scale = 7; p->from.scale = 7;
//print("1. %P\n", p); //print("1. %P\n", p);
mov = AMOVQ;
add = AADDQ;
loaded = 0; loaded = 0;
o = 0; o = 0;
for(c=d-1; c>=0; c--) { for(c=d-1; c>=0; c--) {
...@@ -596,16 +576,16 @@ out: ...@@ -596,16 +576,16 @@ out:
loaded = 1; loaded = 1;
//MOVQ 8(SP), AX //MOVQ 8(SP), AX
p = pc; p = pc;
gins(AMOVQ, N, N); gins(mov, N, N);
p->from.type = D_INDIR+D_SP; p->from.type = D_INDIR+D_SP;
p->from.offset = 8; p->from.offset = widthptr;
p->to.type = D_AX; p->to.type = D_AX;
//print("2. %P\n", p); //print("2. %P\n", p);
} }
//MOVQ o(AX), AX //MOVQ o(AX), AX
p = pc; p = pc;
gins(AMOVQ, N, N); gins(mov, N, N);
p->from.type = D_INDIR+D_AX; p->from.type = D_INDIR+D_AX;
p->from.offset = o; p->from.offset = o;
p->to.type = D_AX; p->to.type = D_AX;
...@@ -615,14 +595,14 @@ out: ...@@ -615,14 +595,14 @@ out:
if(o != 0) { if(o != 0) {
//ADDQ $XX, AX //ADDQ $XX, AX
p = pc; p = pc;
gins(AADDQ, N, N); gins(add, N, N);
p->from.type = D_CONST; p->from.type = D_CONST;
p->from.offset = o; p->from.offset = o;
if(loaded) if(loaded)
p->to.type = D_AX; p->to.type = D_AX;
else { else {
p->to.type = D_INDIR+D_SP; p->to.type = D_INDIR+D_SP;
p->to.offset = 8; p->to.offset = widthptr;
} }
//print("4. %P\n", p); //print("4. %P\n", p);
} }
...@@ -630,10 +610,10 @@ out: ...@@ -630,10 +610,10 @@ out:
//MOVQ AX, 8(SP) //MOVQ AX, 8(SP)
if(loaded) { if(loaded) {
p = pc; p = pc;
gins(AMOVQ, N, N); gins(mov, N, N);
p->from.type = D_AX; p->from.type = D_AX;
p->to.type = D_INDIR+D_SP; p->to.type = D_INDIR+D_SP;
p->to.offset = 8; p->to.offset = widthptr;
//print("5. %P\n", p); //print("5. %P\n", p);
} else { } else {
// TODO(rsc): obviously this is unnecessary, // TODO(rsc): obviously this is unnecessary,
...@@ -651,7 +631,7 @@ out: ...@@ -651,7 +631,7 @@ out:
p = pc; p = pc;
gins(AJMP, N, N); gins(AJMP, N, N);
p->to.type = D_EXTERN; p->to.type = D_EXTERN;
p->to.sym = methodsym(lookup(b->name), ptrto(f->type)); p->to.sym = methodsym(method->sym, ptrto(f->type));
//print("6. %P\n", p); //print("6. %P\n", p);
pc->as = ARET; // overwrite AEND pc->as = ARET; // overwrite AEND
......
...@@ -508,25 +508,7 @@ duintxx(Sym *s, int off, uint64 v, int wid) ...@@ -508,25 +508,7 @@ duintxx(Sym *s, int off, uint64 v, int wid)
} }
int int
duint32(Sym *s, int off, uint32 v) dsymptr(Sym *s, int off, Sym *x, int xoff)
{
return duintxx(s, off, v, 4);
}
int
duint16(Sym *s, int off, uint32 v)
{
return duintxx(s, off, v, 2);
}
int
duintptr(Sym *s, int off, uint32 v)
{
return duintxx(s, off, v, 4);
}
int
dsymptr(Sym *s, int off, Sym *x)
{ {
Prog *p; Prog *p;
...@@ -541,68 +523,65 @@ dsymptr(Sym *s, int off, Sym *x) ...@@ -541,68 +523,65 @@ dsymptr(Sym *s, int off, Sym *x)
p->to.type = D_ADDR; p->to.type = D_ADDR;
p->to.index = D_EXTERN; p->to.index = D_EXTERN;
p->to.sym = x; p->to.sym = x;
p->to.offset = 0; p->to.offset = xoff;
off += widthptr; off += widthptr;
return off; return off;
} }
void void
genembedtramp(Type *t, Sig *b) genembedtramp(Type *rcvr, Type *method, Sym *newnam)
{ {
Sym *e; Sym *e;
int c, d, o; int c, d, o, mov, add, loaded;
Prog *p; Prog *p;
Type *f; Type *f;
e = lookup(b->name); e = method->sym;
for(d=0; d<nelem(dotlist); d++) { for(d=0; d<nelem(dotlist); d++) {
c = adddot1(e, t, d, nil); c = adddot1(e, rcvr, d, nil);
if(c == 1) if(c == 1)
goto out; goto out;
} }
fatal("genembedtramp %T.%s", t, b->name); fatal("genembedtramp %T.%S", rcvr, method->sym);
out: out:
if(d == 0) newplist()->name = newname(newnam);
return;
// print("genembedtramp %d\n", d);
// print(" t = %lT\n", t);
// print(" name = %s\n", b->name);
// print(" sym = %S\n", b->sym);
// print(" hash = 0x%ux\n", b->hash);
newplist()->name = newname(b->sym);
//TEXT main·S_test2(SB),7,$0 //TEXT main·S_test2(SB),7,$0
p = pc; p = pc;
gins(ATEXT, N, N); gins(ATEXT, N, N);
p->from.type = D_EXTERN; p->from.type = D_EXTERN;
p->from.sym = b->sym; p->from.sym = newnam;
p->to.type = D_CONST; p->to.type = D_CONST;
p->to.offset = 0; p->to.offset = 0;
p->from.scale = 7; p->from.scale = 7;
//print("1. %P\n", p); //print("1. %P\n", p);
//MOVL 4(SP), AX mov = AMOVL;
p = pc; add = AADDL;
gins(AMOVL, N, N);
p->from.type = D_INDIR+D_SP;
p->from.offset = widthptr;
p->to.type = D_AX;
//print("2. %P\n", p);
loaded = 0;
o = 0; o = 0;
for(c=d-1; c>=0; c--) { for(c=d-1; c>=0; c--) {
f = dotlist[c].field; f = dotlist[c].field;
o += f->width; o += f->width;
if(!isptr[f->type->etype]) if(!isptr[f->type->etype])
continue; continue;
if(!loaded) {
loaded = 1;
//MOVL 4(SP), AX
p = pc;
gins(mov, N, N);
p->from.type = D_INDIR+D_SP;
p->from.offset = widthptr;
p->to.type = D_AX;
//print("2. %P\n", p);
}
//MOVL o(AX), AX //MOVL o(AX), AX
p = pc; p = pc;
gins(AMOVL, N, N); gins(mov, N, N);
p->from.type = D_INDIR+D_AX; p->from.type = D_INDIR+D_AX;
p->from.offset = o; p->from.offset = o;
p->to.type = D_AX; p->to.type = D_AX;
...@@ -612,20 +591,34 @@ out: ...@@ -612,20 +591,34 @@ out:
if(o != 0) { if(o != 0) {
//ADDL $XX, AX //ADDL $XX, AX
p = pc; p = pc;
gins(AADDL, N, N); gins(add, N, N);
p->from.type = D_CONST; p->from.type = D_CONST;
p->from.offset = o; p->from.offset = o;
p->to.type = D_AX; if(loaded)
p->to.type = D_AX;
else {
p->to.type = D_INDIR+D_SP;
p->to.offset = widthptr;
}
//print("4. %P\n", p); //print("4. %P\n", p);
} }
//MOVL AX, 4(SP) //MOVL AX, 4(SP)
p = pc; if(loaded) {
gins(AMOVL, N, N); p = pc;
p->from.type = D_AX; gins(mov, N, N);
p->to.type = D_INDIR+D_SP; p->from.type = D_AX;
p->to.offset = widthptr; p->to.type = D_INDIR+D_SP;
p->to.offset = widthptr;
//print("5. %P\n", p); //print("5. %P\n", p);
} else {
// TODO(rsc): obviously this is unnecessary,
// but 6l has a bug, and it can't handle
// JMP instructions too close to the top of
// a new function.
p = pc;
gins(ANOP, N, N);
}
f = dotlist[0].field; f = dotlist[0].field;
//JMP main·*Sub_test2(SB) //JMP main·*Sub_test2(SB)
...@@ -634,7 +627,7 @@ out: ...@@ -634,7 +627,7 @@ out:
p = pc; p = pc;
gins(AJMP, N, N); gins(AJMP, N, N);
p->to.type = D_EXTERN; p->to.type = D_EXTERN;
p->to.sym = methodsym(lookup(b->name), ptrto(f->type)); p->to.sym = methodsym(method->sym, ptrto(f->type));
//print("6. %P\n", p); //print("6. %P\n", p);
pc->as = ARET; // overwrite AEND pc->as = ARET; // overwrite AEND
......
...@@ -171,7 +171,7 @@ struct Type ...@@ -171,7 +171,7 @@ struct Type
// TARRAY // TARRAY
int32 bound; // negative is dynamic array int32 bound; // negative is dynamic array
int32 maplineno; // first use of TFORW as map key int32 maplineno; // first use of TFORW as map key
}; };
#define T ((Type*)0) #define T ((Type*)0)
...@@ -550,6 +550,7 @@ EXTERN Idir* idirs; ...@@ -550,6 +550,7 @@ EXTERN Idir* idirs;
EXTERN Type* types[NTYPE]; EXTERN Type* types[NTYPE];
EXTERN uchar simtype[NTYPE]; EXTERN uchar simtype[NTYPE];
EXTERN uchar isptr[NTYPE]; EXTERN uchar isptr[NTYPE];
EXTERN uchar isforw[NTYPE];
EXTERN uchar isint[NTYPE]; EXTERN uchar isint[NTYPE];
EXTERN uchar isfloat[NTYPE]; EXTERN uchar isfloat[NTYPE];
EXTERN uchar issigned[NTYPE]; EXTERN uchar issigned[NTYPE];
...@@ -606,6 +607,7 @@ EXTERN int32 nhunk; ...@@ -606,6 +607,7 @@ EXTERN int32 nhunk;
EXTERN int32 thunk; EXTERN int32 thunk;
EXTERN int exporting; EXTERN int exporting;
EXTERN int noargnames;
EXTERN int funcdepth; EXTERN int funcdepth;
...@@ -1081,11 +1083,15 @@ void zhist(Biobuf *b, int line, vlong offset); ...@@ -1081,11 +1083,15 @@ void zhist(Biobuf *b, int line, vlong offset);
void zname(Biobuf *b, Sym *s, int t); void zname(Biobuf *b, Sym *s, int t);
void nopout(Prog*); void nopout(Prog*);
int dstringptr(Sym *s, int off, char *str); int dstringptr(Sym *s, int off, char *str);
int dsymptr(Sym *s, int off, Sym *x); int dgostringptr(Sym*, int off, char *str);
int duint16(Sym *s, int off, uint32 v); int dgostrlitptr(Sym*, int off, Strlit*);
int dsymptr(Sym *s, int off, Sym *x, int xoff);
int duint8(Sym *s, int off, uint8 v);
int duint16(Sym *s, int off, uint16 v);
int duint32(Sym *s, int off, uint32 v); int duint32(Sym *s, int off, uint32 v);
int duintptr(Sym *s, int off, uint32 v); int duint64(Sym *s, int off, uint64 v);
int duintptr(Sym *s, int off, uint64 v);
int duintxx(Sym *s, int off, uint64 v, int wid); int duintxx(Sym *s, int off, uint64 v, int wid);
void genembedtramp(Type*, Sig*); void genembedtramp(Type*, Type*, Sym*);
int gen_as_init(Node*, Node*); int gen_as_init(Node*, Node*);
...@@ -140,6 +140,36 @@ ieeedtod(uint64 *ieee, double native) ...@@ -140,6 +140,36 @@ ieeedtod(uint64 *ieee, double native)
*ieee = ((uint64)h << 32) | l; *ieee = ((uint64)h << 32) | l;
} }
int
duint8(Sym *s, int off, uint8 v)
{
return duintxx(s, off, v, 1);
}
int
duint16(Sym *s, int off, uint16 v)
{
return duintxx(s, off, v, 2);
}
int
duint32(Sym *s, int off, uint32 v)
{
return duintxx(s, off, v, 4);
}
int
duint64(Sym *s, int off, uint64 v)
{
return duintxx(s, off, v, 8);
}
int
duintptr(Sym *s, int off, uint64 v)
{
return duintxx(s, off, v, widthptr);
}
static int static int
sigcmp(Sig *a, Sig *b) sigcmp(Sig *a, Sig *b)
{ {
...@@ -239,7 +269,7 @@ dumpsigt(Type *progt, Type *ifacet, Type *rcvrt, Type *methodt, Sym *s) ...@@ -239,7 +269,7 @@ dumpsigt(Type *progt, Type *ifacet, Type *rcvrt, Type *methodt, Sym *s)
// using genembedtramp if all that is necessary // using genembedtramp if all that is necessary
// is a pointer adjustment and a JMP. // is a pointer adjustment and a JMP.
if(f->embedded && isptr[ifacet->etype] && !isifacemethod(f)) if(f->embedded && isptr[ifacet->etype] && !isifacemethod(f))
genembedtramp(ifacet, a); genembedtramp(ifacet, f, a->sym);
else else
genwrapper(ifacet, f, a->sym); genwrapper(ifacet, f, a->sym);
} }
...@@ -275,7 +305,7 @@ dumpsigt(Type *progt, Type *ifacet, Type *rcvrt, Type *methodt, Sym *s) ...@@ -275,7 +305,7 @@ dumpsigt(Type *progt, Type *ifacet, Type *rcvrt, Type *methodt, Sym *s)
ot = dstringptr(s, ot, b->name); // field name ot = dstringptr(s, ot, b->name); // field name
ot = duint32(s, ot, b->hash); // hash ot = duint32(s, ot, b->hash); // hash
ot = duint32(s, ot, 0); // offset ot = duint32(s, ot, 0); // offset
ot = dsymptr(s, ot, b->sym); // &method ot = dsymptr(s, ot, b->sym, 0); // &method
} }
// nil field name at end // nil field name at end
......
...@@ -1117,7 +1117,10 @@ Tpretty(Fmt *fp, Type *t) ...@@ -1117,7 +1117,10 @@ Tpretty(Fmt *fp, Type *t)
fmtprint(fp, "func"); fmtprint(fp, "func");
fmtprint(fp, "("); fmtprint(fp, "(");
for(t1=getinargx(t)->type; t1; t1=t1->down) { for(t1=getinargx(t)->type; t1; t1=t1->down) {
fmtprint(fp, "%T", t1); if(noargnames && t1->etype == TFIELD)
fmtprint(fp, "%T", t1->type);
else
fmtprint(fp, "%T", t1);
if(t1->down) if(t1->down)
fmtprint(fp, ", "); fmtprint(fp, ", ");
} }
...@@ -1135,7 +1138,10 @@ Tpretty(Fmt *fp, Type *t) ...@@ -1135,7 +1138,10 @@ Tpretty(Fmt *fp, Type *t)
t1 = getoutargx(t)->type; t1 = getoutargx(t)->type;
fmtprint(fp, " ("); fmtprint(fp, " (");
for(; t1; t1=t1->down) { for(; t1; t1=t1->down) {
fmtprint(fp, "%T", t1); if(noargnames && t1->etype == TFIELD)
fmtprint(fp, "%T", t1->type);
else
fmtprint(fp, "%T", t1);
if(t1->down) if(t1->down)
fmtprint(fp, ", "); fmtprint(fp, ", ");
} }
...@@ -1195,7 +1201,11 @@ Tconv(Fmt *fp) ...@@ -1195,7 +1201,11 @@ Tconv(Fmt *fp)
{ {
char buf[500], buf1[500]; char buf[500], buf1[500];
Type *t, *t1; Type *t, *t1;
int et, exp; int r, et, sharp, minus;
sharp = (fp->flags & FmtSharp);
minus = (fp->flags & FmtLeft);
fp->flags &= ~(FmtSharp|FmtLeft);
t = va_arg(fp->args, Type*); t = va_arg(fp->args, Type*);
if(t == T) if(t == T)
...@@ -1208,17 +1218,19 @@ Tconv(Fmt *fp) ...@@ -1208,17 +1218,19 @@ Tconv(Fmt *fp)
} }
if(!debug['t']) { if(!debug['t']) {
exp = (fp->flags & FmtSharp); if(sharp)
if(exp)
exporting++; exporting++;
if(Tpretty(fp, t) >= 0) { if(minus)
noargnames++;
r = Tpretty(fp, t);
if(sharp)
exporting--;
if(minus)
noargnames--;
if(r >= 0) {
t->trecur--; t->trecur--;
if(exp)
exporting--;
return 0; return 0;
} }
if(exp)
exporting--;
} }
et = t->etype; et = t->etype;
...@@ -2061,7 +2073,7 @@ typehash(Type *at, int addsym, int d) ...@@ -2061,7 +2073,7 @@ typehash(Type *at, int addsym, int d)
case TFUNC: case TFUNC:
t = at->type; t = at->type;
// skip this argument // skip this (receiver) argument
if(t != T) if(t != T)
t = t->down; t = t->down;
for(; t!=T; t=t->down) for(; t!=T; t=t->down)
...@@ -2845,8 +2857,6 @@ expandmeth(Sym *s, Type *t) ...@@ -2845,8 +2857,6 @@ expandmeth(Sym *s, Type *t)
if(t == T) if(t == T)
return; return;
//print("s=%S t=%lT\n", s, t);
// generate all reachable methods // generate all reachable methods
slist = nil; slist = nil;
expand1(t, nelem(dotlist)-1, 0); expand1(t, nelem(dotlist)-1, 0);
...@@ -2858,15 +2868,16 @@ expandmeth(Sym *s, Type *t) ...@@ -2858,15 +2868,16 @@ expandmeth(Sym *s, Type *t)
c = adddot1(sl->field->sym, t, d, &f); c = adddot1(sl->field->sym, t, d, &f);
if(c == 0) if(c == 0)
continue; continue;
if(c == 1 && f == sl->field) if(c == 1) {
sl->good = 1; sl->good = 1;
sl->field = f;
}
break; break;
} }
} }
for(sl=slist; sl!=nil; sl=sl->link) { for(sl=slist; sl!=nil; sl=sl->link) {
if(sl->good) { if(sl->good) {
//print(" %lT\n", sl->field);
// add it to the base type method list // add it to the base type method list
f = typ(TFIELD); f = typ(TFIELD);
*f = *sl->field; *f = *sl->field;
...@@ -2928,26 +2939,25 @@ structargs(Type **tl, int mustname) ...@@ -2928,26 +2939,25 @@ structargs(Type **tl, int mustname)
* and calls the T.M method. * and calls the T.M method.
* The resulting function is for use in method tables. * The resulting function is for use in method tables.
* *
* rcvrtype - U * rcvr - U
* method - M func (t T)(), a TFIELD type struct * method - M func (t T)(), a TFIELD type struct
* newnam - the eventual mangled name of this function * newnam - the eventual mangled name of this function
*/ */
void void
genwrapper(Type *rcvrtype, Type *method, Sym *newnam) genwrapper(Type *rcvr, Type *method, Sym *newnam)
{ {
Node *this, *in, *out, *fn, *args, *call; Node *this, *in, *out, *fn, *args, *call;
Node *l; Node *l;
Iter savel; Iter savel;
if(debug['r']) { if(debug['r'])
print("genwrapper rcvrtype=%T method=%T newnam=%S\n", print("genwrapper rcvrtype=%T method=%T newnam=%S\n",
rcvrtype, method, newnam); rcvr, method, newnam);
}
dclcontext = PEXTERN; dclcontext = PEXTERN;
markdcl(); markdcl();
this = nametodcl(newname(lookup(".this")), rcvrtype); this = nametodcl(newname(lookup(".this")), rcvr);
in = structargs(getinarg(method->type), 1); in = structargs(getinarg(method->type), 1);
out = structargs(getoutarg(method->type), 0); out = structargs(getoutarg(method->type), 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment