@@ -934,6 +934,26 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
insn->target->priv = target;
}
+static void output_op_fpcast(struct function *fn, struct instruction *insn)
+{
+ LLVMTypeRef dtype = symbol_type(insn->type);
+ LLVMValueRef src, target;
+ struct symbol *otype = insn->orig_type;
+ char name[64];
+
+ assert(is_float_type(insn->type));
+
+ pseudo_name(insn->target, name);
+ src = get_operand(fn, otype, insn->src);
+ if (is_float_type(otype))
+ target = LLVMBuildFPCast(fn->builder, src, dtype, name);
+ else if (is_signed_type(otype))
+ target = LLVMBuildSIToFP(fn->builder, src, dtype, name);
+ else
+ target = LLVMBuildUIToFP(fn->builder, src, dtype, name);
+ insn->target->priv = target;
+}
+
static void output_op_setval(struct function *fn, struct instruction *insn)
{
struct expression *val = insn->val;
@@ -1008,7 +1028,7 @@ static void output_insn(struct function *fn, struct instruction *insn)
output_op_cast(fn, insn, LLVMSExt);
break;
case OP_FPCAST:
- assert(0);
+ output_op_fpcast(fn, insn);
break;
case OP_PTRCAST:
output_op_ptrcast(fn, insn);
@@ -1,4 +1,5 @@
typedef _Bool bool;
+typedef signed char schar;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
@@ -14,6 +15,7 @@ typedef unsigned long long ulonglong;
#define DEFINE_CASTS(from) \
DEFINE_CAST(from, bool) \
DEFINE_CAST(from, char) \
+ DEFINE_CAST(from, schar) \
DEFINE_CAST(from, uchar) \
DEFINE_CAST(from, short) \
DEFINE_CAST(from, ushort) \
@@ -23,13 +25,12 @@ typedef unsigned long long ulonglong;
DEFINE_CAST(from, ulong) \
DEFINE_CAST(from, longlong) \
DEFINE_CAST(from, ulonglong) \
-/*
DEFINE_CAST(from, float) \
DEFINE_CAST(from, double)
-*/
DEFINE_CASTS(bool)
DEFINE_CASTS(char)
+DEFINE_CASTS(schar)
DEFINE_CASTS(uchar)
DEFINE_CASTS(short)
DEFINE_CASTS(ushort)
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- sparse-llvm.c | 22 +++++++++++++++++++++- validation/backend/cast.c | 5 +++-- 2 files changed, 24 insertions(+), 3 deletions(-)