scc

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

commit 203eee14a2e6b32e23d94c0dfff68b32346609d3
parent 97c2741373af5f85c0538a671c51d22bb3ef1d97
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Aug 2014 16:27:32 +0200

Make list of variables and parameters of function

It is necessary to make this list because in the preambule of
the function we have to emit code for the list of local varibles
and parameters.

Diffstat:
cc2/cc2.h | 6+++++-
cc2/parser.c | 13++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -1,6 +1,7 @@ -typedef struct { +typedef struct symbol { char public; + struct symbol *next; union { struct { char type; @@ -11,6 +12,8 @@ typedef struct { } l; struct { char *name; + struct symbol *pars; + struct symbol *vars; } f; } u; } Symbol; @@ -46,6 +49,7 @@ enum nerrors { #define AUTO 'A' #define REGISTER 'R' #define STATIC 'T' +#define PARAMETER 'P' #define CONST '#' #define LABEL 'L' #define OADD '+' diff --git a/cc2/parser.c b/cc2/parser.c @@ -197,6 +197,17 @@ declaration(char *token) sym = (class == 'G') ? global(token) : local(token); + switch (class) { + case 'A': + sym->next = curfun->u.f.vars; + curfun->u.f.vars = sym; + case 'P': + sym->next = curfun->u.f.pars; + curfun->u.f.pars = sym; + break; + case 'G': case 'R': case 'T': + break; + } sym->u.v.storage = class; sym->u.v.type = gettype(strtok(NULL, "\t")); } @@ -254,7 +265,7 @@ parse(void) case 'S': /* struct */ break; - case 'T': case 'A': case 'R': + case 'T': case 'A': case 'R': case 'P': if (!funbody) goto syntax_error; fun = declaration;