summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-07-10 11:41:11 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:27 -0400
commit935ab611f0fd841f4f7e54c95ea2e57bba44f8ab (patch)
tree36e5e22c05a1c4f13bb313435d5e2101e9a6c726 /lisc
parent1d62b4bf478a17d7b825bb0064a50dba570dfe01 (diff)
downloadroux-935ab611f0fd841f4f7e54c95ea2e57bba44f8ab.tar.gz
add predecessor computation
Diffstat (limited to 'lisc')
-rw-r--r--lisc/lisc.h8
-rw-r--r--lisc/parse.c7
-rw-r--r--lisc/ssa.c39
3 files changed, 51 insertions, 3 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index dade1c8..bd17025 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -88,7 +88,9 @@ struct Blk {
 	Blk *s2;
 
 	char name[NString];
-	int rpo;
+	Blk *link;
+	Blk **preds;
+	int npreds;
 };
 
 struct Sym {
@@ -110,4 +112,8 @@ struct Fn {
 
 
 /* parse.c */
+void *alloc(size_t);
 Fn *parsefn(FILE *);
+
+/* ssa.c */
+void fillpreds(Fn *);
diff --git a/lisc/parse.c b/lisc/parse.c
index 6beb8a6..ad57d7e 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -53,6 +53,7 @@ static struct {
 	Blk *blk;
 } bmap[NBlks+1];
 static Blk *curb;
+static Blk **blink;
 
 static struct {
 	long long num;
@@ -200,6 +201,8 @@ blocka()
 
 	b = alloc(sizeof *b);
 	*b = zblock;
+	*blink = b;
+	blink = &b->link;
 	return b;
 }
 
@@ -441,8 +444,8 @@ parsefn(FILE *f)
 	curb = 0;
 	lnum = 1;
 	fn = alloc(sizeof *fn);
-	ps = parseline(PLbl);
-	fn->start = curb;  /* todo, it's a hack */
+	blink = &fn->start;
+	ps = PLbl;
 	do
 		ps = parseline(ps);
 	while (ps != PEnd);
diff --git a/lisc/ssa.c b/lisc/ssa.c
new file mode 100644
index 0000000..6f28634
--- /dev/null
+++ b/lisc/ssa.c
@@ -0,0 +1,39 @@
+#include "lisc.h"
+
+static void
+addpred(Blk *bp, Blk *bc)
+{
+	int i;
+
+	if (!bc->preds) {
+		bc->preds = alloc(bc->npreds * sizeof(Blk*));
+		for (i=0; i<bc->npreds; i++)
+			bc->preds[i] = 0;
+	}
+	for (i=0; bc->preds[i]; i++)
+		;
+	bc->preds[i] = bp;
+}
+
+void
+fillpreds(Fn *f)
+{
+	Blk *b;
+
+	for (b=f->start; b; b=b->link) {
+		b->npreds = 0;
+		free(b->preds);
+	}
+	for (b=f->start; b; b=b->link) {
+		if (b->s1)
+			b->s1->npreds++;
+		if (b->s2)
+			b->s2->npreds++;
+	}
+	for (b=f->start; b; b=b->link) {
+		if (b->s1)
+			addpred(b, b->s1);
+		if (b->s2)
+			addpred(b, b->s2);
+	}
+}