summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-07-15 13:23:37 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:28 -0400
commit7e53000a1fce22a89bdaa8b44df9ea23a4b8ce3e (patch)
tree0afa9b4cb1c3bb4dea994269e35197a5c1f75cad /lisc
parent60f60425cd1cd307cbf6012eb6d04115533ca094 (diff)
downloadroux-7e53000a1fce22a89bdaa8b44df9ea23a4b8ce3e.tar.gz
use argument array for all instructions
Diffstat (limited to 'lisc')
-rw-r--r--lisc/lisc.h6
-rw-r--r--lisc/parse.c18
-rw-r--r--lisc/ssa.c17
3 files changed, 19 insertions, 22 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index f49aa6f..e3ea528 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -74,8 +74,7 @@ enum {
 struct Ins {
 	short op;
 	Ref to;
-	Ref l;
-	Ref r;
+	Ref arg[2];
 };
 
 struct Phi {
@@ -111,8 +110,7 @@ struct Sym {
 		STmp,
 	} type;
 	char name[NString];
-	Blk *blk;
-	int pos;
+	int ndef, nuse;
 };
 
 struct Fn {
diff --git a/lisc/parse.c b/lisc/parse.c
index 0d647c1..a3f9e23 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -226,7 +226,6 @@ varref(char *v)
 		err("too many symbols");
 	sym[t].type = STmp;
 	strcpy(sym[t].name, v);
-	sym[t].blk = 0;
 	ntmp++;
 	return SYM(t);
 }
@@ -417,8 +416,8 @@ parseline(PState ps)
 			err("too many instructions in block");
 		curi->op = op;
 		curi->to = r;
-		curi->l = arg[0];
-		curi->r = arg[1];
+		curi->arg[0] = arg[0];
+		curi->arg[1] = arg[1];
 		curi++;
 		return PIns;
 	} else {
@@ -445,11 +444,8 @@ parsefn(FILE *f)
 		bmap[i].name[0] = 0;
 		bmap[i].blk = 0;
 	}
-	for (i=Tmp0; i<NSym; i++) {
-		sym[i].type = SUndef;
-		sym[i].name[0] = 0;
-		sym[i].blk = 0;
-	}
+	for (i=Tmp0; i<NSym; i++)
+		sym[i] = (Sym){.type = SUndef};
 	ntmp = Tmp0;
 	curi = ins;
 	curb = 0;
@@ -461,6 +457,8 @@ parsefn(FILE *f)
 	do
 		ps = parseline(ps);
 	while (ps != PEnd);
+	if (!curb)
+		err("empty file");
 	if (curb->jmp.type == JXXX)
 		err("last block misses jump");
 	fn->sym = alloc(ntmp * sizeof sym[0]);
@@ -517,11 +515,11 @@ printfn(Fn *fn, FILE *f)
 			n = opdesc[i->op].arity;
 			if (n > 0) {
 				fprintf(f, " ");
-				printref(i->l, fn, f);
+				printref(i->arg[0], fn, f);
 			}
 			if (n > 1) {
 				fprintf(f, ", ");
-				printref(i->r, fn, f);
+				printref(i->arg[1], fn, f);
 			}
 			fprintf(f, "\n");
 		}
diff --git a/lisc/ssa.c b/lisc/ssa.c
index 637ac80..c08d6b1 100644
--- a/lisc/ssa.c
+++ b/lisc/ssa.c
@@ -156,10 +156,10 @@ ssafix(Fn *f, int t)
 			}
 		for (i=b->ins; i-b->ins < b->nins; i++) {
 			if (t1) {
-				if (req(i->l, rt))
-					i->l = SYM(t1);
-				if (req(i->r, rt))
-					i->r = SYM(t1);
+				if (req(i->arg[0], rt))
+					i->arg[0] = SYM(t1);
+				if (req(i->arg[1], rt))
+					i->arg[1] = SYM(t1);
 			}
 			if (req(i->to, rt)) {
 				t1 = f->ntmp++;
@@ -177,10 +177,10 @@ ssafix(Fn *f, int t)
 				if (req(p->arg[n], rt))
 					p->arg[n] = botdef(p->blk[n], f);
 		for (i=b->ins; i-b->ins < b->nins; i++) {
-			if (req(i->l, rt))
-				i->l = topdef(b, f);
-			if (req(i->r, rt))
-				i->r = topdef(b, f);
+			if (req(i->arg[0], rt))
+				i->arg[0] = topdef(b, f);
+			if (req(i->arg[1], rt))
+				i->arg[1] = topdef(b, f);
 		}
 		if (req(b->jmp.arg, rt))
 			b->jmp.arg = topdef(b, f);
@@ -190,6 +190,7 @@ ssafix(Fn *f, int t)
 	if (!f->sym)
 		abort();
 	for (t1=t0; t0<f->ntmp; t0++) {
+		f->sym[t0].type = STmp;
 		snprintf(f->sym[t0].name, NString, "%s_%d",
 			f->sym[t].name, t0-t1);
 	}