shithub: scc

Download patch

ref: 42b233b62500a046fc04180f067c48af7030b127
parent: 061575df4ee33bf59cd7ab7f82af38798391bd53
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Mar 21 02:39:31 EDT 2015

Add cast() wrapper in cc2

Sometimes casting are generated even if we have
the cast optimization, and it makes ore difficult
to test. This patch adds a wrapper that works only
with casting of equal size.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -433,12 +433,11 @@
 			abort();
 		}
 		code(op, lp, NULL);
-		if ((np->op = lp->op) == REG) {
-			np->reg = lp->reg;
-			reguse[A] = np;
-		}
-		np->sym = lp->sym;
 		lp->used = 1;
+		np->sym = lp->sym;
+		np->reg = lp->reg;
+		np->op = REG;
+		reguse[A] = np;
 		break;
 	default:
 		abort();
@@ -445,6 +444,23 @@
 	}
 }
 
+static void
+cast(Node *np)
+{
+	Node *lp = np->left;
+	uint8_t reg;
+
+	if (lp->type.size != np->type.size)
+		abort();
+	lp->used = 1;
+	np->sym = lp->sym;
+	if ((np->op = lp->op) == REG) {
+		reg = lp->reg;
+		np->reg = reg;
+		reguse[pair[reg]] = reguse[reg] = np;
+	}
+}
+
 static void (*opnodes[])(Node *) = {
 	[OADD] = add,
 	[OSUB] = add,
@@ -459,7 +475,8 @@
 	[OBAND] = add,
 	[OBXOR] = add,
 	[OCPL] = cpl,
-	[ONEG] = cpl
+	[ONEG] = cpl,
+	[OCAST] = cast
 };
 
 static void