Commit 5a2771e2 authored by Russ Cox's avatar Russ Cox

cmd/gc, cmd/ld, liblink: update for portable Prog, Addr changes

Change-Id: Ia6f8badca56565b9df80c8dbe28c47f6cf7e653f
Reviewed-on: https://go-review.googlesource.com/3515Reviewed-by: 's avatarAustin Clements <austin@google.com>
Reviewed-by: 's avatarAram Hăvărneanu <aram@mgk.ro>
parent 2ec29312
......@@ -19,7 +19,7 @@ vlong
rnd(vlong o, vlong r)
{
if(r < 1 || r > 8 || (r&(r-1)) != 0)
fatal("rnd");
fatal("rnd %lld", r);
return (o+r-1)&~(r-1);
}
......
......@@ -1675,10 +1675,6 @@ struct Arch
int AUNDEF;
int AVARDEF;
int AVARKILL;
int D_AUTO;
int D_BRANCH;
int D_NONE;
int D_PARAM;
vlong MAXWIDTH;
void (*afunclit)(Addr*, Node*);
......
......@@ -127,7 +127,7 @@ removevardef(Prog *firstp)
for(p = firstp; p != P; p = p->link) {
while(p->link != P && (p->link->as == arch.AVARDEF || p->link->as == arch.AVARKILL))
p->link = p->link->link;
if(p->to.type == arch.D_BRANCH)
if(p->to.type == TYPE_BRANCH)
while(p->to.u.branch != P && (p->to.u.branch->as == arch.AVARDEF || p->to.u.branch->as == arch.AVARKILL))
p->to.u.branch = p->to.u.branch->link;
}
......
......@@ -512,7 +512,7 @@ newcfg(Prog *firstp)
bb = newblock(firstp);
arrayadd(cfg, &bb);
for(p = firstp; p != P; p = p->link) {
if(p->to.type == arch.D_BRANCH) {
if(p->to.type == TYPE_BRANCH) {
if(p->to.u.branch == nil)
fatal("prog branch to nil");
if(p->to.u.branch->opt == nil) {
......@@ -551,7 +551,7 @@ newcfg(Prog *firstp)
if(isselectgocall(p))
arrayadd(selectgo, &bb);
}
if(bb->last->to.type == arch.D_BRANCH)
if(bb->last->to.type == TYPE_BRANCH)
addedge(bb, bb->last->to.u.branch->opt);
if(bb->last->link != nil) {
// Add a fall-through when the instruction is
......@@ -704,7 +704,7 @@ progeffects(Prog *prog, Array *vars, Bvec *uevar, Bvec *varkill, Bvec *avarinit)
// The p->to.type == arch.D_NONE limits the bvset to
// non-tail-call return instructions; see note above
// the for loop for details.
if(!node->addrtaken && prog->to.type == arch.D_NONE)
if(!node->addrtaken && prog->to.type == TYPE_NONE)
bvset(uevar, i);
break;
}
......@@ -987,6 +987,10 @@ checkauto(Node *fn, Prog *p, Node *n)
if(l->n->op == ONAME && l->n->class == PAUTO && l->n == n)
return;
if(n == nil) {
print("%L: checkauto %N: nil node in %P\n", p->lineno, curfn, p);
return;
}
print("checkauto %N: %N (%p; class=%d) not found in %P\n", curfn, n, n, n->class, p);
for(l = fn->dcl; l != nil; l = l->next)
print("\t%N (%p; class=%d)\n", l->n, l->n, l->n->class);
......@@ -1018,13 +1022,13 @@ checkparam(Node *fn, Prog *p, Node *n)
static void
checkprog(Node *fn, Prog *p)
{
if(p->from.type == arch.D_AUTO)
if(p->from.name == NAME_AUTO)
checkauto(fn, p, p->from.node);
if(p->from.type == arch.D_PARAM)
if(p->from.name == NAME_PARAM)
checkparam(fn, p, p->from.node);
if(p->to.type == arch.D_AUTO)
if(p->to.name == NAME_AUTO)
checkauto(fn, p, p->to.node);
if(p->to.type == arch.D_PARAM)
if(p->to.name == NAME_PARAM)
checkparam(fn, p, p->to.node);
}
......
......@@ -81,7 +81,7 @@ chasejmp(Prog *p, int *jmploop)
int n;
n = 0;
while(p != P && p->as == arch.AJMP && p->to.type == arch.D_BRANCH) {
while(p != P && p->as == arch.AJMP && p->to.type == TYPE_BRANCH) {
if(++n > 10) {
*jmploop = 1;
break;
......@@ -112,7 +112,7 @@ mark(Prog *firstp)
if(p->opt != dead)
break;
p->opt = alive;
if(p->as != arch.ACALL && p->to.type == arch.D_BRANCH && p->to.u.branch)
if(p->as != arch.ACALL && p->to.type == TYPE_BRANCH && p->to.u.branch)
mark(p->to.u.branch);
if(p->as == arch.AJMP || p->as == arch.ARET || p->as == arch.AUNDEF)
break;
......@@ -133,7 +133,7 @@ fixjmp(Prog *firstp)
for(p=firstp; p; p=p->link) {
if(debug['R'] && debug['v'])
print("%P\n", p);
if(p->as != arch.ACALL && p->to.type == arch.D_BRANCH && p->to.u.branch && p->to.u.branch->as == arch.AJMP) {
if(p->as != arch.ACALL && p->to.type == TYPE_BRANCH && p->to.u.branch && p->to.u.branch->as == arch.AJMP) {
p->to.u.branch = chasejmp(p->to.u.branch, &jmploop);
if(debug['R'] && debug['v'])
print("->%P\n", p);
......@@ -176,7 +176,7 @@ fixjmp(Prog *firstp)
if(!jmploop) {
last = nil;
for(p=firstp; p; p=p->link) {
if(p->as == arch.AJMP && p->to.type == arch.D_BRANCH && p->to.u.branch == p->link) {
if(p->as == arch.AJMP && p->to.type == TYPE_BRANCH && p->to.u.branch == p->link) {
if(debug['R'] && debug['v'])
print("del %P\n", p);
continue;
......@@ -275,7 +275,7 @@ flowstart(Prog *firstp, int size)
f->s1 = f1;
f1->p1 = f;
}
if(p->to.type == arch.D_BRANCH) {
if(p->to.type == TYPE_BRANCH) {
if(p->to.u.branch == P)
fatal("pnil %P", p);
f1 = p->to.u.branch->opt;
......
......@@ -1658,7 +1658,7 @@ writelines(void)
dwfunc->hash = varhash; // enable indexing of children by name
memset(varhash, 0, sizeof varhash);
for(a = s->autom; a; a = a->link) {
switch (a->type) {
switch (a->name) {
case A_AUTO:
dt = DW_ABRV_AUTO;
offs = a->aoffset - PtrSize;
......
......@@ -1411,11 +1411,11 @@ genasmsym(void (*put)(LSym*, char*, int, vlong, vlong, int, LSym*))
for(a=s->autom; a; a=a->link) {
// Emit a or p according to actual offset, even if label is wrong.
// This avoids negative offsets, which cannot be encoded.
if(a->type != A_AUTO && a->type != A_PARAM)
if(a->name != A_AUTO && a->name != A_PARAM)
continue;
// compute offset relative to FP
if(a->type == A_PARAM)
if(a->name == A_PARAM)
off = a->aoffset;
else
off = a->aoffset - PtrSize;
......
......@@ -87,7 +87,7 @@ savedata(Link *ctxt, LSym *s, Prog *p, char *pn)
ctxt->diag("data out of order (already have %d)\n%P", p);
symgrow(ctxt, s, off+siz);
if(p->to.type == ctxt->arch->D_FCONST) {
if(p->to.type == TYPE_FCONST) {
switch(siz) {
default:
case 4:
......@@ -102,10 +102,10 @@ savedata(Link *ctxt, LSym *s, Prog *p, char *pn)
s->p[off+i] = cast[fnuxi8[i]];
break;
}
} else if(p->to.type == ctxt->arch->D_SCONST) {
} else if(p->to.type == TYPE_SCONST) {
for(i=0; i<siz; i++)
s->p[off+i] = p->to.u.sval[i];
} else if(p->to.type == ctxt->arch->D_CONST) {
} else if(p->to.type == TYPE_CONST) {
if(p->to.sym)
goto addr;
o = p->to.offset;
......@@ -132,7 +132,7 @@ savedata(Link *ctxt, LSym *s, Prog *p, char *pn)
s->p[off+i] = cast[inuxi8[i]];
break;
}
} else if(p->to.type == ctxt->arch->D_ADDR) {
} else if(p->to.type == TYPE_ADDR) {
addr:
r = addrel(s);
r->off = off;
......
......@@ -167,7 +167,7 @@ writeobj(Link *ctxt, Biobuf *b)
a = emallocz(sizeof *a);
a->asym = p->from.sym;
a->aoffset = p->from.offset;
a->type = ctxt->arch->symtype(&p->from);
a->name = p->from.name;
a->gotype = p->from.gotype;
a->link = curtext->autom;
curtext->autom = a;
......@@ -240,7 +240,7 @@ writeobj(Link *ctxt, Biobuf *b)
if(curtext == nil) // func _() {}
continue;
if(strcmp(p->to.sym->name, "go_args_stackmap") == 0) {
if(p->from.type != ctxt->arch->D_CONST || p->from.offset != FUNCDATA_ArgsPointerMaps)
if(p->from.type != TYPE_CONST || p->from.offset != FUNCDATA_ArgsPointerMaps)
ctxt->diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps");
p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", curtext->name), curtext->version);
}
......@@ -260,7 +260,7 @@ writeobj(Link *ctxt, Biobuf *b)
continue;
found = 0;
for(p = s->text; p != nil; p = p->link) {
if(p->as == ctxt->arch->AFUNCDATA && p->from.type == ctxt->arch->D_CONST && p->from.offset == FUNCDATA_ArgsPointerMaps) {
if(p->as == ctxt->arch->AFUNCDATA && p->from.type == TYPE_CONST && p->from.offset == FUNCDATA_ArgsPointerMaps) {
found = 1;
break;
}
......@@ -268,14 +268,10 @@ writeobj(Link *ctxt, Biobuf *b)
if(!found) {
p = appendp(ctxt, s->text);
p->as = ctxt->arch->AFUNCDATA;
p->from.type = ctxt->arch->D_CONST;
p->from.type = TYPE_CONST;
p->from.offset = FUNCDATA_ArgsPointerMaps;
if(ctxt->arch->thechar == '6' || ctxt->arch->thechar == '8')
p->to.type = ctxt->arch->D_EXTERN;
else {
p->to.type = ctxt->arch->D_OREG;
p->to.name = ctxt->arch->D_EXTERN;
}
p->to.type = TYPE_MEM;
p->to.name = NAME_EXTERN;
p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", s->name), s->version);
}
}
......@@ -285,7 +281,7 @@ writeobj(Link *ctxt, Biobuf *b)
mkfwd(s);
linkpatch(ctxt, s);
ctxt->arch->follow(ctxt, s);
ctxt->arch->addstacksplit(ctxt, s);
ctxt->arch->preprocess(ctxt, s);
ctxt->arch->assemble(ctxt, s);
linkpcln(ctxt, s);
}
......@@ -407,12 +403,12 @@ writesym(Link *ctxt, Biobuf *b, LSym *s)
for(a = s->autom; a != nil; a = a->link) {
wrsym(b, a->asym);
wrint(b, a->aoffset);
if(a->type == ctxt->arch->D_AUTO)
if(a->name == NAME_AUTO)
wrint(b, A_AUTO);
else if(a->type == ctxt->arch->D_PARAM)
else if(a->name == NAME_PARAM)
wrint(b, A_PARAM);
else
sysfatal("%s: invalid local variable type %d", s->name, a->type);
sysfatal("%s: invalid local variable type %d", s->name, a->name);
wrsym(b, a->gotype);
}
......@@ -649,7 +645,7 @@ overwrite:
a = emallocz(sizeof *a);
a->asym = rdsym(ctxt, f, pkg);
a->aoffset = rdint(f);
a->type = rdint(f);
a->name = rdint(f);
a->gotype = rdsym(ctxt, f, pkg);
a->link = s->autom;
s->autom = a;
......
......@@ -77,7 +77,7 @@ linkpatch(Link *ctxt, LSym *sym)
for(p = sym->text; p != nil; p = p->link) {
if(ctxt->arch->progedit)
ctxt->arch->progedit(ctxt, p);
if(p->to.type != ctxt->arch->D_BRANCH)
if(p->to.type != TYPE_BRANCH)
continue;
if(p->to.u.branch != nil) {
// TODO: Remove to.u.branch in favor of p->pcond.
......@@ -100,7 +100,7 @@ linkpatch(Link *ctxt, LSym *sym)
if(p->to.sym)
name = p->to.sym->name;
ctxt->diag("branch out of range (%#ux)\n%P [%s]", c, p, name);
p->to.type = ctxt->arch->D_NONE;
p->to.type = TYPE_NONE;
}
p->to.u.branch = q;
p->pcond = q;
......@@ -111,7 +111,7 @@ linkpatch(Link *ctxt, LSym *sym)
if(p->pcond != nil) {
p->pcond = brloop(ctxt, p->pcond);
if(p->pcond != nil)
if(p->to.type == ctxt->arch->D_BRANCH)
if(p->to.type == TYPE_BRANCH)
p->to.offset = p->pcond->pc;
}
}
......
......@@ -291,7 +291,7 @@ linkpcln(Link *ctxt, LSym *cursym)
if(p->as == ctxt->arch->AFUNCDATA) {
i = p->from.offset;
pcln->funcdataoff[i] = p->to.offset;
if(p->to.type != ctxt->arch->D_CONST) {
if(p->to.type != TYPE_CONST) {
// TODO: Dedup.
//funcdata_bytes += p->to.sym->size;
pcln->funcdata[i] = p->to.sym;
......
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