Cargo fmt

This commit is contained in:
losfair 2019-08-15 19:13:00 -07:00
parent 8a1f399df6
commit afa0600701
3 changed files with 87 additions and 37 deletions

View File

@ -34,7 +34,12 @@ use crate::stackmap::{StackmapEntry, StackmapEntryKind, StackmapRegistry, ValueS
use crate::state::{ControlFrame, IfElseState, State};
use crate::trampolines::generate_trampolines;
fn func_sig_to_llvm(context: &Context, intrinsics: &Intrinsics, sig: &FuncSig, type_to_llvm: fn(intrinsics: &Intrinsics, ty: Type) -> BasicTypeEnum) -> FunctionType {
fn func_sig_to_llvm(
context: &Context,
intrinsics: &Intrinsics,
sig: &FuncSig,
type_to_llvm: fn(intrinsics: &Intrinsics, ty: Type) -> BasicTypeEnum,
) -> FunctionType {
let user_param_types = sig.params().iter().map(|&ty| type_to_llvm(intrinsics, ty));
let param_types: Vec<_> = std::iter::once(intrinsics.ctx_ptr_ty.as_basic_type_enum())
@ -1437,12 +1442,23 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
LocalOrImport::Local(local_func_index) => {
let params: Vec<_> = std::iter::once(ctx.basic())
.chain(
state.peekn(func_sig.params().len())?.iter().enumerate()
state
.peekn(func_sig.params().len())?
.iter()
.enumerate()
.map(|(i, &v)| match func_sig.params()[i] {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()),
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()),
_ => v
})
Type::F32 => builder.build_bitcast(
v,
intrinsics.i32_ty,
&state.var_name(),
),
Type::F64 => builder.build_bitcast(
v,
intrinsics.i64_ty,
&state.var_name(),
),
_ => v,
}),
)
.collect();
@ -1457,12 +1473,23 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let params: Vec<_> = std::iter::once(ctx_ptr.as_basic_value_enum())
.chain(
state.peekn(func_sig.params().len())?.iter().enumerate()
state
.peekn(func_sig.params().len())?
.iter()
.enumerate()
.map(|(i, &v)| match func_sig.params()[i] {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()),
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()),
_ => v
})
Type::F32 => builder.build_bitcast(
v,
intrinsics.i32_ty,
&state.var_name(),
),
Type::F64 => builder.build_bitcast(
v,
intrinsics.i64_ty,
&state.var_name(),
),
_ => v,
}),
)
.collect();
@ -1510,8 +1537,12 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
if let Some(basic_value) = call_site.try_as_basic_value().left() {
match func_sig.returns().len() {
1 => state.push1(match func_sig.returns()[0] {
Type::F32 => builder.build_bitcast(basic_value, intrinsics.f32_ty, "ret_cast"),
Type::F64 => builder.build_bitcast(basic_value, intrinsics.f64_ty, "ret_cast"),
Type::F32 => {
builder.build_bitcast(basic_value, intrinsics.f32_ty, "ret_cast")
}
Type::F64 => {
builder.build_bitcast(basic_value, intrinsics.f64_ty, "ret_cast")
}
_ => basic_value,
}),
count @ _ => {
@ -1665,15 +1696,18 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let pushed_args = state.popn_save(wasmer_fn_sig.params().len())?;
let args: Vec<_> = std::iter::once(ctx_ptr)
.chain(
pushed_args.into_iter().enumerate()
.map(|(i, v)| match wasmer_fn_sig.params()[i] {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()),
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()),
_ => v
})
)
.collect();
.chain(pushed_args.into_iter().enumerate().map(|(i, v)| {
match wasmer_fn_sig.params()[i] {
Type::F32 => {
builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name())
}
Type::F64 => {
builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name())
}
_ => v,
}
}))
.collect();
let typed_func_ptr = builder.build_pointer_cast(
func_ptr,
@ -1714,8 +1748,12 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
[_] => {
let value = call_site.try_as_basic_value().left().unwrap();
state.push1(match wasmer_fn_sig.returns()[0] {
Type::F32 => builder.build_bitcast(value, intrinsics.f32_ty, "ret_cast"),
Type::F64 => builder.build_bitcast(value, intrinsics.f64_ty, "ret_cast"),
Type::F32 => {
builder.build_bitcast(value, intrinsics.f32_ty, "ret_cast")
}
Type::F64 => {
builder.build_bitcast(value, intrinsics.f64_ty, "ret_cast")
}
_ => value,
});
}
@ -4817,9 +4855,11 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
[one_value] => {
let builder = self.builder.as_ref().unwrap();
let intrinsics = self.intrinsics.as_ref().unwrap();
builder.build_return(Some(
&builder.build_bitcast(one_value.as_basic_value_enum(), type_to_llvm_int_only(intrinsics, self.func_sig.returns()[0]), "return")
));
builder.build_return(Some(&builder.build_bitcast(
one_value.as_basic_value_enum(),
type_to_llvm_int_only(intrinsics, self.func_sig.returns()[0]),
"return",
)));
}
_ => unimplemented!("multi-value returns not yet implemented"),
}
@ -4935,7 +4975,10 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
let alloca = builder.build_alloca(real_ty_llvm, &format!("local{}", index));
//if real_ty_llvm != ty {
builder.build_store(alloca, builder.build_bitcast(param, real_ty_llvm, &state.var_name()));
builder.build_store(
alloca,
builder.build_bitcast(param, real_ty_llvm, &state.var_name()),
);
/*} else {
builder.build_store(alloca, param);
}*/

