scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0e5ae348472d5ffb37f27761e190c6208554cb9c
parent 04331f0a06574d3af45fe75f7264dd4a709cb5fc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 17 Mar 2015 21:15:18 +0000

Allow assignations as expression

This is another step to have full support for expressions. With this step
we can see more cases and continue building the primitives.

Diffstat:
Mcc2/cgen.c | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -1,5 +1,5 @@ -#include <stdarg.h> +#include <assert.h> #include <inttypes.h> #include <stdlib.h> @@ -140,6 +140,9 @@ moveto(Node *np, uint8_t reg) case INDEX: code(LDI, r, np); break; + case REG: + code(MOV, r, np); + break; default: abort(); } @@ -313,6 +316,7 @@ assign(Node *np) { Node *lp = np->left, *rp = np->right; + assert(rp->op == REG); switch (np->type.size) { case 1: switch (lp->op) { @@ -320,9 +324,11 @@ assign(Node *np) code(LDL, lp, rp); break; case REG: + /* TODO: what happens with the previous register? */ code(MOV, lp, rp); break; case MEM: + /* TODO: check if the variable is indexed */ index(lp); code(LDL, lp, rp); break; @@ -333,6 +339,8 @@ assign(Node *np) default: abort(); } + np->op = REG; + np->reg = rp->reg; }