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;
Bputc(b, a->reg);
Bputc(b, s);
Bputc(b, a->name);
+ Bputc(b, gotype);
}
switch(a->type) {
}
}
+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->name;
+ if(t == D_ADDR)
+ t = a->name;
+ 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.name;
- if(t == D_ADDR)
- t = p->from.name;
- 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.name;
- if(t == D_ADDR)
- t = p->to.name;
- 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->scond);
Bputc(bout, p->reg);
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);
}
}
}
errorexit();
}
+static Sym*
+zsym(char *pn, Biobuf *f, Sym *h[])
+{
+ int o;
+
+ o = BGETC(f);
+ if(o == 0)
+ return S;
+ if(o < 0 || o >= NSYM || h[o] == nil)
+ mangle(pn);
+ return h[o];
+}
+
static void
-zaddr(Biobuf *f, Adr *a, Sym *h[])
+zaddr(char *pn, Biobuf *f, Adr *a, Sym *h[])
{
int i, c;
int32 l;
}
a->sym = h[c];
a->name = BGETC(f);
+ adrgotype = zsym(pn, f, h);
if((schar)a->reg < 0 || a->reg > NREG) {
print("register out of range %d\n", a->reg);
if(s == S)
return;
i = a->name;
- if(i != D_AUTO && i != D_PARAM)
+ if(i != D_AUTO && i != D_PARAM) {
+ if(s && adrgotype)
+ s->gotype = adrgotype;
return;
+ }
l = a->offset;
for(u=curauto; u; u=u->link)
if(u->type == i) {
if(u->aoffset > l)
u->aoffset = l;
+ if(adrgotype)
+ u->gotype = adrgotype;
return;
}
u->asym = s;
u->aoffset = l;
u->type = i;
+ u->gotype = adrgotype;
}
void
p->reg = BGETC(f);
p->line = Bget4(f);
- zaddr(f, &p->from, h);
- zaddr(f, &p->to, h);
+ zaddr(pn, f, &p->from, h);
+ fromgotype = adrgotype;
+ zaddr(pn, f, &p->to, h);
if(p->as != ATEXT && p->as != AGLOBL && p->reg > NREG)
diag("register out of range %A %d", p->as, p->reg);
etextp->next = s;
else
textp = s;
+ if(fromgotype) {
+ if(s->gotype && s->gotype != fromgotype)
+ diag("%s: type mismatch for %s", pn, s->name);
+ s->gotype = fromgotype;
+ }
etextp = s;
p->align = 4;
autosize = (p->to.offset+3L) & ~3L;