qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit ec5042148e6b9ac9d01130c93a95cbbd0d34b1c1
parent 03785fbc9a3f786ad49f2bc77518e739a7d4b469
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date:   Tue, 11 Aug 2015 13:40:54 -0400

fix my sloppy understanding of x86 assembly!

Diffstat:
Mlisc/emit.c | 47+++++++++++++++++++++++++++++------------------
Mlisc/isel.c | 21+--------------------
2 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/lisc/emit.c b/lisc/emit.c @@ -80,10 +80,25 @@ cneg(int cmp) } static void -eref(Ref r, Fn *fn, FILE *f) +econ(Con *c, FILE *f) { - Con *c; + switch (c->type) { + case CAddr: + fprintf(f, "%s", c->label); + if (c->val) + fprintf(f, "%+"PRId64, c->val); + break; + case CNum: + fprintf(f, "%"PRId64, c->val); + break; + default: + diag("econ: invalid constant"); + } +} +static void +eref(Ref r, Fn *fn, FILE *f) +{ switch (rtype(r)) { case RReg: fprintf(f, "%%%s", rtoa[r.val]); @@ -92,19 +107,8 @@ eref(Ref r, Fn *fn, FILE *f) fprintf(f, "-%d(%%rbp)", 8 * r.val); break; case RCon: - c = &fn->con[r.val]; - switch (c->type) { - case CAddr: - fprintf(f, "$%s", c->label); - if (c->val) - fprintf(f, "%+"PRId64, c->val); - break; - case CNum: - fprintf(f, "$%"PRId64, c->val); - break; - default: - diag("emitref: invalid constant"); - } + fprintf(f, "$"); + econ(&fn->con[r.val], f); break; default: diag("emitref: invalid reference"); @@ -114,10 +118,17 @@ eref(Ref r, Fn *fn, FILE *f) static void emem(Ref r, Fn *fn, FILE *f) { - if (rtype(r) == RSlot) + switch (rtype(r)) { + default: + diag("emem: invalid memory reference"); + case RSlot: eref(r, fn, f); - else { - assert(rtype(r)!=RReg || BASE(r.val)==r.val); + break; + case RCon: + econ(&fn->con[r.val], f); + break; + case RReg: + assert(BASE(r.val) == r.val); fprintf(f, "("); eref(r, fn, f); fprintf(f, ")"); diff --git a/lisc/isel.c b/lisc/isel.c @@ -115,34 +115,15 @@ sel(Ins i, Fn *fn) case OAdd: case OSub: case OCopy: - emit(i.op, i.to, i.arg[0], i.arg[1]); - break; case OStore: case OStoreb: case OStores: - r0 = i.arg[0]; - goto Load; case OLoad: case OLoadss: case OLoadus: case OLoadsb: case OLoadub: - r0 = i.arg[0]; - if (rtype(r0) == RCon) { - t = newtmp(TLong, fn); - r0 = TMP(t); - } - Load: - r1 = i.arg[1]; - if (rtype(r1) == RCon) { - t = newtmp(TLong, fn); - r1 = TMP(t); - } - emit(i.op, i.to, r0, r1); - if (!req(r0, i.arg[0])) - emit(OCopy, r0, i.arg[0], R); - if (!req(r1, i.arg[1])) - emit(OCopy, r1, i.arg[1], R); + emit(i.op, i.to, i.arg[0], i.arg[1]); break; case ONop: break;