shithub: scc

Download patch

ref: 4d656cc381de1f2573bfc90a74a878a00f95148d
parent: 5ee0c779060595407f6042414f4bf9c1165634b9
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 17 02:25:43 EDT 2015

Remove payload in Node

This payload should be part of the symbol attached to the node.
In other case we have duplicated values in the node and in the
symbol.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -62,6 +62,10 @@
 			short off;
 		} v;
 		struct {
+			/* TODO: Admit inmediate of other type */
+			TINT imm;
+		} i;
+		struct {
 			short addr;
 		} l;
 		struct {
@@ -78,12 +82,8 @@
 	Type type;
 	uint8_t complex;
 	uint8_t addable;
-	union {
-		Symbol *sym;
-		/* TODO: Admit inmediate of other type */
-		TINT imm;
-		uint8_t reg;
-	} u;
+	uint8_t reg;
+	Symbol *sym;
 	struct node *left, *right;
 };
 
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -22,63 +22,63 @@
 Node
 reg_E = {
 	.op = REG,
-	.u.reg = E
+	.reg = E
 },
 reg_D = {
 	.op = REG,
-	.u.reg = D
+	.reg = D
 },
 reg_H = {
 	.op = REG,
-	.u.reg = H
+	.reg = H
 },
 reg_L = {
 	.op = REG,
-	.u.reg = L
+	.reg = L
 },
 reg_C = {
 	.op= REG,
-	.u.reg = C
+	.reg = C
 },
 reg_B = {
 	.op= REG,
-	.u.reg = B
+	.reg = B
 },
 reg_A = {
 	.op= REG,
-	.u.reg = A
+	.reg = A
 },
 reg_IYL = {
 	.op = REG,
-	.u.reg = IYL
+	.reg = IYL
 },
 reg_IYH = {
 	.op = REG,
-	.u.reg = IYH
+	.reg = IYH
 },
 reg_DE = {
 	.op = REG,
-	.u.reg = DE
+	.reg = DE
 },
 reg_HL = {
 	.op = REG,
-	.u.reg = HL
+	.reg = HL
 },
 reg_BC = {
 	.op = REG,
-	.u.reg = BC
+	.reg = BC
 },
 reg_IX = {
 	.op = REG,
-	.u.reg = IX
+	.reg = IX
 },
 reg_IY = {
 	.op = REG,
-	.u.reg = IY
+	.reg = IY
 },
 reg_SP = {
 	.op = REG,
-	.u.reg = SP
+	.reg = SP
 };
 
 Node *regs[] = {
@@ -140,7 +140,7 @@
 		}
 		break;
 	case AUTO:
-		sym = np->u.sym;
+		sym = np->sym;
 		switch (np->type.size) {
 		case 1:
 			code(LDL, regs[reg], np);
@@ -266,7 +266,7 @@
 			accum(lp);
 			break;
 		case REG:
-			if (lp->u.reg != A)
+			if (lp->reg != A)
 				moveto(lp, A);
 			switch (rp->op) {
 			case REG:
@@ -285,7 +285,7 @@
 	add_A:
 		code(ADD, lp, rp);
 		np->op = REG;
-		np->u.reg = A;
+		np->reg = A;
 		break;
 	case 2:
 	case 4:
@@ -306,7 +306,12 @@
 			code(LDL, lp, rp);
 			break;
 		case REG:
+			code(MOV, lp, rp);
+			break;
 		case MEM:
+			index(lp);
+			code(LDL, lp, rp);
+			break;
 		default:
 			abort();
 		}
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -91,16 +91,16 @@
 {
 	switch (addr->kind = np->op) {
 	case REG:
-		addr->u.reg = np->u.reg;
+		addr->u.reg = np->reg;
 		break;
 	case CONST:
-		addr->u.i = np->u.imm;
+		/* TODO: Take the immediate from some place */
 		break;
 	case AUTO:
-		addr->u.i = np->u.sym->u.v.off;
+		addr->u.i = np->sym->u.v.off;
 		break;
 	case MEM:
-		addr->u.sym = np->u.sym;
+		addr->u.sym = np->sym;
 		break;
 	case INDEX:
 		break;
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -235,7 +235,7 @@
 
 	np->op = CONST;
 	np->type = *tp;
-	np->u.imm = i;
+	/* TODO: assign the integer to something */
 	np->left = np->right = NULL;
 }
 
@@ -299,7 +299,7 @@
 	Node *np = newnode();
 	Symbol *sym = symbol(t, token);
 
-	np->u.sym = sym;
+	np->sym = sym;
 	np->op = sym->u.v.sclass;
 	np->type = sym->u.v.type;
 	np->left = np->right = NULL;
@@ -361,7 +361,7 @@
 
 	np->left = np->right = NULL;
 	np->op = LABEL;
-	np->u.sym = local(token);
+	np->sym = local(token);
 	push(np);
 }