[hackers] [scc] [cc2] Remove label() from the target interface || Roberto E. Vargas Caballero

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

commit ce395c866892026f04bedf55761dff941ee7ba78
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Thu Mar 31 18:18:14 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
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
_AT_@ -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);
_AT_@ -149,7 +139,7 @@ data(Node *np)
         putchar('\n');
 }
 
-void
+static void
 label(Symbol *sym)
 {
         int seg, flags = sym->type.flags;
_AT_@ -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
_AT_@ -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);
_AT_@ -148,7 +138,7 @@ data(Node *np)
         putchar('\n');
 }
 
-void
+static void
 label(Symbol *sym)
 {
         int seg, flags = sym->type.flags;
_AT_@ -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
_AT_@ -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
_AT_@ -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
_AT_@ -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
_AT_@ -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
_AT_@ -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);
 }
 
_AT_@ -632,6 +635,7 @@ endfun(void)
         np = newnode();
         np->op = ONOP;
         addnode(np);
+ /* TODO: process the function */
         curfun = NULL;
         funpars = -1;
         endf = 1;
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:17 CEST