From 479ec07fd449d9c0ea27efa186796ef8de8ece3c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 21 Jan 2022 10:14:14 +0900 Subject: [PATCH] [qfcc] Implement ruamoko conversion instructions Thanks to me having done something right 20 years ago, that was pretty easy :). The two boolean types aren't supported yet because I haven't decided on just how to represent their types in qfcc. --- tools/qfcc/source/statements.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index 756b38492..bc4cb396b 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -1318,6 +1318,17 @@ expr_expr (sblock_t *sblock, expr_t *e, operand_t **op) return sblock; } +static int type_map[ev_type_count] = { + [ev_int] = 0, + [ev_float] = 1, + [ev_long] = 2, + [ev_double] = 3, + [ev_uint] = 4, + //[ev_bool32] = 5, + [ev_ulong] = 6, + //[ev_bool64] = 7, +}; + static sblock_t * expr_cast (sblock_t *sblock, expr_t *e, operand_t **op) { @@ -1332,6 +1343,13 @@ expr_cast (sblock_t *sblock, expr_t *e, operand_t **op) *op = temp_operand (e->e.expr.type, e); s = new_statement (st_expr, "conv", e); s->opa = src; + if (options.code.progsversion == PROG_VERSION) { + int from = type_map[src_type->type]; + int to = type_map[type->type]; + int width = type_width (src_type) - 1; + int conv = (width << 6) | (from << 3) | to; + s->opb = short_operand (conv, e); + } s->opc = *op; sblock_add_statement (sblock, s); } else {