diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 15:45:50 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 15:45:50 -0500 |
| commit | 735cdbfdaca6405d1465ea859032412499c658d8 (patch) | |
| tree | a3b6655d26985adafbf71903c5d5bb7049a45454 /src/codegen.cpp | |
| parent | aee7ad3de2e3c334ec5aac2d355e4eed086f1cdf (diff) | |
| download | zig-735cdbfdaca6405d1465ea859032412499c658d8.tar.gz zig-735cdbfdaca6405d1465ea859032412499c658d8.zip | |
IR: pass intToPtrCast test
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 6ab14cffe1..cf737fc7c3 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -969,10 +969,6 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, } else { zig_panic("TODO"); } - case CastOpPtrToInt: - return LLVMBuildPtrToInt(g->builder, expr_val, wanted_type->type_ref, ""); - case CastOpIntToPtr: - return LLVMBuildIntToPtr(g->builder, expr_val, wanted_type->type_ref, ""); case CastOpResizeSlice: { assert(cast_instruction->tmp_ptr); @@ -1114,6 +1110,18 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa instruction->base.value.type, target_val); } +static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) { + TypeTableEntry *wanted_type = instruction->base.value.type; + LLVMValueRef target_val = ir_llvm_value(g, instruction->target); + return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, ""); +} + +static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) { + TypeTableEntry *wanted_type = instruction->base.value.type; + LLVMValueRef target_val = ir_llvm_value(g, instruction->target); + return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, ""); +} + static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable, IrInstructionUnreachable *unreachable_instruction) { @@ -2347,6 +2355,10 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, return ir_render_pointer_reinterpret(g, executable, (IrInstructionPointerReinterpret *)instruction); case IrInstructionIdWidenOrShorten: return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction); + case IrInstructionIdPtrToInt: + return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction); + case IrInstructionIdIntToPtr: + return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction); case IrInstructionIdContainerInitList: return ir_render_container_init_list(g, executable, (IrInstructionContainerInitList *)instruction); case IrInstructionIdSwitchVar: |
