Make LLVM work with one-vmctx imported functions

This commit is contained in:
Syrus
2020-05-19 21:38:10 -07:00
parent a62b720954
commit c76a3d83db
3 changed files with 18 additions and 21 deletions

View File

@ -34,7 +34,6 @@ impl FuncTrampoline {
let trampoline_ty = intrinsics.void_ty.fn_type( let trampoline_ty = intrinsics.void_ty.fn_type(
&[ &[
intrinsics.ctx_ptr_ty.as_basic_type_enum(), // callee_vmctx ptr intrinsics.ctx_ptr_ty.as_basic_type_enum(), // callee_vmctx ptr
intrinsics.ctx_ptr_ty.as_basic_type_enum(), // caller_vmctx ptr
callee_ty callee_ty
.ptr_type(AddressSpace::Generic) .ptr_type(AddressSpace::Generic)
.as_basic_type_enum(), // callee function address .as_basic_type_enum(), // callee function address
@ -120,20 +119,19 @@ fn generate_trampoline<'ctx>(
""); "");
*/ */
let (callee_vmctx_ptr, caller_vmctx_ptr, func_ptr, args_rets_ptr) = let (callee_vmctx_ptr, func_ptr, args_rets_ptr) = match trampoline_func.get_params().as_slice()
match trampoline_func.get_params().as_slice() { {
&[callee_vmctx_ptr, caller_vmctx_ptr, func_ptr, args_rets_ptr] => ( &[callee_vmctx_ptr, func_ptr, args_rets_ptr] => (
callee_vmctx_ptr, callee_vmctx_ptr,
caller_vmctx_ptr, func_ptr.into_pointer_value(),
func_ptr.into_pointer_value(), args_rets_ptr.into_pointer_value(),
args_rets_ptr.into_pointer_value(), ),
), _ => {
_ => { return Err(CompileError::Codegen(
return Err(CompileError::Codegen( "trampoline function unimplemented".to_string(),
"trampoline function unimplemented".to_string(), ))
)) }
} };
};
let cast_ptr_ty = |wasmer_ty| match wasmer_ty { let cast_ptr_ty = |wasmer_ty| match wasmer_ty {
Type::I32 => intrinsics.i32_ptr_ty, Type::I32 => intrinsics.i32_ptr_ty,
@ -145,9 +143,8 @@ fn generate_trampoline<'ctx>(
Type::FuncRef => unimplemented!("funcref unimplemented in trampoline"), Type::FuncRef => unimplemented!("funcref unimplemented in trampoline"),
}; };
let mut args_vec = Vec::with_capacity(func_sig.params().len() + 2); let mut args_vec = Vec::with_capacity(func_sig.params().len() + 1);
args_vec.push(callee_vmctx_ptr); args_vec.push(callee_vmctx_ptr);
args_vec.push(caller_vmctx_ptr);
let mut i = 0; let mut i = 0;
for param_ty in func_sig.params().iter() { for param_ty in func_sig.params().iter() {

View File

@ -184,7 +184,7 @@ impl FuncTranslator {
let ty = wasm_fn_type.params()[idx]; let ty = wasm_fn_type.params()[idx];
let ty = type_to_llvm(&intrinsics, ty); let ty = type_to_llvm(&intrinsics, ty);
let value = func let value = func
.get_nth_param((idx as u32).checked_add(2).unwrap()) .get_nth_param((idx as u32).checked_add(1).unwrap())
.unwrap(); .unwrap();
// TODO: don't interleave allocas and stores. // TODO: don't interleave allocas and stores.
let alloca = cache_builder.build_alloca(ty, "param"); let alloca = cache_builder.build_alloca(ty, "param");
@ -2247,7 +2247,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
}; };
let params: Vec<_> = std::iter::repeat(callee_vmctx) let params: Vec<_> = std::iter::repeat(callee_vmctx)
.take(2) .take(1)
.chain( .chain(
self.state self.state
.peekn_extra(func_type.params().len())? .peekn_extra(func_type.params().len())?
@ -2517,7 +2517,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
let pushed_args = self.state.popn_save_extra(func_type.params().len())?; let pushed_args = self.state.popn_save_extra(func_type.params().len())?;
let args: Vec<_> = std::iter::repeat(ctx_ptr) let args: Vec<_> = std::iter::repeat(ctx_ptr)
.take(2) .take(1)
.chain(pushed_args.into_iter().enumerate().map(|(i, (v, info))| { .chain(pushed_args.into_iter().enumerate().map(|(i, (v, info))| {
match func_type.params()[i] { match func_type.params()[i] {
Type::F32 => self.builder.build_bitcast( Type::F32 => self.builder.build_bitcast(

View File

@ -1042,7 +1042,7 @@ pub fn func_type_to_llvm<'ctx>(
.iter() .iter()
.map(|&ty| type_to_llvm(intrinsics, ty)); .map(|&ty| type_to_llvm(intrinsics, ty));
let param_types: Vec<_> = std::iter::repeat(intrinsics.ctx_ptr_ty.as_basic_type_enum()) let param_types: Vec<_> = std::iter::repeat(intrinsics.ctx_ptr_ty.as_basic_type_enum())
.take(2) .take(1)
.chain(user_param_types) .chain(user_param_types)
.collect(); .collect();