[hackers] [scc] Revert "[cc2] Minimal fix for type symbols" || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 12 Dec 2016 15:53:03 +0100 (CET)

commit 88b40779476d653a5777d0376e78fed4d1e2a938
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Dec 12 10:32:06 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Dec 12 14:58:30 2016 +0100

    Revert "[cc2] Minimal fix for type symbols"
    
    This reverts commit 5c3445da52cc656a9c415d1dcb8142ab9beb7400.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 9c59fdb..b476973 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -102,7 +102,7 @@ tmpnode(Node *np, Type *tp)
 
         if (!np)
                 np = newnode(OTMP);
- sym = getsym(TMPSYM, 1);
+ sym = getsym(TMPSYM);
         sym->type = np->type = *tp;
         sym->kind = STMP;
         np->u.sym = sym;
diff --git a/cc2/arch/qbe/optm.c b/cc2/arch/qbe/optm.c
index ccb20e3..8f3eb14 100644
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
_AT_@ -41,7 +41,7 @@ optm_dep(Node *np)
                 break;
         case OBRANCH:
                 if (!next->label) {
- sym = getsym(TMPSYM, 1);
+ sym = getsym(TMPSYM);
                         sym->kind = SLABEL;
                         next->label = sym;
                 }
diff --git a/cc2/cc2.h b/cc2/cc2.h
index d35e432..cb0d9c4 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -236,7 +236,7 @@ extern Node *nextstmt(void);
 
 /* symbol.c */
 #define TMPSYM 0
-extern Symbol *getsym(unsigned id, int islocal);
+extern Symbol *getsym(unsigned id);
 extern void popctx(void);
 extern void pushctx(void);
 extern void freesym(Symbol *sym);
diff --git a/cc2/code.c b/cc2/code.c
index c37a554..823612b 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -61,7 +61,7 @@ addr(Node *np, Addr *addr)
 Symbol *
 newlabel(void)
 {
- Symbol *sym = getsym(TMPSYM, 1);
+ Symbol *sym = getsym(TMPSYM);
 
         sym->kind = SLABEL;
         return sym;
diff --git a/cc2/parser.c b/cc2/parser.c
index f3e2e47..2b8b8e3 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -178,7 +178,7 @@ composed(char *token, union tokenop u)
 {
         Symbol *sym;
 
- sym = getsym(atoi(token+1), 0);
+ sym = getsym(atoi(token+1));
         push(&sym->type);
 }
 
_AT_@ -192,7 +192,7 @@ static void
 symbol(char *token, union tokenop u)
 {
         Node *np = newnode(u.op & 0xFF);
- Symbol *sym = getsym(atoi(token+1), 1);
+ Symbol *sym = getsym(atoi(token+1));
 
         sclass = u.op >> 8;
         np->u.sym = sym;
diff --git a/cc2/symbol.c b/cc2/symbol.c
index c42689a..ffd705f 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -33,24 +33,31 @@ pushctx(void)
 void
 popctx(void)
 {
- Symbol *sym, *next, **psym;
+ Symbol *sym, *next;
 
         infunction = 0;
         for (sym = locals; sym; sym = next) {
                 next = sym->next;
- if (sym->id != TMPSYM) {
- psym = &symtab[sym->id & NR_SYMHASH-1];
- while (*psym != sym)
- psym = &(*psym)->next;
- *psym = sym->h_next;
- }
+ /*
+ * Symbols are inserted in the hash in the inverted
+ * order they are found in locals and it is impossible
+ * to have a global over a local, because a local is
+ * any symbol defined in the body of a function,
+ * even if it has extern linkage.
+ * For this reason when we raich a symbol in the
+ * locals list we know that it is the head of it
+ * collision list and we can remove it assigning
+ * it h_next to the hash table position
+ */
+ if (sym->id != TMPSYM)
+ symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
                 freesym(sym);
         }
         curlocal = locals = NULL;
 }
 
 Symbol *
-getsym(unsigned id, int islocal)
+getsym(unsigned id)
 {
         Symbol **htab, *sym;
         static unsigned short num;
_AT_@ -68,7 +75,7 @@ getsym(unsigned id, int islocal)
                 sym->id = id;
                 if ((sym->numid = ++num) == 0)
                         error(EIDOVER);
- if (infunction && islocal) {
+ if (infunction) {
                         if (!locals)
                                 locals = sym;
                         if (curlocal)
Received on Mon Dec 12 2016 - 15:53:03 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 12 2016 - 16:00:30 CET