summary refs log tree commit diff
path: root/lisc/emit.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-18 19:11:48 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:32 -0400
commit6f09869ea139782fd97e80182a0645891bf548d5 (patch)
tree1de16ac33bbcbefaf64f572ead798cd5e4e3f023 /lisc/emit.c
parent627e45e330d44c55a8dcd8dfe8ebe1b3b091ef9e (diff)
downloadroux-6f09869ea139782fd97e80182a0645891bf548d5.tar.gz
move spill and emit to the new slot system
In emit, I worked a little to make sure that framesz works
when we change the size of the svec array (if we need more
alignments).
Diffstat (limited to 'lisc/emit.c')
-rw-r--r--lisc/emit.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index e9887ef..ce39168 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -280,12 +280,28 @@ eins(Ins i, Fn *fn, FILE *f)
 	}
 }
 
+static int
+framesz(Fn *fn)
+{
+	enum { N = sizeof (Fn){0}.svec / sizeof (Fn){0}.svec[0] };
+	int i, a, f;
+
+	f = 0;
+	for (i=N-1, a=1<<i; i>=0; i--, a/=2)
+		if (f == 0 || f - a == fn->svec[i])
+			f = fn->svec[i];
+	a = 1 << (N-2);
+	while (f % (2 * a) != a)
+		f += a - f % a;
+	return f * 16 / (1 << (N-1));
+}
+
 void
 emitfn(Fn *fn, FILE *f)
 {
 	Blk *b, *s;
 	Ins *i;
-	int c;
+	int c, fs;
 
 	fprintf(f,
 		".text\n"
@@ -295,6 +311,9 @@ emitfn(Fn *fn, FILE *f)
 		"\tpush %%rbp\n"
 		"\tmov %%rsp, %%rbp\n"
 	);
+	fs = framesz(fn);
+	if (fs)
+		fprintf(f, "\tsub $%d, %%rsp\n", fs);
 	for (b=fn->start; b; b=b->link) {
 		fprintf(f, ".L%s:\n", b->name);
 		for (i=b->ins; i-b->ins < b->nins; i++)