Run cargo fmt on everything.

This commit is contained in:
losfair 2019-10-13 20:02:47 +08:00
parent c18bdd52cc
commit 5499a69ddc
7 changed files with 170 additions and 143 deletions

View File

@ -1,8 +1,11 @@
use std::sync::{
atomic::{AtomicU32, Ordering},
Arc,
};
use wasmer_runtime_core::{
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
module::ModuleInfo,
};
use std::sync::{Arc, atomic::{Ordering, AtomicU32}};
pub struct CallTrace {
counter: Arc<AtomicU32>,

View File

@ -94,11 +94,15 @@ pub fn get_inline_breakpoint_size(arch: Architecture, backend: Backend) -> Optio
match (arch, backend) {
(Architecture::X64, Backend::Singlepass) => Some(7),
(Architecture::Aarch64, Backend::Singlepass) => Some(12),
_ => None
_ => None,
}
}
pub fn read_inline_breakpoint(arch: Architecture, backend: Backend, code: &[u8]) -> Option<InlineBreakpoint> {
pub fn read_inline_breakpoint(
arch: Architecture,
backend: Backend,
code: &[u8],
) -> Option<InlineBreakpoint> {
match arch {
Architecture::X64 => match backend {
Backend::Singlepass => {
@ -118,7 +122,7 @@ pub fn read_inline_breakpoint(arch: Architecture, backend: Backend, code: &[u8])
None
}
}
_ => None
_ => None,
},
Architecture::Aarch64 => match backend {
Backend::Singlepass => {
@ -131,14 +135,14 @@ pub fn read_inline_breakpoint(arch: Architecture, backend: Backend, code: &[u8])
0 => InlineBreakpointType::Trace,
1 => InlineBreakpointType::Middleware,
_ => InlineBreakpointType::Unknown,
}
},
})
} else {
None
}
},
_ => None,
}
_ => None,
},
}
}

View File

