[hackers] [scc] [cc2] change label() + allocdata() to defsym() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 31 Mar 2016 18:24:48 +0200 (CEST)

commit 9b1fb289b5fcb87d7f1b2b64372d476a20f4e7f1
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Thu Mar 31 16:42:08 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
CommitDate: Thu Mar 31 16:42:08 2016 +0200

    [cc2] change label() + allocdata() to defsym()
    
    The parser was calling first to label() and later to allocdata(),
    mainly because this is the way how variable definitions are
    defined in assembler, but it doesn't fit properly with qbe,
    which means that the interface was really bad, and we need
    something more general.

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
index 833a25a..167eb6f 100644
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
_AT_@ -132,9 +132,12 @@ size2asm(Type *tp)
 
 
 void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
 {
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
         puts("0");
 }
 
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
index 5d6cf11..7d9f10d 100644
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
_AT_@ -131,9 +131,12 @@ size2asm(Type *tp)
 }
 
 void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
 {
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
         puts("0");
 }
 
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 8133d11..6143deb 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -8,7 +8,7 @@
 
 
 void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
 {
 }
 
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index b4b179d..1d2cba3 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
_AT_@ -162,9 +162,12 @@ size2asm(Type *tp)
 }
 
 void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
 {
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
         puts("0");
 }
 
diff --git a/cc2/cc2.h b/cc2/cc2.h
index c71049a..77c6a6e 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -164,7 +164,7 @@ extern void peephole(void);
 /* code.c */
 extern void label(Symbol *sym);
 extern void data(Node *np);
-extern void allocdata(Type *tp);
+extern void defsym(Symbol *sym, int alloc);
 extern void writeout(void);
 
 /* node.c */
diff --git a/cc2/parser.c b/cc2/parser.c
index 5ec1f9c..9f59c9f 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -500,14 +500,12 @@ decl(Symbol *sym)
 {
         switch (sym->kind) {
         case EXTRN:
- label(sym);
+ defsym(sym, 0);
                 break;
         case GLOB:
         case PRIVAT:
         case LOCAL:
- label(sym);
- if (!ininit)
- allocdata(&sym->type);
+ defsym(sym, !ininit);
                 break;
         case AUTO:
         case REG:
Received on Thu Mar 31 2016 - 18:24:48 CEST

This archive was generated by hypermail 2.3.0 : Thu Mar 31 2016 - 18:36:14 CEST