diff options
author | Michael Forney <mforney@mforney.org> | 2024-04-27 15:06:32 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-04-27 15:34:27 -0700 |
commit | f66a661359a39e10af01508ad02429517b8460e3 (patch) | |
tree | bfc5ffdc688f02d8c36416bcfef2ce2727c5443f | |
parent | 4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (diff) |
Store enum constant value in struct decl
-rw-r--r-- | cc.h | 2 | ||||
-rw-r--r-- | decl.c | 1 | ||||
-rw-r--r-- | eval.c | 5 | ||||
-rw-r--r-- | qbe.c | 7 |
4 files changed, 5 insertions, 10 deletions
@@ -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 *); @@ -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; @@ -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) @@ -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) { |