aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-19 23:51:25 -0700
committerMichael Forney <mforney@mforney.org>2024-04-20 01:53:14 -0700
commit7837920950b4afc06cff96d04f27149866251378 (patch)
treee8a7ad52a43acdc7e71793865513cf1f0d7a8aed
parent7b2ef1d8f8bb24376c5a79b1a9acec19dfe780f4 (diff)
qbe: Pass struct decl to mkglobal instead of fields from the decl
-rw-r--r--cc.h2
-rw-r--r--decl.c18
-rw-r--r--eval.c2
-rw-r--r--qbe.c15
4 files changed, 20 insertions, 17 deletions
diff --git a/cc.h b/cc.h
index b6effc7..fef4bca 100644
--- a/cc.h
+++ b/cc.h
@@ -542,7 +542,7 @@ void switchcase(struct switchcases *, unsigned long long, struct block *);
struct block *mkblock(char *);
-struct value *mkglobal(char *, bool, bool);
+struct value *mkglobal(struct decl *);
struct value *mkintconst(unsigned long long);
unsigned long long intconstvalue(struct value *);
diff --git a/decl.c b/decl.c
index eb5fc95..1bfce87 100644
--- a/decl.c
+++ b/decl.c
@@ -941,13 +941,8 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
}
}
d = mkdecl(name, kind, t, tq, linkage);
+ d->asmname = asmname;
scopeputdecl(s, d);
- if (kind == DECLFUNC || linkage != LINKNONE || sc & SCSTATIC) {
- if (asmname)
- name = asmname;
- d->value = mkglobal(name, linkage == LINKNONE && !asmname, sc & SCTHREADLOCAL);
- d->asmname = asmname;
- }
return d;
}
@@ -1022,10 +1017,12 @@ decl(struct scope *s, struct func *f)
d = declcommon(s, kind, name, asmname, t, tq, sc, prior);
if (d->u.obj.align < align)
d->u.obj.align = align;
- if (d->linkage == LINKNONE && !(sc & SCSTATIC))
+ if (d->linkage == LINKNONE && !(sc & SCSTATIC)) {
d->u.obj.storage = SDAUTO;
- else
+ } else {
d->u.obj.storage = sc & SCTHREADLOCAL ? SDTHREAD : SDSTATIC;
+ d->value = mkglobal(d);
+ }
init = NULL;
hasinit = false;
if (consume(TASSIGN)) {
@@ -1056,6 +1053,7 @@ decl(struct scope *s, struct func *f)
if (f && sc && sc != SCEXTERN) /* 6.7.1p7 */
error(&tok.loc, "function '%s' with block scope may only have storage class 'extern'", name);
d = declcommon(s, kind, name, asmname, t, tq, sc, prior);
+ d->value = mkglobal(d);
d->u.func.inlinedefn = d->linkage == LINKEXTERN && fs & FUNCINLINE && !(sc & SCEXTERN) && (!prior || prior->u.func.inlinedefn);
if (tok.kind == TLBRACE) {
if (!allowfunc)
@@ -1101,8 +1099,8 @@ stringdecl(struct expr *expr)
entry = mapput(&strings, &key);
d = *entry;
if (!d) {
- d = mkdecl(NULL, DECLOBJECT, expr->type, QUALNONE, LINKNONE);
- d->value = mkglobal("string", true, false);
+ d = mkdecl("string", DECLOBJECT, expr->type, QUALNONE, LINKNONE);
+ d->value = mkglobal(d);
emitdata(d, mkinit(0, expr->type->size, (struct bitfield){0}, expr));
*entry = d;
}
diff --git a/eval.c b/eval.c
index 2c5a84f..7fe0fd9 100644
--- a/eval.c
+++ b/eval.c
@@ -119,7 +119,7 @@ eval(struct expr *expr)
if (expr->u.compound.storage != SDSTATIC)
break;
d = mkdecl(NULL, DECLOBJECT, t, expr->qual, LINKNONE);
- d->value = mkglobal(NULL, true, false);
+ d->value = mkglobal(d);
emitdata(d, expr->u.compound.init);
expr->kind = EXPRIDENT;
expr->u.ident.decl = d;
diff --git a/qbe.c b/qbe.c
index 83fe1ed..571cfaf 100644
--- a/qbe.c
+++ b/qbe.c
@@ -129,16 +129,21 @@ mkblock(char *name)
}
struct value *
-mkglobal(char *name, bool private, bool threadlocal)
+mkglobal(struct decl *d)
{
static unsigned id;
struct value *v;
v = xmalloc(sizeof(*v));
v->kind = VALUE_GLOBAL;
- v->u.name = name;
- v->id = private ? ++id : 0;
- v->threadlocal = threadlocal;
+ if (d->asmname) {
+ v->u.name = d->asmname;
+ v->id = 0;
+ } else {
+ v->u.name = d->name;
+ v->id = d->linkage == LINKNONE ? ++id : 0;
+ }
+ v->threadlocal = d->kind == DECLOBJECT && d->u.obj.storage == SDTHREAD;
return v;
}
@@ -504,7 +509,7 @@ mkfunc(struct decl *decl, char *name, struct type *t, struct scope *s)
t = mkarraytype(&typechar, QUALCONST, strlen(name) + 1);
d = mkdecl("__func__", DECLOBJECT, t, QUALNONE, LINKNONE);
d->u.obj.storage = SDSTATIC;
- d->value = mkglobal(d->name, true, false);
+ d->value = mkglobal(d);
scopeputdecl(s, d);
f->namedecl = d;