shithub: scc

Download patch

ref: 3650d591bcf2c9e4584b12228dd9f2c6f6145b8a
parent: 1bd29f0df1d13a8ef774b3954f7719bc5a690a4b
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 15 10:13:46 EDT 2016

[cc2-qbe] Fix load() in cgen.c

This load has to load the symbol into a temporary, but it was
doing a bad job.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -10,19 +10,29 @@
 };
 
 static Node *
-load(Node *np)
+tmpnode(Node *np)
 {
-	Node *new;
 	Symbol *sym;
 
-	new = newnode();
 	sym = getsym(TMPSYM);
 	sym->type = np->type;
-	new->u.sym = sym;
-	new->op = OLOAD;
+	sym->kind = TMP;
+	np->u.sym = sym;
+	np->op = OTMP;
+	np->flags |= ISTMP;
+	return np;
+}
+
+static Node *
+load(Node *np)
+{
+	Node *new;
+
+	new = tmpnode(newnode());
 	new->left = np;
 	new->type = np->type;
-	new->flags |= ISTMP;
+	code(OLOAD, new, np, NULL);
+
 	return new;
 }
 
@@ -67,15 +77,11 @@
 	case OBXOR:
 	case OCPL:
 		if ((l->flags & (ISTMP|ISCONS)) == 0)
-			np->left = load(l);
+			l = np->left = load(l);
 		if ((r->flags & (ISTMP|ISCONS)) == 0)
-			np->right = load(r);
-		sym = getsym(TMPSYM);
-		sym->type = np->type;
-		np->flags |= ISTMP;
-		np->u.sym = sym;
-		np->op = OTMP;
-		code(op, np, np->left, np->right);
+			r = np->right = load(r);
+		tmpnode(np);
+		code(op, np, l, r);
 		return np;
 	case ONOP:
 	case OBLOOP:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -223,6 +223,7 @@
 	switch (a->kind) {
 	case AUTO:
 	case LABEL:
+	case TMP:
 		return symname(a->u.sym);
 	default:
 		abort();
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -40,7 +40,7 @@
 	STRING   = '"',
 	LABEL    = 'L',
 	INDEX    = 'I',
-	OTMP     = 'T',
+	TMP      = 'T',
 	/* storage class */
 	GLOB     = 'G',
 	EXTRN    = 'X',
@@ -49,6 +49,7 @@
 	MEMBER   = 'M',
 	/* operands */
 	OMEM     = 'M',
+	OTMP     = 'T',
 	OAUTO    = 'A',
 	OREG     = 'R',
 	OCONST   = '#',