uchar index;
uchar etype;
uchar scale; /* doubles as width in DATA op */
+ Sym* gotype;
};
#define A ((Addr*)0)
int Yconv(Fmt*);
void listinit(void);
-void zaddr(Biobuf*, Addr*, int);
+void zaddr(Biobuf*, Addr*, int, int);
Bputc(b, line>>8);
Bputc(b, line>>16);
Bputc(b, line>>24);
- zaddr(b, &zprog.from, 0);
+ zaddr(b, &zprog.from, 0, 0);
a = zprog.to;
if(offset != 0) {
a.offset = offset;
a.type = D_CONST;
}
- zaddr(b, &a, 0);
+ zaddr(b, &a, 0, 0);
}
void
-zaddr(Biobuf *b, Addr *a, int s)
+zaddr(Biobuf *b, Addr *a, int s, int gotype)
{
int32 l;
uint64 e;
t |= T_INDEX;
if(s != 0)
t |= T_SYM;
+ if(gotype != 0)
+ t |= T_GOTYPE;
switch(a->type) {
}
if(t & T_TYPE)
Bputc(b, a->type);
+ if(t & T_GOTYPE)
+ Bputc(b, gotype);
+}
+
+static struct {
+ struct { Sym *sym; short type; } h[NSYM];
+ int sym;
+} z;
+
+static void
+zsymreset(void)
+{
+ for(z.sym=0; z.sym<NSYM; z.sym++) {
+ z.h[z.sym].sym = S;
+ z.h[z.sym].type = 0;
+ }
+ z.sym = 1;
+}
+
+static int
+zsym(Sym *s, int t, int *new)
+{
+ int i;
+
+ *new = 0;
+ if(s == S)
+ return 0;
+
+ i = s->sym;
+ if(i < 0 || i >= NSYM)
+ i = 0;
+ if(z.h[i].type == t && z.h[i].sym == s)
+ return i;
+ i = z.sym;
+ s->sym = i;
+ zname(bout, s, t);
+ z.h[i].sym = s;
+ z.h[i].type = t;
+ if(++z.sym >= NSYM)
+ z.sym = 1;
+ *new = 1;
+ return i;
+}
+
+static int
+zsymaddr(Addr *a, int *new)
+{
+ int t;
+
+ t = a->type;
+ if(t == D_ADDR)
+ t = a->index;
+ return zsym(a->sym, t, new);
}
void
dumpfuncs(void)
{
Plist *pl;
- int sf, st, t, sym;
- struct { Sym *sym; short type; } h[NSYM];
+ int sf, st, gf, gt, new;
Sym *s;
Prog *p;
- for(sym=0; sym<NSYM; sym++) {
- h[sym].sym = S;
- h[sym].type = 0;
- }
- sym = 1;
+ zsymreset();
// fix up pc
pcloc = 0;
}
for(p=pl->firstpc; p!=P; p=p->link) {
- jackpot:
- sf = 0;
- s = p->from.sym;
- while(s != S) {
- sf = s->sym;
- if(sf < 0 || sf >= NSYM)
- sf = 0;
- t = p->from.type;
- if(t == D_ADDR)
- t = p->from.index;
- if(h[sf].type == t)
- if(h[sf].sym == s)
- break;
- s->sym = sym;
- zname(bout, s, t);
- h[sym].sym = s;
- h[sym].type = t;
- sf = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- break;
- }
- st = 0;
- s = p->to.sym;
- while(s != S) {
- st = s->sym;
- if(st < 0 || st >= NSYM)
- st = 0;
- t = p->to.type;
- if(t == D_ADDR)
- t = p->to.index;
- if(h[st].type == t)
- if(h[st].sym == s)
- break;
- s->sym = sym;
- zname(bout, s, t);
- h[sym].sym = s;
- h[sym].type = t;
- st = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- if(st == sf)
- goto jackpot;
+ for(;;) {
+ sf = zsymaddr(&p->from, &new);
+ gf = zsym(p->from.gotype, D_EXTERN, &new);
+ if(new && sf == gf)
+ continue;
+ st = zsymaddr(&p->to, &new);
+ if(new && (st == sf || st == gf))
+ continue;
+ gt = zsym(p->to.gotype, D_EXTERN, &new);
+ if(new && (gt == sf || gt == gf || gt == st))
+ continue;
break;
}
+
Bputc(bout, p->as);
Bputc(bout, p->as>>8);
Bputc(bout, p->lineno);
Bputc(bout, p->lineno>>8);
Bputc(bout, p->lineno>>16);
Bputc(bout, p->lineno>>24);
- zaddr(bout, &p->from, sf);
- zaddr(bout, &p->to, st);
+ zaddr(bout, &p->from, sf, gf);
+ zaddr(bout, &p->to, st, gt);
}
}
}
a->scale = 0;
a->index = D_NONE;
a->type = D_NONE;
+ a->gotype = S;
if(n == N)
return;
case ONAME:
a->etype = 0;
- if(n->type != T)
+ if(n->type != T) {
a->etype = simtype[n->type->etype];
+ if(n->sym != S && strncmp(n->sym->name, "autotmp_", 8) != 0)
+ a->gotype = typename(n->type)->left->sym;
+ }
a->offset = n->xoffset;
a->sym = n->sym;
if(a->sym == S)
T_SYM = 1<<4,
T_SCONST = 1<<5,
T_OFFSET2 = 1<<6,
+ T_GOTYPE = 1<<7,
REGARG = -1,
REGRET = D_AX,
uchar index;
char scale;
int32 offset2;
+ Sym* gotype;
};
#define offset u0.u0offset
Auto* link;
int32 aoffset;
short type;
+ Sym* gotype;
};
struct Sym
{
* go.c
*/
void deadcode(void);
-vlong gotypefor(char *name);
void ldpkg(Biobuf *f, int64 len, char *filename);
}
if(t & T_TYPE)
a->type = Bgetc(f);
+ if(t & T_GOTYPE)
+ a->gotype = h[Bgetc(f)];
s = a->sym;
if(s == S)
return;
t = a->type;
- if(t != D_AUTO && t != D_PARAM)
+ if(t != D_AUTO && t != D_PARAM) {
+ if(a->gotype)
+ s->gotype = a->gotype;
return;
+ }
l = a->offset;
for(u=curauto; u; u=u->link) {
if(u->asym == s)
if(u->type == t) {
if(u->aoffset > l)
u->aoffset = l;
+ if(a->gotype)
+ u->gotype = a->gotype;
return;
}
}
u->asym = s;
u->aoffset = l;
u->type = t;
+ u->gotype = a->gotype;
}
void
}
void
-putsymb(char *s, int t, int32 v, int ver, vlong go)
+putsymb(char *s, int t, int32 v, int ver, Sym *go)
{
int i, f;
+ vlong gv;
if(t == 'f')
s++;
cput(s[i]);
cput(0);
}
- lput(go);
+ gv = 0;
+ if(go)
+ gv = go->value+INITDAT;
+ lput(gv);
- symsize += 4 + 1 + i + 1 + 4;
+ symsize += 4 + 1 + i+1 + 4;
if(debug['n']) {
if(t == 'z' || t == 'Z') {
return;
}
if(ver)
- Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver);
+ Bprint(&bso, "%c %.8lux %s<%d> %s (%.8llux)\n", t, v, s, ver, go ? go->name : "", gv);
else
- Bprint(&bso, "%c %.8lux %s\n", t, v, s);
+ Bprint(&bso, "%c %.8lux %s\n", t, v, s, go ? go->name : "", gv);
}
}
for(s=hash[h]; s!=S; s=s->link)
switch(s->type) {
case SCONST:
- putsymb(s->name, 'D', s->value, s->version, gotypefor(s->name));
+ putsymb(s->name, 'D', s->value, s->version, s->gotype);
continue;
case SDATA:
- putsymb(s->name, 'D', s->value+INITDAT, s->version, gotypefor(s->name));
+ putsymb(s->name, 'D', s->value+INITDAT, s->version, s->gotype);
continue;
case SBSS:
- putsymb(s->name, 'B', s->value+INITDAT, s->version, gotypefor(s->name));
+ putsymb(s->name, 'B', s->value+INITDAT, s->version, s->gotype);
continue;
case SFILE:
if(a->type == D_FILE1)
putsymb(a->asym->name, 'Z', a->aoffset, 0, 0);
- putsymb(s->name, 'T', s->value, s->version, gotypefor(s->name));
+ putsymb(s->name, 'T', s->value, s->version, s->gotype);
/* frame, auto and param after */
putsymb(".frame", 'm', p->to.offset+4, 0, 0);
for(a=p->to.autom; a; a=a->link)
if(a->type == D_AUTO)
- putsymb(a->asym->name, 'a', -a->aoffset, 0, 0);
+ putsymb(a->asym->name, 'a', -a->aoffset, 0, a->gotype);
else
if(a->type == D_PARAM)
- putsymb(a->asym->name, 'p', a->aoffset, 0, 0);
+ putsymb(a->asym->name, 'p', a->aoffset, 0, a->gotype);
}
if(debug['v'] || debug['n'])
Bprint(&bso, "symsize = %lud\n", symsize);
return x;
}
-vlong
-gotypefor(char *name)
-{
-/*
- Import *x;
- char *s, *p;
-
- s = strdup(name);
- p = utfrune(s, 0xB7); // center dot
- if(p == nil)
- return nil;
- *p++ = '.';
- memmove(p, p+1, strlen(p));
- x = ilookup(s);
- free(s);
- if(x == nil || x->prefix == nil)
- return nil;
- if(strcmp(x->prefix, "var") != 0 && strcmp(x->prefix, "func") != 0)
- return nil;
- return x->def;
-*/
- return 0;
-}
-
static void loadpkgdata(char*, char*, int);
static int parsemethod(char**, char*, char**);
static int parsepkgdata(char*, char**, char*, char**, char**, char**);
off = 0;
a.sym = -1;
a.flags = Bgetc(bp); /* flags */
+ a.gotype = 0;
if(a.flags & T_INDEX)
skip(bp, 2);
if(a.flags & T_OFFSET){
{
char sym;
char flags;
+ char gotype;
};
static Addr addr(Biobuf*);
static char type2char(int);
if(a.sym > 0 && (t==D_PARAM || t==D_AUTO))
_offset(a.sym, off);
}
+ if(a.flags & T_GOTYPE)
+ a.gotype = Bgetc(bp);
return a;
}
byte* getenv(int8*);
int32 atoi(byte*);
void newosproc(M *m, G *g, void *stk, void (*fn)(void));
-void sigaltstack(void*, void*);
void signalstack(byte*, int32);
G* malg(int32);
void minit(void);