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::state::{ControlFrame, IfElseState, State};
use crate::trampolines::generate_trampolines; 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 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()) 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) => { LocalOrImport::Local(local_func_index) => {
let params: Vec<_> = std::iter::once(ctx.basic()) let params: Vec<_> = std::iter::once(ctx.basic())
.chain( .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] { .map(|(i, &v)| match func_sig.params()[i] {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()), Type::F32 => builder.build_bitcast(
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()), v,
_ => v intrinsics.i32_ty,
}) &state.var_name(),
),
Type::F64 => builder.build_bitcast(
v,
intrinsics.i64_ty,
&state.var_name(),
),
_ => v,
}),
) )
.collect(); .collect();
@ -1457,12 +1473,23 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let params: Vec<_> = std::iter::once(ctx_ptr.as_basic_value_enum()) let params: Vec<_> = std::iter::once(ctx_ptr.as_basic_value_enum())
.chain( .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] { .map(|(i, &v)| match func_sig.params()[i] {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()), Type::F32 => builder.build_bitcast(
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()), v,
_ => v intrinsics.i32_ty,
}) &state.var_name(),
),
Type::F64 => builder.build_bitcast(
v,
intrinsics.i64_ty,
&state.var_name(),
),
_ => v,
}),
) )
.collect(); .collect();
@ -1510,8 +1537,12 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
if let Some(basic_value) = call_site.try_as_basic_value().left() { if let Some(basic_value) = call_site.try_as_basic_value().left() {
match func_sig.returns().len() { match func_sig.returns().len() {
1 => state.push1(match func_sig.returns()[0] { 1 => state.push1(match func_sig.returns()[0] {
Type::F32 => builder.build_bitcast(basic_value, intrinsics.f32_ty, "ret_cast"), Type::F32 => {
Type::F64 => builder.build_bitcast(basic_value, intrinsics.f64_ty, "ret_cast"), builder.build_bitcast(basic_value, intrinsics.f32_ty, "ret_cast")
}
Type::F64 => {
builder.build_bitcast(basic_value, intrinsics.f64_ty, "ret_cast")
}
_ => basic_value, _ => basic_value,
}), }),
count @ _ => { count @ _ => {
@ -1665,15 +1696,18 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let pushed_args = state.popn_save(wasmer_fn_sig.params().len())?; let pushed_args = state.popn_save(wasmer_fn_sig.params().len())?;
let args: Vec<_> = std::iter::once(ctx_ptr) let args: Vec<_> = std::iter::once(ctx_ptr)
.chain( .chain(pushed_args.into_iter().enumerate().map(|(i, v)| {
pushed_args.into_iter().enumerate() match wasmer_fn_sig.params()[i] {
.map(|(i, v)| match wasmer_fn_sig.params()[i] { Type::F32 => {
Type::F32 => builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name()), builder.build_bitcast(v, intrinsics.i32_ty, &state.var_name())
Type::F64 => builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name()), }
_ => v Type::F64 => {
}) builder.build_bitcast(v, intrinsics.i64_ty, &state.var_name())
) }
.collect(); _ => v,
}
}))
.collect();
let typed_func_ptr = builder.build_pointer_cast( let typed_func_ptr = builder.build_pointer_cast(
func_ptr, func_ptr,
@ -1714,8 +1748,12 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
[_] => { [_] => {
let value = call_site.try_as_basic_value().left().unwrap(); let value = call_site.try_as_basic_value().left().unwrap();
state.push1(match wasmer_fn_sig.returns()[0] { state.push1(match wasmer_fn_sig.returns()[0] {
Type::F32 => builder.build_bitcast(value, intrinsics.f32_ty, "ret_cast"), Type::F32 => {
Type::F64 => builder.build_bitcast(value, intrinsics.f64_ty, "ret_cast"), builder.build_bitcast(value, intrinsics.f32_ty, "ret_cast")
}
Type::F64 => {
builder.build_bitcast(value, intrinsics.f64_ty, "ret_cast")
}
_ => value, _ => value,
}); });
} }
@ -4817,9 +4855,11 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
[one_value] => { [one_value] => {
let builder = self.builder.as_ref().unwrap(); let builder = self.builder.as_ref().unwrap();
let intrinsics = self.intrinsics.as_ref().unwrap(); let intrinsics = self.intrinsics.as_ref().unwrap();
builder.build_return(Some( builder.build_return(Some(&builder.build_bitcast(
&builder.build_bitcast(one_value.as_basic_value_enum(), type_to_llvm_int_only(intrinsics, self.func_sig.returns()[0]), "return") 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"), _ => 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)); let alloca = builder.build_alloca(real_ty_llvm, &format!("local{}", index));
//if real_ty_llvm != ty { //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 { /*} else {
builder.build_store(alloca, param); builder.build_store(alloca, param);
}*/ }*/

View File

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

View File

@ -18,6 +18,7 @@ use wasmer_runtime_core::{
}, },
cache::{Artifact, Error as CacheError}, cache::{Artifact, Error as CacheError},
codegen::*, codegen::*,
fault::raw::register_preservation_trampoline,
loader::CodeMemory, loader::CodeMemory,
memory::MemoryType, memory::MemoryType,
module::{ModuleInfo, ModuleInner}, module::{ModuleInfo, ModuleInner},
@ -32,7 +33,6 @@ use wasmer_runtime_core::{
TableIndex, Type, TableIndex, Type,
}, },
vm::{self, LocalGlobal, LocalTable, INTERNALS_SIZE}, vm::{self, LocalGlobal, LocalTable, INTERNALS_SIZE},
fault::raw::register_preservation_trampoline,
}; };
use wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}; 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 { 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 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 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.addr_rax = target_address as u64;
trampoline.movabsq_r11[0] = 0x49; trampoline.movabsq_r11[0] = 0x49;
trampoline.movabsq_r11[1] = 0xbb; 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[0] = 0x41;
trampoline.jmpq_r11[1] = 0xff; trampoline.jmpq_r11[1] = 0xff;
trampoline.jmpq_r11[2] = 0xe3; trampoline.jmpq_r11[2] = 0xe3;