mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-15 23:54:07 +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);
|
||||
|
||||
bool bigger_int = build_context.word_size != build_context.int_size;
|
||||
|
||||
switch (type->kind) {
|
||||
case Type_Basic:
|
||||
switch (type->Basic.kind) {
|
||||
@@ -1760,8 +1762,8 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
return type;
|
||||
}
|
||||
|
||||
case Basic_int: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size);
|
||||
case Basic_uint: 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.int_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:
|
||||
{
|
||||
LLVMTypeRef fields[2] = {
|
||||
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
|
||||
lb_type(m, t_int), // len
|
||||
};
|
||||
return LLVMStructTypeInContext(ctx, fields, 2, false);
|
||||
if (bigger_int) {
|
||||
LLVMTypeRef fields[3] = {
|
||||
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
|
||||
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding
|
||||
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;
|
||||
|
||||
case Type_DynamicArray:
|
||||
{
|
||||
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, 4, false);
|
||||
if (bigger_int) {
|
||||
LLVMTypeRef fields[5] = {
|
||||
LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data
|
||||
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding
|
||||
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);
|
||||
} 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;
|
||||
|
||||
@@ -2145,9 +2167,17 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
case Type_SoaPointer:
|
||||
{
|
||||
unsigned field_count = 2;
|
||||
if (bigger_int) {
|
||||
field_count = 3;
|
||||
}
|
||||
LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user