ref: 5b9afbb363cb05947f13429fbc69e0497d32a887
parent: f6438ea2b892167da0e192156793687279177952
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Mar 31 12:42:08 EDT 2016
[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.
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -132,9 +132,12 @@
void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
{
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
puts("0");
}
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -131,9 +131,12 @@
}
void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
{
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
puts("0");
}
--- 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)
{
}
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -162,9 +162,12 @@
}
void
-allocdata(Type *tp)
+defsym(Symbol *sym, int alloc)
{
- size2asm(tp);
+ label(sym);
+ if (!alloc)
+ return;
+ size2asm(&sym->type);
puts("0");
}
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -164,7 +164,7 @@
/* 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 */
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -500,14 +500,12 @@
{
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: