aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-27 15:06:32 -0700
committerMichael Forney <mforney@mforney.org>2024-04-27 15:34:27 -0700
commitf66a661359a39e10af01508ad02429517b8460e3 (patch)
treebfc5ffdc688f02d8c36416bcfef2ce2727c5443f
parent4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (diff)
Store enum constant value in struct decl
-rw-r--r--cc.h2
-rw-r--r--decl.c1
-rw-r--r--eval.c5
-rw-r--r--qbe.c7
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)
{