scc

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

commit 1fb38e3bfef9e594f46b257c63ed0acb6c9a1cba
parent 05bdb414f7c5f42f335679f0c3461c391e0ed20c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 17 Mar 2015 14:03:10 +0000

Fix generation of immediate and register nodes

These nodes were broken after the last commits, and this commit fix them
although it introduces some new problems (for example a memory leak),
but they will be fixed later.

Diffstat:
Mcc2/cc2.h | 9++-------
Mcc2/cgen.c | 2+-
Mcc2/code.c | 2+-
Mcc2/parser.c | 5++++-
4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -56,16 +56,14 @@ struct symbol { bool public : 1; bool extrn : 1; union { + /* TODO: Admit inmediate of other type */ + TINT imm; struct { Type type; char sclass; short off; } v; struct { - /* TODO: Admit inmediate of other type */ - TINT imm; - } i; - struct { short addr; } l; struct { @@ -124,9 +122,6 @@ enum { SP = NREGS, AF, HL, DE, BC, IX, IY }; -extern Type Funct, l_int8, l_int16, l_int32, l_int64, - l_uint8, l_uint16, l_uint32, l_uint64; - extern Symbol *curfun; /* main.c */ diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -159,6 +159,7 @@ moveto(Node *np, uint8_t reg) abort(); } np->op = REG; + np->reg = reg; } static void @@ -353,7 +354,6 @@ cgen(Node *np, Node *parent) cgen(p, np); cgen(q, np); } - (*opnodes[np->op])(np); } diff --git a/cc2/code.c b/cc2/code.c @@ -94,7 +94,7 @@ addr(char op, Node *np, Addr *addr) addr->u.reg = np->reg; break; case CONST: - /* TODO: Take the immediate from some place */ + addr->u.i = np->sym->u.imm; break; case AUTO: addr->u.i = np->sym->u.v.off; diff --git a/cc2/parser.c b/cc2/parser.c @@ -234,8 +234,11 @@ imm(TINT i) np->op = CONST; np->type = l_int16; - /* TODO: assign the integer to something */ + /* FIX: memory leak */ + np->sym = xmalloc(sizeof(Symbol *)); + np->sym->u.imm = i; np->left = np->right = NULL; + return np; } static void