summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-04 10:28:31 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-04 10:30:13 -0500
commit4467769253ea6f11a8899529c075249d8bc7d135 (patch)
tree2863bc97d13f06676a310b578d5ca656f3e37b1e
parent169411a220f4cb10c973d5bb613b4a6b9915efb7 (diff)
downloadroux-4467769253ea6f11a8899529c075249d8bc7d135.tar.gz
get rid of hard coded NBlk
-rw-r--r--lisc/lisc.h3
-rw-r--r--lisc/parse.c23
-rw-r--r--lisc/rega.c2
-rw-r--r--lisc/util.c2
4 files changed, 11 insertions, 19 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 5702182..3b43d47 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -78,7 +78,6 @@ enum Reg {
 enum {
 	NString = 32,
 	NPred   = 15,
-	NBlk    = 128,
 	NIns    = 256,
 	NAlign  = 3,
 	NSeg    = 32,
@@ -467,7 +466,7 @@ void diag(char *);
 void *emalloc(size_t);
 void *alloc(size_t);
 void freeall(void);
-Blk *bnew(void);
+Blk *blknew(void);
 void emit(int, int, Ref, Ref, Ref);
 void emiti(Ins);
 void idup(Ins **, Ins *, ulong);
diff --git a/lisc/parse.c b/lisc/parse.c
index 7798dcd..113ea9f 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -133,7 +133,7 @@ static Con *con;
 static int ntmp;
 static int ncon;
 static Phi **plink;
-static Blk *bmap[NBlk+1];
+static Blk **bmap;
 static Blk *curb;
 static Blk **blink;
 static int nblk;
@@ -466,17 +466,12 @@ findblk(char *name)
 {
 	int i;
 
-	assert(name[0]);
-	for (i=0; i<NBlk; i++)
-		if (!bmap[i] || strcmp(bmap[i]->name, name) == 0)
-			break;
-	if (i == NBlk)
-		err("too many blocks");
-	if (!bmap[i]) {
-		bmap[i] = bnew();
-		nblk++;
-		strcpy(bmap[i]->name, name);
-	}
+	for (i=0; i<nblk; i++)
+		if (strcmp(bmap[i]->name, name) == 0)
+			return bmap[i];
+	vgrow(&bmap, ++nblk);
+	bmap[i] = blknew();
+	strcpy(bmap[i]->name, name);
 	return bmap[i];
 }
 
@@ -640,7 +635,6 @@ DoOp:
 static Fn *
 parsefn()
 {
-	int i;
 	PState ps;
 	Fn *fn;
 
@@ -651,11 +645,10 @@ parsefn()
 	curi = insb;
 	tmp = vnew(ntmp, sizeof tmp[0]);
 	con = vnew(ncon, sizeof con[0]);
+	bmap = vnew(nblk, sizeof bmap[0]);
 	con[0].type = CBits;
 	fn = alloc(sizeof *fn);
 	blink = &fn->start;
-	for (i=0; i<NBlk; i++)
-		bmap[i] = 0;
 	if (peek() != TGlo)
 		rcls = parsecls(&fn->retty);
 	else
diff --git a/lisc/rega.c b/lisc/rega.c
index 5e10451..b50321c 100644
--- a/lisc/rega.c
+++ b/lisc/rega.c
@@ -564,7 +564,7 @@ rega(Fn *fn)
 			pmgen();
 			if (curi == insb)
 				continue;
-			b1 = bnew();
+			b1 = blknew();
 			b1->loop = (b->loop+s->loop) / 2;
 			b1->link = blist;
 			blist = b1;
diff --git a/lisc/util.c b/lisc/util.c
index 58c9b7d..cccbcf6 100644
--- a/lisc/util.c
+++ b/lisc/util.c
@@ -81,7 +81,7 @@ freeall()
 }
 
 Blk *
-bnew()
+blknew()
 {
 	static Blk z;
 	Blk *b;