harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 757e74c31678cc1ed88e9e0249113d2bef312c60
parent 1b88738358055b47dcc0220615d74a10db3f9a9e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  1 Jul 2021 14:28:53 -0400

gen: implement enums

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 10+++++++---
Msrc/qinstr.c | 4+++-
Msrc/qtype.c | 5++++-
3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -96,7 +96,12 @@ gen_expr_constant(struct gen_context *ctx, struct qbe_value qout, qval = {0}; qval_temp(ctx, &qout, out); - switch (type_dealias(expr->result)->storage) { + enum type_storage storage = type_dealias(expr->result)->storage; + if (storage == STORAGE_ENUM) { + storage = type_dealias(expr->result)->_enum.storage; + } + + switch (storage) { case STORAGE_CHAR: case STORAGE_I8: case STORAGE_U8: @@ -123,8 +128,6 @@ gen_expr_constant(struct gen_context *ctx, case STORAGE_POINTER: case STORAGE_F32: case STORAGE_F64: - case STORAGE_ENUM: - assert(0); // TODO case STORAGE_ARRAY: case STORAGE_NULL: case STORAGE_SLICE: @@ -136,6 +139,7 @@ gen_expr_constant(struct gen_context *ctx, assert(0); // TODO case STORAGE_ICONST: case STORAGE_FCONST: + case STORAGE_ENUM: case STORAGE_VOID: case STORAGE_ALIAS: case STORAGE_FUNCTION: diff --git a/src/qinstr.c b/src/qinstr.c @@ -15,8 +15,10 @@ alloc_for_align(size_t align) return Q_ALLOC4; case 8: return Q_ALLOC8; - default: + case 16: return Q_ALLOC16; + default: + abort(); } } diff --git a/src/qtype.c b/src/qtype.c @@ -3,6 +3,7 @@ #include "gen.h" #include "qbe.h" #include "types.h" +#include "type_store.h" const struct qbe_type *qtype_lookup( struct gen_context *ctx, @@ -36,7 +37,9 @@ const struct qbe_type *qtype_lookup( case STORAGE_F64: return &qbe_double; case STORAGE_ENUM: - assert(0); // TODO + return qtype_lookup(ctx, + builtin_type_for_storage(type->_enum.storage, false), + xtype); case STORAGE_ALIAS: return qtype_lookup(ctx, type->alias.type, xtype); case STORAGE_ARRAY: