From f66a661359a39e10af01508ad02429517b8460e3 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 27 Apr 2024 15:06:32 -0700 Subject: Store enum constant value in struct decl --- cc.h | 2 +- decl.c | 1 + eval.c | 5 +++-- qbe.c | 7 ------- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cc.h b/cc.h index ce0d6ca..cb53b0d 100644 --- a/cc.h +++ b/cc.h @@ -287,6 +287,7 @@ struct decl { bool inlinedefn; bool isnoreturn; } func; + unsigned long long enumconst; enum builtinkind builtin; } u; }; @@ -553,7 +554,6 @@ struct block *mkblock(char *); struct value *mkglobal(struct decl *); struct value *mkintconst(unsigned long long); -unsigned long long intconstvalue(struct value *); struct func *mkfunc(struct decl *, char *, struct type *, struct scope *); void delfunc(struct func *); diff --git a/decl.c b/decl.c index 4e148ac..228c776 100644 --- a/decl.c +++ b/decl.c @@ -274,6 +274,7 @@ tagspec(struct scope *s) assert(i < LEN(inttypes)); } d = mkdecl(name, DECLCONST, et, QUALNONE, LINKNONE); + d->u.enumconst = value; d->value = mkintconst(value); d->next = enumconsts; enumconsts = d; diff --git a/eval.c b/eval.c index 7b3a576..98f5ec9 100644 --- a/eval.c +++ b/eval.c @@ -110,10 +110,11 @@ eval(struct expr *expr) t = expr->type; switch (expr->kind) { case EXPRIDENT: - if (expr->u.ident.decl->kind != DECLCONST) + d = expr->u.ident.decl; + if (d->kind != DECLCONST) break; expr->kind = EXPRCONST; - expr->u.constant.u = intconstvalue(expr->u.ident.decl->value); + expr->u.constant.u = d->u.enumconst; break; case EXPRCOMPOUND: if (expr->u.compound.decl->u.obj.storage != SDSTATIC) diff --git a/qbe.c b/qbe.c index 1cb87c8..33d6b71 100644 --- a/qbe.c +++ b/qbe.c @@ -163,13 +163,6 @@ mkintconst(unsigned long long n) return v; } -unsigned long long -intconstvalue(struct value *v) -{ - assert(v->kind == VALUE_INTCONST); - return v->u.i; -} - static struct value * mkfltconst(int kind, double n) { -- cgit v1.2.3