scc

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

commit 162d7ec1030b696b09740e1dc5494f1d644a53d6
parent 6ea8920a77633b7ea3190e2db5ba390a9cfc1f22
Author: Roberto E. Vargas Caballero <roberto.vargas@igrid-td.com>
Date:   Thu, 14 Apr 2016 08:24:31 +0200

[cc2] Add locals at the end of the list

We were inserting always in the head of the list, and it means
that the list had inverse order. This patch modifies it and
now the symbols are inserted at the end of the list.

Diffstat:
cc2/symbol.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/cc2/symbol.c b/cc2/symbol.c @@ -11,7 +11,7 @@ #define NR_SYMHASH 64 -static Symbol *symtab[NR_SYMHASH]; +static Symbol *symtab[NR_SYMHASH], *curlocal; static Symbol *locals; static int infunction; @@ -40,7 +40,7 @@ popctx(void) symtab[sym->id & NR_SYMHASH-1] = sym->h_next; freesym(sym); } - locals = NULL; + curlocal = locals = NULL; } Symbol * @@ -59,11 +59,12 @@ getsym(unsigned id) if (!sym) { sym = xcalloc(1, sizeof(*sym)); sym->id = id; - if (!infunction) { - sym->next = NULL; - } else { - sym->next = locals; - locals = sym; + if (infunction) { + if (!locals) + locals = sym; + if (curlocal) + curlocal->next = sym; + curlocal = sym; } sym->h_next = *htab; *htab = sym;