diff options
author | Michael Forney <mforney@mforney.org> | 2021-09-29 14:47:02 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-09-29 14:47:41 -0700 |
commit | dbdab3ac59af6469e715f8ce9dfe3fdfc523cddf (patch) | |
tree | 27d82017b08acc1ebdb8b304e4105fac165a5297 | |
parent | 83e2a1c124a229351df23b336a44db1603862d98 (diff) |
Rename uint64_t field of constant union to u
This will prepare us for adding a signed int64_t field called i.
-rw-r--r-- | cc.h | 2 | ||||
-rw-r--r-- | decl.c | 4 | ||||
-rw-r--r-- | eval.c | 80 | ||||
-rw-r--r-- | expr.c | 14 | ||||
-rw-r--r-- | qbe.c | 12 |
5 files changed, 56 insertions, 56 deletions
@@ -327,7 +327,7 @@ struct expr { struct decl *decl; } ident; union { - uint64_t i; + uint64_t u; double f; } constant; struct { @@ -220,7 +220,7 @@ tagspec(struct scope *s) e = constexpr(s); if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) error(&tok.loc, "expected integer constant expression"); - i = e->constant.i; + i = e->constant.u; if (e->type->basic.issigned && i >= 1ull << 63) { if (i < -1ull << 31) goto invalid; @@ -564,7 +564,7 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs e = eval(assignexpr(s), EVALARITH); if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) error(&tok.loc, "VLAs are not yet supported"); - i = e->constant.i; + i = e->constant.u; if (e->type->basic.issigned && i > INT64_MAX) error(&tok.loc, "array length must be non-negative"); delexpr(e); @@ -17,12 +17,12 @@ cast(struct expr *expr) else if (expr->type->prop & PROPINT && expr->type->basic.issigned) size |= S; switch (size) { - case 1: expr->constant.i = (uint8_t)expr->constant.i; break; - case 1|S: expr->constant.i = (int8_t)expr->constant.i; break; - case 2: expr->constant.i = (uint16_t)expr->constant.i; break; - case 2|S: expr->constant.i = (int16_t)expr->constant.i; break; - case 4: expr->constant.i = (uint32_t)expr->constant.i; break; - case 4|S: expr->constant.i = (int32_t)expr->constant.i; break; + case 1: expr->constant.u = (uint8_t)expr->constant.u; break; + case 1|S: expr->constant.u = (int8_t)expr->constant.u; break; + case 2: expr->constant.u = (uint16_t)expr->constant.u; break; + case 2|S: expr->constant.u = (int16_t)expr->constant.u; break; + case 4: expr->constant.u = (uint32_t)expr->constant.u; break; + case 4|S: expr->constant.u = (int32_t)expr->constant.u; break; case 4|F: expr->constant.f = (float)expr->constant.f; break; } } @@ -37,47 +37,47 @@ binary(struct expr *expr, enum tokenkind op, struct expr *l, struct expr *r) op |= S; switch (op) { case TMUL: - case TMUL|S: expr->constant.i = l->constant.i * r->constant.i; break; + case TMUL|S: expr->constant.u = l->constant.u * r->constant.u; break; case TMUL|F: expr->constant.f = l->constant.f * r->constant.f; break; - case TDIV: expr->constant.i = l->constant.i / r->constant.i; break; - case TDIV|S: expr->constant.i = (int64_t)l->constant.i / (int64_t)r->constant.i; break; + case TDIV: expr->constant.u = l->constant.u / r->constant.u; break; + case TDIV|S: expr->constant.u = (int64_t)l->constant.u / (int64_t)r->constant.u; break; case TDIV|F: expr->constant.f = l->constant.f / r->constant.f; break; - case TMOD: expr->constant.i = l->constant.i % r->constant.i; break; - case TMOD|S: expr->constant.i = (int64_t)l->constant.i % (int64_t)r->constant.i; break; + case TMOD: expr->constant.u = l->constant.u % r->constant.u; break; + case TMOD|S: expr->constant.u = (int64_t)l->constant.u % (int64_t)r->constant.u; break; case TADD: - case TADD|S: expr->constant.i = l->constant.i + r->constant.i; break; + case TADD|S: expr->constant.u = l->constant.u + r->constant.u; break; case TADD|F: expr->constant.f = l->constant.f + r->constant.f; break; case TSUB: - case TSUB|S: expr->constant.i = l->constant.i - r->constant.i; break; + case TSUB|S: expr->constant.u = l->constant.u - r->constant.u; break; case TSUB|F: expr->constant.f = l->constant.f - r->constant.f; break; case TSHL: - case TSHL|S: expr->constant.i = l->constant.i << r->constant.i; break; - case TSHR: expr->constant.i = l->constant.i >> r->constant.i; break; - case TSHR|S: expr->constant.i = (int64_t)l->constant.i >> r->constant.i; break; + case TSHL|S: expr->constant.u = l->constant.u << r->constant.u; break; + case TSHR: expr->constant.u = l->constant.u >> r->constant.u; break; + case TSHR|S: expr->constant.u = (int64_t)l->constant.u >> r->constant.u; break; case TBAND: - case TBAND|S: expr->constant.i = l->constant.i & r->constant.i; break; + case TBAND|S: expr->constant.u = l->constant.u & r->constant.u; break; case TBOR: - case TBOR|S: expr->constant.i = l->constant.i | r->constant.i; break; + case TBOR|S: expr->constant.u = l->constant.u | r->constant.u; break; case TXOR: - case TXOR|S: expr->constant.i = l->constant.i ^ r->constant.i; break; - case TLESS: expr->constant.i = l->constant.i < r->constant.i; break; - case TLESS|S: expr->constant.i = (int64_t)l->constant.i < (int64_t)r->constant.i; break; - case TLESS|F: expr->constant.i = l->constant.f < r->constant.f; break; - case TGREATER: expr->constant.i = l->constant.i > r->constant.i; break; - case TGREATER|S: expr->constant.i = (int64_t)l->constant.i > (int64_t)r->constant.i; break; - case TGREATER|F: expr->constant.i = l->constant.f > r->constant.f; break; - case TLEQ: expr->constant.i = l->constant.i <= r->constant.i; break; - case TLEQ|S: expr->constant.i = (int64_t)l->constant.i <= (int64_t)r->constant.i; break; - case TLEQ|F: expr->constant.i = l->constant.f <= r->constant.f; break; - case TGEQ: expr->constant.i = l->constant.i >= r->constant.i; break; - case TGEQ|S: expr->constant.i = (int64_t)l->constant.i >= (int64_t)r->constant.i; break; - case TGEQ|F: expr->constant.i = l->constant.f >= r->constant.f; break; + case TXOR|S: expr->constant.u = l->constant.u ^ r->constant.u; break; + case TLESS: expr->constant.u = l->constant.u < r->constant.u; break; + case TLESS|S: expr->constant.u = (int64_t)l->constant.u < (int64_t)r->constant.u; break; + case TLESS|F: expr->constant.u = l->constant.f < r->constant.f; break; + case TGREATER: expr->constant.u = l->constant.u > r->constant.u; break; + case TGREATER|S: expr->constant.u = (int64_t)l->constant.u > (int64_t)r->constant.u; break; + case TGREATER|F: expr->constant.u = l->constant.f > r->constant.f; break; + case TLEQ: expr->constant.u = l->constant.u <= r->constant.u; break; + case TLEQ|S: expr->constant.u = (int64_t)l->constant.u <= (int64_t)r->constant.u; break; + case TLEQ|F: expr->constant.u = l->constant.f <= r->constant.f; break; + case TGEQ: expr->constant.u = l->constant.u >= r->constant.u; break; + case TGEQ|S: expr->constant.u = (int64_t)l->constant.u >= (int64_t)r->constant.u; break; + case TGEQ|F: expr->constant.u = l->constant.f >= r->constant.f; break; case TEQL: - case TEQL|S: expr->constant.i = l->constant.i == r->constant.i; break; - case TEQL|F: expr->constant.i = l->constant.f == r->constant.f; break; + case TEQL|S: expr->constant.u = l->constant.u == r->constant.u; break; + case TEQL|F: expr->constant.u = l->constant.f == r->constant.f; break; case TNEQ: - case TNEQ|S: expr->constant.i = l->constant.i != r->constant.i; break; - case TNEQ|F: expr->constant.i = l->constant.f != r->constant.f; break; + case TNEQ|S: expr->constant.u = l->constant.u != r->constant.u; break; + case TNEQ|F: expr->constant.u = l->constant.f != r->constant.f; break; default: fatal("internal error; unknown binary expression"); } @@ -97,7 +97,7 @@ eval(struct expr *expr, enum evalkind kind) if (expr->ident.decl->kind != DECLCONST) break; expr->kind = EXPRCONST; - expr->constant.i = intconstvalue(expr->ident.decl->value); + expr->constant.u = intconstvalue(expr->ident.decl->value); break; case EXPRCOMPOUND: if (kind != EVALINIT) @@ -131,9 +131,9 @@ eval(struct expr *expr, enum evalkind kind) if (l->kind == EXPRCONST) { expr->kind = EXPRCONST; if (l->type->prop & PROPINT && expr->type->prop & PROPFLOAT) - expr->constant.f = l->constant.i; + expr->constant.f = l->constant.u; else if (l->type->prop & PROPFLOAT && expr->type->prop & PROPINT) - expr->constant.i = l->constant.f; + expr->constant.u = l->constant.f; else expr->constant = l->constant; cast(expr); @@ -173,11 +173,11 @@ eval(struct expr *expr, enum evalkind kind) case TLOR: if (l->kind != EXPRCONST) break; - return l->constant.i ? l : r; + return l->constant.u ? l : r; case TLAND: if (l->kind != EXPRCONST) break; - return l->constant.i ? r : l; + return l->constant.u ? r : l; default: if (l->kind != EXPRCONST || r->kind != EXPRCONST) break; @@ -80,7 +80,7 @@ mkconstexpr(struct type *t, uint64_t n) struct expr *e; e = mkexpr(EXPRCONST, t, NULL); - e->constant.i = n; + e->constant.u = n; return e; } @@ -184,7 +184,7 @@ nullpointer(struct expr *e) return false; if (!(e->type->prop & PROPINT) && (e->type->kind != TYPEPOINTER || e->type->base != &typevoid)) return false; - return e->constant.i == 0; + return e->constant.u == 0; } static struct expr * @@ -527,10 +527,10 @@ primaryexpr(struct scope *s) } else { /* integer constant */ errno = 0; - e->constant.i = strtoull(tok.lit, &end, 0); + e->constant.u = strtoull(tok.lit, &end, 0); if (errno) error(&tok.loc, "invalid integer constant '%s': %s", tok.lit, strerror(errno)); - e->type = inttype(e->constant.i, base == 10, end); + e->type = inttype(e->constant.u, base == 10, end); } next(); break; @@ -1050,7 +1050,7 @@ condexpr(struct scope *s) } e = eval(e, EVALARITH); if (e->kind == EXPRCONST && e->type->prop & PROPINT) - return exprconvert(e->constant.i ? l : r, t); + return exprconvert(e->constant.u ? l : r, t); e = mkexpr(EXPRCOND, t, e); e->cond.t = l; e->cond.f = r; @@ -1071,9 +1071,9 @@ intconstexpr(struct scope *s, bool allowneg) e = constexpr(s); if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) error(&tok.loc, "not an integer constant expression"); - if (!allowneg && e->type->basic.issigned && e->constant.i > INT64_MAX) + if (!allowneg && e->type->basic.issigned && e->constant.u > INT64_MAX) error(&tok.loc, "integer constant expression cannot be negative"); - return e->constant.i; + return e->constant.u; } static struct expr * @@ -738,7 +738,7 @@ funcexpr(struct func *f, struct expr *e) case EXPRCONST: t = e->type; if (t->prop & PROPINT || t->kind == TYPEPOINTER) - return mkintconst(e->constant.i); + return mkintconst(e->constant.u); assert(t->prop & PROPFLOAT); return mkfltconst(t->size == 4 ? VALUE_FLTCONST : VALUE_DBLCONST, e->constant.f); case EXPRBITFIELD: @@ -1321,7 +1321,7 @@ dataitem(struct expr *expr, uint64_t size) if (expr->type->prop & PROPFLOAT) printf("%c_%.17g", expr->type->size == 4 ? 's' : 'd', expr->constant.f); else - printf("%" PRIu64, expr->constant.i); + printf("%" PRIu64, expr->constant.u); break; case EXPRSTRING: w = expr->type->base->size; @@ -1384,9 +1384,9 @@ emitdata(struct decl *d, struct init *init) assert(init->expr->kind == EXPRCONST); i = (init->start - cur->start) / cur->expr->type->base->size; switch (cur->expr->type->base->size) { - case 1: cur->expr->string.data[i] = init->expr->constant.i; break; - case 2: cur->expr->string.data16[i] = init->expr->constant.i; break; - case 4: cur->expr->string.data32[i] = init->expr->constant.i; break; + case 1: cur->expr->string.data[i] = init->expr->constant.u; break; + case 2: cur->expr->string.data16[i] = init->expr->constant.u; break; + case 4: cur->expr->string.data32[i] = init->expr->constant.u; break; } } start = cur->start + cur->bits.before / 8; @@ -1402,7 +1402,7 @@ emitdata(struct decl *d, struct init *init) /* XXX: little-endian specific */ assert(cur->expr->type->prop & PROPINT); assert(cur->expr->kind == EXPRCONST); - bits |= cur->expr->constant.i << cur->bits.before % 8; + bits |= cur->expr->constant.u << cur->bits.before % 8; for (offset = start; offset < end; ++offset, bits >>= 8) printf("b %u, ", (unsigned)bits & 0xff); /* |