commit 9b1fb289b5fcb87d7f1b2b64372d476a20f4e7f1
parent c6d93597a53015d6c31c8aebc789075196493a89
Author: Roberto E. Vargas Caballero <roberto.vargas@igrid-td.com>
Date: Thu, 31 Mar 2016 16:42:08 +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.
Diffstat:
6 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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: