ref: 4fafd289207621b7b95e606825acfe80404c5017
parent: 7e5eb0d9f025aab0d247d0566f1a970cdb18ece9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Mar 16 09:50:50 EDT 2015
Fix push() in cgen Push() was marking as pushed the static node that is used for registers, but it was not the node that was pushed. There were another problems, mainly related to pair register, because each element can represent different nodes.
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -11,6 +11,13 @@
static Node *reguse[NREGS];
static char upper[] = {[DE] = D, [HL] = H, [BC] = B, [IY] = IYH};
static char lower[] = {[DE] = E, [HL] = L, [BC] = C, [IY] = IYL};
+static char pair[] = {
+ [A] = A,
+ [H] = HL, [L] = HL,
+ [B] = BC, [C] = BC,
+ [D] = DE, [E] = DE,
+ [IYL] = IY, [IYH] = IY
+};
Node
reg_E = {
@@ -162,10 +169,17 @@
}
static void
-push(Node *np)
+push(uint8_t reg)
{
- code(PUSH, NULL, np);
- np->op = PUSHED;
+ Node *np;
+
+ if (reg < NREGS)
+ reg = pair[reg];
+ if ((np = reguse[lower[reg]]) != NULL)
+ np->op = PUSHED;
+ if ((np = reguse[upper[reg]]) != NULL)
+ np->op = PUSHED;
+ code(PUSH, NULL, regs[reg]);
}
static void
@@ -174,12 +188,12 @@
switch (np->type.size) {
case 1:
if (reguse[A])
- push(reguse[A]);
+ push(A);
moveto(np, A);
break;
case 2:
if (reguse[H] || reguse[L])
- push(®_HL);
+ push(HL);
moveto(np, HL);
break;
case 4:
@@ -192,7 +206,7 @@
index(Node *np)
{
if (reguse[H] || reguse[L])
- push(®_HL);
+ push(HL);
code(LDI, ®_HL, np);
reguse[H] = reguse[L] = np;
np->op = INDEX;