shithub: scc

Download patch

ref: 0e5ae348472d5ffb37f27761e190c6208554cb9c
parent: 04331f0a06574d3af45fe75f7264dd4a709cb5fc
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 17 17:15:18 EDT 2015

Allow assignations as expression

This is another step to have full support for expressions. With this step
we can see more cases and continue building the primitives.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -1,5 +1,5 @@
 
-#include <stdarg.h>
+#include <assert.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
@@ -140,6 +140,9 @@
 		case INDEX:
 			code(LDI, r, np);
 			break;
+		case REG:
+			code(MOV, r, np);
+			break;
 		default:
 			abort();
 		}
@@ -313,6 +316,7 @@
 {
 	Node *lp = np->left, *rp = np->right;
 
+	assert(rp->op == REG);
 	switch (np->type.size) {
 	case 1:
 		switch (lp->op) {
@@ -320,9 +324,11 @@
 			code(LDL, lp, rp);
 			break;
 		case REG:
+			/* TODO: what happens with the previous register? */
 			code(MOV, lp, rp);
 			break;
 		case MEM:
+			/* TODO: check if the variable is indexed */
 			index(lp);
 			code(LDL, lp, rp);
 			break;
@@ -333,6 +339,8 @@
 	default:
 		abort();
 	}
+	np->op = REG;
+	np->reg = rp->reg;
 }