diff options
| author | Michael Forney <mforney@mforney.org> | 2024-04-19 23:34:09 -0700 | 
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2024-04-20 01:53:14 -0700 | 
| commit | 7b2ef1d8f8bb24376c5a79b1a9acec19dfe780f4 (patch) | |
| tree | 6bd566de27374920c97febdd43cdbc313a789485 | |
| parent | 6ffd48df61b75c728021d682c21b41d232c4b46c (diff) | |
| download | cproc-7b2ef1d8f8bb24376c5a79b1a9acec19dfe780f4.tar.xz | |
decl: Keep track of storage duration in struct decl
| -rw-r--r-- | cc.h | 1 | ||||
| -rw-r--r-- | decl.c | 15 | ||||
| -rw-r--r-- | qbe.c | 4 | 
3 files changed, 15 insertions, 5 deletions
| @@ -278,6 +278,7 @@ struct decl {  		struct {  			/* alignment of object storage (may be stricter than type requires) */  			int align; +			enum storageduration storage;  		} obj;  		struct {  			/* the function might have an "inline definition" (C11 6.7.4p7) */ @@ -710,6 +710,7 @@ declarator(struct scope *s, struct qualtype base, char **name, struct scope **fu  static struct decl *  parameter(struct scope *s)  { +	struct decl *d;  	char *name;  	struct qualtype t;  	enum storageclass sc; @@ -722,7 +723,9 @@ parameter(struct scope *s)  		error(&tok.loc, "parameter declaration has invalid storage-class specifier");  	t = declarator(s, t, &name, NULL, true);  	t.type = typeadjust(t.type, &t.qual); -	return mkdecl(name, DECLOBJECT, t.type, t.qual, LINKNONE); +	d = mkdecl(name, DECLOBJECT, t.type, t.qual, LINKNONE); +	d->u.obj.storage = SDAUTO; +	return d;  }  static void @@ -1019,6 +1022,10 @@ 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)) +				d->u.obj.storage = SDAUTO; +			else +				d->u.obj.storage = sc & SCTHREADLOCAL ? SDTHREAD : SDSTATIC;  			init = NULL;  			hasinit = false;  			if (consume(TASSIGN)) { @@ -1036,10 +1043,10 @@ decl(struct scope *s, struct func *f)  				}  				break;  			} -			if (d->linkage != LINKNONE || sc & SCSTATIC) -				emitdata(d, init); -			else +			if (d->u.obj.storage == SDAUTO)  				funcinit(f, d, init, hasinit); +			else +				emitdata(d, init);  			d->defined = true;  			break;  		case DECLFUNC: @@ -503,6 +503,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);  	scopeputdecl(s, d);  	f->namedecl = d; @@ -637,6 +638,7 @@ funclval(struct func *f, struct expr *e)  		break;  	case EXPRCOMPOUND:  		d = mkdecl(NULL, DECLOBJECT, e->type, e->qual, LINKNONE); +		d->u.obj.storage = SDAUTO;  		funcinit(f, d, e->u.compound.init, true);  		lval.addr = d->value;  		break; @@ -1328,7 +1330,7 @@ emitdata(struct decl *d, struct init *init)  	align = d->u.obj.align;  	for (cur = init; cur; cur = cur->next)  		cur->expr = eval(cur->expr); -	if (d->value->threadlocal) +	if (d->u.obj.storage == SDTHREAD)  		fputs("thread ", stdout);  	if (d->linkage == LINKEXTERN)  		fputs("export ", stdout); | 
