aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-04 02:11:50 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-04 02:11:50 -0700
commitfdadab40c61a6f70a65472cc95ccd5ba52c01772 (patch)
treef471173c1e54a3cd4e35759970adfcd36c991c0b /src/codegen.cpp
parent3a9009b08e278dafd7b59b7d09408c80ea67f1fe (diff)
downloadzig-fdadab40c61a6f70a65472cc95ccd5ba52c01772.tar.gz
zig-fdadab40c61a6f70a65472cc95ccd5ba52c01772.zip
implement constant values for enums with payload
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index a96fe9ba0f..7dd91b6a66 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2567,7 +2567,20 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
if (type_entry->data.enumeration.gen_field_count == 0) {
return tag_value;
} else {
- zig_panic("TODO");
+ TypeTableEntry *union_type = type_entry->data.enumeration.union_type;
+ TypeEnumField *enum_field = &type_entry->data.enumeration.fields[const_val->data.x_enum.tag];
+ assert(enum_field->value == const_val->data.x_enum.tag);
+ LLVMValueRef union_value;
+ if (type_has_bits(enum_field->type_entry)) {
+ union_value = gen_const_val(g, union_type, const_val->data.x_enum.payload);
+ } else {
+ union_value = LLVMGetUndef(union_type->type_ref);
+ }
+ LLVMValueRef fields[] = {
+ tag_value,
+ union_value,
+ };
+ return LLVMConstNamedStruct(type_entry->type_ref, fields, 2);
}
}
case TypeTableEntryIdFn: