shithub: scc

Download patch

ref: 7b4b809f9c1352da0292da3ff3ffbb8f037792f4
parent: 00f7f68edd041f8514eea2d5dc668551c8f2e4cd
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Aug 10 14:45:05 EDT 2014

Fix correct order of children in cc2

cc2 was building an incorrect tree because it was changing left
and right, generating the inverse tree.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -1,4 +1,5 @@
 
+#include <assert.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -117,9 +118,10 @@
 
 	switch (np->op) {
 	case OADD:
-		if (lp->op == CONST) {
-			off = rp->u.sym->u.v.off;
-			imm = lp->u.imm;
+		if (rp->op == CONST) {
+			/*  TODO: check that it is AUTO */
+			off = lp->u.sym->u.v.off;
+			imm = rp->u.imm;
 			emit(LDI, A, imm&0xFF);
 			emit(ADDX, A, IX, -(off+1));
 			emit(LD, L, A);
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -210,8 +210,8 @@
 {
 	Node *np = newnode();
 
-	np->left = pop();
 	np->right = pop();
+	np->left = pop();
 	np->type = gettype(token+1);
 	np->op = token[0];
 	push(np);
--