diff options
| author | gingerBill <bill@gingerbill.org> | 2021-10-02 17:22:56 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-10-02 17:22:56 +0100 |
| commit | 00671a59a038c5fc9d4b2af02ca2194092b00778 (patch) | |
| tree | c5e0689afb44fc3444a1666686d7fef4d7c03aba /src/llvm_backend_general.cpp | |
| parent | ebca0398a7ec76374322001e697a0aaa531eb22f (diff) | |
Minor code cleanup for backend; add `struct_fields_index_by_increasing_offset` for future use
Diffstat (limited to 'src/llvm_backend_general.cpp')
| -rw-r--r-- | src/llvm_backend_general.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index fcdc1d979..61f256066 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -1700,18 +1700,18 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { auto fields = array_make<LLVMTypeRef>(temporary_allocator(), 0, type->Struct.fields.count*2 + 1); i64 padding_offset = 0; - for_array(i, type->Struct.fields) { - GB_ASSERT(type->Struct.offsets != nullptr); - - Entity *field = type->Struct.fields[i]; - i64 padding = type->Struct.offsets[i] - padding_offset; + // auto field_indices = struct_fields_index_by_increasing_offset(type, temporary_allocator()); + // for (i32 field_index : field_indices) { + for (isize field_index = 0; field_index < type->Struct.fields.count; field_index++) { + Entity *field = type->Struct.fields[field_index]; + i64 padding = type->Struct.offsets[field_index] - padding_offset; if (padding != 0) { LLVMTypeRef padding_type = lb_type_padding_filler(m, padding, type_align_of(field->type)); array_add(&fields, padding_type); } - field_remapping[i] = cast(i32)fields.count; + field_remapping[field_index] = cast(i32)fields.count; array_add(&fields, lb_type(m, field->type)); if (!type->Struct.is_packed) { @@ -1720,7 +1720,8 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { padding_offset += type_size_of(field->type); } - i64 end_padding = type_size_of(type)-padding_offset; + i64 full_type_size = type_size_of(type); + i64 end_padding = full_type_size-padding_offset; if (end_padding > 0) { array_add(&fields, lb_type_padding_filler(m, end_padding, 1)); } @@ -1731,7 +1732,8 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { LLVMTypeRef struct_type = LLVMStructTypeInContext(ctx, fields.data, cast(unsigned)fields.count, type->Struct.is_packed); map_set(&m->struct_field_remapping, hash_pointer(struct_type), field_remapping); - map_set(&m->struct_field_remapping, hash_pointer(type), field_remapping); + map_set(&m->struct_field_remapping, hash_pointer(type), field_remapping); + GB_ASSERT(lb_sizeof(struct_type) == full_type_size); return struct_type; } break; |