pass pointer to C as first argument

This commit is contained in:
Folkert 2022-01-11 22:08:58 +01:00
parent b2e05b92d1
commit 1b149d215d

View file

@ -6238,7 +6238,7 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
.void_type()
.fn_type(&function_arguments(env, &cc_argument_types), false),
CCReturn::ByPointer => {
cc_argument_types.push(return_type.ptr_type(AddressSpace::Generic).into());
cc_argument_types.insert(0, return_type.ptr_type(AddressSpace::Generic).into());
env.context
.void_type()
.fn_type(&function_arguments(env, &cc_argument_types), false)
@ -6285,6 +6285,11 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
RocReturn::ByPointer => fastcc_parameters.pop().unwrap().into_pointer_value(),
};
if let CCReturn::ByPointer = cc_return {
cc_arguments.push(return_pointer.into());
cc_argument_types.remove(0);
}
let it = fastcc_parameters.into_iter().zip(cc_argument_types.iter());
for (param, cc_type) in it {
if param.get_type() == *cc_type {
@ -6296,10 +6301,6 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
}
}
if let CCReturn::ByPointer = cc_return {
cc_arguments.push(return_pointer.into());
}
let call = env.builder.build_call(cc_function, &cc_arguments, "tmp");
call.set_call_convention(C_CALL_CONV);