commit d2b15f1ea22699cecc79a9cf2a10c236b807a191
parent d7cd0ce876107c05e34c7c00cef311e2023a9352
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 24 Jan 2016 22:17:20 +0100
[cc2] Generate code for static variables no initialized
These variables must go to BSS.
Diffstat:
5 files changed, 47 insertions(+), 6 deletions(-)
diff --git 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)
{
}
diff --git 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)
{
}
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
@@ -104,15 +104,16 @@ emittree(Node *np)
}
}
-void
-data(Node *np)
+
+static void
+size2asm(Type *tp)
{
char *s;
/*
* In z80 we can ignore the alignment
*/
- switch (np->type.size) {
+ switch (tp->size) {
case 1:
s = "\tDB\t";
break;
@@ -123,10 +124,23 @@ data(Node *np)
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');
}
diff --git a/cc2/cc2.h b/cc2/cc2.h
@@ -153,6 +153,7 @@ extern void peephole(void);
/* code.c */
extern void label(Symbol *sym);
extern void data(Node *np);
+extern void allocdata(Type *tp);
extern void writeout(void);
/* node.c */
diff --git a/cc2/parser.c b/cc2/parser.c
@@ -208,9 +208,11 @@ constant(char *token, union tokenop u)
++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++);
@@ -349,6 +351,20 @@ vardecl(void)
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();
np = pop();