From b642cf8c002d8ec4ededc239311f2ea54fc9deba Mon Sep 17 00:00:00 2001 From: Ken Thompson Date: Sat, 25 Oct 2008 13:31:25 -0700 Subject: [PATCH] embedded methods R=r OCL=17851 CL=17851 --- src/cmd/6g/obj.c | 83 ++++++++++++++++++++++++++++++++++++++--------- src/cmd/gc/go.h | 4 +-- src/cmd/gc/subr.c | 14 ++------ 3 files changed, 71 insertions(+), 30 deletions(-) diff --git a/src/cmd/6g/obj.c b/src/cmd/6g/obj.c index 8070af4b483..74f8908fb54 100644 --- a/src/cmd/6g/obj.c +++ b/src/cmd/6g/obj.c @@ -513,7 +513,9 @@ void gentramp(Type *t, Sig *b) { Sym *e; - int c, d; + int c, d, o; + Prog *p; + Type *f; e = lookup(b->name); for(d=0; dname); - print(" sym = %S\n", b->sym); - print(" hash = 0x%ux\n", b->hash); +// print("gentramp %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); + //TEXT main·S_test2(SB),7,$0 + p = pc; + gins(ATEXT, N, N); + p->from.type = D_EXTERN; + p->from.sym = b->sym; + p->to.type = D_CONST; + p->to.offset = 0; + p->from.scale = 7; +//print("1. %P\n", p); + + //MOVQ 8(SP), AX + p = pc; + gins(AMOVQ, N, N); + p->from.type = D_INDIR+D_SP; + p->from.offset = 8; + p->to.type = D_AX; +//print("2. %P\n", p); + + o = 0; for(c=d-1; c>=0; c--) { - print(" %d %d %S\n", - dotlist[c].ptr, - dotlist[c].offset, - dotlist[c].sym); + f = dotlist[c].field; + o += f->width; + if(!isptr[f->type->etype]) + continue; + //MOVQ o(AX), AX + p = pc; + gins(AMOVQ, N, N); + p->from.type = D_INDIR+D_AX; + p->from.offset = o; + p->to.type = D_AX; +//print("3. %P\n", p); + o = 0; + } + if(o != 0) { + //ADDQ $XX, AX + p = pc; + gins(AADDQ, N, N); + p->from.type = D_CONST; + p->from.offset = o; + p->to.type = D_AX; +//print("4. %P\n", p); } -//TEXT main·S_test2(SB),7,$0 -// MOVQ 8(SP), AX -// MOVQ XX(AX), AX -// ADDQ $XX, AX -// MOVQ AX, 8(SP) -// JMP main·Sub_test2(SB) + //MOVQ AX, 8(SP) + p = pc; + gins(AMOVQ, N, N); + p->from.type = D_AX; + p->to.type = D_INDIR+D_SP; + p->to.offset = 8; +//print("5. %P\n", p); + + f = dotlist[0].field; + //JMP main·Sub_test2(SB) + snprint(namebuf, sizeof(namebuf), "%s_%s", + f->sym->name, b->name); + if(isptr[f->type->etype]) + f = f->type; + p = pc; + gins(AJMP, N, N); + p->to.type = D_EXTERN; + p->to.sym = pkglookup(namebuf, f->type->sym->opackage); +//print("6. %P\n", p); } void diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h index b8250b1d4f7..7c1d06ee720 100644 --- a/src/cmd/gc/go.h +++ b/src/cmd/gc/go.h @@ -402,9 +402,7 @@ struct Io typedef struct Dlist Dlist; struct Dlist { - Sym* sym; - uchar ptr; - int offset; + Type* field; }; EXTERN Dlist dotlist[10]; // size is max depth of embeddeds diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 710c12f3ded..d4e482984f7 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -2445,13 +2445,8 @@ adddot1(Sym *s, Type *t, int d) if(f->sym == S) continue; a = adddot1(s, f->type, d); - if(a != 0 && c == 0) { - dotlist[d].sym = f->sym; - dotlist[d].offset = f->width; - dotlist[d].ptr = 0; - if(isptr[f->type->etype]) - dotlist[d].ptr = 1; - } + if(a != 0 && c == 0) + dotlist[d].field = f; c += a; } @@ -2497,7 +2492,7 @@ out: // rebuild elided dots for(c=d-1; c>=0; c--) { n = nod(ODOT, n, n->right); - n->left->right = newname(dotlist[c].sym); + n->left->right = newname(dotlist[c].field->sym); } return n; } @@ -2609,7 +2604,6 @@ expandmeth(Sym *s, Type *t) } } -//print("expand %S: %lT", s, t); for(sl=slist; sl!=nil; sl=sl->link) { if(sl->good) { // add it to the base type method list @@ -2620,8 +2614,6 @@ expandmeth(Sym *s, Type *t) f->down = t->method; t->method = f; -//print(" %T", f); } } -//print("\n"); }