ref: d2b15f1ea22699cecc79a9cf2a10c236b807a191
parent: d7cd0ce876107c05e34c7c00cef311e2023a9352
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jan 24 17:17:20 EST 2016
[cc2] Generate code for static variables no initialized These variables must go to BSS.
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -3,6 +3,11 @@
#include "../../cc2.h"
void
+allocdata(Type *tp)
+{
+}
+
+void
data(Node *np)
{
}
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -3,6 +3,11 @@
#include "../../cc2.h"
void
+allocdata(Type *tp)
+{
+}
+
+void
data(Node *np)
{
}
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -104,8 +104,9 @@
}
}
-void
-data(Node *np)
+
+static void
+size2asm(Type *tp)
{
char *s;
@@ -112,7 +113,7 @@
/*
* In z80 we can ignore the alignment
*/
- switch (np->type.size) {
+ switch (tp->size) {
case 1:
s = "\tDB\t";
break;
@@ -123,10 +124,23 @@
s = "\tDD\t";
break;
default:
- s = "\tDS\t";
+ s = (tp->flags & STRF) ? "\tTEXT\t" : "\tDS\t%llu,";
break;
}
- fputs(s, stdout);
+ printf(s, (unsigned long long) tp->size);
+}
+
+void
+allocdata(Type *tp)
+{
+ size2asm(tp);
+ puts("0");
+}
+
+void
+data(Node *np)
+{
+ size2asm(&np->type);
emittree(np);
putchar('\n');
}
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -153,6 +153,7 @@
/* code.c */
extern void label(Symbol *sym);
extern void data(Node *np);
+extern void allocdata(Type *tp);
extern void writeout(void);
/* node.c */
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -208,9 +208,11 @@
++token;
if (*token == OSTRING) {
+ ++token;
np->op = OSTRING;
np->type.flags = STRF;
- np->u.s = xstrdup(++token);
+ np->type.size = strlen(token);
+ np->u.s = xstrdup(token);
} else {
np->op = OCONST;
np->type = *gettype(token++);
@@ -348,6 +350,20 @@
Node *np;
Symbol *sym;
char *name;
+
+ if (lastsym && (lastsym->type.flags & INITF) == 0) {
+ switch (lastsym->kind) {
+ case EXTRN:
+ label(lastsym);
+ break;
+ case GLOB:
+ case PRIVAT:
+ case LOCAL:
+ label(lastsym);
+ allocdata(&lastsym->type);
+ break;
+ }
+ }
name = pop();
tp = pop();