shithub: scc

Download patch

ref: 8c5632d62fb15b51382e21845995469d75cd96ab
parent: c305b6f188a2d59e8ba7e87b6ee6761922d09447
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Mar 16 06:10:10 EDT 2015

Fix generation of INDEX operands

In this operands we want the address not the content.

--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -193,7 +193,8 @@
 {
 	if (reguse[H] || reguse[L])
 		push(&reg_HL);
-	code(MOV, &reg_HL, np);
+	code(LDI, &reg_HL, np);
+	reguse[H] = reguse[L] = np;
 	np->op = INDEX;
 }
 
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -133,9 +133,10 @@
 }
 
 static void
-addr2txt(Addr *a)
+addr2txt(char op, Addr *a)
 {
 	Symbol *sym;
+	char *fmt;
 
 	switch (a->kind) {
 	case REG:
@@ -154,9 +155,9 @@
 	case MEM:
 		sym = a->u.sym;
 		if (sym->name)
-			printf("(%s)", sym);
+			printf((op == LDI) ? "%s" : "(%s)", sym);
 		else
-			printf("(T%u)", sym->id);
+			printf((op == LDI) ? "T%u" : "(T%u)", sym->id);
 		break;
 	default:
 		abort();
@@ -172,8 +173,10 @@
 static void
 inst1(void)
 {
-	printf("\t%s\t", insttext[pc->op]);
-	addr2txt((pc->to.kind != NONE) ? &pc->to : &pc->from);
+	char op = pc->op;
+
+	printf("\t%s\t", insttext[op]);
+	addr2txt(op, (pc->to.kind != NONE) ? &pc->to : &pc->from);
 	putchar('\n');
 }
 
@@ -180,9 +183,11 @@
 static void
 inst2(void)
 {
-	printf("\t%s\t", insttext[pc->op]);
-	addr2txt(&pc->to);
+	char op = pc->op;
+
+	printf("\t%s\t", insttext[op]);
+	addr2txt(op, &pc->to);
 	putchar(',');
-	addr2txt(&pc->from);
+	addr2txt(op, &pc->from);
 	putchar('\n');
 }
--