@ -244,7 +244,9 @@ extern "C" fn signal_trap_handler(
siginfo: *mut siginfo_t,
ucontext: *mut c_void,
) {
use crate::backend::{Architecture, InlineBreakpointType, get_inline_breakpoint_size, read_inline_breakpoint};
use crate::backend::{
get_inline_breakpoint_size, read_inline_breakpoint, Architecture, InlineBreakpointType,
};
#[cfg(target_arch = "x86_64")]
static ARCH: Architecture = Architecture::X64;
@ -260,18 +262,23 @@ extern "C" fn signal_trap_handler(
let magic_size = if let Some(x) = get_inline_breakpoint_size(ARCH, v.backend) {
x
} else {
continue
continue;
};
let ip = fault.ip.get();
let end = v.base + v.msm.total_size;
if ip >= v.base && ip < end && ip + magic_size <= end {
if let Some(ib) = read_inline_breakpoint(ARCH, v.backend, std::slice::from_raw_parts(ip as *const u8, magic_size)) {
if let Some(ib) = read_inline_breakpoint(
ARCH,
v.backend,
std::slice::from_raw_parts(ip as *const u8, magic_size),
) {
fault.ip.set(ip + magic_size);
match ib.ty {
InlineBreakpointType::Trace => {},
InlineBreakpointType::Trace => {}
InlineBreakpointType::Middleware => {
let out: Option<Result<(), Box<dyn Any>>> = with_breakpoint_map(|bkpt_map| {
let out: Option<Result<(), Box<dyn Any>>> =
with_breakpoint_map(|bkpt_map| {
bkpt_map.and_then(|x| x.get(&ip)).map(|x| {
x(BreakpointInfo {
fault: Some(&fault),
@ -283,7 +290,7 @@ extern "C" fn signal_trap_handler(
println!("Failed calling middleware: {:?}", out);
}
}
_ => println!("Unknown breakpoint type: {:?}", ib.ty)
_ => println!("Unknown breakpoint type: {:?}", ib.ty),
}
return true;
}

View File

@ -1,6 +1,6 @@
use crate::backend::Backend;
use std::collections::BTreeMap;
use std::ops::Bound::{Included, Unbounded};
use crate::backend::Backend;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct RegisterIndex(pub usize);

View File

@ -1,6 +1,6 @@
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
use wasmer_runtime_core::backend::InlineBreakpointType;
pub use wasmer_runtime_core::state::x64_decl::{GPR, XMM};
use wasmer_runtime_core::backend::{InlineBreakpointType};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Location {

View File

@ -3,7 +3,7 @@
use crate::codegen_x64::*;
use crate::emitter_x64::*;
use dynasmrt::{aarch64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
use wasmer_runtime_core::backend::{InlineBreakpointType};
use wasmer_runtime_core::backend::InlineBreakpointType;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct AX(pub u32);
@ -558,7 +558,7 @@ impl Emitter for Assembler {
}
dynasm!(self ; str D(map_xmm(src).v()), [x_tmp3] );
}
_ => panic!("NOT IMPL: {:?} {:?} {:?}", sz, src, dst)
_ => panic!("NOT IMPL: {:?} {:?} {:?}", sz, src, dst),
}
}
@ -844,7 +844,7 @@ impl Emitter for Assembler {
; ldr w_tmp1, [x_tmp3]
; cmp w_tmp1, W(map_gpr(left).x())
)
},
}
(Size::S64, Location::GPR(left), Location::Memory(base, disp)) => {
if disp >= 0 {
dynasm!(self ; add x_tmp3, X(map_gpr(base).x()), disp as u32);
@ -856,7 +856,7 @@ impl Emitter for Assembler {
; ldr x_tmp1, [x_tmp3]
; cmp x_tmp1, X(map_gpr(left).x())
)
},
}
(Size::S32, Location::Memory(base, disp), Location::GPR(right)) => {
if disp >= 0 {
dynasm!(self ; add x_tmp3, X(map_gpr(base).x()), disp as u32);
@ -868,7 +868,7 @@ impl Emitter for Assembler {
; ldr w_tmp1, [x_tmp3]
; cmp W(map_gpr(right).x()), w_tmp1
)
},
}
(Size::S64, Location::Memory(base, disp), Location::GPR(right)) => {
if disp >= 0 {
dynasm!(self ; add x_tmp3, X(map_gpr(base).x()), disp as u32);
@ -880,7 +880,7 @@ impl Emitter for Assembler {
; ldr x_tmp1, [x_tmp3]
; cmp X(map_gpr(right).x()), x_tmp1
)
},
}
_ => unreachable!(),
}
}
@ -927,7 +927,7 @@ impl Emitter for Assembler {
; ldr w_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
dynasm!(
self
@ -953,7 +953,7 @@ impl Emitter for Assembler {
; ldr x_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
dynasm!(
self
@ -962,7 +962,7 @@ impl Emitter for Assembler {
; msub X(map_gpr(GPR::RDX).x()), X(map_gpr(GPR::RAX).x()), x_tmp1, x_tmp2
)
}
_ => unreachable!()
_ => unreachable!(),
}
}
fn emit_idiv(&mut self, sz: Size, divisor: Location) {
@ -984,7 +984,7 @@ impl Emitter for Assembler {
; ldr w_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
dynasm!(
self
@ -1010,7 +1010,7 @@ impl Emitter for Assembler {
; ldr x_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
dynasm!(
self
@ -1019,7 +1019,7 @@ impl Emitter for Assembler {
; msub X(map_gpr(GPR::RDX).x()), X(map_gpr(GPR::RAX).x()), x_tmp1, x_tmp2
)
}
_ => unreachable!()
_ => unreachable!(),
}
}
fn emit_shl(&mut self, sz: Size, src: Location, dst: Location) {
@ -1034,11 +1034,12 @@ impl Emitter for Assembler {
fn emit_rol(&mut self, sz: Size, src: Location, dst: Location) {
// TODO: We are changing content of `src` (possibly RCX) here. Will this break any assumptions?
match sz {
Size::S32 => {
match src {
Size::S32 => match src {
Location::Imm8(x) => {
assert!(x < 32);
binop_shift!(ror, self, sz, Location::Imm8(32 - x), dst, { unreachable!("rol") });
binop_shift!(ror, self, sz, Location::Imm8(32 - x), dst, {
unreachable!("rol")
});
}
Location::GPR(GPR::RCX) => {
dynasm!(
@ -1048,14 +1049,14 @@ impl Emitter for Assembler {
);
binop_shift!(ror, self, sz, src, dst, { unreachable!("rol") });
}
_ => unreachable!()
}
}
Size::S64 => {
match src {
_ => unreachable!(),
},
Size::S64 => match src {
Location::Imm8(x) => {
assert!(x < 64);
binop_shift!(ror, self, sz, Location::Imm8(64 - x), dst, { unreachable!("rol") });
binop_shift!(ror, self, sz, Location::Imm8(64 - x), dst, {
unreachable!("rol")
});
}
Location::GPR(GPR::RCX) => {
dynasm!(
@ -1065,13 +1066,11 @@ impl Emitter for Assembler {
);
binop_shift!(ror, self, sz, src, dst, { unreachable!("rol") });
}
_ => unreachable!()
_ => unreachable!(),
},
_ => unreachable!(),
}
}
_ => unreachable!()
}
}
fn emit_ror(&mut self, sz: Size, src: Location, dst: Location) {
binop_shift!(ror, self, sz, src, dst, { unreachable!("ror") });
}
@ -1485,16 +1484,20 @@ impl Emitter for Assembler {
}
}
fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &Location, reversed: bool) {
fn emit_clz_variant(
assembler: &mut Assembler,
sz: Size,
src: &Location,
dst: &Location,
reversed: bool,
) {
match sz {
Size::S32 => {
match *src {
Location::GPR(src) => {
dynasm!(
Location::GPR(src) => dynasm!(
assembler
; mov w_tmp1, W(map_gpr(src).x())
)
}
),
Location::Memory(base, disp) => {
if disp >= 0 {
dynasm!(assembler ; add x_tmp3, X(map_gpr(base).x()), disp as u32);
@ -1506,7 +1509,7 @@ fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &L
; ldr w_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
match *dst {
Location::GPR(dst) => {
@ -1518,17 +1521,15 @@ fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &L
; clz W(map_gpr(dst).x()), w_tmp1
);
}
_ => unreachable!()
_ => unreachable!(),
}
}
Size::S64 => {
match *src {
Location::GPR(src) => {
dynasm!(
Location::GPR(src) => dynasm!(
assembler
; mov x_tmp1, X(map_gpr(src).x())
)
}
),
Location::Memory(base, disp) => {
if disp >= 0 {
dynasm!(assembler ; add x_tmp3, X(map_gpr(base).x()), disp as u32);
@ -1540,7 +1541,7 @@ fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &L
; ldr x_tmp1, [x_tmp3]
)
}
_ => unreachable!()
_ => unreachable!(),
}
match *dst {
Location::GPR(dst) => {
@ -1552,9 +1553,9 @@ fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &L
; clz X(map_gpr(dst).x()), x_tmp1
);
}
_ => unreachable!()
_ => unreachable!(),
}
}
_ => unreachable!()
_ => unreachable!(),
}
}

View File

@ -621,10 +621,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
options
.optimized_backends
.iter()
.map(|&backend| -> (Backend, Box<dyn Fn() -> Box<dyn Compiler> + Send>) {
.map(
|&backend| -> (Backend, Box<dyn Fn() -> Box<dyn Compiler> + Send>) {
let options = options.clone();
(backend, Box::new(move || get_compiler_by_backend(backend, &options).unwrap()))
})
(
backend,
Box::new(move || {
get_compiler_by_backend(backend, &options).unwrap()
}),
)
},
)
.collect(),
interactive_shell,
)?
@ -635,13 +642,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
{
use wasmer_runtime::error::RuntimeError;
use wasmer_runtime_core::{
fault::{push_code_version, pop_code_version},
state::CodeVersion
fault::{pop_code_version, push_code_version},
state::CodeVersion,
};
push_code_version(CodeVersion {
baseline: true,
msm: instance.module.runnable_module.get_module_state_map().unwrap(),
msm: instance
.module
.runnable_module
.get_module_state_map()
.unwrap(),
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
backend: options.backend,
});
@ -815,7 +826,7 @@ fn validate(validate: Validate) {
}
fn get_compiler_by_backend(backend: Backend, opts: &Run) -> Option<Box<dyn Compiler>> {
use wasmer_runtime_core::codegen::{MiddlewareChain};
use wasmer_runtime_core::codegen::MiddlewareChain;
let opts = opts.clone();
let middlewares_gen = move || {
let mut middlewares = MiddlewareChain::new();
@ -829,10 +840,11 @@ fn get_compiler_by_backend(backend: Backend, opts: &Run) -> Option<Box<dyn Compi
Some(match backend {
#[cfg(feature = "backend-singlepass")]
Backend::Singlepass => {
use wasmer_runtime_core::codegen::StreamingCompiler;
use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG;
use wasmer_runtime_core::codegen::{StreamingCompiler};
let c: StreamingCompiler<SinglePassMCG, _, _, _, _> = StreamingCompiler::new(middlewares_gen);
let c: StreamingCompiler<SinglePassMCG, _, _, _, _> =
StreamingCompiler::new(middlewares_gen);
Box::new(c)
}
#[cfg(not(feature = "backend-singlepass"))]