shithub: scc

Download patch

ref: 0a32c4a074ed8411162f5d26b24dcf3206ba3bd6
parent: e915714cbfee3ac1d5bcfcbb3cda56939f64821e
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jun 7 05:19:17 EDT 2016

[cc2-qbe] Add assign() in cgen.c

We need to do assigments like temporal step in some of the operations
of the nodes, so having this function can make the code simpler.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -289,6 +289,32 @@
 	return np->right = cgen(tmp);
 }
 
+static Node *
+assign(Node *to, Node *from)
+{
+	Type *tp = &to->type;
+	int op;
+
+	switch (tp->size) {
+	case 1:
+		op = ASSTB;
+		break;
+	case 2:
+		op = ASSTH;
+		break;
+	case 4:
+		op = (tp->flags & INTF) ? ASSTW : ASSTS;
+		break;
+	case 8:
+		op = (tp->flags & INTF) ? ASSTL : ASSTD;
+		break;
+	default:
+		abort();
+	}
+	code(op, to, from, NULL);
+	return from;
+}
+
 /* TODO: Fix "memory leaks" */
 Node *
 cgen(Node *np)
@@ -379,24 +405,7 @@
 		abort();
 	case OASSIG:
 		abbrev(np);
-		switch (tp->size) {
-		case 1:
-			op = ASSTB;
-			break;
-		case 2:
-			op = ASSTH;
-			break;
-		case 4:
-			op = (tp->flags & INTF) ? ASSTW : ASSTS;
-			break;
-		case 8:
-			op = (tp->flags & INTF) ? ASSTL : ASSTD;
-			break;
-		default:
-			abort();
-		}
-		code(op, np->left, load(np, LOADR), NULL);
-		return np->right;
+		return assign(np->left, load(np, LOADR));
 	case OCOMMA:
 		return np->right;
 	case OCALL: