aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-26 16:34:18 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-26 16:34:18 -0500
commit66a83d87383cd8de62898171b6665cb1d70af231 (patch)
treeff09db18060a350166cd07a9fb039b43d1a63e37 /src/codegen.cpp
parentc8a7ab7eff0f261c47926cf0637e919d42e41940 (diff)
downloadzig-66a83d87383cd8de62898171b6665cb1d70af231.tar.gz
zig-66a83d87383cd8de62898171b6665cb1d70af231.zip
IR: pass intToEnum test
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index cf737fc7c3..070ad98a7c 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1075,10 +1075,6 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
assert(wanted_type->id == TypeTableEntryIdInt);
assert(actual_type->id == TypeTableEntryIdBool);
return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
-
- case CastOpIntToEnum:
- return gen_widen_or_shorten(g, ir_want_debug_safety(g, &cast_instruction->base),
- actual_type, wanted_type->data.enumeration.tag_type, expr_val);
}
zig_unreachable();
}
@@ -1122,6 +1118,24 @@ static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, I
return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, "");
}
+static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
+ TypeTableEntry *wanted_type = instruction->base.value.type;
+ assert(wanted_type->id == TypeTableEntryIdEnum);
+ TypeTableEntry *tag_type = wanted_type->data.enumeration.tag_type;
+ TypeTableEntry *wanted_int_type;
+ if (tag_type->id == TypeTableEntryIdEnumTag) {
+ wanted_int_type = tag_type->data.enum_tag.int_type;
+ } else if (tag_type->id == TypeTableEntryIdInt) {
+ wanted_int_type = tag_type;
+ } else {
+ zig_unreachable();
+ }
+
+ LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
+ return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),
+ instruction->target->value.type, wanted_int_type, target_val);
+}
+
static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
IrInstructionUnreachable *unreachable_instruction)
{
@@ -2359,6 +2373,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction);
case IrInstructionIdIntToPtr:
return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction);
+ case IrInstructionIdIntToEnum:
+ return ir_render_int_to_enum(g, executable, (IrInstructionIntToEnum *)instruction);
case IrInstructionIdContainerInitList:
return ir_render_container_init_list(g, executable, (IrInstructionContainerInitList *)instruction);
case IrInstructionIdSwitchVar: