diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-11 15:31:07 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-11 15:31:07 -0500 |
| commit | 3429639e848a9ffa9ff9fbd940d3fc2d348e10e7 (patch) | |
| tree | 67ff12dd3c9a578d443f46be232db38b49b08b7f /src/codegen.cpp | |
| parent | 433c17aeb192740053b1b9aea6220dca760303e2 (diff) | |
| download | zig-3429639e848a9ffa9ff9fbd940d3fc2d348e10e7.tar.gz zig-3429639e848a9ffa9ff9fbd940d3fc2d348e10e7.zip | |
IR: implement truncate builtin
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index e4eb8dd323..0642fbd7ec 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1879,6 +1879,14 @@ static LLVMValueRef ir_render_div_exact(CodeGen *g, IrExecutable *executable, Ir return gen_div(g, want_debug_safety, op1_val, op2_val, instruction->base.type_entry, true); } +static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) { + assert(instruction->dest_type->type_entry->id == TypeTableEntryIdMetaType); + TypeTableEntry *dest_type = get_underlying_type(instruction->dest_type->static_value.data.x_type); + assert(dest_type->id == TypeTableEntryIdInt); + LLVMValueRef target_val = ir_llvm_value(g, instruction->target); + return LLVMBuildTrunc(g->builder, target_val, dest_type->type_ref, ""); +} + static void set_debug_location(CodeGen *g, IrInstruction *instruction) { AstNode *source_node = instruction->source_node; Scope *scope = instruction->scope; @@ -1974,6 +1982,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, return ir_render_fence(g, executable, (IrInstructionFence *)instruction); case IrInstructionIdDivExact: return ir_render_div_exact(g, executable, (IrInstructionDivExact *)instruction); + case IrInstructionIdTruncate: + return ir_render_truncate(g, executable, (IrInstructionTruncate *)instruction); case IrInstructionIdSwitchVar: case IrInstructionIdContainerInitList: case IrInstructionIdStructInit: |
