summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-03 10:18:21 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:29 -0400
commit93601b6d0234875cf97e57b7e56fdd5a1803eac0 (patch)
tree7658243c9ae9346451bc5a9b66bbf6dd2870dd35
parent033dce6e17ea10997498e8fa189f6d079a6105b9 (diff)
downloadroux-93601b6d0234875cf97e57b7e56fdd5a1803eac0.tar.gz
patch isel to use symbol types
-rw-r--r--lisc/isel.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/lisc/isel.c b/lisc/isel.c
index 8585703..f933c92 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -24,6 +24,20 @@ emit(short op, Ref to, Ref arg0, Ref arg1)
 	*--curi = (Ins){op, to, {arg0, arg1}};
 }
 
+static int
+newsym(int type, Fn *fn)
+{
+	int s;
+
+	s = fn->nsym++;
+	fn->sym = realloc(fn->sym, fn->nsym * sizeof(Sym));
+	if (!fn->sym)
+		diag("isel: out of memory");
+	fn->sym[s] = (Sym){.type = type};
+	sprintf(fn->sym[s].name, "isel%d", s);
+	return s;
+}
+
 static void
 sel(Ins *i, Fn *fn)
 {
@@ -45,7 +59,7 @@ sel(Ins *i, Fn *fn)
 			/* immediates not allowed for
 			 * divisions in x86
 			 */
-			t = fn->ntmp++;
+			t = newsym(fn->sym[i->to.val].type, fn);
 			r0 = SYM(t);
 		} else
 			r0 = i->arg[1];
@@ -72,10 +86,8 @@ isel(Fn *fn)
 {
 	Blk *b;
 	Ins *i;
-	int t0, t;
 	uint nins;
 
-	t0 = fn->ntmp;
 	for (b=fn->start; b; b=b->link) {
 		curi = &insb[NIns];
 		for (i=&b->ins[b->nins]; i!=b->ins;) {
@@ -87,13 +99,4 @@ isel(Fn *fn)
 		memcpy(b->ins, curi, nins * sizeof b->ins[0]);
 		b->nins = nins;
 	}
-	if (fn->ntmp == t0)
-		return;
-	fn->sym = realloc(fn->sym, fn->ntmp * sizeof(Sym));
-	if (!fn->sym)
-		diag("isel: out of memory");
-	for (t=t0; t<fn->ntmp; t++) {
-		fn->sym[t].type = STmp;
-		sprintf(fn->sym[t].name, "isel%d", t-t0);
-	}
 }