From be68bf9f26122b764a43cf61369ca54c203d1df3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 13 Sep 2021 11:29:46 +0100 Subject: Only store `field_index` remove `field_src_index` (for the time being) --- src/llvm_backend_utility.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/llvm_backend_utility.cpp') diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index db3cb443e..63e27f428 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -807,6 +807,13 @@ lbValue lb_address_from_load(lbProcedure *p, lbValue value) { return {}; } +i32 lb_convert_struct_index(Type *t, i32 index) { + if (t->kind == Type_Struct && t->Struct.custom_align != 0) { + index += 1; + } + return index; +} + lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { GB_ASSERT(is_type_pointer(s.type)); Type *t = base_type(type_deref(s.type)); @@ -883,10 +890,9 @@ lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { } GB_ASSERT_MSG(result_type != nullptr, "%s %d", type_to_string(t), index); - - if (t->kind == Type_Struct && t->Struct.custom_align != 0) { - index += 1; - } + + index = lb_convert_struct_index(t, index); + if (lb_is_const(s)) { lbModule *m = p->module; lbValue res = {}; @@ -1006,10 +1012,8 @@ lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) { } GB_ASSERT_MSG(result_type != nullptr, "%s, %d", type_to_string(s.type), index); - - if (t->kind == Type_Struct && t->Struct.custom_align != 0) { - index += 1; - } + + index = lb_convert_struct_index(t, index); lbValue res = {}; res.value = LLVMBuildExtractValue(p->builder, s.value, cast(unsigned)index, ""); -- cgit v1.2.3