aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp10
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: