ref: d9bc0a023ad88e2a8848db1c0577c224c1b00fa3
parent: b50a3944fd28e8e2e607edf3836df821e0a49c0e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Mar 20 16:24:56 EDT 2015
Fix return generation
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -86,7 +86,7 @@
static void moveto(Node *np, uint8_t reg);
-static uint8_t
+static void
allocreg(Node *np)
{
static uint8_t reg8[] = {A, B, C, D, E, H, L, IYL, IY, 0};
@@ -106,9 +106,10 @@
}
for (bp = ary; c = *bp; ++bp) {
r = reguse[c];
- if (r && !r->used)
- continue;
- moveto(np, c);
+ if (!r || r->used) {
+ moveto(np, c);
+ return;
+ }
}
/* TODO: What to do here? */
abort();
@@ -363,11 +364,21 @@
code(JP, &retnode, NULL);
}
+static void
+nop(Node *np)
+{
+}
+
static void (*opnodes[])(Node *) = {
[OADD] = add,
[OSUB] = add,
[OASSIG] = assign,
- [ORET] = ret
+ [ORET] = ret,
+ [MEM] = nop,
+ [REG] = nop,
+ [AUTO] = nop,
+ [CONST] = nop,
+ [PAR] = nop
};
static void
@@ -399,18 +410,12 @@
(*opnodes[np->op])(np);
}
-static Node *
-applycgen(Node *np)
-{
- cgen(np, NULL);
- return NULL;
-}
-
void
generate(void)
{
uint8_t size = curfun->u.f.locals;
static short id = 1000;
+ Node **stmt, *np;
retlabel.id = id++;
@@ -425,7 +430,8 @@
code(PUSH, NULL, ®s[HL]);
}
- apply(applycgen);
+ for (stmt = curfun->u.f.body; np = *stmt; ++stmt)
+ cgen(np, NULL);
code(MOV, ®s[SP], ®s[IX]);
retlabel.u.pc = pc;