diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-05-04 23:18:54 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-05-04 23:18:54 +0100 |
| commit | 51ea59d76a3e0ee72a9a3bb59bd61845dea64e5e (patch) | |
| tree | 2cd3a1f7db2fa4992f291940efdb39926a9c26bd /src/types.c | |
| parent | 789b297f324206a18128f61679bfd36b9c6265b2 (diff) | |
Fix calculation of vector type sizes
Diffstat (limited to 'src/types.c')
| -rw-r--r-- | src/types.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/types.c b/src/types.c index 4001253f8..e363c6b2c 100644 --- a/src/types.c +++ b/src/types.c @@ -93,6 +93,7 @@ typedef struct TypeRecord { Entity **variants; i32 variant_count; Entity * union__tag; + i64 variant_block_size; // NOTE(bill): Internal use only i64 * offsets; @@ -1817,18 +1818,18 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) { total_size = (total_size_in_bits+7)/8; return total_size; #else - i64 count, align, size, alignment; - count = t->Vector.count; + i64 count = t->Vector.count; if (count == 0) { return 0; } - align = type_align_of_internal(allocator, t->Vector.elem, path); + i64 elem_align = type_align_of_internal(allocator, t->Vector.elem, path); if (path->failure) { return FAILURE_SIZE; } - size = type_size_of_internal( allocator, t->Vector.elem, path); - alignment = align_formula(size, align); - return alignment*(count-1) + size; + i64 vector_align = type_align_of_internal(allocator, t, path); + i64 elem_size = type_size_of_internal(allocator, t->Vector.elem, path); + i64 alignment = align_formula(elem_size, elem_align); + return align_formula(alignment*(count-1) + elem_size, vector_align); #endif } break; @@ -1904,6 +1905,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) { i64 end_size = type_size_of_internal(allocator, end_type, path); max = end_offset + end_size ; } + i64 field_size = max; for (isize i = 1; i < variant_count; i++) { Type *variant_type = t->Record.variants[i]->type; @@ -1912,9 +1914,13 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) { max = size; } } + // NOTE(bill): Align to int i64 size = align_formula(max, build_context.word_size); - size += type_size_of_internal(allocator, t_int, path); + // NOTE(bill): Calculate the padding between the common fields and the tag + t->Record.variant_block_size = size - field_size; + + size += type_size_of(allocator, t_int); size = align_formula(size, align); return size; } break; |