[hackers] [scc] Fix storage for functions in IR || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 8 Aug 2015 23:02:35 +0200 (CEST)

commit 1c925d70a8145ed26506926dc92c1afa4c92fb11
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Aug 8 21:18:18 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Aug 8 21:18:18 2015 +0200

    Fix storage for functions in IR
    
    There are three kind os static variables:
            - GLOBAL: Variable visibles to the full program
            - PRIVATE: Variable visible only in the current module
            - LOCAL: Variable visible only in the current function.
    
    This patch adds different flags for every one of them, and
    independent of the IS_STATIC flag.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7fd62f8..4506a6c 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -125,15 +125,17 @@ enum {
 
 /* symbol flags */
 enum {
- ISGLOBAL = 1,
- ISSTATIC = 2,
- ISAUTO = 4,
- ISREGISTER = 8,
- ISDEFINED = 16,
- ISFIELD = 32,
- ISEXTERN = 64,
- ISUSED = 128,
- ISCONSTANT = 256
+ ISSTATIC = 1,
+ ISAUTO = 2,
+ ISREGISTER = 4,
+ ISDEFINED = 8,
+ ISFIELD = 16,
+ ISEXTERN = 32,
+ ISUSED = 64,
+ ISCONSTANT = 128,
+ ISGLOBAL = 256,
+ ISPRIVATE = 512,
+ ISLOCAL = 1024
 };
 
 
diff --git a/cc1/code.c b/cc1/code.c
index ca9337b..2403f52 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -151,14 +151,17 @@ static void
 emitvar(Symbol *sym)
 {
         char c;
+ short flags = sym->flags;
 
- if (sym->flags & ISSTATIC)
- c = (sym->flags & ISGLOBAL) ? L_PRIVATE : L_STATIC;
- else if (sym->flags & ISGLOBAL)
+ if (flags & ISLOCAL)
+ c = L_LOCAL;
+ else if (flags & ISPRIVATE)
+ c = L_PRIVATE;
+ else if (flags & ISGLOBAL)
                 c = L_PUBLIC;
- else if (sym->flags & ISREGISTER)
+ else if (flags & ISREGISTER)
                 c = L_REGISTER;
- else if (sym->flags & ISFIELD)
+ else if (flags & ISFIELD)
                 c = L_FIELD;
         else
                 c = L_AUTO;
diff --git a/cc1/decl.c b/cc1/decl.c
index 5b8d0df..58f0458 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -461,6 +461,8 @@ internal(Symbol *sym, int sclass, Type *data)
                         initializer(sym);
                 /* TODO: check if the variable is extern and has initializer */
         }
+ if (sym->flags & ISSTATIC)
+ sym->flags |= ISLOCAL;
         emit(ODECL, sym);
 }
 
_AT_@ -471,10 +473,10 @@ external(Symbol *sym, int sclass, Type *data)
                 warn("empty declaration");
                 return;
         }
- sym->flags |= ISSTATIC|ISGLOBAL;
 
         if (sym->flags & (ISREGISTER|ISAUTO))
                 error("incorrect storage class for file-scope declaration");
+ sym->flags |= (sym->flags & ISSTATIC) ? ISPRIVATE : ISGLOBAL;
 
         if (sym->type->op == FTN && yytoken == '{') {
                 if (sym->token == TYPEIDEN)
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 93648ec..4b25f16 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -191,7 +191,6 @@ install(unsigned ns, Symbol *sym)
                 if (sym->flags & ISDEFINED)
                         return NULL;
                 sym->flags |= ISDEFINED;
- sym = yylval.sym;
         } else {
                 char *name = sym->name;
                 Symbol **h;
diff --git a/inc/cc.h b/inc/cc.h
index 050c904..41a1dda 100644
--- a/inc/cc.h
+++ b/inc/cc.h
_AT_@ -61,7 +61,7 @@ typedef unsigned bool;
 
 #define L_PUBLIC 'G'
 #define L_PRIVATE 'Y'
-#define L_STATIC 'T'
+#define L_LOCAL 'T'
 #define L_REGISTER 'R'
 #define L_FIELD 'M'
 #define L_AUTO 'A'
Received on Sat Aug 08 2015 - 23:02:35 CEST

This archive was generated by hypermail 2.3.0 : Sat Aug 08 2015 - 23:12:16 CEST