scc

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

commit 00f81a75f35cbb0e33e92a0a3bf4486aa742427d
parent 09ca91a889f294f7cc61677ac57c16d8303248f2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 10 Sep 2014 22:58:10 +0200

Remove list of locals and parameters of cc2

These list is a non sense because we can calculate the
offset in each declaration. We lost know how much
arguments and locals has the function, but I think it
is not important (we can recover it later).

Diffstat:
Mcc2/cc2.h | 6++----
Mcc2/cgen.c | 19++-----------------
Mcc2/parser.c | 17++++++++---------
3 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -11,7 +11,6 @@ typedef struct symbol { bool public : 1; bool extrn : 1; char type; - struct symbol *next; union { struct { Type *type; @@ -22,9 +21,8 @@ typedef struct symbol { short addr; } l; struct { - short stack; - struct symbol *pars; - struct symbol *vars; + short locals; + short params; } f; } u; } Symbol; diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -9,21 +9,6 @@ #include <stdio.h> -void -genstack(Symbol *fun) -{ - Symbol *p; - short off; - - for (off = 0, p = fun->u.f.vars; p; p = p->next) { - if (p->u.v.sclass == AUTO) { - p->u.v.off = off; - off += p->u.v.type->align; - } - } - - fun->u.f.stack = off; -} enum { PUSH, POP, LD, ADD, RET, ADDI, LDI, ADDR, ADDX, ADCX, LDX @@ -144,13 +129,13 @@ cgen(Symbol *sym, Node *list[]) { extern char odebug; Node *np; - char frame = sym->u.f.stack != 0 || odebug; + char frame = sym->u.f.locals != 0 || odebug; emit(ADDR, sym->name); if (frame) { emit(PUSH, IX); emit(LD, IX, SP); - emit(LDI, HL, -sym->u.f.stack); + emit(LDI, HL, -sym->u.f.locals); emit(ADD, HL, SP); emit(LD, SP, HL); } diff --git a/cc2/parser.c b/cc2/parser.c @@ -83,6 +83,8 @@ parameter(char *num) static Symbol tbl[NR_FUNPARAM]; unsigned i = atoi(num); + if (!curfun) + error(ESYNTAX); if (i >= NR_FUNPARAM) error(EPARNUM); return &tbl[i]; @@ -94,6 +96,8 @@ local(char *num) static Symbol tbl[NR_INT_IDENT]; unsigned i = atoi(num); + if (!curfun) + error(ESYNTAX); if (i >= NR_INT_IDENT) error(EINTNUM); return &tbl[i]; @@ -366,7 +370,6 @@ endfunction(char *token) if (!curfun) error(ESYNTAX); listp = NULL; - genstack(curfun); genaddable(listexp); cgen(curfun, listexp); curfun = NULL; @@ -378,8 +381,6 @@ declaration(uint8_t t, char class, char *token) Symbol *sym = symbol(t, token); char *s; - if (t == LOCAL && !curfun) - error(ESYNTAX); if (sym->name) free(sym->name); memset(sym, 0, sizeof(*sym)); @@ -416,8 +417,6 @@ globdcl(char *token) error(ESYNTAX); sym->type = FUN; - sym->u.f.vars = NULL; - sym->u.f.pars = NULL; curfun = sym; listp = listexp; newp = nodepool; @@ -427,16 +426,16 @@ static void paramdcl(char *token) { Symbol *sym = declaration(PARAMETER, AUTO, token); - sym->next = curfun->u.f.pars; - curfun->u.f.pars = sym; + sym->u.v.off = -curfun->u.f.params; + curfun->u.f.params += sym->u.v.type->size; } static void localdcl(char *token) { Symbol *sym = declaration(LOCAL, token[0], token); - sym->next = curfun->u.f.vars; - curfun->u.f.vars = sym; + sym->u.v.off = -curfun->u.f.locals; + curfun->u.f.locals += sym->u.v.type->size; } void