shithub: scc

Download patch

ref: 54e5f131aa340b2ad1ff8bf2cc23024029fa8b50
parent: 1fb38e3bfef9e594f46b257c63ed0acb6c9a1cba
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 17 10:42:51 EDT 2015

Inver switch order in moveto()

This new order will be better if we want to mark the register as used,
because the work done depends of the size.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -1,5 +1,4 @@
 
-#include <assert.h>
 #include <stdarg.h>
 #include <inttypes.h>
 #include <stdlib.h>
@@ -126,31 +125,31 @@
 static void
 moveto(Node *np, uint8_t reg)
 {
-	Symbol *sym;
+	Symbol *sym = np->sym;
+	char op = np->op;
 
-	switch (np->op) {
-	case CONST:
-		switch (np->type.size) {
-		case 1:
-		case 2:
+	switch (np->type.size) {
+	case 1:
+		switch (op) {
+		case CONST:
 			code(LDI, regs[reg], np);
 			break;
+		case AUTO:
+			code(LDL, regs[reg], np);
+			break;
 		default:
 			abort();
 		}
 		break;
-	case AUTO:
-		sym = np->sym;
-		switch (np->type.size) {
-		case 1:
+	case 2:
+		switch (op) {
+		case CONST:
 			code(LDL, regs[reg], np);
 			break;
-		case 2:
+		case AUTO:
 			code(LDL, regs[lower[reg]], np);
 			code(LDH, regs[upper[reg]], np);
 			break;
-		case 4:
-		case 8:
 		default:
 			abort();
 		}