harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit b48e6b3ea5357acac3b5e3aa986515ce827e0908
parent ddc981b7dcceb86ff6084366ed32e241683a7370
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sat, 18 Feb 2023 02:22:59 +0100

gen: simplify gen_data_item for enum values

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/gen.c | 38++++----------------------------------
1 file changed, 4 insertions(+), 34 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -3476,6 +3476,9 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, struct qbe_def *def; const struct expression_constant *constant = &expr->constant; const struct type *type = type_dealias(expr->result); + if (type->storage == STORAGE_ENUM) { + type = type->alias.type; + } type = lower_const(type, NULL); if (constant->object) { item->type = QD_SYMOFFS; @@ -3651,40 +3654,6 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, } } break; - case STORAGE_ENUM: - switch (type->alias.type->storage) { - case STORAGE_I8: - case STORAGE_U8: - case STORAGE_CHAR: - item->type = QD_VALUE; - item->value = constw((uint8_t)constant->uval); - item->value.type = &qbe_byte; - break; - case STORAGE_I16: - case STORAGE_U16: - item->type = QD_VALUE; - item->value = constw((uint16_t)constant->uval); - item->value.type = &qbe_half; - break; - case STORAGE_I32: - case STORAGE_U32: - case STORAGE_RUNE: - case STORAGE_INT: // XXX: arch - case STORAGE_UINT: - item->type = QD_VALUE; - item->value = constw((uint32_t)constant->uval); - break; - case STORAGE_U64: - case STORAGE_I64: - case STORAGE_SIZE: // XXX: arch - case STORAGE_UINTPTR: - item->type = QD_VALUE; - item->value = constl((uint64_t)constant->uval); - break; - default: - assert(0); - } - break; case STORAGE_TUPLE: for (const struct tuple_constant *tuple = constant->tuple; tuple; tuple = tuple->next) { @@ -3740,6 +3709,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, item->zeroed = type->size - type->align - constant->tagged.tag->size; } break; + case STORAGE_ENUM: case STORAGE_UNION: case STORAGE_ALIAS: case STORAGE_ERROR: