From e74a7264ad3b221dfef0c959c1fdd6275f7c70ef Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 31 Jan 2016 21:05:17 -0700 Subject: support casting between int and float types --- src/codegen.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 01f3fe60c9..24608bc553 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -478,6 +478,25 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { return cast_expr->tmp_ptr; } + case CastOpIntToFloat: + assert(actual_type->id == TypeTableEntryIdInt); + if (actual_type->data.integral.is_signed) { + add_debug_source_node(g, node); + return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, ""); + } else { + add_debug_source_node(g, node); + return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, ""); + } + case CastOpFloatToInt: + assert(wanted_type->id == TypeTableEntryIdInt); + if (wanted_type->data.integral.is_signed) { + add_debug_source_node(g, node); + return LLVMBuildFPToSI(g->builder, expr_val, wanted_type->type_ref, ""); + } else { + add_debug_source_node(g, node); + return LLVMBuildFPToUI(g->builder, expr_val, wanted_type->type_ref, ""); + } + } zig_unreachable(); } -- cgit v1.2.3