ref: 243a9a7629fb99ad8a62db46b3c9e249a8b575a4
parent: 24a097c15570c35a997628d0f0c553261d7254a7
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Apr 14 04:24:31 EDT 2016
[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.
--- 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 @@
symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
freesym(sym);
}
- locals = NULL;
+ curlocal = locals = NULL;
}
Symbol *
@@ -59,11 +59,12 @@
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;