From 729aa97b799f72afdec3604f96526760701f36bc Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Wed, 30 Mar 2016 12:04:43 -0400 Subject: cleanup error handling --- copy.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'copy.c') diff --git a/copy.c b/copy.c index ef2d01d..419b079 100644 --- a/copy.c +++ b/copy.c @@ -47,7 +47,6 @@ visitphi(Phi *p, Ref *cp, RList **w) break; } } - assert(!req(r, R)); update(p->to, r, cp, w); } @@ -65,6 +64,15 @@ visitins(Ins *i, Ref *cp, RList **w) } } +static void +subst(Ref *r, Ref *cp, Fn *fn) +{ + if (rtype(*r) == RTmp && req(copyof(*r, cp), R)) + err("temporary %%%s is used undefined", + fn->tmp[r->val].name); + *r = copyof(*r, cp); +} + void copy(Fn *fn) { @@ -93,8 +101,6 @@ copy(Fn *fn) u1 = u + fn->tmp[t].nuse; for (; utype) { - default: - diag("copy: invalid use"); case UPhi: visitphi(u->u.phi, cp, &w); break; @@ -103,6 +109,8 @@ copy(Fn *fn) break; case UJmp: break; + default: + die("invalid use %d", u->type); } } for (b=fn->start; b; b=b->link) { @@ -113,31 +121,19 @@ copy(Fn *fn) continue; } for (a=0; anarg; a++) - if (rtype(p->arg[a]) == RTmp) { - r = cp[p->arg[a].val]; - assert(!req(r, R)); - p->arg[a] = r; - } + subst(&p->arg[a], cp, fn); pp=&p->link; } for (i=b->ins; i-b->ins < b->nins; i++) { - r = cp[i->to.val]; + r = copyof(i->to, cp); if (!req(r, i->to)) { *i = (Ins){.op = ONop}; continue; } for (a=0; a<2; a++) - if (rtype(i->arg[a]) == RTmp) { - r = cp[i->arg[a].val]; - assert(!req(r, R)); - i->arg[a] = r; - } - } - if (rtype(b->jmp.arg) == RTmp) { - r = cp[b->jmp.arg.val]; - assert(!req(r, R)); - b->jmp.arg = r; + subst(&i->arg[a], cp, fn); } + subst(&b->jmp.arg, cp, fn); } if (debug['C']) { fprintf(stderr, "\n> Copy information:"); -- cgit 1.4.1