shithub: scc

Download patch

ref: 496963e823b09f572271baea68b42376b2c58ad4
parent: 6902f4ced599888da040b7abe331a07ddf88c46b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Mar 15 06:01:44 EDT 2015

Use a Node array instead of bool in reguse

We want to know whcich is the node which is using some register
so the best option is to keep it in the register array.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -8,7 +8,7 @@
 #include "cc2.h"
 
 
-static bool reguse[NREGS];
+static Node *reguse[NREGS];
 static char upper[] = {[DE] = D, [HL] = H, [BC] = B,  [IY] = IYH};
 static char lower[] = {[DE] = E, [HL] = L, [BC] = C, [IY] = IYL};
 
@@ -88,7 +88,7 @@
 allocreg(Node *np)
 {
 	static char reg8[] = {A, B, C, D, E, H, L, IYL, IY, 0};
-	static char reg16[] = {BC, HL, DE, IY, 0};
+	static char reg16[] = {BC, DE, IY, 0};
 	char *bp, c;
 
 	switch (np->type.size) {
@@ -96,7 +96,7 @@
 		for (bp = reg8; (c = *bp); ++bp) {
 			if (reguse[c])
 				continue;
-			reguse[c] = 1;
+			reguse[c] = np;
 			return c;
 		}
 		/* TODO: Move variable to stack using PUSH/POP */
@@ -107,8 +107,7 @@
 
 			if (reguse[u] || reguse[l])
 				continue;
-			reguse[l] = 1;
-			reguse[u];
+			reguse[u] = reguse[l] = np;
 			return c;
 		}
 		/* TODO: Move variable to stack using PUSH/POP */