From 78bf28f56e7dcdd89efba5c69bd90ed858658162 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Wed, 12 Aug 2015 15:25:53 -0400 Subject: add basic support for stack allocation --- lisc/emit.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lisc/emit.c') diff --git a/lisc/emit.c b/lisc/emit.c index 15be31e..a08ad52 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -128,6 +128,7 @@ eins(Ins i, Fn *fn, FILE *f) static char *otoa[NOp] = { [OAdd] = "add", [OSub] = "sub", + [OAnd] = "and", [OLoad] = "mov", [OLoadss] = "movsw", [OLoadus] = "movzw", @@ -140,12 +141,13 @@ eins(Ins i, Fn *fn, FILE *f) [OStores - OStorel] = "w", [OStoreb - OStorel] = "b", }; - int r; + int reg; int64_t val; switch (i.op) { case OAdd: case OSub: + case OAnd: if (req(i.to, i.arg[1])) { if (i.op == OSub) { eop("neg", i.to, R, fn, f); @@ -177,8 +179,8 @@ eins(Ins i, Fn *fn, FILE *f) case OStoreb: fprintf(f, "\tmov%s ", stoa[i.op - OStorel]); if (rtype(i.arg[0]) == RReg) { - r = RBASE(i.arg[0].val); - fprintf(f, "%%%s", rsub[r][i.op - OStorel]); + reg = RBASE(i.arg[0].val); + fprintf(f, "%%%s", rsub[reg][i.op - OStorel]); } else eref(i.arg[0], fn, f); fprintf(f, ", "); @@ -200,6 +202,11 @@ eins(Ins i, Fn *fn, FILE *f) eref(i.to, fn, f); fprintf(f, "\n"); break; + case OAlloc: + eop("sub", i.arg[0], REG(RSP), fn, f); + if (!req(i.to, R)) + eop("mov", REG(RSP), i.to, fn ,f); + break; case OSwap: eop("xchg", i.arg[0], i.arg[1], fn, f); break; -- cgit 1.4.1