harec

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

commit d12dd7b53bc9d5d19d0ba1fee657dea153e1ed7d
parent ebf77236b94e149f3afd161f146f77b2247b1126
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 10 Aug 2021 09:59:18 +0200

gen: implement qbe subtype extension

Fixes 15-enums

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

Diffstat:
Msrc/gen.c | 34++++++++++++++++++++++++++++++++++
Mtests/configure | 3+--
2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -576,6 +576,26 @@ gen_expr_assign(struct gen_context *ctx, const struct expression *expr) return gv_void; } +static struct qbe_value +extend(struct gen_context *ctx, struct qbe_value v, const struct type *type) +{ + enum qbe_instr op; + switch (type->size) { + case 1: + op = type_is_signed(type) ? Q_EXTSB : Q_EXTUB; + break; + case 2: + op = type_is_signed(type) ? Q_EXTSH : Q_EXTUH; + break; + default: + return v; + } + + struct qbe_value temp = mkqtmp(ctx, &qbe_word, "ext.%d"); + pushi(ctx->current, &temp, op, &v, NULL); + return temp; +} + static struct gen_value gen_expr_binarithm(struct gen_context *ctx, const struct expression *expr) { @@ -614,6 +634,20 @@ gen_expr_binarithm(struct gen_context *ctx, const struct expression *expr) struct qbe_value qlval = mkqval(ctx, &lvalue); struct qbe_value qrval = mkqval(ctx, &rvalue); + switch (expr->binarithm.op) { + case BIN_GREATER: + case BIN_GREATEREQ: + case BIN_LEQUAL: + case BIN_LESS: + case BIN_LESSEQ: + case BIN_NEQUAL: + qlval = extend(ctx, qlval, ltype); + qrval = extend(ctx, qrval, rtype); + break; + default: + break; + } + assert((ltype->storage == STORAGE_STRING) == (rtype->storage == STORAGE_STRING)); if (ltype->storage == STORAGE_STRING) { struct qbe_value rtfunc = mkrtfunc(ctx, "rt.strcmp"); diff --git a/tests/configure b/tests/configure @@ -52,6 +52,7 @@ EOF 11-globals \ 13-tagged \ 14-switch \ + 15-enums \ 17-alloc \ 20-if \ 24-imports \ @@ -62,8 +63,6 @@ EOF # Disabled tests #08-slices \ #12-loops \ - #13-tagged \ - #15-enums \ #16-defer \ #17-alloc \ #18-match \