scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7c88dc7a0c96e24b53b0aeea66d74b3a757be2d4
parent c405c48a66cc5a7eeb192db81d42c08da2b19d73
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 12 Feb 2015 12:44:10 +0100

Add assign operation in cc2

This is a basic implementation, that only implements byte assignments.
It will be expanded later.

Diffstat:
cc2/cgen.c | 29+++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -104,22 +104,24 @@ cgen(Node *np, Node *parent) lp = np->left; rp = np->right; if (np->addable >= ADDABLE) { + if (parent && parent->op == OASSIG) + return; move(np); return; } if (!lp) { - cgen(rp); + cgen(rp, np); } else if (!rp) { - cgen(lp); + cgen(lp, np); } else { Node *p, *q; if (lp->complex > rp->complex) p = lp, q = rp; else p = rp, q = lp; - cgen(p); - cgen(q); + cgen(p, np); + cgen(q, np); } switch (np->op) { @@ -149,12 +151,31 @@ cgen(Node *np, Node *parent) code(LD, L, lower[lp->u.reg]); } code(ADD, lp->u.reg, rp->u.reg); + np->op = REG; + np->u.reg = lp->u.reg; break; case 4: case 8: abort(); } break; + case OASSIG: + switch (np->type->size) { + case 1: + switch (lp->op) { + case AUTO: + code(LDX, IX, lp->u.sym->u.v.off, rp->u.reg); + break; + case REG: + case MEM: + default: + abort(); + } + break; + default: + abort(); + } + break; default: abort(); }