summary refs log tree commit diff
path: root/lisc/parse.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-13 16:10:54 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit5fc8104e00187335411e35ec951bef53562c8fcd (patch)
treeb4f26312a5eef7062c3aa8501a6a8f6efe77a675 /lisc/parse.c
parent78bf28f56e7dcdd89efba5c69bd90ed858658162 (diff)
downloadroux-5fc8104e00187335411e35ec951bef53562c8fcd.tar.gz
major lifting: get rid of RReg
I've been septic since I introduced it, this commit
proves that it costs more than it helps.  I've also fixed
a bad bug in rega() where I alloc'ed the wrong size for
internal arrays.  Enums now have names so I can use them
to cast in gdb to get the name corresponding to a constant.
Diffstat (limited to 'lisc/parse.c')
-rw-r--r--lisc/parse.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/lisc/parse.c b/lisc/parse.c
index fc35800..5a06911 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -257,7 +257,7 @@ tmpref(char *v, int use)
 {
 	int t;
 
-	for (t=0; t<ntmp; t++)
+	for (t=Tmp0; t<ntmp; t++)
 		if (strcmp(v, tmp[t].name) == 0)
 			goto Found;
 	if (ntmp++ >= NTmp)
@@ -496,9 +496,12 @@ parsefn(FILE *f)
 	for (i=0; i<NBlk; i++)
 		bmap[i] = 0;
 	for (i=0; i<NTmp; i++)
-		tmp[i] = (Tmp){.name = ""};
-	ntmp = 1; /* first tmp is invalid */
-	ncon = 1; /* first con in 0 */
+		if (i < Tmp0)
+			tmp[i] = (Tmp){.type = TReg};
+		else
+			tmp[i] = (Tmp){.name = ""};
+	ntmp = Tmp0;
+	ncon = 1; /* first constant must be 0 */
 	curi = insb;
 	curb = 0;
 	lnum = 1;
@@ -531,11 +534,15 @@ printref(Ref r, Fn *fn, FILE *f)
 		[TUndef] = "?",
 		[TWord] = "w",
 		[TLong] = "l",
+		[TReg] = "",
 	};
 
 	switch (r.type) {
 	case RTmp:
-		fprintf(f, "%%%s", fn->tmp[r.val].name);
+		if (r.val < Tmp0)
+			fprintf(f, "R%d", r.val);
+		else
+			fprintf(f, "%%%s", fn->tmp[r.val].name);
 		return ttoa[fn->tmp[r.val].type];
 	case RCon:
 		switch (fn->con[r.val].type) {
@@ -554,9 +561,6 @@ printref(Ref r, Fn *fn, FILE *f)
 	case RSlot:
 		fprintf(f, "$%d", r.val);
 		break;
-	case RReg:
-		fprintf(f, "R%d", r.val);
-		break;
 	}
 	return "";
 }