ref: 37382404ddb754527377141d0e17fd9df287f643
parent: 0221fe4f3687d2482eceacdc21ae7389f4634640
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Mar 20 13:04:47 EDT 2015
Add used field in Nodes of cc2 This field allows to know when a node was already used and the register used by it can be reused.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -81,6 +81,7 @@
uint8_t addable;
uint8_t reg;
Symbol *sym;
+ bool used : 1;
struct node *left, *right;
};
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -86,20 +86,22 @@
{
static uint8_t reg8[] = {A, B, C, D, E, H, L, IYL, IY, 0};
static uint8_t reg16[] = {BC, DE, IY, 0};
- uint8_t *bp, c;
+ Node *np;
+ uint8_t *ary, *bp, c;
switch (size) {
case 1:
- bp = reg8;
+ ary = reg8;
break;
case 2:
- bp = reg16;
+ ary = reg16;
break;
default:
abort();
}
- while (c = *bp++) {
- if (reguse[c])
+ for (bp = ary; c = *bp; ++bp) {
+ np = reguse[c];
+ if (np && !np->used)
continue;
return c;
}
@@ -299,6 +301,7 @@
add1:
move(rp, np);
code((np->op == OADD) ? ADD : SUB, lp, rp);
+ lp->used = rp->used = 1;
np->op = REG;
np->reg = A;
reguse[A] = np;
@@ -315,7 +318,6 @@
Symbol *sym = lp->sym;
assert(rp->op == REG);
- /* TODO: what happens with the previous register? */
switch (np->type.size) {
case 1:
switch (lp->op) {
@@ -337,6 +339,7 @@
abort();
}
+ lp->used = 1;
np->op = REG;
np->reg = rp->reg;
}