[hackers] [scc] [cc2] Move generation of numid to getsym() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 27 Apr 2016 20:46:34 +0200 (CEST)

commit 394f3485b1f97dc88cdc8d130f9a693d624c5d58
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Tue Apr 26 19:54:01 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Tue Apr 26 20:02:09 2016 +0200

    [cc2] Move generation of numid to getsym()
    
    This change frees to the target of doing this operation, and it also allows
    that some opimizations can use the numid field. It also has the drawback
    of gerating numids that will be not used, and it means that temporary
    labels are not going to be consecutive.

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
index 29617b8..368dfbf 100644
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
_AT_@ -45,8 +45,6 @@ symname(Symbol *sym)
                 }
         }
 
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
         sprintf(name, ".L%d", sym->numid);
 
         return name;
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
index f55ff66..b58a7f1 100644
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
_AT_@ -45,8 +45,6 @@ symname(Symbol *sym)
                 }
         }
 
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
         sprintf(name, ".L%d", sym->numid);
 
         return name;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index a5a01e0..02d0226 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -171,9 +171,6 @@ symname(Symbol *sym)
                         abort();
                 }
         }
-
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
         sprintf(buff, "%c.%u", c, sym->numid);
 
         return buff;
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index 8b200fd..cb22dac 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
_AT_@ -48,8 +48,6 @@ symname(Symbol *sym)
                 }
         }
 
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
         sprintf(name, ".%d", sym->numid);
 
         return name;
diff --git a/cc2/symbol.c b/cc2/symbol.c
index a761abf..c4fa4f8 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -48,6 +48,7 @@ Symbol *
 getsym(unsigned id)
 {
         Symbol **htab, *sym;
+ static unsigned short num;
 
         if (id > USHRT_MAX)
                 error(EBADID);
_AT_@ -60,6 +61,8 @@ getsym(unsigned id)
         if (!sym) {
                 sym = xcalloc(1, sizeof(*sym));
                 sym->id = id;
+ if ((sym->numid = ++num) == 0)
+ error(EIDOVER);
                 if (infunction) {
                         if (!locals)
                                 locals = sym;
Received on Wed Apr 27 2016 - 20:46:34 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 27 2016 - 20:48:28 CEST