diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-08-09 16:42:36 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-15 23:01:30 -0400 |
commit | 88d9573b7670d26ffb7c6ae666b73d0aa0f1b4db (patch) | |
tree | 729dc84e8e94a34a3b9c5215aa93345c5b420d50 | |
parent | e3b8ea4904deec4fb071ef2f8433cafca26c9b7c (diff) | |
download | roux-88d9573b7670d26ffb7c6ae666b73d0aa0f1b4db.tar.gz |
attempt factoring store emission code
-rw-r--r-- | lisc/emit.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/lisc/emit.c b/lisc/emit.c index 2e76209..0ed3d7e 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -35,7 +35,8 @@ static char *rtoa[] = { [R15D] = "r15d", }; -static struct { char *s, *b; } rsub[] = { +enum { SSHORT, SBYTE }; +static char *rsub[][2] = { [RXX] = {"OH GOD!", "OH NO!"}, [RAX] = {"ax", "al"}, [RBX] = {"bx", "bl"}, @@ -147,7 +148,12 @@ eins(Ins i, Fn *fn, FILE *f) [OLoadsb] = "movsb", [OLoadub] = "movzb", }; - char *s; + static char *stoa[] = { + [OStore - OStore] = "l", + [OStores - OStore] = "w", + [OStoreb - OStore] = "b", + }; + int r; switch (i.op) { case OAdd: @@ -170,35 +176,23 @@ eins(Ins i, Fn *fn, FILE *f) eop("mov", i.arg[0], i.to, fn, f); break; case OStore: - if (rtype(i.arg[0]) == RCon) { + /* todo, fix inconsistency */ + if (rtype(i.arg[0]) == RCon) fprintf(f, "\tmovl "); - eref(i.arg[0], fn, f); - fprintf(f, ", "); - } else { - assert(rtype(i.arg[0]) == RReg); - fprintf(f, "\tmov %%%s, ", rtoa[i.arg[0].val]); - } - goto Store; + else + fprintf(f, "\tmov "); + eref(i.arg[0], fn, f); + if (0) { case OStores: - if (rtype(i.arg[0]) == RCon) { - fprintf(f, "\tmovw "); - eref(i.arg[0], fn, f); - fprintf(f, ", "); - } else { - assert(rtype(i.arg[0]) == RReg); - fprintf(f, "\tmovw %%%s, ", rsub[BASE(i.arg[0].val)].s); - } - goto Store; case OStoreb: - if (rtype(i.arg[0]) == RCon) { - fprintf(f, "\tmovb "); + fprintf(f, "\tmov%s ", stoa[i.op - OStore]); + if (rtype(i.arg[0]) == RReg) { + r = BASE(i.arg[0].val); + fprintf(f, "%%%s", rsub[r][i.op - OStores]); + } else eref(i.arg[0], fn, f); - fprintf(f, ", "); - } else { - assert(rtype(i.arg[0]) == RReg); - fprintf(f, "\tmovb %%%s, ", rsub[BASE(i.arg[0].val)].b); - } - Store: + } + fprintf(f, ", "); emem(i.arg[1], fn, f); fprintf(f, "\n"); break; @@ -239,7 +233,7 @@ eins(Ins i, Fn *fn, FILE *f) eop("mov $0,", i.to, R, fn, f); fprintf(f, "\tset%s %%%s\n", ctoa[i.op-OXSet], - rsub[BASE(i.to.val)].b); + rsub[BASE(i.to.val)][SBYTE]); break; } diag("emit: unhandled instruction (3)"); |