ref: 7144207c5a7cc559901322704be568daf4df2eaf
parent: 47e8c646766773c8fda7e0fe44b10544c3f91695
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Mar 17 15:42:00 EDT 2015
Move reguse to index() and moveto() These are the places where the register are really reserved, so it is the best place for updating the status of the registers. We cannot merge index() and moveto() because one move the address while the other move the content.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -119,7 +119,8 @@
enum {
A = 1, B, C, D, E, H, L, IYL, IYH, NREGS,
- SP = NREGS, AF, HL, DE, BC, IX, IY
+ AF = NREGS, HL, DE, BC, IY, NPAIRS,
+ SP = NPAIRS, IX
};
extern Symbol *curfun;
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -99,22 +99,20 @@
switch (np->type.size) {
case 1:
- for (bp = reg8; (c = *bp); ++bp) {
- if (reguse[c])
- continue;
- return c;
- }
+ bp = reg8;
break;
case 2:
- for (bp = reg16; (c = *bp); ++bp) {
- char u = upper[c], l = lower[c];
-
- if (reguse[u] || reguse[l])
- continue;
- return c;
- }
+ bp = reg16;
break;
+ default:
+ abort();
}
+ while (c = *bp++) {
+ if (reguse[c])
+ continue;
+ return c;
+ }
+ /* TODO: What to do here? */
abort();
}
@@ -121,27 +119,35 @@
static void
moveto(Node *np, uint8_t reg)
{
- Symbol *sym = np->sym;
+ Node *r = regs[reg], *u = reguse[reg];
char op = np->op;
+ if (u) {
+ Symbol *sym = np->sym;
+ if (op == u->op && sym && sym == u->sym)
+ return;
+ else
+ ; /* TODO: Push the value? */
+ }
+
switch (np->type.size) {
case 1:
switch (op) {
- case CONST:
- code(LDI, regs[reg], np);
- break;
case AUTO:
- code(LDL, regs[reg], np);
+ code(LDL, r, np);
break;
+ case CONST:
+ case INDEX:
+ code(LDI, r, np);
+ break;
default:
abort();
}
- reguse[reg] = np;
break;
case 2:
switch (op) {
case CONST:
- code(LDL, regs[reg], np);
+ code(LDL, r, np);
break;
case AUTO:
code(LDL, regs[lower[reg]], np);
@@ -150,11 +156,12 @@
default:
abort();
}
- reguse[upper[reg]] = reguse[lower[reg]] = np;
+ reguse[upper[reg]] = reguse[lower[reg]] = np;
break;
default:
abort();
}
+ reguse[reg] = np;
np->op = REG;
np->reg = reg;
}
@@ -202,11 +209,20 @@
static void
index(Node *np)
{
- if (reguse[H] || reguse[L])
- push(HL);
+ Node *u = reguse[HL];
+
+ if (u) {
+ Symbol *sym = np->sym;
+
+ if (u->op == INDEX && sym && sym == u->sym) {
+ np->op = INDEX;
+ return;
+ } else
+ ; /* TODO: Push the value? */
+ }
code(LDI, ®_HL, np);
- reguse[H] = reguse[L] = np;
np->op = INDEX;
+ reguse[HL] = reguse[H] = reguse[L] = np;
}
static void