harec

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

commit a9a4b07f3984f53d7e179ee2d5a75e44ca37fa1f
parent 45dd46a199d8552edeec22a23730dde720d7b613
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 12 Aug 2021 07:53:18 +0200

gen: relocate cast special cases

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

Diffstat:
Msrc/gen.c | 31++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -1151,6 +1151,22 @@ gen_expr_cast(struct gen_context *ctx, const struct expression *expr) return out; } + // Special cases + switch (type_dealias(to)->storage) { + case STORAGE_POINTER: + if (type_dealias(from)->storage == STORAGE_SLICE) { + struct gen_value value = gen_expr(ctx, expr->cast.value); + value.type = to; + return gen_load(ctx, value); + } + break; + case STORAGE_VOID: + gen_expr(ctx, expr->cast.value); // Side-effects + return gv_void; + default: break; + } + + // Special case: tagged => non-tagged if (type_dealias(from)->storage == STORAGE_TAGGED) { struct gen_value value = gen_expr(ctx, expr->cast.value); @@ -1177,21 +1193,6 @@ gen_expr_cast(struct gen_context *ctx, const struct expression *expr) return value; } - // Other special cases - switch (type_dealias(to)->storage) { - case STORAGE_POINTER: - if (type_dealias(from)->storage == STORAGE_SLICE) { - struct gen_value value = gen_expr(ctx, expr->cast.value); - value.type = to; - return gen_load(ctx, value); - } - break; - case STORAGE_VOID: - gen_expr(ctx, expr->cast.value); // Side-effects - return gv_void; - default: break; - } - struct gen_value value = gen_expr(ctx, expr->cast.value); struct qbe_value qvalue = mkqval(ctx, &value); struct gen_value result = mktemp(ctx, expr->result, "cast.%d");