View File

@ -373,7 +373,9 @@ impl InstanceImage {
pub mod x64 {
use super::*;
use crate::codegen::BreakpointMap;
use crate::fault::{catch_unsafe_unwind, run_on_alternative_stack, get_boundary_register_preservation};
use crate::fault::{
catch_unsafe_unwind, get_boundary_register_preservation, run_on_alternative_stack,
};
use crate::structures::TypedIndex;
use crate::types::LocalGlobalIndex;
use crate::vm::Ctx;
@ -808,11 +810,16 @@ pub mod x64 {
// Are we unwinding through an optimized/baseline boundary?
if is_baseline && !was_baseline {
let callee_saved = &*get_boundary_register_preservation();
known_registers[X64Register::GPR(GPR::R15).to_index().0] = Some(callee_saved.r15);
known_registers[X64Register::GPR(GPR::R14).to_index().0] = Some(callee_saved.r14);
known_registers[X64Register::GPR(GPR::R13).to_index().0] = Some(callee_saved.r13);
known_registers[X64Register::GPR(GPR::R12).to_index().0] = Some(callee_saved.r12);
known_registers[X64Register::GPR(GPR::RBX).to_index().0] = Some(callee_saved.rbx);
known_registers[X64Register::GPR(GPR::R15).to_index().0] =
Some(callee_saved.r15);
known_registers[X64Register::GPR(GPR::R14).to_index().0] =
Some(callee_saved.r14);
known_registers[X64Register::GPR(GPR::R13).to_index().0] =
Some(callee_saved.r13);
known_registers[X64Register::GPR(GPR::R12).to_index().0] =
Some(callee_saved.r12);
known_registers[X64Register::GPR(GPR::RBX).to_index().0] =
Some(callee_saved.rbx);
}
was_baseline = is_baseline;

View File

@ -18,6 +18,7 @@ use wasmer_runtime_core::{
},
cache::{Artifact, Error as CacheError},
codegen::*,
fault::raw::register_preservation_trampoline,
loader::CodeMemory,
memory::MemoryType,
module::{ModuleInfo, ModuleInner},
@ -32,7 +33,6 @@ use wasmer_runtime_core::{
TableIndex, Type,
},
vm::{self, LocalGlobal, LocalTable, INTERNALS_SIZE},
fault::raw::register_preservation_trampoline,
};
use wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType};
@ -221,7 +221,6 @@ impl RunnableModule for X64ExecutionContext {
}
unsafe fn patch_local_function(&self, idx: usize, target_address: usize) -> bool {
/*
0: 48 b8 42 42 42 42 42 42 42 42 movabsq $4774451407313060418, %rax
a: 49 bb 43 43 43 43 43 43 43 43 movabsq $4846791580151137091, %r11
@ -245,7 +244,8 @@ impl RunnableModule for X64ExecutionContext {
trampoline.addr_rax = target_address as u64;
trampoline.movabsq_r11[0] = 0x49;
trampoline.movabsq_r11[1] = 0xbb;
trampoline.addr_r11 = register_preservation_trampoline as unsafe extern "C" fn() as usize as u64;
trampoline.addr_r11 =
register_preservation_trampoline as unsafe extern "C" fn() as usize as u64;
trampoline.jmpq_r11[0] = 0x41;
trampoline.jmpq_r11[1] = 0xff;
trampoline.jmpq_r11[2] = 0xe3;