| ... | ... | @@ -2181,6 +2181,30 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable, |
| 2181 | 2181 | return instruction->tmp_ptr; |
| 2182 | 2182 | } |
| 2183 | 2183 | |
| 2184 | static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable, |
| 2185 | IrInstructionContainerInitList *instruction) |
| 2186 | { |
| 2187 | TypeTableEntry *array_type = instruction->base.value.type; |
| 2188 | assert(array_type->id == TypeTableEntryIdArray); |
| 2189 | LLVMValueRef tmp_array_ptr = instruction->tmp_ptr; |
| 2190 | assert(tmp_array_ptr); |
| 2191 | |
| 2192 | size_t field_count = instruction->item_count; |
| 2193 | |
| 2194 | TypeTableEntry *child_type = array_type->data.array.child_type; |
| 2195 | for (size_t i = 0; i < field_count; i += 1) { |
| 2196 | LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]); |
| 2197 | LLVMValueRef indices[] = { |
| 2198 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |
| 2199 | LLVMConstInt(g->builtin_types.entry_usize->type_ref, i, false), |
| 2200 | }; |
| 2201 | LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); |
| 2202 | gen_assign_raw(g, elem_ptr, elem_val, child_type); |
| 2203 | } |
| 2204 | |
| 2205 | return tmp_array_ptr; |
| 2206 | } |
| 2207 | |
| 2184 | 2208 | static void set_debug_location(CodeGen *g, IrInstruction *instruction) { |
| 2185 | 2209 | AstNode *source_node = instruction->source_node; |
| 2186 | 2210 | Scope *scope = instruction->scope; |
| ... | ... | @@ -2323,10 +2347,10 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 2323 | 2347 | return ir_render_pointer_reinterpret(g, executable, (IrInstructionPointerReinterpret *)instruction); |
| 2324 | 2348 | case IrInstructionIdWidenOrShorten: |
| 2325 | 2349 | return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction); |
| 2350 | case IrInstructionIdContainerInitList: |
| 2351 | return ir_render_container_init_list(g, executable, (IrInstructionContainerInitList *)instruction); |
| 2326 | 2352 | case IrInstructionIdSwitchVar: |
| 2327 | 2353 | zig_panic("TODO render switch var instruction to LLVM"); |
| 2328 | | case IrInstructionIdContainerInitList: |
| 2329 | | zig_panic("TODO render container init list instruction to LLVM"); |
| 2330 | 2354 | } |
| 2331 | 2355 | zig_unreachable(); |
| 2332 | 2356 | } |