mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-25 01:39:26 +00:00
Code cleanup. Remove reimplementation of type_to_llvm_ptr, use the one in intrinsics instead.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
use crate::config::LLVMConfig;
|
use crate::config::LLVMConfig;
|
||||||
use crate::object_file::load_object_file;
|
use crate::object_file::load_object_file;
|
||||||
use crate::translator::intrinsics::{func_type_to_llvm, Intrinsics};
|
use crate::translator::intrinsics::{func_type_to_llvm, type_to_llvm_ptr, Intrinsics};
|
||||||
use inkwell::{
|
use inkwell::{
|
||||||
context::Context, module::Linkage, passes::PassManager, targets::FileType, types::BasicType,
|
context::Context, module::Linkage, passes::PassManager, targets::FileType, types::BasicType,
|
||||||
values::FunctionValue, AddressSpace,
|
values::FunctionValue, AddressSpace,
|
||||||
@ -145,16 +145,6 @@ fn generate_trampoline<'ctx>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let cast_ptr_ty = |wasmer_ty| match wasmer_ty {
|
|
||||||
Type::I32 => intrinsics.i32_ptr_ty,
|
|
||||||
Type::F32 => intrinsics.f32_ptr_ty,
|
|
||||||
Type::I64 => intrinsics.i64_ptr_ty,
|
|
||||||
Type::F64 => intrinsics.f64_ptr_ty,
|
|
||||||
Type::V128 => intrinsics.i128_ptr_ty,
|
|
||||||
Type::AnyRef => unimplemented!("anyref unimplemented in trampoline"),
|
|
||||||
Type::FuncRef => unimplemented!("funcref unimplemented in trampoline"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut args_vec = Vec::with_capacity(func_sig.params().len() + 1);
|
let mut args_vec = Vec::with_capacity(func_sig.params().len() + 1);
|
||||||
args_vec.push(callee_vmctx_ptr);
|
args_vec.push(callee_vmctx_ptr);
|
||||||
|
|
||||||
@ -164,7 +154,7 @@ fn generate_trampoline<'ctx>(
|
|||||||
let item_pointer =
|
let item_pointer =
|
||||||
unsafe { builder.build_in_bounds_gep(args_rets_ptr, &[index], "arg_ptr") };
|
unsafe { builder.build_in_bounds_gep(args_rets_ptr, &[index], "arg_ptr") };
|
||||||
|
|
||||||
let casted_pointer_type = cast_ptr_ty(*param_ty);
|
let casted_pointer_type = type_to_llvm_ptr(intrinsics, *param_ty);
|
||||||
|
|
||||||
let typed_item_pointer =
|
let typed_item_pointer =
|
||||||
builder.build_pointer_cast(item_pointer, casted_pointer_type, "typed_arg_pointer");
|
builder.build_pointer_cast(item_pointer, casted_pointer_type, "typed_arg_pointer");
|
||||||
@ -182,7 +172,7 @@ fn generate_trampoline<'ctx>(
|
|||||||
match *func_sig.results() {
|
match *func_sig.results() {
|
||||||
[] => {}
|
[] => {}
|
||||||
[one_ret] => {
|
[one_ret] => {
|
||||||
let ret_ptr_type = cast_ptr_ty(one_ret);
|
let ret_ptr_type = type_to_llvm_ptr(intrinsics, one_ret);
|
||||||
|
|
||||||
let typed_ret_ptr =
|
let typed_ret_ptr =
|
||||||
builder.build_pointer_cast(args_rets_ptr, ret_ptr_type, "typed_ret_ptr");
|
builder.build_pointer_cast(args_rets_ptr, ret_ptr_type, "typed_ret_ptr");
|
||||||
|
@ -55,10 +55,7 @@ fn wptype_to_type(ty: wasmparser::Type) -> WasmResult<Type> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FuncTranslator {
|
// TODO: move this into inkwell.
|
||||||
ctx: Context,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn const_zero(ty: BasicTypeEnum) -> BasicValueEnum {
|
fn const_zero(ty: BasicTypeEnum) -> BasicValueEnum {
|
||||||
match ty {
|
match ty {
|
||||||
BasicTypeEnum::ArrayType(ty) => ty.const_zero().as_basic_value_enum(),
|
BasicTypeEnum::ArrayType(ty) => ty.const_zero().as_basic_value_enum(),
|
||||||
@ -70,6 +67,10 @@ fn const_zero(ty: BasicTypeEnum) -> BasicValueEnum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FuncTranslator {
|
||||||
|
ctx: Context,
|
||||||
|
}
|
||||||
|
|
||||||
impl FuncTranslator {
|
impl FuncTranslator {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -40,6 +40,18 @@ pub fn type_to_llvm_ptr<'ctx>(intrinsics: &Intrinsics<'ctx>, ty: Type) -> Pointe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn type_to_llvm<'ctx>(intrinsics: &Intrinsics<'ctx>, ty: Type) -> BasicTypeEnum<'ctx> {
|
||||||
|
match ty {
|
||||||
|
Type::I32 => intrinsics.i32_ty.as_basic_type_enum(),
|
||||||
|
Type::I64 => intrinsics.i64_ty.as_basic_type_enum(),
|
||||||
|
Type::F32 => intrinsics.f32_ty.as_basic_type_enum(),
|
||||||
|
Type::F64 => intrinsics.f64_ty.as_basic_type_enum(),
|
||||||
|
Type::V128 => intrinsics.i128_ty.as_basic_type_enum(),
|
||||||
|
Type::AnyRef => unimplemented!("anyref in the llvm backend"),
|
||||||
|
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Struct containing LLVM and VM intrinsics.
|
/// Struct containing LLVM and VM intrinsics.
|
||||||
pub struct Intrinsics<'ctx> {
|
pub struct Intrinsics<'ctx> {
|
||||||
pub ctlz_i32: FunctionValue<'ctx>,
|
pub ctlz_i32: FunctionValue<'ctx>,
|
||||||
@ -923,15 +935,3 @@ pub fn func_type_to_llvm<'ctx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_to_llvm<'ctx>(intrinsics: &Intrinsics<'ctx>, ty: Type) -> BasicTypeEnum<'ctx> {
|
|
||||||
match ty {
|
|
||||||
Type::I32 => intrinsics.i32_ty.as_basic_type_enum(),
|
|
||||||
Type::I64 => intrinsics.i64_ty.as_basic_type_enum(),
|
|
||||||
Type::F32 => intrinsics.f32_ty.as_basic_type_enum(),
|
|
||||||
Type::F64 => intrinsics.f64_ty.as_basic_type_enum(),
|
|
||||||
Type::V128 => intrinsics.i128_ty.as_basic_type_enum(),
|
|
||||||
Type::AnyRef => unimplemented!("anyref in the llvm backend"),
|
|
||||||
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user