riscv64: use a Slice for the coerce offsets

This commit is contained in:
kalsprite
2026-08-17 18:54:58 -07:00
parent ffbaafd39c
commit c6fcad51f8
2 changed files with 21 additions and 28 deletions

View File

@@ -684,7 +684,7 @@ gb_internal void lb_begin_procedure_body(lbProcedure *p) {
if (e->token.string.len != 0 && !is_blank_ident(e->token.string)) {
LLVMTypeRef param_type = lb_type(p->module, e->type);
LLVMValueRef original_value = LLVMGetParam(p->value, param_offset+llvm_param_index);
LLVMValueRef value = arg_type->coerce_offset_count > 0
LLVMValueRef value = arg_type->coerce_offsets.count > 0
? lb_coerce_fields_store(p, original_value, e->type, arg_type)
: OdinLLVMBuildTransmute(p, original_value, param_type);
@@ -939,14 +939,14 @@ gb_internal LLVMValueRef lb_coerce_fields_load(lbProcedure *p, lbValue x, lbArgT
lbValue base = lb_address_from_load_or_generate_local(p, x);
if (LLVMGetTypeKind(arg->cast_type) != LLVMStructTypeKind) {
GB_ASSERT(arg->coerce_offset_count == 1);
GB_ASSERT(arg->coerce_offsets.count == 1);
LLVMValueRef index = LLVMConstInt(i64t, cast(unsigned long long)arg->coerce_offsets[0], false);
LLVMValueRef ptr = LLVMBuildInBoundsGEP2(p->builder, i8, base.value, &index, 1, "");
return LLVMBuildLoad2(p->builder, arg->cast_type, ptr, "");
}
unsigned count = LLVMCountStructElementTypes(arg->cast_type);
GB_ASSERT(cast(isize)count == arg->coerce_offset_count);
GB_ASSERT(cast(isize)count == arg->coerce_offsets.count);
LLVMValueRef result = LLVMGetUndef(arg->cast_type);
for (unsigned i = 0; i < count; i += 1) {
LLVMTypeRef elem_type = LLVMStructGetTypeAtIndex(arg->cast_type, i);
@@ -971,7 +971,7 @@ gb_internal LLVMValueRef lb_coerce_fields_store(lbProcedure *p, LLVMValueRef coe
if (is_struct) {
count = LLVMCountStructElementTypes(arg->cast_type);
}
GB_ASSERT(cast(isize)count == arg->coerce_offset_count);
GB_ASSERT(cast(isize)count == arg->coerce_offsets.count);
for (unsigned i = 0; i < count; i += 1) {
LLVMValueRef elem = is_struct ? LLVMBuildExtractValue(p->builder, coerced, i, "") : coerced;
LLVMValueRef index = LLVMConstInt(i64t, cast(unsigned long long)arg->coerce_offsets[i], false);
@@ -1255,7 +1255,7 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c
if (!abi_type) {
abi_type = arg->type;
}
if (arg->coerce_offset_count > 0) {
if (arg->coerce_offsets.count > 0) {
x.value = lb_coerce_fields_load(p, x, arg);
array_add(&processed_args, x);
} else if (xt == abi_type) {
@@ -1328,7 +1328,7 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c
result = lb_emit_load(p, return_ptr);
} else if (rt != nullptr) {
result = lb_emit_call_internal(p, value, {}, processed_args, rt, context_ptr, inlining, tailing);
if (ft->ret.coerce_offset_count > 0) {
if (ft->ret.coerce_offsets.count > 0) {
result.value = lb_coerce_fields_store(p, result.value, rt, &ft->ret);
} else {
if (ft->ret.cast_type) {