summary refs log tree commit diff
path: root/lisc/emit.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-12 15:25:53 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit78bf28f56e7dcdd89efba5c69bd90ed858658162 (patch)
tree071be80e60e3d6ef0f4109112ac9a3803db5a896 /lisc/emit.c
parent8be35bf2be509f32d2fccc182743ae409838c4e4 (diff)
downloadroux-78bf28f56e7dcdd89efba5c69bd90ed858658162.tar.gz
add basic support for stack allocation
Diffstat (limited to 'lisc/emit.c')
-rw-r--r--lisc/emit.c13
1 files changed, 10 insertions, 3 deletions
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;