ref: 0a2a2afd4bc2e8c740c46a575419a35c54c83ca1
parent: 5b9afbb363cb05947f13429fbc69e0497d32a887
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Mar 31 14:18:14 EDT 2016
[cc2] Remove label() from the target interface Label() was a really low level interface, which didn't fit properly with qbe.
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -132,16 +132,6 @@
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 @@
putchar('\n');
}
-void
+static void
label(Symbol *sym)
{
int seg, flags = sym->type.flags;
@@ -181,6 +171,16 @@
if (sym->type.align != 1)
printf("\t.align\t%d\n",sym->type.align );
printf("%s:\n", name);
+}
+
+void
+defsym(Symbol *sym, int alloc)
+{
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
+ puts("0");
}
void
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -131,16 +131,6 @@
}
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 @@
putchar('\n');
}
-void
+static void
label(Symbol *sym)
{
int seg, flags = sym->type.flags;
@@ -180,6 +170,16 @@
if (sym->type.align != 1)
printf("\t.align\t%d\n",sym->type.align );
printf("%s:\n", name);
+}
+
+void
+defsym(Symbol *sym, int alloc)
+{
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
+ puts("0");
}
void
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -18,11 +18,6 @@
}
void
-label(Symbol *sym)
-{
-}
-
-void
writeout(void)
{
}
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -59,7 +59,7 @@
{
}
-void
+static void
label(Symbol *sym)
{
int seg, flags = sym->type.flags;
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -162,7 +162,6 @@
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);
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -498,25 +498,35 @@
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 @@
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 @@
np = newnode();
np->op = ONOP;
addnode(np);
+ /* TODO: process the function */
curfun = NULL;
funpars = -1;
endf = 1;