diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 03:16:19 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 03:16:19 -0500 |
| commit | 73a751911e2c2be646287eb8c8d579dded25afe3 (patch) | |
| tree | 77d14408a8eb895878baa9678ee714dfa03497b7 /src/codegen.cpp | |
| parent | 6ed835ca67670098da79d4e329c6efcb12419599 (diff) | |
| download | zig-73a751911e2c2be646287eb8c8d579dded25afe3.tar.gz zig-73a751911e2c2be646287eb8c8d579dded25afe3.zip | |
IR: pass staticEvalListInit test
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 39cd6c8fd9..6ab14cffe1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2181,6 +2181,30 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable, return instruction->tmp_ptr; } +static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable, + IrInstructionContainerInitList *instruction) +{ + TypeTableEntry *array_type = instruction->base.value.type; + assert(array_type->id == TypeTableEntryIdArray); + LLVMValueRef tmp_array_ptr = instruction->tmp_ptr; + assert(tmp_array_ptr); + + size_t field_count = instruction->item_count; + + TypeTableEntry *child_type = array_type->data.array.child_type; + for (size_t i = 0; i < field_count; i += 1) { + LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]); + LLVMValueRef indices[] = { + LLVMConstNull(g->builtin_types.entry_usize->type_ref), + LLVMConstInt(g->builtin_types.entry_usize->type_ref, i, false), + }; + LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); + gen_assign_raw(g, elem_ptr, elem_val, child_type); + } + + return tmp_array_ptr; +} + static void set_debug_location(CodeGen *g, IrInstruction *instruction) { AstNode *source_node = instruction->source_node; Scope *scope = instruction->scope; @@ -2323,10 +2347,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 IrInstructionIdContainerInitList: + return ir_render_container_init_list(g, executable, (IrInstructionContainerInitList *)instruction); case IrInstructionIdSwitchVar: zig_panic("TODO render switch var instruction to LLVM"); - case IrInstructionIdContainerInitList: - zig_panic("TODO render container init list instruction to LLVM"); } zig_unreachable(); } |
