From 7f0620a20fc431717d017d0c19f1e1f29723d93f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 7 Jun 2017 22:56:57 -0400 Subject: partial implementation of printing floating point numbers with errol3 also add bitCast builtin function. closes #387 --- src/codegen.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 0e5b8a5ea1..3a1fad3958 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1693,6 +1693,14 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable, return LLVMBuildBitCast(g->builder, ptr, wanted_type->type_ref, ""); } +static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable, + IrInstructionBitCast *instruction) +{ + TypeTableEntry *wanted_type = instruction->base.value.type; + LLVMValueRef value = ir_llvm_value(g, instruction->value); + return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, ""); +} + static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable, IrInstructionWidenOrShorten *instruction) { @@ -3180,6 +3188,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, return ir_render_struct_init(g, executable, (IrInstructionStructInit *)instruction); case IrInstructionIdPtrCast: return ir_render_ptr_cast(g, executable, (IrInstructionPtrCast *)instruction); + case IrInstructionIdBitCast: + return ir_render_bit_cast(g, executable, (IrInstructionBitCast *)instruction); case IrInstructionIdWidenOrShorten: return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction); case IrInstructionIdPtrToInt: @@ -4514,6 +4524,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdSetGlobalLinkage, "setGlobalLinkage", 2); create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1); create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2); + create_builtin_fn(g, BuiltinFnIdBitCast, "bitCast", 2); create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2); create_builtin_fn(g, BuiltinFnIdEnumTagName, "enumTagName", 1); create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3); -- cgit v1.2.3