mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Add internal padding to types where ptr size != int size
This commit is contained in:
@@ -1626,6 +1626,8 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
|||||||
|
|
||||||
GB_ASSERT(type != t_invalid);
|
GB_ASSERT(type != t_invalid);
|
||||||
|
|
||||||
|
bool bigger_int = build_context.word_size != build_context.int_size;
|
||||||
|
|
||||||
switch (type->kind) {
|
switch (type->kind) {
|
||||||
case Type_Basic:
|
case Type_Basic:
|
||||||
switch (type->Basic.kind) {
|
switch (type->Basic.kind) {
|
||||||
@@ -1760,8 +1762,8 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Basic_int: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
case Basic_int: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
|
||||||
case Basic_uint: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
case Basic_uint: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
|
||||||
|
|
||||||
case Basic_uintptr: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
case Basic_uintptr: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
||||||
|
|
||||||
@@ -1922,23 +1924,43 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
|||||||
|
|
||||||
case Type_Slice:
|
case Type_Slice:
|
||||||
{
|
{
|
||||||
LLVMTypeRef fields[2] = {
|
if (bigger_int) {
|
||||||
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
|
LLVMTypeRef fields[3] = {
|
||||||
lb_type(m, t_int), // len
|
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
|
||||||
};
|
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding
|
||||||
return LLVMStructTypeInContext(ctx, fields, 2, false);
|
lb_type(m, t_int), // len
|
||||||
|
};
|
||||||
|
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
|
||||||
|
} else {
|
||||||
|
LLVMTypeRef fields[2] = {
|
||||||
|
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
|
||||||
|
lb_type(m, t_int), // len
|
||||||
|
};
|
||||||
|
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_DynamicArray:
|
case Type_DynamicArray:
|
||||||
{
|
{
|
||||||
LLVMTypeRef fields[4] = {
|
if (bigger_int) {
|
||||||
LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data
|
LLVMTypeRef fields[5] = {
|
||||||
lb_type(m, t_int), // len
|
LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data
|
||||||
lb_type(m, t_int), // cap
|
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding
|
||||||
lb_type(m, t_allocator), // allocator
|
lb_type(m, t_int), // len
|
||||||
};
|
lb_type(m, t_int), // cap
|
||||||
return LLVMStructTypeInContext(ctx, fields, 4, false);
|
lb_type(m, t_allocator), // allocator
|
||||||
|
};
|
||||||
|
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
|
||||||
|
} else {
|
||||||
|
LLVMTypeRef fields[4] = {
|
||||||
|
LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data
|
||||||
|
lb_type(m, t_int), // len
|
||||||
|
lb_type(m, t_int), // cap
|
||||||
|
lb_type(m, t_allocator), // allocator
|
||||||
|
};
|
||||||
|
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -2145,9 +2167,17 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
|||||||
case Type_SoaPointer:
|
case Type_SoaPointer:
|
||||||
{
|
{
|
||||||
unsigned field_count = 2;
|
unsigned field_count = 2;
|
||||||
|
if (bigger_int) {
|
||||||
|
field_count = 3;
|
||||||
|
}
|
||||||
LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count);
|
LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count);
|
||||||
fields[0] = LLVMPointerType(lb_type(m, type->Pointer.elem), 0);
|
fields[0] = LLVMPointerType(lb_type(m, type->Pointer.elem), 0);
|
||||||
fields[1] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
if (bigger_int) {
|
||||||
|
fields[1] = lb_type_padding_filler(m, build_context.word_size, build_context.word_size);
|
||||||
|
fields[2] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
|
||||||
|
} else {
|
||||||
|
fields[1] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
|
||||||
|
}
|
||||||
return LLVMStructTypeInContext(ctx, fields, field_count, false);
|
return LLVMStructTypeInContext(ctx, fields, field_count, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -929,7 +929,33 @@ gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t)
|
|||||||
gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
|
gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
|
||||||
if (t->kind == Type_Struct) {
|
if (t->kind == Type_Struct) {
|
||||||
auto field_remapping = lb_get_struct_remapping(m, t);
|
auto field_remapping = lb_get_struct_remapping(m, t);
|
||||||
index = field_remapping[index];
|
return field_remapping[index];
|
||||||
|
} else if (build_context.word_size != build_context.int_size) {
|
||||||
|
switch (t->kind) {
|
||||||
|
case Type_Slice:
|
||||||
|
GB_ASSERT(build_context.word_size*2 == build_context.int_size);
|
||||||
|
switch (index) {
|
||||||
|
case 0: return 0; // data
|
||||||
|
case 1: return 2; // len
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Type_DynamicArray:
|
||||||
|
GB_ASSERT(build_context.word_size*2 == build_context.int_size);
|
||||||
|
switch (index) {
|
||||||
|
case 0: return 0; // data
|
||||||
|
case 1: return 2; // len
|
||||||
|
case 2: return 3; // cap
|
||||||
|
case 3: return 4; // allocator
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Type_SoaPointer:
|
||||||
|
GB_ASSERT(build_context.word_size*2 == build_context.int_size);
|
||||||
|
switch (index) {
|
||||||
|
case 0: return 0; // data
|
||||||
|
case 1: return 2; // offset
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user