Make translator::intrinsics accessible to trampoline.

Start filling in the code to generate trampolines. Move func_type_to_llvm and type_to_llvm from code.rs to intrinsics.rs so that trampoline code can reuse them.
This commit is contained in:
Nick Lewycky
2020-04-24 16:42:14 -07:00
parent a6bde15ce5
commit 1de21f0c33
5 changed files with 85 additions and 49 deletions

View File

@ -1,5 +1,7 @@
use super::{
intrinsics::{tbaa_label, CtxType, GlobalCache, Intrinsics, MemoryCache},
intrinsics::{
func_type_to_llvm, tbaa_label, type_to_llvm, CtxType, GlobalCache, Intrinsics, MemoryCache,
},
read_info::blocktype_to_type,
// stackmap::{StackmapEntry, StackmapEntryKind, StackmapRegistry, ValueSemantic},
state::{ControlFrame, ExtraInfo, IfElseState, State},
@ -313,47 +315,6 @@ impl FuncTranslator {
}
}
fn func_type_to_llvm<'ctx>(
context: &'ctx Context,
intrinsics: &Intrinsics<'ctx>,
fntype: &FuncType,
) -> FunctionType<'ctx> {
let user_param_types = fntype
.params()
.iter()
.map(|&ty| type_to_llvm(intrinsics, ty));
let param_types: Vec<_> = std::iter::once(intrinsics.ctx_ptr_ty.as_basic_type_enum())
.chain(user_param_types)
.collect();
match fntype.results() {
&[] => intrinsics.void_ty.fn_type(&param_types, false),
&[single_value] => type_to_llvm(intrinsics, single_value).fn_type(&param_types, false),
returns @ _ => {
let basic_types: Vec<_> = returns
.iter()
.map(|&ty| type_to_llvm(intrinsics, ty))
.collect();
context
.struct_type(&basic_types, false)
.fn_type(&param_types, false)
}
}
}
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"),
}
}
// Create a vector where each lane contains the same value.
fn splat_vector<'ctx>(
builder: &Builder<'ctx>,