commit ce395c866892026f04bedf55761dff941ee7ba78
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Mar 31 18:18:14 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Mar 31 18:18:14 2016 +0200

    [cc2] Remove label() from the target interface
    
    Label() was a really low level interface, which didn't fit
    properly with qbe.

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
index 167eb6f..9d3ce60 100644
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -132,16 +132,6 @@ size2asm(Type *tp)
 
 
 void
-defsym(Symbol *sym, int alloc)
-{
-       label(sym);
-       if (!alloc)
-               return;
-       size2asm(&sym->type);
-       puts("0");
-}
-
-void
 data(Node *np)
 {
        size2asm(&np->type);
@@ -149,7 +139,7 @@ data(Node *np)
        putchar('\n');
 }
 
-void
+static void
 label(Symbol *sym)
 {
        int seg, flags = sym->type.flags;
@@ -184,6 +174,16 @@ label(Symbol *sym)
 }
 
 void
+defsym(Symbol *sym, int alloc)
+{
+       label(sym);
+       if (!alloc)
+               return;
+       size2asm(&sym->type);
+       puts("0");
+}
+
+void
 writeout(void)
 {
 }
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
index 7d9f10d..d032c1b 100644
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -131,16 +131,6 @@ size2asm(Type *tp)
 }
 
 void
-defsym(Symbol *sym, int alloc)
-{
-       label(sym);
-       if (!alloc)
-               return;
-       size2asm(&sym->type);
-       puts("0");
-}
-
-void
 data(Node *np)
 {
        size2asm(&np->type);
@@ -148,7 +138,7 @@ data(Node *np)
        putchar('\n');
 }
 
-void
+static void
 label(Symbol *sym)
 {
        int seg, flags = sym->type.flags;
@@ -183,6 +173,16 @@ label(Symbol *sym)
 }
 
 void
+defsym(Symbol *sym, int alloc)
+{
+       label(sym);
+       if (!alloc)
+               return;
+       size2asm(&sym->type);
+       puts("0");
+}
+
+void
 writeout(void)
 {
 }
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 6143deb..7c75e3a 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -18,11 +18,6 @@ data(Node *np)
 }
 
 void
-label(Symbol *sym)
-{
-}
-
-void
 writeout(void)
 {
 }
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index 1d2cba3..e2223af 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -59,7 +59,7 @@ code(int op, Node *to, Node *from)
 {
 }
 
-void
+static void
 label(Symbol *sym)
 {
        int seg, flags = sym->type.flags;
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 77c6a6e..b6257ed 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -162,7 +162,6 @@ extern void generate(void);
 extern void peephole(void);
 
 /* code.c */
-extern void label(Symbol *sym);
 extern void data(Node *np);
 extern void defsym(Symbol *sym, int alloc);
 extern void writeout(void);
diff --git a/cc2/parser.c b/cc2/parser.c
index 9f59c9f..83e8ecd 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -498,25 +498,35 @@ array(void)
 static void
 decl(Symbol *sym)
 {
-       switch (sym->kind) {
-       case EXTRN:
-               defsym(sym, 0);
-               break;
-       case GLOB:
-       case PRIVAT:
-       case LOCAL:
-               defsym(sym, !ininit);
-               break;
-       case AUTO:
-       case REG:
-               if (funpars >= 0) {
-                       if (funpars == NR_FUNPARAM)
-                               error(EOUTPAR);
-                       params[funpars++] = sym;
+       int alloc;
+       Type *tp = &sym->type;
+
+       if (tp->flags & FUNF) {
+               curfun = sym;
+               return;
+       } else {
+               switch (sym->kind) {
+               case EXTRN:
+                       alloc = 0;
+                       break;
+               case GLOB:
+               case PRIVAT:
+               case LOCAL:
+                       alloc = (tp->flags & INITF) == 0;
                        break;
+               case AUTO:
+               case REG:
+                       if (funpars >= 0) {
+                               if (funpars == NR_FUNPARAM)
+                                       error(EOUTPAR);
+                               params[funpars++] = sym;
+                       }
+                       return;
+               default:
+                       abort();
                }
-               break;
        }
+       defsym(sym, alloc);
 }
 
 static void
@@ -544,14 +554,7 @@ vardecl(void)
 
        if (ininit)
                sym->type.flags |= INITF;
-
-       if ((tp->flags & FUNF) == 0) {
-               decl(sym);
-       } else {
-               curfun = sym;
-               label(sym);
-       }
-
+       decl(sym);
        delnode(np);
 }
 
@@ -632,6 +635,7 @@ endfun(void)
        np = newnode();
        np->op = ONOP;
        addnode(np);
+       /* TODO: process the function */
        curfun = NULL;
        funpars = -1;
        endf = 1;

Reply via email to