scc

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

commit 7b4b809f9c1352da0292da3ff3ffbb8f037792f4
parent 00f7f68edd041f8514eea2d5dc668551c8f2e4cd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Aug 2014 18:45:05 +0200

Fix correct order of children in cc2

cc2 was building an incorrect tree because it was changing left
and right, generating the inverse tree.

Diffstat:
cc2/cgen.c | 8+++++---
cc2/parser.c | 2+-
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -1,4 +1,5 @@ +#include <assert.h> #include <stdarg.h> #include <stdint.h> #include <stdlib.h> @@ -117,9 +118,10 @@ xcgen(Node *np) switch (np->op) { case OADD: - if (lp->op == CONST) { - off = rp->u.sym->u.v.off; - imm = lp->u.imm; + if (rp->op == CONST) { + /* TODO: check that it is AUTO */ + off = lp->u.sym->u.v.off; + imm = rp->u.imm; emit(LDI, A, imm&0xFF); emit(ADDX, A, IX, -(off+1)); emit(LD, L, A); diff --git a/cc2/parser.c b/cc2/parser.c @@ -210,8 +210,8 @@ operator(char *token) { Node *np = newnode(); - np->left = pop(); np->right = pop(); + np->left = pop(); np->type = gettype(token+1); np->op = token[0]; push(np);