diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index 8da52b401..fc27b3240 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -75,16 +75,21 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri ), i32, > = dyn_f_many.native().unwrap(); - c.bench_function(&format!("basic static func with many args {}", compiler_name), |b| { - b.iter(|| { - let result = black_box( - f_many - .call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) - .unwrap(), - ); - assert_eq!(result, 210); - }) - }); + c.bench_function( + &format!("basic static func with many args {}", compiler_name), + |b| { + b.iter(|| { + let result = black_box( + f_many + .call( + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + ) + .unwrap(), + ); + assert_eq!(result, 210); + }) + }, + ); } pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Criterion) { @@ -105,37 +110,40 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr }); let dyn_f_many: &Function = instance.exports.get("add20").unwrap(); - c.bench_function(&format!("basic dynfunc with many args {}", compiler_name), |b| { - b.iter(|| { - let dyn_result = black_box( - dyn_f_many - .call(&[ - Val::I32(1), - Val::I32(2), - Val::I32(3), - Val::I32(4), - Val::I32(5), - Val::I32(6), - Val::I32(7), - Val::I32(8), - Val::I32(9), - Val::I32(10), - Val::I32(11), - Val::I32(12), - Val::I32(13), - Val::I32(14), - Val::I32(15), - Val::I32(16), - Val::I32(17), - Val::I32(18), - Val::I32(19), - Val::I32(20), - ]) - .unwrap(), - ); - assert_eq!(dyn_result[0], Val::I32(210)); - }) - }); + c.bench_function( + &format!("basic dynfunc with many args {}", compiler_name), + |b| { + b.iter(|| { + let dyn_result = black_box( + dyn_f_many + .call(&[ + Val::I32(1), + Val::I32(2), + Val::I32(3), + Val::I32(4), + Val::I32(5), + Val::I32(6), + Val::I32(7), + Val::I32(8), + Val::I32(9), + Val::I32(10), + Val::I32(11), + Val::I32(12), + Val::I32(13), + Val::I32(14), + Val::I32(15), + Val::I32(16), + Val::I32(17), + Val::I32(18), + Val::I32(19), + Val::I32(20), + ]) + .unwrap(), + ); + assert_eq!(dyn_result[0], Val::I32(210)); + }) + }, + ); } fn run_static_benchmarks(_c: &mut Criterion) { diff --git a/build.rs b/build.rs index f798c0170..588d1b7de 100644 --- a/build.rs +++ b/build.rs @@ -30,8 +30,11 @@ fn main() -> anyhow::Result<()> { // Spectests test generation { - let mut spectests = - Testsuite { buffer: String::new(), path: vec![], ignores: ignores.clone() }; + let mut spectests = Testsuite { + buffer: String::new(), + path: vec![], + ignores: ignores.clone(), + }; with_features(&mut spectests, &compilers, |mut spectests| { with_test_module(&mut spectests, "spec", |spectests| { @@ -64,7 +67,11 @@ fn main() -> anyhow::Result<()> { // Wasitest test generation { - let mut wasitests = Testsuite { buffer: String::new(), path: vec![], ignores }; + let mut wasitests = Testsuite { + buffer: String::new(), + path: vec![], + ignores, + }; let wasi_versions = ["unstable", "snapshot1"]; with_features(&mut wasitests, &compilers, |mut wasitests| { with_test_module(&mut wasitests, "wasitests", |wasitests| { diff --git a/examples/early_exit.rs b/examples/early_exit.rs index 39d02cf71..334cae384 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -87,7 +87,10 @@ fn main() -> anyhow::Result<()> { // When we call a function it can either succeed or fail. We expect it to fail. match run_func.call(1, 7) { Ok(result) => { - bail!("Expected early termination with `ExitCode`, found: {}", result); + bail!( + "Expected early termination with `ExitCode`, found: {}", + result + ); } // In case of a failure, which we expect, we attempt to downcast the error into the error // type that we were expecting. diff --git a/examples/errors.rs b/examples/errors.rs index 7c3b958e7..6823a2e90 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -59,7 +59,10 @@ fn main() -> Result<(), Box> { // produce an error. // // Let's get it. - let div_by_zero = instance.exports.get_function("div_by_zero")?.native::<(), i32>()?; + let div_by_zero = instance + .exports + .get_function("div_by_zero")? + .native::<(), i32>()?; println!("Calling `div_by_zero` function..."); // Let's call the `div_by_zero` exported function. diff --git a/examples/exports_global.rs b/examples/exports_global.rs index 7f5d4363a..bf6f6c234 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -88,7 +88,10 @@ fn main() -> Result<(), Box> { // // We will use an exported function for the `one` global // and the Global API for `some`. - let get_one = instance.exports.get_function("get_one")?.native::<(), f32>()?; + let get_one = instance + .exports + .get_function("get_one")? + .native::<(), f32>()?; let one_value = get_one.call()?; let some_value = some.get(); @@ -117,7 +120,10 @@ fn main() -> Result<(), Box> { // 2. Using the Global API directly. // // We will use both for the `some` global. - let set_some = instance.exports.get_function("set_some")?.native::()?; + let set_some = instance + .exports + .get_function("set_some")? + .native::()?; set_some.call(21.0)?; let some_result = some.get(); println!("`some` value after `set_some`: {:?}", some_result); diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index 253920c84..bfc250722 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -50,7 +50,9 @@ fn main() -> Result<(), Box> { // Let's instantiate the Wasm module. let instance = Instance::new(&module, &import_object)?; - let load = instance.exports.get_native_function::<(), (WasmPtr, i32)>("load")?; + let load = instance + .exports + .get_native_function::<(), (WasmPtr, i32)>("load")?; // Here we go. // diff --git a/examples/imports_exports.rs b/examples/imports_exports.rs index da2b315d2..127c07abf 100644 --- a/examples/imports_exports.rs +++ b/examples/imports_exports.rs @@ -59,8 +59,9 @@ fn main() -> Result<(), Box> { // covered in more detail in other examples. println!("Creating the imported function..."); let host_function_signature = FunctionType::new(vec![], vec![Type::I32]); - let host_function = - Function::new(&store, &host_function_signature, |_args| Ok(vec![Value::I32(42)])); + let host_function = Function::new(&store, &host_function_signature, |_args| { + Ok(vec![Value::I32(42)]) + }); println!("Creating the imported global..."); let host_global = Global::new(&store, Value::I32(42)); diff --git a/examples/imports_function.rs b/examples/imports_function.rs index c29714121..c42b4d497 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -85,7 +85,10 @@ fn main() -> Result<(), Box> { // Here we go. // // The Wasm module exports a function called `sum`. Let's get it. - let sum = instance.exports.get_function("sum")?.native::<(i32, i32), i32>()?; + let sum = instance + .exports + .get_function("sum")? + .native::<(i32, i32), i32>()?; println!("Calling `sum` function..."); // Let's call the `sum` exported function. It will call each diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index 084610b8c..b7636ad6f 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -100,8 +100,10 @@ fn main() -> Result<(), Box> { // Here we go. // // The Wasm module exports a function called `increment_counter_loop`. Let's get it. - let increment_counter_loop = - instance.exports.get_function("increment_counter_loop")?.native::()?; + let increment_counter_loop = instance + .exports + .get_function("increment_counter_loop")? + .native::()?; let counter_value: i32 = *shared_counter.lock().unwrap(); println!("Initial ounter value: {:?}", counter_value); diff --git a/examples/imports_global.rs b/examples/imports_global.rs index 29fb35169..59ce9da2d 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -65,8 +65,14 @@ fn main() -> Result<(), Box> { // // The Wasm module only imports some globals. We'll have to interact // with them either using the Global API or exported functions. - let get_some = instance.exports.get_function("get_some")?.native::<(), f32>()?; - let get_other = instance.exports.get_function("get_other")?.native::<(), f32>()?; + let get_some = instance + .exports + .get_function("get_some")? + .native::<(), f32>()?; + let get_other = instance + .exports + .get_function("get_other")? + .native::<(), f32>()?; let some_result = get_some.call()?; let other_result = get_other.call()?; @@ -96,7 +102,10 @@ fn main() -> Result<(), Box> { println!("Altering global values through exported functions..."); // Changes made to global through exported functions will // be reflected on the host side. - let set_other = instance.exports.get_function("set_other")?.native::()?; + let set_other = instance + .exports + .get_function("set_other")? + .native::()?; set_other.call(42.0)?; println!("other value (via Global API): {:?}", other.get()); diff --git a/examples/instance.rs b/examples/instance.rs index 9dadda986..0ecbaa88a 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -60,7 +60,10 @@ fn main() -> Result<(), Box> { // Here we are retrieving the exported function. We won't go into details here // as the main focus of this example is to show how to create an instance out // of a Wasm module and have basic interactions with it. - let add_one = instance.exports.get_function("add_one")?.native::()?; + let add_one = instance + .exports + .get_function("add_one")? + .native::()?; println!("Calling `add_one` function..."); let result = add_one.call(1)?; diff --git a/examples/metering.rs b/examples/metering.rs index d2c1ea2f6..d98e30a11 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -87,7 +87,10 @@ fn main() -> anyhow::Result<()> { // // Our module exports a single `add_one` function. We want to // measure the cost of executing this function. - let add_one = instance.exports.get_function("add_one")?.native::()?; + let add_one = instance + .exports + .get_function("add_one")? + .native::()?; println!("Calling `add_one` function once..."); add_one.call(1)?; @@ -99,9 +102,15 @@ fn main() -> anyhow::Result<()> { // * `i32.const` is a `Operator::I32Const` which costs 1 point; // * `i32.add` is a `Operator::I32Add` which costs 2 points. let remaining_points_after_first_call = get_remaining_points(&instance); - assert_eq!(remaining_points_after_first_call, MeteringPoints::Remaining(6)); + assert_eq!( + remaining_points_after_first_call, + MeteringPoints::Remaining(6) + ); - println!("Remaining points after the first call: {:?}", remaining_points_after_first_call); + println!( + "Remaining points after the first call: {:?}", + remaining_points_after_first_call + ); println!("Calling `add_one` function twice..."); add_one.call(1)?; @@ -109,9 +118,15 @@ fn main() -> anyhow::Result<()> { // We spent 4 more points with the second call. // We have 2 remaining points. let remaining_points_after_second_call = get_remaining_points(&instance); - assert_eq!(remaining_points_after_second_call, MeteringPoints::Remaining(2)); + assert_eq!( + remaining_points_after_second_call, + MeteringPoints::Remaining(2) + ); - println!("Remaining points after the second call: {:?}", remaining_points_after_second_call); + println!( + "Remaining points after the second call: {:?}", + remaining_points_after_second_call + ); // Because calling our `add_one` function consumes 4 points, // calling it a third time will fail: we already consume 8 @@ -119,7 +134,10 @@ fn main() -> anyhow::Result<()> { println!("Calling `add_one` function a third time..."); match add_one.call(1) { Ok(result) => { - bail!("Expected failure while calling `add_one`, found: {}", result); + bail!( + "Expected failure while calling `add_one`, found: {}", + result + ); } Err(_) => { println!("Calling `add_one` failed."); diff --git a/examples/table.rs b/examples/table.rs index da5bfddd1..dc88f4cea 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -74,7 +74,14 @@ fn main() -> anyhow::Result<()> { let guest_table = instance.exports.get_table("__indirect_function_table")?; // And demonstrate that it has the properties that we set in the Wasm. assert_eq!(guest_table.size(), 3); - assert_eq!(guest_table.ty(), &TableType { ty: Type::FuncRef, minimum: 3, maximum: Some(6) }); + assert_eq!( + guest_table.ty(), + &TableType { + ty: Type::FuncRef, + minimum: 3, + maximum: Some(6) + } + ); // == Setting elements in a table == @@ -101,7 +108,14 @@ fn main() -> anyhow::Result<()> { assert_eq!(previous_size, 3); assert_eq!(guest_table.size(), 6); - assert_eq!(guest_table.ty(), &TableType { ty: Type::FuncRef, minimum: 3, maximum: Some(6) }); + assert_eq!( + guest_table.ty(), + &TableType { + ty: Type::FuncRef, + minimum: 3, + maximum: Some(6) + } + ); // Now demonstrate that the function we grew the table with is actually in the table. for table_index in 3..6 { if let Value::FuncRef(Some(f)) = guest_table.get(table_index as _).unwrap() { diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index e5cdc2e30..8d2f92d3b 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -105,7 +105,8 @@ impl Tunables for LimitingTunables { ) -> Result, MemoryError> { let adjusted = self.adjust_memory(ty); self.validate_memory(&adjusted)?; - self.base.create_vm_memory(&adjusted, style, vm_definition_location) + self.base + .create_vm_memory(&adjusted, style, vm_definition_location) } /// Create a table owned by the host given a [`TableType`] and a [`TableStyle`]. @@ -163,8 +164,12 @@ fn main() -> Result<(), Box> { let instance = Instance::new(&module, &import_object)?; // Check what happened - let mut memories: Vec = - instance.exports.iter().memories().map(|pair| pair.1.clone()).collect(); + let mut memories: Vec = instance + .exports + .iter() + .memories() + .map(|pair| pair.1.clone()) + .collect(); assert_eq!(memories.len(), 1); let first_memory = memories.pop().unwrap(); diff --git a/examples/wasi.rs b/examples/wasi.rs index 5a1fdcc52..93d37a9df 100644 --- a/examples/wasi.rs +++ b/examples/wasi.rs @@ -21,8 +21,10 @@ use wasmer_engine_jit::JIT; use wasmer_wasi::WasiState; fn main() -> Result<(), Box> { - let wasm_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/wasi-wast/wasi/unstable/hello.wasm"); + let wasm_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/wasi-wast/wasi/unstable/hello.wasm" + ); // Let's declare the Wasm module with the text representation. let wasm_bytes = std::fs::read(wasm_path)?; diff --git a/examples/wasi_pipes.rs b/examples/wasi_pipes.rs index 13539f55d..4ab0fae0c 100644 --- a/examples/wasi_pipes.rs +++ b/examples/wasi_pipes.rs @@ -17,8 +17,10 @@ use wasmer_engine_jit::JIT; use wasmer_wasi::{Pipe, WasiState}; fn main() -> Result<(), Box> { - let wasm_path = - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/wasi-wast/wasi/unstable/pipe_reverse.wasm"); + let wasm_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/wasi-wast/wasi/unstable/pipe_reverse.wasm" + ); // Let's declare the Wasm module with the text representation. let wasm_bytes = std::fs::read(wasm_path)?; @@ -36,8 +38,10 @@ fn main() -> Result<(), Box> { // First, we create the `WasiEnv` with the stdio pipes let input = Pipe::new(); let output = Pipe::new(); - let mut wasi_env = - WasiState::new("hello").stdin(Box::new(input)).stdout(Box::new(output)).finalize()?; + let mut wasi_env = WasiState::new("hello") + .stdin(Box::new(input)) + .stdout(Box::new(output)) + .finalize()?; println!("Instantiating module with WASI imports..."); // Then, we get the import object related to our WASI diff --git a/lib/api/src/env.rs b/lib/api/src/env.rs index dd6b7a794..9a4f7e088 100644 --- a/lib/api/src/env.rs +++ b/lib/api/src/env.rs @@ -140,7 +140,10 @@ pub struct LazyInit { impl LazyInit { /// Creates an unitialized value. pub fn new() -> Self { - Self { data: std::mem::MaybeUninit::uninit(), initialized: false } + Self { + data: std::mem::MaybeUninit::uninit(), + initialized: false, + } } /// # Safety @@ -173,16 +176,24 @@ impl LazyInit { impl std::fmt::Debug for LazyInit { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct("LazyInit").field("data", &self.get_ref()).finish() + f.debug_struct("LazyInit") + .field("data", &self.get_ref()) + .finish() } } impl Clone for LazyInit { fn clone(&self) -> Self { if let Some(inner) = self.get_ref() { - Self { data: std::mem::MaybeUninit::new(inner.clone()), initialized: true } + Self { + data: std::mem::MaybeUninit::new(inner.clone()), + initialized: true, + } } else { - Self { data: std::mem::MaybeUninit::uninit(), initialized: false } + Self { + data: std::mem::MaybeUninit::uninit(), + initialized: false, + } } } } diff --git a/lib/api/src/exports.rs b/lib/api/src/exports.rs index 25129391c..4bfea97ed 100644 --- a/lib/api/src/exports.rs +++ b/lib/api/src/exports.rs @@ -75,7 +75,9 @@ impl Exports { /// Creates a new `Exports` with capacity `n`. pub fn with_capacity(n: usize) -> Self { - Self { map: Arc::new(IndexMap::with_capacity(n)) } + Self { + map: Arc::new(IndexMap::with_capacity(n)), + } } /// Return the number of exports in the `Exports` map. @@ -94,7 +96,9 @@ impl Exports { S: Into, E: Into, { - Arc::get_mut(&mut self.map).unwrap().insert(name.into(), value.into()); + Arc::get_mut(&mut self.map) + .unwrap() + .insert(name.into(), value.into()); } /// Get an export given a `name`. @@ -144,7 +148,9 @@ impl Exports { Args: WasmTypeList, Rets: WasmTypeList, { - self.get_function(name)?.native().map_err(|_| ExportError::IncompatibleType) + self.get_function(name)? + .native() + .map_err(|_| ExportError::IncompatibleType) } /// Hack to get this working with nativefunc too @@ -175,7 +181,9 @@ impl Exports { /// Get an iterator over the exports. pub fn iter(&self) -> ExportsIterator> { - ExportsIterator { iter: self.map.iter() } + ExportsIterator { + iter: self.map.iter(), + } } } @@ -252,7 +260,9 @@ where impl FromIterator<(String, Extern)> for Exports { fn from_iter>(iter: I) -> Self { - Self { map: Arc::new(IndexMap::from_iter(iter)) } + Self { + map: Arc::new(IndexMap::from_iter(iter)), + } } } @@ -262,7 +272,10 @@ impl LikeNamespace for Exports { } fn get_namespace_exports(&self) -> Vec<(String, Export)> { - self.map.iter().map(|(k, v)| (k.clone(), v.to_export())).collect() + self.map + .iter() + .map(|(k, v)| (k.clone(), v.to_export())) + .collect() } } diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs index ee0aa0ea1..0980d88ba 100644 --- a/lib/api/src/externals/function.rs +++ b/lib/api/src/externals/function.rs @@ -109,7 +109,9 @@ where }); let host_env_clone_fn = |ptr: *mut c_void| -> *mut c_void { let env_ref: &Env = unsafe { - ptr.cast::().as_ref().expect("`ptr` to the environment is null when cloning it") + ptr.cast::() + .as_ref() + .expect("`ptr` to the environment is null when cloning it") }; Box::into_raw(Box::new(env_ref.clone())) as _ }; @@ -350,7 +352,9 @@ impl Function { } let function = inner::Function::::new(func); let address = function.address() as *const VMFunctionBody; - let vmctx = VMFunctionEnvironment { host_env: std::ptr::null_mut() as *mut _ }; + let vmctx = VMFunctionEnvironment { + host_env: std::ptr::null_mut() as *mut _, + }; let signature = function.ty(); Self { @@ -513,7 +517,11 @@ impl Function { results: &mut [Val], ) -> Result<(), RuntimeError> { let format_types_for_error_message = |items: &[Val]| { - items.iter().map(|param| param.ty().to_string()).collect::>().join(", ") + items + .iter() + .map(|param| param.ty().to_string()) + .collect::>() + .join(", ") }; let signature = self.ty(); if signature.params().len() != params.len() { @@ -790,7 +798,11 @@ impl Function { } } - Ok(NativeFunc::new(self.store.clone(), self.exported.clone(), self.definition.clone())) + Ok(NativeFunc::new( + self.store.clone(), + self.exported.clone(), + self.definition.clone(), + )) } #[track_caller] @@ -814,7 +826,10 @@ impl<'a> Exportable<'a> for Function { impl fmt::Debug for Function { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.debug_struct("Function").field("ty", &self.ty()).finish() + formatter + .debug_struct("Function") + .field("ty", &self.ty()) + .finish() } } @@ -890,7 +905,10 @@ trait VMDynamicFunctionCall { impl VMDynamicFunctionCall for VMDynamicFunctionContext { fn from_context(ctx: T) -> Self { - Self { address: Self::address_ptr(), ctx } + Self { + address: Self::address_ptr(), + ctx, + } } fn address_ptr() -> *const VMFunctionBody { @@ -1294,7 +1312,10 @@ mod inner { T: HostFunctionKind, E: Sized, { - Self { address: function.function_body_ptr(), _phantom: PhantomData } + Self { + address: function.function_body_ptr(), + _phantom: PhantomData, + } } /// Get the function type of this `Function`. @@ -1713,8 +1734,14 @@ mod inner { #[test] fn test_function_types() { assert_eq!(Function::new(func).ty(), FunctionType::new(vec![], vec![])); - assert_eq!(Function::new(func__i32).ty(), FunctionType::new(vec![], vec![Type::I32])); - assert_eq!(Function::new(func_i32).ty(), FunctionType::new(vec![Type::I32], vec![])); + assert_eq!( + Function::new(func__i32).ty(), + FunctionType::new(vec![], vec![Type::I32]) + ); + assert_eq!( + Function::new(func_i32).ty(), + FunctionType::new(vec![Type::I32], vec![]) + ); assert_eq!( Function::new(func_i32__i32).ty(), FunctionType::new(vec![Type::I32], vec![Type::I32]) diff --git a/lib/api/src/externals/global.rs b/lib/api/src/externals/global.rs index 74c1d9b6c..0d111e0ee 100644 --- a/lib/api/src/externals/global.rs +++ b/lib/api/src/externals/global.rs @@ -63,14 +63,20 @@ impl Global { if !val.comes_from_same_store(store) { return Err(RuntimeError::new("cross-`Store` globals are not supported")); } - let global = RuntimeGlobal::new(GlobalType { mutability, ty: val.ty() }); + let global = RuntimeGlobal::new(GlobalType { + mutability, + ty: val.ty(), + }); unsafe { global .set_unchecked(val.clone()) .map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?; }; - Ok(Self { store: store.clone(), global: Arc::new(global) }) + Ok(Self { + store: store.clone(), + global: Arc::new(global), + }) } /// Returns the [`GlobalType`] of the `Global`. @@ -169,13 +175,18 @@ impl Global { return Err(RuntimeError::new("cross-`Store` values are not supported")); } unsafe { - self.global.set(val).map_err(|e| RuntimeError::new(format!("{}", e)))?; + self.global + .set(val) + .map_err(|e| RuntimeError::new(format!("{}", e)))?; } Ok(()) } pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportGlobal) -> Self { - Self { store: store.clone(), global: wasmer_export.vm_global.from } + Self { + store: store.clone(), + global: wasmer_export.vm_global.from, + } } /// Returns whether or not these two globals refer to the same data. @@ -207,8 +218,13 @@ impl fmt::Debug for Global { impl<'a> Exportable<'a> for Global { fn to_export(&self) -> Export { - ExportGlobal { vm_global: VMExportGlobal { from: self.global.clone(), instance_ref: None } } - .into() + ExportGlobal { + vm_global: VMExportGlobal { + from: self.global.clone(), + instance_ref: None, + }, + } + .into() } fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { diff --git a/lib/api/src/externals/memory.rs b/lib/api/src/externals/memory.rs index 09d0727aa..8cfe9f876 100644 --- a/lib/api/src/externals/memory.rs +++ b/lib/api/src/externals/memory.rs @@ -49,7 +49,10 @@ impl Memory { let style = tunables.memory_style(&ty); let memory = tunables.create_host_memory(&ty, &style)?; - Ok(Self { store: store.clone(), memory }) + Ok(Self { + store: store.clone(), + memory, + }) } /// Returns the [`MemoryType`] of the `Memory`. @@ -219,7 +222,10 @@ impl Memory { } pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportMemory) -> Self { - Self { store: store.clone(), memory: wasmer_export.vm_memory.from } + Self { + store: store.clone(), + memory: wasmer_export.vm_memory.from, + } } /// Returns whether or not these two memories refer to the same data. @@ -241,8 +247,13 @@ impl Memory { impl<'a> Exportable<'a> for Memory { fn to_export(&self) -> Export { - ExportMemory { vm_memory: VMExportMemory { from: self.memory.clone(), instance_ref: None } } - .into() + ExportMemory { + vm_memory: VMExportMemory { + from: self.memory.clone(), + instance_ref: None, + }, + } + .into() } fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { diff --git a/lib/api/src/externals/table.rs b/lib/api/src/externals/table.rs index 042da811a..6806067d2 100644 --- a/lib/api/src/externals/table.rs +++ b/lib/api/src/externals/table.rs @@ -43,14 +43,19 @@ impl Table { let item = init.into_table_reference(store)?; let tunables = store.tunables(); let style = tunables.table_style(&ty); - let table = tunables.create_host_table(&ty, &style).map_err(RuntimeError::new)?; + let table = tunables + .create_host_table(&ty, &style) + .map_err(RuntimeError::new)?; let num_elements = table.size(); for i in 0..num_elements { set_table_item(table.as_ref(), i, item.clone())?; } - Ok(Self { store: store.clone(), table }) + Ok(Self { + store: store.clone(), + table, + }) } /// Returns the [`TableType`] of the `Table`. @@ -111,7 +116,9 @@ impl Table { len: u32, ) -> Result<(), RuntimeError> { if !Store::same(&dst_table.store, &src_table.store) { - return Err(RuntimeError::new("cross-`Store` table copies are not supported")); + return Err(RuntimeError::new( + "cross-`Store` table copies are not supported", + )); } RuntimeTable::copy( dst_table.table.as_ref(), @@ -125,7 +132,10 @@ impl Table { } pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportTable) -> Self { - Self { store: store.clone(), table: wasmer_export.vm_table.from } + Self { + store: store.clone(), + table: wasmer_export.vm_table.from, + } } /// Returns whether or not these two tables refer to the same data. @@ -136,8 +146,13 @@ impl Table { impl<'a> Exportable<'a> for Table { fn to_export(&self) -> Export { - ExportTable { vm_table: VMExportTable { from: self.table.clone(), instance_ref: None } } - .into() + ExportTable { + vm_table: VMExportTable { + from: self.table.clone(), + instance_ref: None, + }, + } + .into() } fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { diff --git a/lib/api/src/import_object.rs b/lib/api/src/import_object.rs index 9fffb9e9b..1d507baa7 100644 --- a/lib/api/src/import_object.rs +++ b/lib/api/src/import_object.rs @@ -137,7 +137,9 @@ impl IntoIterator for ImportObject { type Item = ((String, String), Export); fn into_iter(self) -> Self::IntoIter { - ImportObjectIterator { elements: self.get_objects() } + ImportObjectIterator { + elements: self.get_objects(), + } } } @@ -168,7 +170,10 @@ impl fmt::Debug for ImportObject { } f.debug_struct("ImportObject") - .field("map", &SecretMap::new(self.map.lock().unwrap().borrow().len())) + .field( + "map", + &SecretMap::new(self.map.lock().unwrap().borrow().len()), + ) .finish() } } diff --git a/lib/api/src/instance.rs b/lib/api/src/instance.rs index 8c5992bb3..592fd2eec 100644 --- a/lib/api/src/instance.rs +++ b/lib/api/src/instance.rs @@ -125,8 +125,11 @@ impl Instance { }) .collect::(); - let instance = - Self { handle: Arc::new(Mutex::new(handle)), module: module.clone(), exports }; + let instance = Self { + handle: Arc::new(Mutex::new(handle)), + module: module.clone(), + exports, + }; // # Safety // `initialize_host_envs` should be called after instantiation but before @@ -165,6 +168,8 @@ impl Instance { impl fmt::Debug for Instance { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Instance").field("exports", &self.exports).finish() + f.debug_struct("Instance") + .field("exports", &self.exports) + .finish() } } diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 5ab4eee36..4c9508b1c 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -2,7 +2,12 @@ html_logo_url = "https://github.com/wasmerio.png?size=200", html_favicon_url = "https://wasmer.io/static/icons/favicon.ico" )] -#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, broken_intra_doc_links)] +#![deny( + missing_docs, + trivial_numeric_casts, + unused_extern_crates, + broken_intra_doc_links +)] #![warn(unused_import_braces)] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/api/src/module.rs b/lib/api/src/module.rs index dc8070877..ea2b8b8d8 100644 --- a/lib/api/src/module.rs +++ b/lib/api/src/module.rs @@ -101,7 +101,10 @@ impl Module { pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result { #[cfg(feature = "wat")] let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| { - CompileError::Wasm(WasmError::Generic(format!("Error when converting wat: {}", e))) + CompileError::Wasm(WasmError::Generic(format!( + "Error when converting wat: {}", + e + ))) })?; Self::from_binary(store, bytes.as_ref()) @@ -250,7 +253,10 @@ impl Module { } fn from_artifact(store: &Store, artifact: Arc) -> Self { - Self { store: store.clone(), artifact } + Self { + store: store.clone(), + artifact, + } } pub(crate) fn instantiate( @@ -259,7 +265,8 @@ impl Module { ) -> Result { unsafe { let instance_handle = - self.artifact.instantiate(self.store.tunables(), resolver, Box::new(()))?; + self.artifact + .instantiate(self.store.tunables(), resolver, Box::new(()))?; // After the instance handle is created, we need to initialize // the data, call the start function and so. However, if any @@ -418,6 +425,8 @@ impl Module { impl fmt::Debug for Module { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Module").field("name", &self.name()).finish() + f.debug_struct("Module") + .field("name", &self.name()) + .finish() } } diff --git a/lib/api/src/native.rs b/lib/api/src/native.rs index a51ab01f5..2229dc01f 100644 --- a/lib/api/src/native.rs +++ b/lib/api/src/native.rs @@ -41,7 +41,12 @@ where exported: ExportFunction, definition: FunctionDefinition, ) -> Self { - Self { definition, store, exported, _phantom: PhantomData } + Self { + definition, + store, + exported, + _phantom: PhantomData, + } } pub(crate) fn vmctx(&self) -> VMFunctionEnvironment { @@ -92,7 +97,11 @@ where Rets: WasmTypeList, { fn from(other: NativeFunc) -> Self { - Self { store: other.store, definition: other.definition, exported: other.exported } + Self { + store: other.store, + definition: other.definition, + exported: other.exported, + } } } diff --git a/lib/api/src/ptr.rs b/lib/api/src/ptr.rs index 4e1f55d20..1c3ebb525 100644 --- a/lib/api/src/ptr.rs +++ b/lib/api/src/ptr.rs @@ -43,7 +43,10 @@ impl WasmPtr { /// Create a new `WasmPtr` at the given offset. #[inline] pub fn new(offset: u32) -> Self { - Self { offset, _phantom: PhantomData } + Self { + offset, + _phantom: PhantomData, + } } /// Get the offset into Wasm linear memory for this `WasmPtr`. @@ -267,7 +270,10 @@ unsafe impl FromToNativeWasmType for WasmPtr { self.offset as i32 } fn from_native(n: Self::Native) -> Self { - Self { offset: n as u32, _phantom: PhantomData } + Self { + offset: n as u32, + _phantom: PhantomData, + } } } @@ -275,7 +281,10 @@ unsafe impl ValueType for WasmPtr {} impl Clone for WasmPtr { fn clone(&self) -> Self { - Self { offset: self.offset, _phantom: PhantomData } + Self { + offset: self.offset, + _phantom: PhantomData, + } } } diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index c5effdf11..2371fd18b 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -39,7 +39,10 @@ impl Store { where E: Engine + ?Sized, { - Self { engine: engine.cloned(), tunables: Arc::new(tunables) } + Self { + engine: engine.cloned(), + tunables: Arc::new(tunables), + } } /// Returns the [`Tunables`]. @@ -106,7 +109,10 @@ impl Default for Store { let config = get_config(); let engine = get_engine(config); let tunables = BaseTunables::for_target(engine.target()); - Store { engine: Arc::new(engine), tunables: Arc::new(tunables) } + Store { + engine: Arc::new(engine), + tunables: Arc::new(tunables), + } } } diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index b01fd0e77..d714ffd60 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -84,7 +84,9 @@ impl Tunables for BaseTunables { offset_guard_size: self.static_memory_offset_guard_size, } } else { - MemoryStyle::Dynamic { offset_guard_size: self.dynamic_memory_offset_guard_size } + MemoryStyle::Dynamic { + offset_guard_size: self.dynamic_memory_offset_guard_size, + } } } @@ -113,7 +115,11 @@ impl Tunables for BaseTunables { style: &MemoryStyle, vm_definition_location: NonNull, ) -> Result, MemoryError> { - Ok(Arc::new(LinearMemory::from_definition(&ty, &style, vm_definition_location)?)) + Ok(Arc::new(LinearMemory::from_definition( + &ty, + &style, + vm_definition_location, + )?)) } /// Create a table owned by the host given a [`TableType`] and a [`TableStyle`]. @@ -136,7 +142,11 @@ impl Tunables for BaseTunables { style: &TableStyle, vm_definition_location: NonNull, ) -> Result, String> { - Ok(Arc::new(LinearTable::from_definition(&ty, &style, vm_definition_location)?)) + Ok(Arc::new(LinearTable::from_definition( + &ty, + &style, + vm_definition_location, + )?)) } } @@ -172,7 +182,10 @@ mod tests { let requested = MemoryType::new(3, Some(16), true); let style = tunables.memory_style(&requested); match style { - MemoryStyle::Static { bound, offset_guard_size } => { + MemoryStyle::Static { + bound, + offset_guard_size, + } => { assert_eq!(bound, Pages(2048)); assert_eq!(offset_guard_size, 128); } diff --git a/lib/api/src/types.rs b/lib/api/src/types.rs index 1d1aebf71..5a0ab3db6 100644 --- a/lib/api/src/types.rs +++ b/lib/api/src/types.rs @@ -66,8 +66,10 @@ impl ValFuncRef for Val { let anyfunc: *const wasmer_vm::VMCallerCheckedAnyfunc = *func_ref; &*anyfunc }; - let signature = - store.engine().lookup_signature(item.type_index).expect("Signature not found in store"); + let signature = store + .engine() + .lookup_signature(item.type_index) + .expect("Signature not found in store"); let export = wasmer_engine::ExportFunction { // TODO: // figure out if we ever need a value here: need testing with complicated import patterns diff --git a/lib/api/tests/externals.rs b/lib/api/tests/externals.rs index 6685cf50e..8386dc07d 100644 --- a/lib/api/tests/externals.rs +++ b/lib/api/tests/externals.rs @@ -5,10 +5,22 @@ use wasmer::*; fn global_new() -> Result<()> { let store = Store::default(); let global = Global::new(&store, Value::I32(10)); - assert_eq!(*global.ty(), GlobalType { ty: Type::I32, mutability: Mutability::Const }); + assert_eq!( + *global.ty(), + GlobalType { + ty: Type::I32, + mutability: Mutability::Const + } + ); let global_mut = Global::new_mut(&store, Value::I32(10)); - assert_eq!(*global_mut.ty(), GlobalType { ty: Type::I32, mutability: Mutability::Var }); + assert_eq!( + *global_mut.ty(), + GlobalType { + ty: Type::I32, + mutability: Mutability::Var + } + ); Ok(()) } @@ -49,7 +61,11 @@ fn global_set() -> Result<()> { #[test] fn table_new() -> Result<()> { let store = Store::default(); - let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: None }; + let table_type = TableType { + ty: Type::FuncRef, + minimum: 0, + maximum: None, + }; let f = Function::new_native(&store, || {}); let table = Table::new(&store, table_type, Value::FuncRef(Some(f)))?; assert_eq!(*table.ty(), table_type); @@ -70,7 +86,11 @@ fn table_new() -> Result<()> { #[ignore] fn table_get() -> Result<()> { let store = Store::default(); - let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: Some(1) }; + let table_type = TableType { + ty: Type::FuncRef, + minimum: 0, + maximum: Some(1), + }; let f = Function::new_native(&store, |num: i32| num + 1); let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?; assert_eq!(*table.ty(), table_type); @@ -89,7 +109,11 @@ fn table_set() -> Result<()> { #[test] fn table_grow() -> Result<()> { let store = Store::default(); - let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: Some(10) }; + let table_type = TableType { + ty: Type::FuncRef, + minimum: 0, + maximum: Some(10), + }; let f = Function::new_native(&store, |num: i32| num + 1); let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?; // Growing to a bigger maximum should return None @@ -113,7 +137,11 @@ fn table_copy() -> Result<()> { #[test] fn memory_new() -> Result<()> { let store = Store::default(); - let memory_type = MemoryType { shared: false, minimum: Pages(0), maximum: Some(Pages(10)) }; + let memory_type = MemoryType { + shared: false, + minimum: Pages(0), + maximum: Some(Pages(10)), + }; let memory = Memory::new(&store, memory_type)?; assert_eq!(memory.size(), Pages(0)); assert_eq!(*memory.ty(), memory_type); @@ -135,7 +163,10 @@ fn memory_grow() -> Result<()> { let result = memory.grow(Pages(10)); assert_eq!( result, - Err(MemoryError::CouldNotGrow { current: 12.into(), attempted_delta: 10.into() }) + Err(MemoryError::CouldNotGrow { + current: 12.into(), + attempted_delta: 10.into() + }) ); let bad_desc = MemoryType::new(Pages(15), Some(Pages(10)), false); @@ -152,14 +183,20 @@ fn function_new() -> Result<()> { let function = Function::new_native(&store, || {}); assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![])); let function = Function::new_native(&store, |_a: i32| {}); - assert_eq!(function.ty().clone(), FunctionType::new(vec![Type::I32], vec![])); + assert_eq!( + function.ty().clone(), + FunctionType::new(vec![Type::I32], vec![]) + ); let function = Function::new_native(&store, |_a: i32, _b: i64, _c: f32, _d: f64| {}); assert_eq!( function.ty().clone(), FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); let function = Function::new_native(&store, || -> i32 { 1 }); - assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![Type::I32])); + assert_eq!( + function.ty().clone(), + FunctionType::new(vec![], vec![Type::I32]) + ); let function = Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); assert_eq!( function.ty().clone(), @@ -179,7 +216,10 @@ fn function_new_env() -> Result<()> { assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![])); let function = Function::new_native_with_env(&store, my_env.clone(), |_env: &MyEnv, _a: i32| {}); - assert_eq!(function.ty().clone(), FunctionType::new(vec![Type::I32], vec![])); + assert_eq!( + function.ty().clone(), + FunctionType::new(vec![Type::I32], vec![]) + ); let function = Function::new_native_with_env( &store, my_env.clone(), @@ -191,7 +231,10 @@ fn function_new_env() -> Result<()> { ); let function = Function::new_native_with_env(&store, my_env.clone(), |_env: &MyEnv| -> i32 { 1 }); - assert_eq!(function.ty().clone(), FunctionType::new(vec![], vec![Type::I32])); + assert_eq!( + function.ty().clone(), + FunctionType::new(vec![], vec![Type::I32]) + ); let function = Function::new_native_with_env( &store, my_env.clone(), @@ -370,7 +413,10 @@ fn manually_generate_wasmer_env() -> Result<()> { env.val + arg1 + arg2 } - let mut env = MyEnv { val: 5, memory: LazyInit::new() }; + let mut env = MyEnv { + val: 5, + memory: LazyInit::new(), + }; let result = host_function(&mut env, 7, 9); assert_eq!(result, 21); diff --git a/lib/api/tests/instance.rs b/lib/api/tests/instance.rs index 3ba4e2c92..697338774 100644 --- a/lib/api/tests/instance.rs +++ b/lib/api/tests/instance.rs @@ -30,7 +30,10 @@ fn exports_work_after_multiple_instances_have_been_freed() -> Result<()> { drop(instance3); // All instances have been dropped, but `sum` continues to work! - assert_eq!(sum.call(&[Value::I32(1), Value::I32(2)])?.into_vec(), vec![Value::I32(3)],); + assert_eq!( + sum.call(&[Value::I32(1), Value::I32(2)])?.into_vec(), + vec![Value::I32(3)], + ); Ok(()) } diff --git a/lib/api/tests/module.rs b/lib/api/tests/module.rs index c6201648b..64708d2ae 100644 --- a/lib/api/tests/module.rs +++ b/lib/api/tests/module.rs @@ -63,19 +63,35 @@ fn imports() -> Result<()> { // Now we test the iterators assert_eq!( module.imports().functions().collect::>(), - vec![ImportType::new("host", "func", FunctionType::new(vec![], vec![])),] + vec![ImportType::new( + "host", + "func", + FunctionType::new(vec![], vec![]) + ),] ); assert_eq!( module.imports().memories().collect::>(), - vec![ImportType::new("host", "memory", MemoryType::new(Pages(1), None, false)),] + vec![ImportType::new( + "host", + "memory", + MemoryType::new(Pages(1), None, false) + ),] ); assert_eq!( module.imports().tables().collect::>(), - vec![ImportType::new("host", "table", TableType::new(Type::FuncRef, 1, None)),] + vec![ImportType::new( + "host", + "table", + TableType::new(Type::FuncRef, 1, None) + ),] ); assert_eq!( module.imports().globals().collect::>(), - vec![ImportType::new("host", "global", GlobalType::new(Type::I32, Mutability::Const)),] + vec![ImportType::new( + "host", + "global", + GlobalType::new(Type::I32, Mutability::Const) + ),] ); Ok(()) } @@ -93,9 +109,18 @@ fn exports() -> Result<()> { assert_eq!( module.exports().collect::>(), vec![ - ExportType::new("func", ExternType::Function(FunctionType::new(vec![], vec![]))), - ExportType::new("memory", ExternType::Memory(MemoryType::new(Pages(1), None, false))), - ExportType::new("table", ExternType::Table(TableType::new(Type::FuncRef, 1, None))), + ExportType::new( + "func", + ExternType::Function(FunctionType::new(vec![], vec![])) + ), + ExportType::new( + "memory", + ExternType::Memory(MemoryType::new(Pages(1), None, false)) + ), + ExportType::new( + "table", + ExternType::Table(TableType::new(Type::FuncRef, 1, None)) + ), ExportType::new( "global", ExternType::Global(GlobalType::new(Type::I32, Mutability::Const)) @@ -110,15 +135,24 @@ fn exports() -> Result<()> { ); assert_eq!( module.exports().memories().collect::>(), - vec![ExportType::new("memory", MemoryType::new(Pages(1), None, false)),] + vec![ExportType::new( + "memory", + MemoryType::new(Pages(1), None, false) + ),] ); assert_eq!( module.exports().tables().collect::>(), - vec![ExportType::new("table", TableType::new(Type::FuncRef, 1, None)),] + vec![ExportType::new( + "table", + TableType::new(Type::FuncRef, 1, None) + ),] ); assert_eq!( module.exports().globals().collect::>(), - vec![ExportType::new("global", GlobalType::new(Type::I32, Mutability::Const)),] + vec![ExportType::new( + "global", + GlobalType::new(Type::I32, Mutability::Const) + ),] ); Ok(()) } diff --git a/lib/api/tests/reference_types.rs b/lib/api/tests/reference_types.rs index 164acb8c2..8a1aaa6e0 100644 --- a/lib/api/tests/reference_types.rs +++ b/lib/api/tests/reference_types.rs @@ -112,8 +112,9 @@ fn func_ref_passed_and_called() -> Result<()> { } { - let f: NativeFunc<(), i32> = - instance.exports.get_native_function("call_host_func_with_wasm_func")?; + let f: NativeFunc<(), i32> = instance + .exports + .get_native_function("call_host_func_with_wasm_func")?; let result = f.call()?; assert_eq!(result, 63); } @@ -414,10 +415,12 @@ fn extern_ref_ref_counting_table_instructions() -> Result<()> { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let grow_table_with_ref: NativeFunc<(ExternRef, i32), i32> = - instance.exports.get_native_function("grow_table_with_ref")?; - let fill_table_with_ref: NativeFunc<(ExternRef, i32, i32), ()> = - instance.exports.get_native_function("fill_table_with_ref")?; + let grow_table_with_ref: NativeFunc<(ExternRef, i32), i32> = instance + .exports + .get_native_function("grow_table_with_ref")?; + let fill_table_with_ref: NativeFunc<(ExternRef, i32, i32), ()> = instance + .exports + .get_native_function("fill_table_with_ref")?; let copy_into_table2: NativeFunc<(), ()> = instance.exports.get_native_function("copy_into_table2")?; let table1: &Table = instance.exports.get_table("table1")?; diff --git a/lib/c-api/src/deprecated/export.rs b/lib/c-api/src/deprecated/export.rs index 0f38299e0..f9a39670a 100644 --- a/lib/c-api/src/deprecated/export.rs +++ b/lib/c-api/src/deprecated/export.rs @@ -142,8 +142,9 @@ pub unsafe extern "C" fn wasmer_export_descriptors( ) { let module = &*(module as *const Module); - let named_export_descriptors: Box = - Box::new(NamedExportDescriptors(module.exports().into_iter().map(|e| e.into()).collect())); + let named_export_descriptors: Box = Box::new(NamedExportDescriptors( + module.exports().into_iter().map(|e| e.into()).collect(), + )); *export_descriptors = Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t; } @@ -402,8 +403,10 @@ pub unsafe extern "C" fn wasmer_export_to_memory( let named_export = &*(export as *const NamedExport); let instance = named_export.instance.as_ref(); - if let Ok(exported_memory) = - instance.instance.exports.get::(&named_export.export_type.name()) + if let Ok(exported_memory) = instance + .instance + .exports + .get::(&named_export.export_type.name()) { let mem = Box::new(exported_memory.clone()); *memory = Box::into_raw(mem) as *mut wasmer_memory_t; @@ -446,12 +449,16 @@ pub unsafe extern "C" fn wasmer_export_func_call( results_len: c_uint, ) -> wasmer_result_t { if func.is_null() { - update_last_error(CApiError { msg: "func ptr is null".to_string() }); + update_last_error(CApiError { + msg: "func ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } if params_len > 0 && params.is_null() { - update_last_error(CApiError { msg: "params ptr is null".to_string() }); + update_last_error(CApiError { + msg: "params ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } @@ -472,7 +479,11 @@ pub unsafe extern "C" fn wasmer_export_func_call( let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize); let instance = named_export.instance.as_ref(); - let f: &Function = match instance.instance.exports.get(&named_export.export_type.name()) { + let f: &Function = match instance + .instance + .exports + .get(&named_export.export_type.name()) + { Ok(f) => f, Err(err) => { update_last_error(err); @@ -519,7 +530,10 @@ pub unsafe extern "C" fn wasmer_export_func_call( impl From for NamedExportDescriptor { fn from(et: ExportType) -> Self { - NamedExportDescriptor { name: et.name().to_string(), kind: et.into() } + NamedExportDescriptor { + name: et.name().to_string(), + kind: et.into(), + } } } diff --git a/lib/c-api/src/deprecated/global.rs b/lib/c-api/src/deprecated/global.rs index fdc55f33f..b6d007fd7 100644 --- a/lib/c-api/src/deprecated/global.rs +++ b/lib/c-api/src/deprecated/global.rs @@ -61,7 +61,10 @@ pub unsafe extern "C" fn wasmer_global_get_descriptor( ) -> wasmer_global_descriptor_t { let global = &*(global as *mut Global); let descriptor = global.ty(); - wasmer_global_descriptor_t { mutable: descriptor.mutability.into(), kind: descriptor.ty.into() } + wasmer_global_descriptor_t { + mutable: descriptor.mutability.into(), + kind: descriptor.ty.into(), + } } /// Frees memory for the given Global diff --git a/lib/c-api/src/deprecated/import/mod.rs b/lib/c-api/src/deprecated/import/mod.rs index 50155adb5..d972c7af8 100644 --- a/lib/c-api/src/deprecated/import/mod.rs +++ b/lib/c-api/src/deprecated/import/mod.rs @@ -343,7 +343,9 @@ pub unsafe extern "C" fn wasmer_import_object_iter_at_end( let mut import_object_iter = if let Some(import_object_iter) = import_object_iter { import_object_iter.cast::() } else { - update_last_error(CApiError { msg: "import_object_iter must not be null".to_owned() }); + update_last_error(CApiError { + msg: "import_object_iter must not be null".to_owned(), + }); return true; }; let iter = import_object_iter.as_mut(); @@ -357,7 +359,11 @@ pub unsafe extern "C" fn wasmer_import_object_iter_destroy( import_object_iter: Option>, ) { if let Some(import_object_iter) = import_object_iter { - let _ = Box::from_raw(import_object_iter.cast::().as_ptr()); + let _ = Box::from_raw( + import_object_iter + .cast::() + .as_ptr(), + ); } } @@ -420,8 +426,10 @@ pub unsafe extern "C" fn wasmer_import_object_extend( let mut import_data: HashMap = HashMap::new(); let imports: &[wasmer_import_t] = slice::from_raw_parts(imports, imports_len as usize); for import in imports { - let module_name = - slice::from_raw_parts(import.module_name.bytes, import.module_name.bytes_len as usize); + let module_name = slice::from_raw_parts( + import.module_name.bytes, + import.module_name.bytes_len as usize, + ); let module_name = if let Ok(s) = std::str::from_utf8(module_name) { s } else { @@ -430,8 +438,10 @@ pub unsafe extern "C" fn wasmer_import_object_extend( }); return wasmer_result_t::WASMER_ERROR; }; - let import_name = - slice::from_raw_parts(import.import_name.bytes, import.import_name.bytes_len as usize); + let import_name = slice::from_raw_parts( + import.import_name.bytes, + import.import_name.bytes_len as usize, + ); let import_name = if let Ok(s) = std::str::from_utf8(import_name) { s } else { @@ -451,7 +461,9 @@ pub unsafe extern "C" fn wasmer_import_object_extend( // TODO: investigate consistent usage of `FunctionWrapper` in this context let func_wrapper = import.value.func as *mut FunctionWrapper; let func_export = (*func_wrapper).func.as_ptr(); - import_object.instance_pointers_to_update.push((*func_wrapper).legacy_env.clone()); + import_object + .instance_pointers_to_update + .push((*func_wrapper).legacy_env.clone()); Extern::Function((&*func_export).clone()) } wasmer_import_export_kind::WASM_GLOBAL => { @@ -464,7 +476,9 @@ pub unsafe extern "C" fn wasmer_import_object_extend( } }; - let export_entry = import_data.entry(module_name.to_string()).or_insert_with(Exports::new); + let export_entry = import_data + .entry(module_name.to_string()) + .or_insert_with(Exports::new); export_entry.insert(import_name.to_string(), export); } @@ -632,7 +646,9 @@ unsafe impl Sync for LegacyEnv {} impl LegacyEnv { pub(crate) fn ctx_ptr(&self) -> *mut CAPIInstance { - self.instance_ptr.map(|p| p.as_ptr()).unwrap_or(ptr::null_mut()) + self.instance_ptr + .map(|p| p.as_ptr()) + .unwrap_or(ptr::null_mut()) } } @@ -750,7 +766,9 @@ pub unsafe extern "C" fn wasmer_trap( error_message: *const c_char, ) -> wasmer_result_t { if error_message.is_null() { - update_last_error(CApiError { msg: "error_message is null in wasmer_trap".to_string() }); + update_last_error(CApiError { + msg: "error_message is null in wasmer_trap".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } diff --git a/lib/c-api/src/deprecated/import/wasi.rs b/lib/c-api/src/deprecated/import/wasi.rs index 52c90e78c..6549053d5 100644 --- a/lib/c-api/src/deprecated/import/wasi.rs +++ b/lib/c-api/src/deprecated/import/wasi.rs @@ -213,8 +213,9 @@ pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wa let mut wasi_state_builder = wasi::WasiState::new("wasmer-wasi-default-program-name"); let wasi_state = wasi_state_builder.build().unwrap(); let wasi_env = wasi::WasiEnv::new(wasi_state); - let import_object_inner: Box = - Box::new(wasi::generate_import_object_from_env(store, wasi_env, wasi::WasiVersion::Latest)); + let import_object_inner: Box = Box::new( + wasi::generate_import_object_from_env(store, wasi_env, wasi::WasiVersion::Latest), + ); let import_object: Box = Box::new(CAPIImportObject { import_object: import_object_inner, imported_memories: vec![], diff --git a/lib/c-api/src/deprecated/instance.rs b/lib/c-api/src/deprecated/instance.rs index e12e06436..b5d5cf39d 100644 --- a/lib/c-api/src/deprecated/instance.rs +++ b/lib/c-api/src/deprecated/instance.rs @@ -124,25 +124,34 @@ pub unsafe extern "C" fn wasmer_instantiate( let wasm_bytes = if let Some(wasm_bytes_inner) = wasm_bytes { wasm_bytes_inner } else { - update_last_error(CApiError { msg: "wasm bytes ptr is null".to_string() }); + update_last_error(CApiError { + msg: "wasm bytes ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; }; if imports_len > 0 && imports.is_null() { - update_last_error(CApiError { msg: "imports ptr is null".to_string() }); + update_last_error(CApiError { + msg: "imports ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } let mut imported_memories = vec![]; let mut instance_pointers_to_update = vec![]; - let imports: &[wasmer_import_t] = - if imports_len == 0 { &[] } else { slice::from_raw_parts(imports, imports_len as usize) }; + let imports: &[wasmer_import_t] = if imports_len == 0 { + &[] + } else { + slice::from_raw_parts(imports, imports_len as usize) + }; let mut import_object = ImportObject::new(); let mut namespaces = HashMap::new(); for import in imports { - let module_name = - slice::from_raw_parts(import.module_name.bytes, import.module_name.bytes_len as usize); + let module_name = slice::from_raw_parts( + import.module_name.bytes, + import.module_name.bytes_len as usize, + ); let module_name = if let Ok(s) = std::str::from_utf8(module_name) { s } else { @@ -151,8 +160,10 @@ pub unsafe extern "C" fn wasmer_instantiate( }); return wasmer_result_t::WASMER_ERROR; }; - let import_name = - slice::from_raw_parts(import.import_name.bytes, import.import_name.bytes_len as usize); + let import_name = slice::from_raw_parts( + import.import_name.bytes, + import.import_name.bytes_len as usize, + ); let import_name = if let Ok(s) = std::str::from_utf8(import_name) { s } else { @@ -212,7 +223,11 @@ pub unsafe extern "C" fn wasmer_instantiate( return wasmer_result_t::WASMER_ERROR; } }; - let c_api_instance = CAPIInstance { instance: new_instance, imported_memories, ctx_data: None }; + let c_api_instance = CAPIInstance { + instance: new_instance, + imported_memories, + ctx_data: None, + }; let c_api_instance_pointer = Box::into_raw(Box::new(c_api_instance)); for to_update in instance_pointers_to_update { let mut to_update_guard = to_update.lock().unwrap(); @@ -307,19 +322,25 @@ pub unsafe extern "C" fn wasmer_instance_call( results_len: u32, ) -> wasmer_result_t { if instance.is_null() { - update_last_error(CApiError { msg: "instance ptr is null".to_string() }); + update_last_error(CApiError { + msg: "instance ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } if name.is_null() { - update_last_error(CApiError { msg: "name ptr is null".to_string() }); + update_last_error(CApiError { + msg: "name ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } if params_len > 0 && params.is_null() { - update_last_error(CApiError { msg: "params ptr is null".to_string() }); + update_last_error(CApiError { + msg: "params ptr is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } @@ -448,7 +469,10 @@ pub unsafe extern "C" fn wasmer_instance_exports( .instance .module() .exports() - .map(|export_type| NamedExport { export_type, instance }) + .map(|export_type| NamedExport { + export_type, + instance, + }) .collect(); let named_exports: Box = Box::new(NamedExports(exports_vec)); @@ -554,13 +578,19 @@ pub unsafe extern "C" fn wasmer_instance_context_memory( { name } else { - update_last_error(CApiError { msg: "Could not find an exported memory".to_string() }); + update_last_error(CApiError { + msg: "Could not find an exported memory".to_string(), + }); return None; }; - let memory = instance.instance.exports.get_memory(exported_memory_name).expect(&format!( - "Module exports memory named `{}` but it's inaccessible", - &exported_memory_name - )); + let memory = instance + .instance + .exports + .get_memory(exported_memory_name) + .expect(&format!( + "Module exports memory named `{}` but it's inaccessible", + &exported_memory_name + )); Some(&*(Box::into_raw(Box::new(memory.clone())) as *const wasmer_memory_t)) } } diff --git a/lib/c-api/src/deprecated/memory.rs b/lib/c-api/src/deprecated/memory.rs index 55b3b1004..1c5393930 100644 --- a/lib/c-api/src/deprecated/memory.rs +++ b/lib/c-api/src/deprecated/memory.rs @@ -60,7 +60,11 @@ pub unsafe extern "C" fn wasmer_memory_new( memory: *mut *mut wasmer_memory_t, limits: wasmer_limits_t, ) -> wasmer_result_t { - let max = if limits.max.has_some { Some(Pages(limits.max.some)) } else { None }; + let max = if limits.max.has_some { + Some(Pages(limits.max.some)) + } else { + None + }; let store = get_global_store(); let desc = MemoryType::new(Pages(limits.min), max, false); match Memory::new(store, desc) { @@ -69,7 +73,9 @@ pub unsafe extern "C" fn wasmer_memory_new( wasmer_result_t::WASMER_OK } Err(err) => { - update_last_error(CApiError { msg: err.to_string() }); + update_last_error(CApiError { + msg: err.to_string(), + }); wasmer_result_t::WASMER_ERROR } } @@ -95,7 +101,9 @@ pub unsafe extern "C" fn wasmer_memory_new( #[no_mangle] pub extern "C" fn wasmer_memory_grow(memory: *mut wasmer_memory_t, delta: u32) -> wasmer_result_t { if memory.is_null() { - update_last_error(CApiError { msg: "`memory` is NULL.".to_string() }); + update_last_error(CApiError { + msg: "`memory` is NULL.".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } @@ -106,7 +114,9 @@ pub extern "C" fn wasmer_memory_grow(memory: *mut wasmer_memory_t, delta: u32) - match grow_result { Ok(_) => wasmer_result_t::WASMER_OK, Err(err) => { - update_last_error(CApiError { msg: err.to_string() }); + update_last_error(CApiError { + msg: err.to_string(), + }); wasmer_result_t::WASMER_ERROR } } diff --git a/lib/c-api/src/deprecated/module.rs b/lib/c-api/src/deprecated/module.rs index f7802419c..4b72ab960 100644 --- a/lib/c-api/src/deprecated/module.rs +++ b/lib/c-api/src/deprecated/module.rs @@ -92,8 +92,10 @@ pub unsafe extern "C" fn wasmer_module_instantiate( let mut import_object = ImportObject::new(); let mut namespaces = HashMap::new(); for import in imports { - let module_name = - slice::from_raw_parts(import.module_name.bytes, import.module_name.bytes_len as usize); + let module_name = slice::from_raw_parts( + import.module_name.bytes, + import.module_name.bytes_len as usize, + ); let module_name = if let Ok(s) = std::str::from_utf8(module_name) { s } else { @@ -102,8 +104,10 @@ pub unsafe extern "C" fn wasmer_module_instantiate( }); return wasmer_result_t::WASMER_ERROR; }; - let import_name = - slice::from_raw_parts(import.import_name.bytes, import.import_name.bytes_len as usize); + let import_name = slice::from_raw_parts( + import.import_name.bytes, + import.import_name.bytes_len as usize, + ); let import_name = if let Ok(s) = std::str::from_utf8(import_name) { s } else { @@ -149,7 +153,11 @@ pub unsafe extern "C" fn wasmer_module_instantiate( } }; - let c_api_instance = CAPIInstance { instance: new_instance, imported_memories, ctx_data: None }; + let c_api_instance = CAPIInstance { + instance: new_instance, + imported_memories, + ctx_data: None, + }; *instance = Box::into_raw(Box::new(c_api_instance)) as *mut wasmer_instance_t; wasmer_result_t::WASMER_OK @@ -216,7 +224,9 @@ pub unsafe extern "C" fn wasmer_module_serialize( wasmer_result_t::WASMER_OK } Err(_) => { - update_last_error(CApiError { msg: "Failed to serialize the module".to_string() }); + update_last_error(CApiError { + msg: "Failed to serialize the module".to_string(), + }); wasmer_result_t::WASMER_ERROR } } @@ -258,8 +268,10 @@ pub unsafe extern "C" fn wasmer_serialized_module_from_bytes( return wasmer_result_t::WASMER_ERROR; } - let serialized_module_bytes: &[u8] = - slice::from_raw_parts(serialized_module_bytes, serialized_module_bytes_length as usize); + let serialized_module_bytes: &[u8] = slice::from_raw_parts( + serialized_module_bytes, + serialized_module_bytes_length as usize, + ); *serialized_module = Box::into_raw(Box::new(serialized_module_bytes)) as _; wasmer_result_t::WASMER_OK @@ -281,7 +293,9 @@ pub unsafe extern "C" fn wasmer_module_deserialize( let serialized_module: &[u8] = if let Some(sm) = serialized_module { &*(sm as *const wasmer_serialized_module_t as *const &[u8]) } else { - update_last_error(CApiError { msg: "`serialized_module` pointer is null".to_string() }); + update_last_error(CApiError { + msg: "`serialized_module` pointer is null".to_string(), + }); return wasmer_result_t::WASMER_ERROR; }; diff --git a/lib/c-api/src/deprecated/table.rs b/lib/c-api/src/deprecated/table.rs index c371d3631..5043d4857 100644 --- a/lib/c-api/src/deprecated/table.rs +++ b/lib/c-api/src/deprecated/table.rs @@ -36,8 +36,16 @@ pub unsafe extern "C" fn wasmer_table_new( table: *mut *mut wasmer_table_t, limits: wasmer_limits_t, ) -> wasmer_result_t { - let max = if limits.max.has_some { Some(limits.max.some) } else { None }; - let desc = TableType { ty: ValType::FuncRef, minimum: limits.min, maximum: max }; + let max = if limits.max.has_some { + Some(limits.max.some) + } else { + None + }; + let desc = TableType { + ty: ValType::FuncRef, + minimum: limits.min, + maximum: max, + }; let store = get_global_store(); let result = Table::new(store, desc, get_default_table_value(ValType::FuncRef)); let new_table = match result { diff --git a/lib/c-api/src/deprecated/value.rs b/lib/c-api/src/deprecated/value.rs index 6d485a94c..922448440 100644 --- a/lib/c-api/src/deprecated/value.rs +++ b/lib/c-api/src/deprecated/value.rs @@ -74,18 +74,22 @@ impl From for Val { unsafe { #[allow(unreachable_patterns, non_snake_case)] match v { - wasmer_value_t { tag: wasmer_value_tag::WASM_I32, value: wasmer_value { I32 } } => { - Val::I32(I32) - } - wasmer_value_t { tag: wasmer_value_tag::WASM_I64, value: wasmer_value { I64 } } => { - Val::I64(I64) - } - wasmer_value_t { tag: wasmer_value_tag::WASM_F32, value: wasmer_value { F32 } } => { - Val::F32(F32) - } - wasmer_value_t { tag: wasmer_value_tag::WASM_F64, value: wasmer_value { F64 } } => { - Val::F64(F64) - } + wasmer_value_t { + tag: wasmer_value_tag::WASM_I32, + value: wasmer_value { I32 }, + } => Val::I32(I32), + wasmer_value_t { + tag: wasmer_value_tag::WASM_I64, + value: wasmer_value { I64 }, + } => Val::I64(I64), + wasmer_value_t { + tag: wasmer_value_tag::WASM_F32, + value: wasmer_value { F32 }, + } => Val::F32(F32), + wasmer_value_t { + tag: wasmer_value_tag::WASM_F64, + value: wasmer_value { F64 }, + } => Val::F64(F64), _ => unreachable!("unknown Wasm type"), } } @@ -95,18 +99,22 @@ impl From for Val { impl From for wasmer_value_t { fn from(val: Val) -> Self { match val { - Val::I32(x) => { - wasmer_value_t { tag: wasmer_value_tag::WASM_I32, value: wasmer_value { I32: x } } - } - Val::I64(x) => { - wasmer_value_t { tag: wasmer_value_tag::WASM_I64, value: wasmer_value { I64: x } } - } - Val::F32(x) => { - wasmer_value_t { tag: wasmer_value_tag::WASM_F32, value: wasmer_value { F32: x } } - } - Val::F64(x) => { - wasmer_value_t { tag: wasmer_value_tag::WASM_F64, value: wasmer_value { F64: x } } - } + Val::I32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I32, + value: wasmer_value { I32: x }, + }, + Val::I64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_I64, + value: wasmer_value { I64: x }, + }, + Val::F32(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F32, + value: wasmer_value { F32: x }, + }, + Val::F64(x) => wasmer_value_t { + tag: wasmer_value_tag::WASM_F64, + value: wasmer_value { F64: x }, + }, Val::V128(_) => unimplemented!("V128 not supported in C API"), Val::ExternRef(_) => unimplemented!("ExternRef not supported in C API"), Val::FuncRef(_) => unimplemented!("FuncRef not supported in C API"), diff --git a/lib/c-api/src/error.rs b/lib/c-api/src/error.rs index 8e397bc12..9011303dc 100644 --- a/lib/c-api/src/error.rs +++ b/lib/c-api/src/error.rs @@ -144,7 +144,11 @@ pub unsafe extern "C" fn wasmer_last_error_message( let buffer = slice::from_raw_parts_mut(buffer.cast::().as_ptr(), length); - ptr::copy_nonoverlapping(error_message.as_ptr(), buffer.as_mut_ptr(), error_message.len()); + ptr::copy_nonoverlapping( + error_message.as_ptr(), + buffer.as_mut_ptr(), + error_message.len(), + ); // Add a trailing null so people using the string as a `char *` don't // accidentally read into garbage. diff --git a/lib/c-api/src/ordered_resolver.rs b/lib/c-api/src/ordered_resolver.rs index e625e3db0..dfe4493d1 100644 --- a/lib/c-api/src/ordered_resolver.rs +++ b/lib/c-api/src/ordered_resolver.rs @@ -17,7 +17,9 @@ pub struct OrderedResolver { impl Resolver for OrderedResolver { fn resolve(&self, index: u32, _module: &str, _name: &str) -> Option { - self.externs.get(index as usize).map(|extern_| extern_.to_export()) + self.externs + .get(index as usize) + .map(|extern_| extern_.to_export()) } } diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 6858be645..e90143202 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -435,7 +435,9 @@ pub extern "C" fn wasm_engine_new_with_config( where M: ToString, { - update_last_error(CApiError { msg: msg.to_string() }); + update_last_error(CApiError { + msg: msg.to_string(), + }); return None; } diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs index 39a85b0bb..98d184649 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -18,7 +18,10 @@ pub struct wasm_func_t { impl wasm_func_t { pub(crate) fn new(function: Function) -> Self { - Self { tag: CApiExternTag::Function, inner: Box::new(function) } + Self { + tag: CApiExternTag::Function, + inner: Box::new(function), + } } } @@ -168,7 +171,10 @@ pub unsafe extern "C" fn wasm_func_new_with_env( let function = Function::new_with_env( &store.inner, func_sig, - WrapperEnv { env, env_finalizer: Arc::new(env_finalizer) }, + WrapperEnv { + env, + env_finalizer: Arc::new(env_finalizer), + }, trampoline, ); diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index ec7ebfd19..14b6edb71 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -16,7 +16,10 @@ pub struct wasm_global_t { impl wasm_global_t { pub(crate) fn new(global: Global) -> Self { - Self { tag: CApiExternTag::Global, inner: Box::new(global) } + Self { + tag: CApiExternTag::Global, + inner: Box::new(global), + } } } diff --git a/lib/c-api/src/wasm_c_api/externals/memory.rs b/lib/c-api/src/wasm_c_api/externals/memory.rs index 02d614fdd..4e73c6aec 100644 --- a/lib/c-api/src/wasm_c_api/externals/memory.rs +++ b/lib/c-api/src/wasm_c_api/externals/memory.rs @@ -14,7 +14,10 @@ pub struct wasm_memory_t { impl wasm_memory_t { pub(crate) fn new(memory: Memory) -> Self { - Self { tag: CApiExternTag::Memory, inner: Box::new(memory) } + Self { + tag: CApiExternTag::Memory, + inner: Box::new(memory), + } } } diff --git a/lib/c-api/src/wasm_c_api/externals/mod.rs b/lib/c-api/src/wasm_c_api/externals/mod.rs index f78e2cb22..2b8a670b9 100644 --- a/lib/c-api/src/wasm_c_api/externals/mod.rs +++ b/lib/c-api/src/wasm_c_api/externals/mod.rs @@ -99,17 +99,25 @@ impl Clone for wasm_extern_t { fn clone(&self) -> Self { match self.get_tag() { CApiExternTag::Function => Self { - inner: wasm_extern_inner { function: unsafe { self.inner.function.clone() } }, + inner: wasm_extern_inner { + function: unsafe { self.inner.function.clone() }, + }, + }, + CApiExternTag::Memory => Self { + inner: wasm_extern_inner { + memory: unsafe { self.inner.memory.clone() }, + }, + }, + CApiExternTag::Global => Self { + inner: wasm_extern_inner { + global: unsafe { self.inner.global.clone() }, + }, + }, + CApiExternTag::Table => Self { + inner: wasm_extern_inner { + table: unsafe { self.inner.table.clone() }, + }, }, - CApiExternTag::Memory => { - Self { inner: wasm_extern_inner { memory: unsafe { self.inner.memory.clone() } } } - } - CApiExternTag::Global => { - Self { inner: wasm_extern_inner { global: unsafe { self.inner.global.clone() } } } - } - CApiExternTag::Table => { - Self { inner: wasm_extern_inner { table: unsafe { self.inner.table.clone() } } } - } } } } diff --git a/lib/c-api/src/wasm_c_api/externals/table.rs b/lib/c-api/src/wasm_c_api/externals/table.rs index 8e89ca6bd..f90f8607d 100644 --- a/lib/c-api/src/wasm_c_api/externals/table.rs +++ b/lib/c-api/src/wasm_c_api/externals/table.rs @@ -13,7 +13,10 @@ pub struct wasm_table_t { impl wasm_table_t { pub(crate) fn new(table: Table) -> Self { - Self { tag: CApiExternTag::Table, inner: Box::new(table) } + Self { + tag: CApiExternTag::Table, + inner: Box::new(table), + } } } diff --git a/lib/c-api/src/wasm_c_api/module.rs b/lib/c-api/src/wasm_c_api/module.rs index 5a99745b8..aee356b03 100644 --- a/lib/c-api/src/wasm_c_api/module.rs +++ b/lib/c-api/src/wasm_c_api/module.rs @@ -39,7 +39,9 @@ pub unsafe extern "C" fn wasm_module_new( let bytes = bytes.into_slice()?; let module = c_try!(Module::from_binary(&store.inner, bytes)); - Some(Box::new(wasm_module_t { inner: Arc::new(module) })) + Some(Box::new(wasm_module_t { + inner: Arc::new(module), + })) } /// Deletes a WebAssembly module. @@ -486,7 +488,11 @@ pub unsafe extern "C" fn wasm_module_deserialize( let module = c_try!(Module::deserialize(&store.inner, byte_slice)); - Some(NonNull::new_unchecked(Box::into_raw(Box::new(wasm_module_t { inner: Arc::new(module) })))) + Some(NonNull::new_unchecked(Box::into_raw(Box::new( + wasm_module_t { + inner: Arc::new(module), + }, + )))) } /// Serializes a module into a binary representation that the diff --git a/lib/c-api/src/wasm_c_api/types/export.rs b/lib/c-api/src/wasm_c_api/types/export.rs index 3d0f74d1f..a2d94d3c0 100644 --- a/lib/c-api/src/wasm_c_api/types/export.rs +++ b/lib/c-api/src/wasm_c_api/types/export.rs @@ -16,7 +16,10 @@ pub extern "C" fn wasm_exporttype_new( extern_type: Option>, ) -> Option> { let name = unsafe { owned_wasm_name_t::new(name?) }; - Some(Box::new(wasm_exporttype_t { name, extern_type: extern_type? })) + Some(Box::new(wasm_exporttype_t { + name, + extern_type: extern_type?, + })) } #[no_mangle] diff --git a/lib/c-api/src/wasm_c_api/types/function.rs b/lib/c-api/src/wasm_c_api/types/function.rs index 245031925..131a79461 100644 --- a/lib/c-api/src/wasm_c_api/types/function.rs +++ b/lib/c-api/src/wasm_c_api/types/function.rs @@ -13,7 +13,11 @@ impl WasmFunctionType { let params: Box = Box::new(function_type.params().into()); let results: Box = Box::new(function_type.results().into()); - Self { function_type, params, results } + Self { + function_type, + params, + results, + } } } @@ -32,7 +36,9 @@ pub struct wasm_functype_t { impl wasm_functype_t { pub(crate) fn new(function_type: FunctionType) -> Self { - Self { extern_type: wasm_externtype_t::new(ExternType::Function(function_type)) } + Self { + extern_type: wasm_externtype_t::new(ExternType::Function(function_type)), + } } pub(crate) fn inner(&self) -> &WasmFunctionType { @@ -55,15 +61,24 @@ pub unsafe extern "C" fn wasm_functype_new( let params = params?; let results = results?; - let params_as_valtype: Vec = - params.into_slice()?.into_iter().map(|val| val.as_ref().into()).collect::>(); - let results_as_valtype: Vec = - results.into_slice()?.iter().map(|val| val.as_ref().into()).collect::>(); + let params_as_valtype: Vec = params + .into_slice()? + .into_iter() + .map(|val| val.as_ref().into()) + .collect::>(); + let results_as_valtype: Vec = results + .into_slice()? + .iter() + .map(|val| val.as_ref().into()) + .collect::>(); wasm_valtype_vec_delete(Some(params)); wasm_valtype_vec_delete(Some(results)); - Some(Box::new(wasm_functype_t::new(FunctionType::new(params_as_valtype, results_as_valtype)))) + Some(Box::new(wasm_functype_t::new(FunctionType::new( + params_as_valtype, + results_as_valtype, + )))) } #[no_mangle] diff --git a/lib/c-api/src/wasm_c_api/types/global.rs b/lib/c-api/src/wasm_c_api/types/global.rs index f81232420..769002802 100644 --- a/lib/c-api/src/wasm_c_api/types/global.rs +++ b/lib/c-api/src/wasm_c_api/types/global.rs @@ -15,7 +15,10 @@ impl WasmGlobalType { pub(crate) fn new(global_type: GlobalType) -> Self { let content = Box::new(global_type.ty.into()); - Self { global_type, content } + Self { + global_type, + content, + } } } @@ -28,7 +31,9 @@ pub struct wasm_globaltype_t { impl wasm_globaltype_t { pub(crate) fn new(global_type: GlobalType) -> Self { - Self { extern_type: wasm_externtype_t::new(ExternType::Global(global_type)) } + Self { + extern_type: wasm_externtype_t::new(ExternType::Global(global_type)), + } } pub(crate) fn inner(&self) -> &WasmGlobalType { @@ -50,8 +55,10 @@ pub unsafe extern "C" fn wasm_globaltype_new( ) -> Option> { let valtype = valtype?; let mutability: wasm_mutability_enum = mutability.try_into().ok()?; - let global_type = - Box::new(wasm_globaltype_t::new(GlobalType::new((*valtype).into(), mutability.into()))); + let global_type = Box::new(wasm_globaltype_t::new(GlobalType::new( + (*valtype).into(), + mutability.into(), + ))); wasm_valtype_delete(Some(valtype)); diff --git a/lib/c-api/src/wasm_c_api/types/import.rs b/lib/c-api/src/wasm_c_api/types/import.rs index 8f03d3040..8e2e5361c 100644 --- a/lib/c-api/src/wasm_c_api/types/import.rs +++ b/lib/c-api/src/wasm_c_api/types/import.rs @@ -18,9 +18,17 @@ pub extern "C" fn wasm_importtype_new( name: Option<&wasm_name_t>, extern_type: Option>, ) -> Option> { - let (module, name) = - unsafe { (owned_wasm_name_t::new(module?), owned_wasm_name_t::new(name?)) }; - Some(Box::new(wasm_importtype_t { name, module, extern_type: extern_type? })) + let (module, name) = unsafe { + ( + owned_wasm_name_t::new(module?), + owned_wasm_name_t::new(name?), + ) + }; + Some(Box::new(wasm_importtype_t { + name, + module, + extern_type: extern_type?, + })) } #[no_mangle] @@ -53,6 +61,10 @@ impl From<&ImportType> for wasm_importtype_t { let name: owned_wasm_name_t = other.name().to_string().into(); let extern_type: Box = Box::new(other.ty().into()); - wasm_importtype_t { module, name, extern_type } + wasm_importtype_t { + module, + name, + extern_type, + } } } diff --git a/lib/c-api/src/wasm_c_api/types/memory.rs b/lib/c-api/src/wasm_c_api/types/memory.rs index 20659aa2c..6565fbe69 100644 --- a/lib/c-api/src/wasm_c_api/types/memory.rs +++ b/lib/c-api/src/wasm_c_api/types/memory.rs @@ -11,10 +11,16 @@ impl WasmMemoryType { pub(crate) fn new(memory_type: MemoryType) -> Self { let limits = Box::new(wasm_limits_t { min: memory_type.minimum.0 as _, - max: memory_type.maximum.map(|max| max.0 as _).unwrap_or(LIMITS_MAX_SENTINEL), + max: memory_type + .maximum + .map(|max| max.0 as _) + .unwrap_or(LIMITS_MAX_SENTINEL), }); - Self { memory_type, limits } + Self { + memory_type, + limits, + } } } @@ -27,7 +33,9 @@ pub struct wasm_memorytype_t { impl wasm_memorytype_t { pub(crate) fn new(memory_type: MemoryType) -> Self { - Self { extern_type: wasm_externtype_t::new(ExternType::Memory(memory_type)) } + Self { + extern_type: wasm_externtype_t::new(ExternType::Memory(memory_type)), + } } pub(crate) fn inner(&self) -> &WasmMemoryType { @@ -45,10 +53,15 @@ wasm_declare_boxed_vec!(memorytype); #[no_mangle] pub unsafe extern "C" fn wasm_memorytype_new(limits: &wasm_limits_t) -> Box { let min_pages = Pages(limits.min as _); - let max_pages = - if limits.max == LIMITS_MAX_SENTINEL { None } else { Some(Pages(limits.max as _)) }; + let max_pages = if limits.max == LIMITS_MAX_SENTINEL { + None + } else { + Some(Pages(limits.max as _)) + }; - Box::new(wasm_memorytype_t::new(MemoryType::new(min_pages, max_pages, false))) + Box::new(wasm_memorytype_t::new(MemoryType::new( + min_pages, max_pages, false, + ))) } #[no_mangle] diff --git a/lib/c-api/src/wasm_c_api/types/mod.rs b/lib/c-api/src/wasm_c_api/types/mod.rs index 205c4428b..541747045 100644 --- a/lib/c-api/src/wasm_c_api/types/mod.rs +++ b/lib/c-api/src/wasm_c_api/types/mod.rs @@ -50,7 +50,10 @@ impl owned_wasm_name_t { /// You must ensure that the data pointed to by `wasm_name_t` is valid and /// that it is not owned by anyone else. pub unsafe fn new(name: &wasm_name_t) -> Self { - Self(wasm_name_t { size: name.size, data: name.data }) + Self(wasm_name_t { + size: name.size, + data: name.data, + }) } } diff --git a/lib/c-api/src/wasm_c_api/types/table.rs b/lib/c-api/src/wasm_c_api/types/table.rs index 9e1c4156b..40ea30037 100644 --- a/lib/c-api/src/wasm_c_api/types/table.rs +++ b/lib/c-api/src/wasm_c_api/types/table.rs @@ -23,7 +23,11 @@ impl WasmTableType { }); let content = Box::new(table_type.ty.into()); - Self { table_type, limits, content } + Self { + table_type, + limits, + content, + } } } @@ -36,7 +40,9 @@ pub struct wasm_tabletype_t { impl wasm_tabletype_t { pub(crate) fn new(table_type: TableType) -> Self { - Self { extern_type: wasm_externtype_t::new(ExternType::Table(table_type)) } + Self { + extern_type: wasm_externtype_t::new(ExternType::Table(table_type)), + } } pub(crate) fn inner(&self) -> &WasmTableType { @@ -55,7 +61,11 @@ pub unsafe extern "C" fn wasm_tabletype_new( limits: &wasm_limits_t, ) -> Option> { let valtype = valtype?; - let max_elements = if limits.max == LIMITS_MAX_SENTINEL { None } else { Some(limits.max as _) }; + let max_elements = if limits.max == LIMITS_MAX_SENTINEL { + None + } else { + Some(limits.max as _) + }; let table_type = Box::new(wasm_tabletype_t::new(TableType::new( (*valtype).into(), limits.min as _, diff --git a/lib/c-api/src/wasm_c_api/types/value.rs b/lib/c-api/src/wasm_c_api/types/value.rs index aa8d2a9e0..647956175 100644 --- a/lib/c-api/src/wasm_c_api/types/value.rs +++ b/lib/c-api/src/wasm_c_api/types/value.rs @@ -50,7 +50,9 @@ pub struct wasm_valtype_t { impl Default for wasm_valtype_t { fn default() -> Self { - Self { valkind: wasm_valkind_enum::WASM_I32 } + Self { + valkind: wasm_valkind_enum::WASM_I32, + } } } @@ -70,7 +72,9 @@ impl From<&wasm_valtype_t> for ValType { impl From for wasm_valtype_t { fn from(other: ValType) -> Self { - Self { valkind: other.into() } + Self { + valkind: other.into(), + } } } @@ -87,5 +91,7 @@ pub unsafe extern "C" fn wasm_valtype_delete(_valtype: Option) -> wasm_valkind_t { - valtype.expect("`wasm_valtype_kind: argument is a null pointer").valkind as wasm_valkind_t + valtype + .expect("`wasm_valtype_kind: argument is a null pointer") + .valkind as wasm_valkind_t } diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index d9780dd3f..f20d00742 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -133,7 +133,10 @@ mod tests { #[test] fn test_wasmer_is_headless() { - set_var("COMPILER", if cfg!(feature = "compiler") { "0" } else { "1" }); + set_var( + "COMPILER", + if cfg!(feature = "compiler") { "0" } else { "1" }, + ); (assert_c! { #include "tests/wasmer_wasm.h" @@ -152,9 +155,23 @@ mod tests { #[test] fn test_wasmer_is_compiler_available() { - set_var("CRANELIFT", if cfg!(feature = "cranelift") { "1" } else { "0" }); + set_var( + "CRANELIFT", + if cfg!(feature = "cranelift") { + "1" + } else { + "0" + }, + ); set_var("LLVM", if cfg!(feature = "llvm") { "1" } else { "0" }); - set_var("SINGLEPASS", if cfg!(feature = "singlepass") { "1" } else { "0" }); + set_var( + "SINGLEPASS", + if cfg!(feature = "singlepass") { + "1" + } else { + "0" + }, + ); (assert_c! { #include "tests/wasmer_wasm.h" @@ -179,7 +196,14 @@ mod tests { fn test_wasmer_is_engine_available() { set_var("JIT", if cfg!(feature = "jit") { "1" } else { "0" }); set_var("NATIVE", if cfg!(feature = "native") { "1" } else { "0" }); - set_var("OBJECT_FILE", if cfg!(feature = "object-file") { "1" } else { "0" }); + set_var( + "OBJECT_FILE", + if cfg!(feature = "object-file") { + "1" + } else { + "0" + }, + ); (assert_c! { #include "tests/wasmer_wasm.h" diff --git a/lib/c-api/src/wasm_c_api/unstable/features.rs b/lib/c-api/src/wasm_c_api/unstable/features.rs index 27bd802cf..8c781488c 100644 --- a/lib/c-api/src/wasm_c_api/unstable/features.rs +++ b/lib/c-api/src/wasm_c_api/unstable/features.rs @@ -55,7 +55,9 @@ pub struct wasmer_features_t { /// See the module's documentation. #[no_mangle] pub extern "C" fn wasmer_features_new() -> Box { - Box::new(wasmer_features_t { inner: Features::new() }) + Box::new(wasmer_features_t { + inner: Features::new(), + }) } /// Delete a [`wasmer_features_t`]. diff --git a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs index 5292ed653..4d5a420ff 100644 --- a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs +++ b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs @@ -215,7 +215,10 @@ pub extern "C" fn wasmer_metering_get_remaining_points(instance: &wasm_instance_ /// See module's documentation. #[no_mangle] pub extern "C" fn wasmer_metering_points_are_exhausted(instance: &wasm_instance_t) -> bool { - matches!(get_remaining_points(&instance.inner), MeteringPoints::Exhausted,) + matches!( + get_remaining_points(&instance.inner), + MeteringPoints::Exhausted, + ) } /// Set a new amount of points for the given metering middleware. @@ -310,5 +313,7 @@ pub extern "C" fn wasmer_metering_as_middleware( ) -> Option> { let metering = metering?; - Some(Box::new(wasmer_middleware_t { inner: metering.inner })) + Some(Box::new(wasmer_middleware_t { + inner: metering.inner, + })) } diff --git a/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs b/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs index 584d074e3..cf16829f7 100644 --- a/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs +++ b/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs @@ -147,7 +147,10 @@ pub unsafe extern "C" fn wasmer_triple_new( triple: Option<&wasm_name_t>, ) -> Option> { let triple = triple?; - let triple = c_try!(str::from_utf8(slice::from_raw_parts(triple.data, triple.size))); + let triple = c_try!(str::from_utf8(slice::from_raw_parts( + triple.data, + triple.size + ))); Some(Box::new(wasmer_triple_t { inner: c_try!(Triple::from_str(triple).map_err(|e| CApiError { msg: e.to_string() })), @@ -180,7 +183,9 @@ pub unsafe extern "C" fn wasmer_triple_new( /// See also [`wasmer_triple_new`]. #[no_mangle] pub extern "C" fn wasmer_triple_new_from_host() -> Box { - Box::new(wasmer_triple_t { inner: Triple::host() }) + Box::new(wasmer_triple_t { + inner: Triple::host(), + }) } /// Delete a [`wasmer_triple_t`]. @@ -260,7 +265,9 @@ pub struct wasmer_cpu_features_t { /// See [`wasmer_cpu_features_t`]. #[no_mangle] pub extern "C" fn wasmer_cpu_features_new() -> Box { - Box::new(wasmer_cpu_features_t { inner: CpuFeature::set() }) + Box::new(wasmer_cpu_features_t { + inner: CpuFeature::set(), + }) } /// Delete a [`wasmer_cpu_features_t`]. diff --git a/lib/c-api/src/wasm_c_api/unstable/wasi.rs b/lib/c-api/src/wasm_c_api/unstable/wasi.rs index 957683562..8b3801be8 100644 --- a/lib/c-api/src/wasm_c_api/unstable/wasi.rs +++ b/lib/c-api/src/wasm_c_api/unstable/wasi.rs @@ -171,9 +171,11 @@ fn wasi_get_unordered_imports_inner( let store = &store.inner; - let version = c_try!(get_wasi_version(&module.inner, false).ok_or_else(|| CApiError { - msg: "could not detect a WASI version on the given module".to_string(), - })); + let version = c_try!( + get_wasi_version(&module.inner, false).ok_or_else(|| CApiError { + msg: "could not detect a WASI version on the given module".to_string(), + }) + ); let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version); diff --git a/lib/c-api/src/wasm_c_api/value.rs b/lib/c-api/src/wasm_c_api/value.rs index d5b9bd156..2415f3bea 100644 --- a/lib/c-api/src/wasm_c_api/value.rs +++ b/lib/c-api/src/wasm_c_api/value.rs @@ -114,7 +114,10 @@ wasm_declare_vec!(val); impl Clone for wasm_val_t { fn clone(&self) -> Self { - wasm_val_t { kind: self.kind, of: self.of.clone() } + wasm_val_t { + kind: self.kind, + of: self.of.clone(), + } } } @@ -127,10 +130,18 @@ pub unsafe extern "C" fn wasm_val_copy( out.kind = val.kind; out.of = match val.kind.try_into() { Ok(kind) => match kind { - wasm_valkind_enum::WASM_I32 => wasm_val_inner { int32_t: val.of.int32_t }, - wasm_valkind_enum::WASM_I64 => wasm_val_inner { int64_t: val.of.int64_t }, - wasm_valkind_enum::WASM_F32 => wasm_val_inner { float32_t: val.of.float32_t }, - wasm_valkind_enum::WASM_F64 => wasm_val_inner { float64_t: val.of.float64_t }, + wasm_valkind_enum::WASM_I32 => wasm_val_inner { + int32_t: val.of.int32_t, + }, + wasm_valkind_enum::WASM_I64 => wasm_val_inner { + int64_t: val.of.int64_t, + }, + wasm_valkind_enum::WASM_F32 => wasm_val_inner { + float32_t: val.of.float32_t, + }, + wasm_valkind_enum::WASM_F64 => wasm_val_inner { + float64_t: val.of.float64_t, + }, wasm_valkind_enum::WASM_ANYREF => wasm_val_inner { wref: val.of.wref }, wasm_valkind_enum::WASM_FUNCREF => wasm_val_inner { wref: val.of.wref }, }, diff --git a/lib/c-api/src/wasm_c_api/wasi/capture_files.rs b/lib/c-api/src/wasm_c_api/wasi/capture_files.rs index cb8a82e05..f5c62d744 100644 --- a/lib/c-api/src/wasm_c_api/wasi/capture_files.rs +++ b/lib/c-api/src/wasm_c_api/wasi/capture_files.rs @@ -13,7 +13,9 @@ pub struct OutputCapturer { impl OutputCapturer { pub fn new() -> Self { - Self { buffer: VecDeque::new() } + Self { + buffer: VecDeque::new(), + } } } @@ -46,21 +48,36 @@ impl WasiFile for OutputCapturer { // fail when reading or Seeking impl Read for OutputCapturer { fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from capturing stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from capturing stdout", + )) } fn read_to_end(&mut self, _buf: &mut Vec) -> std::io::Result { - Err(std::io::Error::new(std::io::ErrorKind::Other, "can not read from capturing stdout")) + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "can not read from capturing stdout", + )) } fn read_to_string(&mut self, _buf: &mut String) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from capturing stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from capturing stdout", + )) } fn read_exact(&mut self, _buf: &mut [u8]) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not read from capturing stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from capturing stdout", + )) } } impl Seek for OutputCapturer { fn seek(&mut self, _pos: io::SeekFrom) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not seek capturing stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not seek capturing stdout", + )) } } impl Write for OutputCapturer { diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index c2ef86ed6..1097665b2 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -175,18 +175,24 @@ pub struct wasi_env_t { #[no_mangle] pub extern "C" fn wasi_env_new(mut config: Box) -> Option> { if !config.inherit_stdout { - config.state_builder.stdout(Box::new(capture_files::OutputCapturer::new())); + config + .state_builder + .stdout(Box::new(capture_files::OutputCapturer::new())); } if !config.inherit_stderr { - config.state_builder.stderr(Box::new(capture_files::OutputCapturer::new())); + config + .state_builder + .stderr(Box::new(capture_files::OutputCapturer::new())); } // TODO: impl capturer for stdin let wasi_state = c_try!(config.state_builder.build()); - Some(Box::new(wasi_env_t { inner: WasiEnv::new(wasi_state) })) + Some(Box::new(wasi_env_t { + inner: WasiEnv::new(wasi_state), + })) } /// Delete a [`wasi_env_t`]. @@ -266,7 +272,10 @@ fn read_inner(wasi_file: &mut Box, inner_buffer: &mut [u8]) -> isi if let Some(oc) = wasi_file.downcast_mut::() { let total_to_read = min(inner_buffer.len(), oc.buffer.len()); - for (address, value) in inner_buffer.iter_mut().zip(oc.buffer.drain(..total_to_read)) { + for (address, value) in inner_buffer + .iter_mut() + .zip(oc.buffer.drain(..total_to_read)) + { *address = value; } @@ -358,9 +367,11 @@ fn wasi_get_imports_inner( let store = &store.inner; - let version = c_try!(get_wasi_version(&module.inner, false).ok_or_else(|| CApiError { - msg: "could not detect a WASI version on the given module".to_string(), - })); + let version = c_try!( + get_wasi_version(&module.inner, false).ok_or_else(|| CApiError { + msg: "could not detect a WASI version on the given module".to_string(), + }) + ); let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version); diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index 14458e4bd..8a9650ef8 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -18,9 +18,11 @@ pub fn store_cache_jit(c: &mut Criterion) { let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); let store = Store::new(&JIT::new(compiler).engine()); - let module = - Module::new(&store, std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap()) - .unwrap(); + let module = Module::new( + &store, + std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap(), + ) + .unwrap(); c.bench_function("store jit module in filesystem cache", |b| { b.iter(|| { @@ -35,9 +37,11 @@ pub fn load_cache_jit(c: &mut Criterion) { let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); let store = Store::new(&JIT::new(compiler).engine()); - let module = - Module::new(&store, std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap()) - .unwrap(); + let module = Module::new( + &store, + std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap(), + ) + .unwrap(); let key = Hash::new([0u8; 32]); fs_cache.store(key, &module).unwrap(); @@ -51,9 +55,11 @@ pub fn store_cache_native(c: &mut Criterion) { let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); let store = Store::new(&Native::new(compiler).engine()); - let module = - Module::new(&store, std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap()) - .unwrap(); + let module = Module::new( + &store, + std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap(), + ) + .unwrap(); c.bench_function("store native module in filesystem cache", |b| { b.iter(|| { @@ -68,9 +74,11 @@ pub fn load_cache_native(c: &mut Criterion) { let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); let store = Store::new(&Native::new(compiler).engine()); - let module = - Module::new(&store, std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap()) - .unwrap(); + let module = Module::new( + &store, + std::fs::read("../../lib/c-api/tests/assets/qjs.wasm").unwrap(), + ) + .unwrap(); let key = Hash::new([0u8; 32]); fs_cache.store(key, &module).unwrap(); diff --git a/lib/cache/src/filesystem.rs b/lib/cache/src/filesystem.rs index 80cb41ece..1d6987191 100644 --- a/lib/cache/src/filesystem.rs +++ b/lib/cache/src/filesystem.rs @@ -55,7 +55,10 @@ impl FileSystemCache { // This path points to a file. Err(io::Error::new( io::ErrorKind::PermissionDenied, - format!("the supplied path already points to a file: {}", path.display()), + format!( + "the supplied path already points to a file: {}", + path.display() + ), )) } } else { diff --git a/lib/cli/src/c_gen/mod.rs b/lib/cli/src/c_gen/mod.rs index da34af754..b87b0e226 100644 --- a/lib/cli/src/c_gen/mod.rs +++ b/lib/cli/src/c_gen/mod.rs @@ -59,13 +59,19 @@ pub enum CType { impl CType { /// Convenience function to get a mutable void pointer type. pub fn void_ptr() -> Self { - CType::PointerTo { is_const: false, inner: Box::new(CType::Void) } + CType::PointerTo { + is_const: false, + inner: Box::new(CType::Void), + } } /// Convenience function to get a const void pointer type. #[allow(dead_code)] pub fn const_void_ptr() -> Self { - CType::PointerTo { is_const: true, inner: Box::new(CType::Void) } + CType::PointerTo { + is_const: true, + inner: Box::new(CType::Void), + } } /// Generate the C source code for a type into the given `String`. @@ -111,10 +117,15 @@ impl CType { Self::ISize => { w.push_str("size_t"); } - Self::Function { arguments, return_value } => { + Self::Function { + arguments, + return_value, + } => { // function with no, name, assume it's a function pointer - let ret: CType = - return_value.as_ref().map(|i: &Box| (&**i).clone()).unwrap_or_default(); + let ret: CType = return_value + .as_ref() + .map(|i: &Box| (&**i).clone()) + .unwrap_or_default(); ret.generate_c(w); w.push(' '); w.push_str("(*)"); @@ -160,9 +171,14 @@ impl CType { w.push(' '); w.push_str(name); } - Self::Function { arguments, return_value } => { - let ret: CType = - return_value.as_ref().map(|i: &Box| (&**i).clone()).unwrap_or_default(); + Self::Function { + arguments, + return_value, + } => { + let ret: CType = return_value + .as_ref() + .map(|i: &Box| (&**i).clone()) + .unwrap_or_default(); ret.generate_c(w); w.push(' '); w.push_str(&name); @@ -248,7 +264,13 @@ impl CStatement { /// Generate C source code for the given CStatement. fn generate_c(&self, w: &mut String) { match &self { - Self::Declaration { name, is_extern, is_const, ctype, definition } => { + Self::Declaration { + name, + is_extern, + is_const, + ctype, + definition, + } => { if *is_const { w.push_str("const "); } @@ -279,14 +301,20 @@ impl CStatement { Self::LiteralConstant { value } => { w.push_str(&value); } - Self::Cast { target_type, expression } => { + Self::Cast { + target_type, + expression, + } => { w.push('('); target_type.generate_c(w); w.push(')'); w.push(' '); expression.generate_c(w); } - Self::TypeDef { source_type, new_name } => { + Self::TypeDef { + source_type, + new_name, + } => { w.push_str("typedef "); // leaky abstraction / hack, doesn't fully solve the problem if let CType::Function { .. } = source_type { @@ -343,17 +371,26 @@ mod test { assert_c_type!(CType::ISize, "size_t"); assert_c_type!(CType::TypeDef("my_type".to_string()), "my_type"); assert_c_type!( - CType::Function { arguments: vec![CType::U8, CType::ISize], return_value: None }, + CType::Function { + arguments: vec![CType::U8, CType::ISize], + return_value: None + }, "void (*)(unsigned char, size_t)" ); assert_c_type!( - CType::Function { arguments: vec![], return_value: Some(Box::new(CType::ISize)) }, + CType::Function { + arguments: vec![], + return_value: Some(Box::new(CType::ISize)) + }, "size_t (*)()" ); assert_c_type!( CType::PointerTo { is_const: true, - inner: Box::new(CType::PointerTo { is_const: false, inner: Box::new(CType::U32) }) + inner: Box::new(CType::PointerTo { + is_const: false, + inner: Box::new(CType::U32) + }) }, "const unsigned int**" ); @@ -384,21 +421,34 @@ mod test { assert_c_type!(CType::I32, "data", "int data"); assert_c_type!(CType::I64, "data", "long long data"); assert_c_type!(CType::ISize, "data", "size_t data"); - assert_c_type!(CType::TypeDef("my_type".to_string()), "data", "my_type data"); assert_c_type!( - CType::Function { arguments: vec![CType::U8, CType::ISize], return_value: None }, + CType::TypeDef("my_type".to_string()), + "data", + "my_type data" + ); + assert_c_type!( + CType::Function { + arguments: vec![CType::U8, CType::ISize], + return_value: None + }, "my_func", "void my_func(unsigned char, size_t)" ); assert_c_type!( - CType::Function { arguments: vec![], return_value: Some(Box::new(CType::ISize)) }, + CType::Function { + arguments: vec![], + return_value: Some(Box::new(CType::ISize)) + }, "my_func", "size_t my_func()" ); assert_c_type!( CType::PointerTo { is_const: true, - inner: Box::new(CType::PointerTo { is_const: false, inner: Box::new(CType::U32) }) + inner: Box::new(CType::PointerTo { + is_const: false, + inner: Box::new(CType::U32) + }) }, "data", "const unsigned int** data" @@ -418,7 +468,9 @@ mod test { } assert_c_expr!( - CStatement::LiteralConstant { value: "\"Hello, world!\"".to_string() }, + CStatement::LiteralConstant { + value: "\"Hello, world!\"".to_string() + }, "\"Hello, world!\"" ); assert_c_expr!( @@ -434,9 +486,15 @@ mod test { assert_c_expr!( CStatement::LiteralArray { items: vec![ - CStatement::LiteralConstant { value: "1".to_string() }, - CStatement::LiteralConstant { value: "2".to_string() }, - CStatement::LiteralConstant { value: "3".to_string() }, + CStatement::LiteralConstant { + value: "1".to_string() + }, + CStatement::LiteralConstant { + value: "2".to_string() + }, + CStatement::LiteralConstant { + value: "3".to_string() + }, ] }, "{\n\t1,\n\t2,\n\t3,\n}" @@ -447,12 +505,20 @@ mod test { name: "my_array".to_string(), is_extern: false, is_const: true, - ctype: CType::Array { inner: Box::new(CType::I32) }, + ctype: CType::Array { + inner: Box::new(CType::I32) + }, definition: Some(Box::new(CStatement::LiteralArray { items: vec![ - CStatement::LiteralConstant { value: "1".to_string() }, - CStatement::LiteralConstant { value: "2".to_string() }, - CStatement::LiteralConstant { value: "3".to_string() }, + CStatement::LiteralConstant { + value: "1".to_string() + }, + CStatement::LiteralConstant { + value: "2".to_string() + }, + CStatement::LiteralConstant { + value: "3".to_string() + }, ] })) }, @@ -463,7 +529,9 @@ mod test { name: "my_array".to_string(), is_extern: true, is_const: true, - ctype: CType::Array { inner: Box::new(CType::I32) }, + ctype: CType::Array { + inner: Box::new(CType::I32) + }, definition: None, }, "const extern int my_array[];\n" diff --git a/lib/cli/src/c_gen/object_file_header.rs b/lib/cli/src/c_gen/object_file_header.rs index 63c72cd9c..f76b189a5 100644 --- a/lib/cli/src/c_gen/object_file_header.rs +++ b/lib/cli/src/c_gen/object_file_header.rs @@ -94,7 +94,9 @@ pub fn generate_header_file( name: "WASMER_METADATA".to_string(), is_extern: true, is_const: true, - ctype: CType::Array { inner: Box::new(CType::U8) }, + ctype: CType::Array { + inner: Box::new(CType::U8), + }, definition: None, }); let function_declarations = module_info @@ -111,7 +113,10 @@ pub fn generate_header_file( name: function_name, is_extern: false, is_const: false, - ctype: CType::Function { arguments: vec![CType::Void], return_value: None }, + ctype: CType::Function { + arguments: vec![CType::Void], + return_value: None, + }, definition: None, } }); @@ -139,7 +144,9 @@ pub fn generate_header_file( CStatement::Cast { target_type: CType::void_ptr(), - expression: Box::new(CStatement::LiteralConstant { value: function_name }), + expression: Box::new(CStatement::LiteralConstant { + value: function_name, + }), } }) .collect::>(); @@ -148,7 +155,9 @@ pub fn generate_header_file( name: "function_pointers".to_string(), is_extern: false, is_const: true, - ctype: CType::Array { inner: Box::new(CType::void_ptr()) }, + ctype: CType::Array { + inner: Box::new(CType::void_ptr()), + }, definition: Some(Box::new(CStatement::LiteralArray { items: function_pointer_array_statements, })), @@ -156,21 +165,24 @@ pub fn generate_header_file( } let func_trampoline_declarations = - module_info.signatures.iter().map(|(sig_index, _func_type)| { - let function_name = - symbol_registry.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index)); + module_info + .signatures + .iter() + .map(|(sig_index, _func_type)| { + let function_name = + symbol_registry.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index)); - CStatement::Declaration { - name: function_name, - is_extern: false, - is_const: false, - ctype: CType::Function { - arguments: vec![CType::void_ptr(), CType::void_ptr(), CType::void_ptr()], - return_value: None, - }, - definition: None, - } - }); + CStatement::Declaration { + name: function_name, + is_extern: false, + is_const: false, + ctype: CType::Function { + arguments: vec![CType::void_ptr(), CType::void_ptr(), CType::void_ptr()], + return_value: None, + }, + definition: None, + } + }); c_statements.push(CStatement::LiteralConstant { value: r#" // Trampolines (functions by which we can call into Wasm) ordered by signature. @@ -189,7 +201,9 @@ pub fn generate_header_file( .map(|(sig_index, _vm_shared_index)| { let function_name = symbol_registry.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index)); - CStatement::LiteralConstant { value: function_name } + CStatement::LiteralConstant { + value: function_name, + } }) .collect::>(); @@ -197,15 +211,20 @@ pub fn generate_header_file( name: "function_trampolines".to_string(), is_extern: false, is_const: true, - ctype: CType::Array { inner: Box::new(CType::void_ptr()) }, + ctype: CType::Array { + inner: Box::new(CType::void_ptr()), + }, definition: Some(Box::new(CStatement::LiteralArray { items: function_trampoline_statements, })), }); } - let dyn_func_declarations = - module_info.functions.keys().take(module_info.num_imported_functions).map(|func_index| { + let dyn_func_declarations = module_info + .functions + .keys() + .take(module_info.num_imported_functions) + .map(|func_index| { let function_name = symbol_registry.symbol_to_name(Symbol::DynamicFunctionTrampoline(func_index)); // TODO: figure out the signature here @@ -247,7 +266,9 @@ pub fn generate_header_file( .map(|func_index| { let function_name = symbol_registry.symbol_to_name(Symbol::DynamicFunctionTrampoline(func_index)); - CStatement::LiteralConstant { value: function_name } + CStatement::LiteralConstant { + value: function_name, + } }) .collect::>(); c_statements.push(CStatement::Declaration { @@ -263,7 +284,9 @@ pub fn generate_header_file( }); } - c_statements.push(CStatement::LiteralConstant { value: HELPER_FUNCTIONS.to_string() }); + c_statements.push(CStatement::LiteralConstant { + value: HELPER_FUNCTIONS.to_string(), + }); c_statements.push(CStatement::LiteralConstant { value: "\n#ifdef __cplusplus\n}\n#endif\n\n".to_string(), diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index 803cdfd91..00ba69227 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -19,7 +19,11 @@ use clap::{Clap, ErrorKind}; )] #[cfg_attr( feature = "headless", - clap(name = "wasmer-headless", about = "Headless WebAssembly standalone runtime.", author) + clap( + name = "wasmer-headless", + about = "Headless WebAssembly standalone runtime.", + author + ) )] /// The options for the wasmer Command Line Interface enum WasmerCLIOptions { diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index d238582c8..56bc69b8c 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -34,7 +34,8 @@ pub struct Compile { impl Compile { /// Runs logic for the `compile` subcommand pub fn execute(&self) -> Result<()> { - self.inner_execute().context(format!("failed to compile `{}`", self.path.display())) + self.inner_execute() + .context(format!("failed to compile `{}`", self.path.display())) } pub(crate) fn get_recommend_extension( @@ -62,8 +63,11 @@ impl Compile { .target_triple .as_ref() .map(|target_triple| { - let mut features = - self.cpu_features.clone().into_iter().fold(CpuFeature::set(), |a, b| a | b); + let mut features = self + .cpu_features + .clone() + .into_iter() + .fold(CpuFeature::set(), |a, b| a | b); // Cranelift requires SSE2, so we have this "hack" for now to facilitate // usage features |= CpuFeature::SSE2; @@ -94,7 +98,10 @@ impl Compile { let module = Module::from_file(&store, &self.path)?; let _ = module.serialize_to_file(&self.output)?; - eprintln!("✔ File compiled successfully to `{}`.", self.output.display(),); + eprintln!( + "✔ File compiled successfully to `{}`.", + self.output.display(), + ); #[cfg(feature = "object-file")] if engine_type == EngineType::ObjectFile { @@ -128,7 +135,10 @@ impl Compile { use std::io::Write; header.write_all(header_file_src.as_bytes())?; - eprintln!("✔ Header file generated successfully at `{}`.", header_path.display(),); + eprintln!( + "✔ Header file generated successfully at `{}`.", + header_path.display(), + ); } Ok(()) } diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index dfcb5d018..888bc9b20 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -40,13 +40,21 @@ pub struct Config { impl Config { /// Runs logic for the `config` subcommand pub fn execute(&self) -> Result<()> { - self.inner_execute().context("failed to retrieve the wasmer config".to_string()) + self.inner_execute() + .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { let key = "WASMER_DIR"; let wasmer_dir = env::var(key) - .or_else(|e| option_env!("WASMER_INSTALL_PREFIX").map(str::to_string).ok_or(e)) - .context(format!("failed to retrieve the {} environment variables", key))?; + .or_else(|e| { + option_env!("WASMER_INSTALL_PREFIX") + .map(str::to_string) + .ok_or(e) + }) + .context(format!( + "failed to retrieve the {} environment variables", + key + ))?; let prefix = PathBuf::from(wasmer_dir); diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index e260498f8..4de45e922 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -45,8 +45,11 @@ impl CreateExe { .target_triple .as_ref() .map(|target_triple| { - let mut features = - self.cpu_features.clone().into_iter().fold(CpuFeature::set(), |a, b| a | b); + let mut features = self + .cpu_features + .clone() + .into_iter() + .fold(CpuFeature::set(), |a, b| a | b); // Cranelift requires SSE2, so we have this "hack" for now to facilitate // usage features |= CpuFeature::SSE2; @@ -54,8 +57,9 @@ impl CreateExe { }) .unwrap_or_default(); let engine_type = EngineType::ObjectFile; - let (store, compiler_type) = - self.compiler.get_store_for_target_and_engine(target.clone(), engine_type)?; + let (store, compiler_type) = self + .compiler + .get_store_for_target_and_engine(target.clone(), engine_type)?; println!("Engine: {}", engine_type.to_string()); println!("Compiler: {}", compiler_type.to_string()); @@ -93,7 +97,10 @@ impl CreateExe { generate_header(header_file_src.as_bytes())?; self.compile_c(wasm_object_path, output_path)?; - eprintln!("✔ Native executable compiled successfully to `{}`.", self.output.display(),); + eprintln!( + "✔ Native executable compiled successfully to `{}`.", + self.output.display(), + ); Ok(()) } @@ -149,7 +156,11 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> { fn get_wasmer_dir() -> anyhow::Result { Ok(PathBuf::from( env::var("WASMER_DIR") - .or_else(|e| option_env!("WASMER_INSTALL_PREFIX").map(str::to_string).ok_or(e)) + .or_else(|e| { + option_env!("WASMER_INSTALL_PREFIX") + .map(str::to_string) + .ok_or(e) + }) .context("Trying to read env var `WASMER_DIR`")?, )) } @@ -257,8 +268,17 @@ impl LinkCode { let mut command = Command::new(&self.linker_path); let command = command .arg(&self.optimization_flag) - .args(self.object_paths.iter().map(|path| path.canonicalize().unwrap())) - .arg(&self.libwasmer_path.canonicalize().context("Failed to find libwasmer")?); + .args( + self.object_paths + .iter() + .map(|path| path.canonicalize().unwrap()), + ) + .arg( + &self + .libwasmer_path + .canonicalize() + .context("Failed to find libwasmer")?, + ); let command = if let Some(target) = &self.target { command.arg("-target").arg(format!("{}", target)) } else { @@ -267,12 +287,18 @@ impl LinkCode { // Add libraries required per platform. // We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers. #[cfg(windows)] - let command = command.arg("-luserenv").arg("-lWs2_32").arg("-ladvapi32").arg("-lbcrypt"); + let command = command + .arg("-luserenv") + .arg("-lWs2_32") + .arg("-ladvapi32") + .arg("-lbcrypt"); // On unix we need dlopen-related symbols, libmath for a few things, and pthreads. #[cfg(not(windows))] let command = command.arg("-ldl").arg("-lm").arg("-pthread"); - let link_aganist_extra_libs = - self.additional_libraries.iter().map(|lib| format!("-l{}", lib)); + let link_aganist_extra_libs = self + .additional_libraries + .iter() + .map(|lib| format!("-l{}", lib)); let command = command.args(link_aganist_extra_libs); let output = command.arg("-o").arg(&self.output_path).output()?; diff --git a/lib/cli/src/commands/inspect.rs b/lib/cli/src/commands/inspect.rs index 8137b78d9..b105a0de7 100644 --- a/lib/cli/src/commands/inspect.rs +++ b/lib/cli/src/commands/inspect.rs @@ -19,13 +19,21 @@ pub struct Inspect { impl Inspect { /// Runs logic for the `validate` subcommand pub fn execute(&self) -> Result<()> { - self.inner_execute().context(format!("failed to inspect `{}`", self.path.display())) + self.inner_execute() + .context(format!("failed to inspect `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { let (store, _engine_type, _compiler_type) = self.store.get_store()?; let module_contents = std::fs::read(&self.path)?; let module = Module::new(&store, &module_contents)?; - println!("Type: {}", if !is_wasm(&module_contents) { "wat" } else { "wasm" }); + println!( + "Type: {}", + if !is_wasm(&module_contents) { + "wat" + } else { + "wasm" + } + ); println!("Size: {}", ByteSize(module_contents.len() as _)); println!("Imports:"); println!(" Functions:"); diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 8d484d418..255d3e250 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -80,7 +80,11 @@ impl Run { format!( "failed to run `{}`{}", self.path.display(), - if CompilerType::enabled().is_empty() { " (no compilers enabled)" } else { "" } + if CompilerType::enabled().is_empty() { + " (no compilers enabled)" + } else { + "" + } ) }) } @@ -94,7 +98,11 @@ impl Run { let result = self.invoke_function(&instance, &invoke, &self.args)?; println!( "{}", - result.iter().map(|val| val.to_string()).collect::>().join(" ") + result + .iter() + .map(|val| val.to_string()) + .collect::>() + .join(" ") ); return Ok(()); } @@ -149,7 +157,11 @@ impl Run { let program_name = self .command_name .clone() - .or_else(|| self.path.file_name().map(|f| f.to_string_lossy().to_string())) + .or_else(|| { + self.path + .file_name() + .map(|f| f.to_string_lossy().to_string()) + }) .unwrap_or_default(); return self .wasi @@ -347,19 +359,31 @@ impl Run { .iter() .zip(func_ty.params().iter()) .map(|(arg, param_type)| match param_type { - ValType::I32 => Ok(Val::I32( - arg.parse().map_err(|_| anyhow!("Can't convert `{}` into a i32", arg))?, + ValType::I32 => { + Ok(Val::I32(arg.parse().map_err(|_| { + anyhow!("Can't convert `{}` into a i32", arg) + })?)) + } + ValType::I64 => { + Ok(Val::I64(arg.parse().map_err(|_| { + anyhow!("Can't convert `{}` into a i64", arg) + })?)) + } + ValType::F32 => { + Ok(Val::F32(arg.parse().map_err(|_| { + anyhow!("Can't convert `{}` into a f32", arg) + })?)) + } + ValType::F64 => { + Ok(Val::F64(arg.parse().map_err(|_| { + anyhow!("Can't convert `{}` into a f64", arg) + })?)) + } + _ => Err(anyhow!( + "Don't know how to convert {} into {:?}", + arg, + param_type )), - ValType::I64 => Ok(Val::I64( - arg.parse().map_err(|_| anyhow!("Can't convert `{}` into a i64", arg))?, - )), - ValType::F32 => Ok(Val::F32( - arg.parse().map_err(|_| anyhow!("Can't convert `{}` into a f32", arg))?, - )), - ValType::F64 => Ok(Val::F64( - arg.parse().map_err(|_| anyhow!("Can't convert `{}` into a f64", arg))?, - )), - _ => Err(anyhow!("Don't know how to convert {} into {:?}", arg, param_type)), }) .collect::>>()?; Ok(func.call(&invoke_args)?) diff --git a/lib/cli/src/commands/self_update.rs b/lib/cli/src/commands/self_update.rs index be93be26a..f42e7c4c2 100644 --- a/lib/cli/src/commands/self_update.rs +++ b/lib/cli/src/commands/self_update.rs @@ -23,8 +23,10 @@ impl SelfUpdate { .stdout(Stdio::piped()) .spawn()?; - let mut process = - Command::new("sh").stdin(cmd.stdout.unwrap()).stdout(Stdio::inherit()).spawn()?; + let mut process = Command::new("sh") + .stdin(cmd.stdout.unwrap()) + .stdout(Stdio::inherit()) + .spawn()?; process.wait().unwrap(); Ok(()) diff --git a/lib/cli/src/commands/validate.rs b/lib/cli/src/commands/validate.rs index 09eae9387..771c8fbf5 100644 --- a/lib/cli/src/commands/validate.rs +++ b/lib/cli/src/commands/validate.rs @@ -18,7 +18,8 @@ pub struct Validate { impl Validate { /// Runs logic for the `validate` subcommand pub fn execute(&self) -> Result<()> { - self.inner_execute().context(format!("failed to validate `{}`", self.path.display())) + self.inner_execute() + .context(format!("failed to validate `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { let (store, _engine_type, _compiler_type) = self.store.get_store()?; diff --git a/lib/cli/src/commands/wast.rs b/lib/cli/src/commands/wast.rs index 3927ff6e8..d92fd2b74 100644 --- a/lib/cli/src/commands/wast.rs +++ b/lib/cli/src/commands/wast.rs @@ -23,7 +23,8 @@ pub struct Wast { impl Wast { /// Runs logic for the `validate` subcommand pub fn execute(&self) -> Result<()> { - self.inner_execute().context(format!("failed to test the wast `{}`", self.path.display())) + self.inner_execute() + .context(format!("failed to test the wast `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { let (store, _engine_name, _compiler_name) = self.store.get_store()?; diff --git a/lib/cli/src/logging.rs b/lib/cli/src/logging.rs index 956960ddb..fd2eaafc0 100644 --- a/lib/cli/src/logging.rs +++ b/lib/cli/src/logging.rs @@ -5,8 +5,10 @@ use std::time; /// Subroutine to instantiate the loggers pub fn set_up_logging() -> Result<(), String> { - let colors_line = - ColoredLevelConfig::new().error(Color::Red).warn(Color::Yellow).trace(Color::BrightBlack); + let colors_line = ColoredLevelConfig::new() + .error(Color::Red) + .warn(Color::Yellow) + .trace(Color::BrightBlack); let should_color = wasmer_should_print_color(); let colors_level = colors_line.info(Color::Green); diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index d89ff8c12..2a8095c3c 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -73,7 +73,10 @@ impl CompilerOptions { } else if self.singlepass { Ok(CompilerType::Singlepass) } else if let Some(backend) = self.backend.clone() { - warning!("the `--backend={0}` flag is deprecated, please use `--{0}` instead", backend); + warning!( + "the `--backend={0}` flag is deprecated, please use `--{0}` instead", + backend + ); CompilerType::from_str(&backend) } else { // Auto mode, we choose the best compiler for that platform @@ -155,7 +158,10 @@ impl CompilerOptions { .engine(), ), #[cfg(not(all(feature = "jit", feature = "native", feature = "object-file")))] - engine => bail!("The `{}` engine is not included in this binary.", engine.to_string()), + engine => bail!( + "The `{}` engine is not included in this binary.", + engine.to_string() + ), }; Ok(engine) @@ -288,7 +294,10 @@ impl CompilerOptions { } #[cfg(not(all(feature = "singlepass", feature = "cranelift", feature = "llvm",)))] compiler => { - bail!("The `{}` compiler is not included in this binary.", compiler.to_string()) + bail!( + "The `{}` compiler is not included in this binary.", + compiler.to_string() + ) } }; @@ -394,7 +403,9 @@ impl StoreOptions { compiler_config: Box, ) -> Result<(Box, EngineType)> { let engine_type = self.get_engine()?; - let engine = self.compiler.get_engine_by_type(target, compiler_config, engine_type)?; + let engine = self + .compiler + .get_engine_by_type(target, compiler_config, engine_type)?; Ok((engine, engine_type)) } @@ -439,7 +450,10 @@ impl StoreOptions { Arc::new(wasmer_engine_object_file::ObjectFile::headless().engine()) } #[cfg(not(all(feature = "jit", feature = "native", feature = "object-file")))] - engine => bail!("The `{}` engine is not included in this binary.", engine.to_string()), + engine => bail!( + "The `{}` engine is not included in this binary.", + engine.to_string() + ), }; Ok((engine, engine_type)) } diff --git a/lib/cli/src/utils.rs b/lib/cli/src/utils.rs index 0e14784b0..a032f26f4 100644 --- a/lib/cli/src/utils.rs +++ b/lib/cli/src/utils.rs @@ -84,6 +84,9 @@ mod tests { ); assert_eq!(parse_envvar("A=B").unwrap(), ("A".into(), "B".into())); assert_eq!(parse_envvar(" A=B\t").unwrap(), ("A".into(), "B".into())); - assert_eq!(parse_envvar("A=B=C=D").unwrap(), ("A".into(), "B=C=D".into())); + assert_eq!( + parse_envvar("A=B=C=D").unwrap(), + ("A".into(), "B=C=D".into()) + ); } } diff --git a/lib/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index f12a9bd0f..0b10df177 100644 --- a/lib/compiler-cranelift/src/address_map.rs +++ b/lib/compiler-cranelift/src/address_map.rs @@ -47,5 +47,11 @@ pub fn get_function_address_map<'data>( let start_srcloc = SourceLoc::new(data.module_offset as u32); let end_srcloc = SourceLoc::new((data.module_offset + data.data.len()) as u32); - FunctionAddressMap { instructions, start_srcloc, end_srcloc, body_offset: 0, body_len } + FunctionAddressMap { + instructions, + start_srcloc, + end_srcloc, + body_offset: 0, + body_len, + } } diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index edb381520..dd2970330 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -178,10 +178,16 @@ impl Compiler for CraneliftCompiler { let func_jt_offsets = transform_jump_table(context.func.jt_offsets); Ok(CompiledFunction { - body: FunctionBody { body: code_buf, unwind_info }, + body: FunctionBody { + body: code_buf, + unwind_info, + }, jt_offsets: func_jt_offsets, relocations: reloc_sink.func_relocs, - frame_info: CompiledFunctionFrameInfo { address_map, traps: trap_sink.traps }, + frame_info: CompiledFunctionFrameInfo { + address_map, + traps: trap_sink.traps, + }, }) }) .collect::, CompileError>>()? @@ -193,7 +199,11 @@ impl Compiler for CraneliftCompiler { let mut custom_sections = PrimaryMap::new(); let dwarf = if let Some((dwarf_frametable, _cie_id)) = dwarf_frametable { let mut eh_frame = EhFrame(WriterRelocate::new(target.triple().endianness().ok())); - dwarf_frametable.lock().unwrap().write_eh_frame(&mut eh_frame).unwrap(); + dwarf_frametable + .lock() + .unwrap() + .write_eh_frame(&mut eh_frame) + .unwrap(); let eh_frame_section = eh_frame.0.into_section(); custom_sections.push(eh_frame_section); diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 525bd1f0d..6834e1d52 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -113,10 +113,14 @@ impl Cranelift { builder.enable("has_avx2").expect("should be valid flag"); } if cpu_features.contains(CpuFeature::AVX512DQ) { - builder.enable("has_avx512dq").expect("should be valid flag"); + builder + .enable("has_avx512dq") + .expect("should be valid flag"); } if cpu_features.contains(CpuFeature::AVX512VL) { - builder.enable("has_avx512vl").expect("should be valid flag"); + builder + .enable("has_avx512vl") + .expect("should be valid flag"); } if cpu_features.contains(CpuFeature::LZCNT) { builder.enable("has_lzcnt").expect("should be valid flag"); @@ -131,16 +135,26 @@ impl Cranelift { // There are two possible traps for division, and this way // we get the proper one if code traps. - flags.enable("avoid_div_traps").expect("should be valid flag"); + flags + .enable("avoid_div_traps") + .expect("should be valid flag"); if self.enable_pic { flags.enable("is_pic").expect("should be a valid flag"); } // Invert cranelift's default-on verification to instead default off. - let enable_verifier = if self.enable_verifier { "true" } else { "false" }; - flags.set("enable_verifier", enable_verifier).expect("should be valid flag"); - flags.set("enable_safepoints", "true").expect("should be valid flag"); + let enable_verifier = if self.enable_verifier { + "true" + } else { + "false" + }; + flags + .set("enable_verifier", enable_verifier) + .expect("should be valid flag"); + flags + .set("enable_safepoints", "true") + .expect("should be valid flag"); let opt_level = if self.enable_simd { "none" @@ -152,13 +166,20 @@ impl Cranelift { } }; - flags.set("opt_level", opt_level).expect("should be valid flag"); + flags + .set("opt_level", opt_level) + .expect("should be valid flag"); let enable_simd = if self.enable_simd { "true" } else { "false" }; - flags.set("enable_simd", enable_simd).expect("should be valid flag"); + flags + .set("enable_simd", enable_simd) + .expect("should be valid flag"); - let enable_nan_canonicalization = - if self.enable_nan_canonicalization { "true" } else { "false" }; + let enable_nan_canonicalization = if self.enable_nan_canonicalization { + "true" + } else { + "false" + }; flags .set("enable_nan_canonicalization", enable_nan_canonicalization) .expect("should be valid flag"); diff --git a/lib/compiler-cranelift/src/dwarf.rs b/lib/compiler-cranelift/src/dwarf.rs index 4db6a8bab..07e67bbdb 100644 --- a/lib/compiler-cranelift/src/dwarf.rs +++ b/lib/compiler-cranelift/src/dwarf.rs @@ -20,7 +20,10 @@ impl WriterRelocate { // We autodetect it, based on the host None => RunTimeEndian::default(), }; - WriterRelocate { relocs: Vec::new(), writer: EndianVec::new(endianness) } + WriterRelocate { + relocs: Vec::new(), + writer: EndianVec::new(endianness), + } } pub fn into_section(mut self) -> CustomSection { @@ -69,7 +72,12 @@ impl Writer for WriterRelocate { _ => unimplemented!("dwarf relocation size not yet supported: {}", size), }; let addend = 0; - self.relocs.push(Relocation { kind, reloc_target, offset, addend }); + self.relocs.push(Relocation { + kind, + reloc_target, + offset, + addend, + }); self.write_udata(addend as u64, size) } else { unreachable!("Symbol {} in DWARF not recognized", symbol); diff --git a/lib/compiler-cranelift/src/func_environ.rs b/lib/compiler-cranelift/src/func_environ.rs index 559d5b197..56e451f4c 100644 --- a/lib/compiler-cranelift/src/func_environ.rs +++ b/lib/compiler-cranelift/src/func_environ.rs @@ -223,7 +223,10 @@ impl<'module_environment> FuncEnvironment<'module_environment> { &mut self, func: &mut Function, ) -> (ir::SigRef, VMBuiltinFunctionIndex) { - (self.get_externref_inc_sig(func), VMBuiltinFunctionIndex::get_externref_inc_index()) + ( + self.get_externref_inc_sig(func), + VMBuiltinFunctionIndex::get_externref_inc_index(), + ) } fn get_externref_dec_sig(&mut self, func: &mut Function) -> ir::SigRef { @@ -242,7 +245,10 @@ impl<'module_environment> FuncEnvironment<'module_environment> { &mut self, func: &mut Function, ) -> (ir::SigRef, VMBuiltinFunctionIndex) { - (self.get_externref_dec_sig(func), VMBuiltinFunctionIndex::get_externref_dec_index()) + ( + self.get_externref_dec_sig(func), + VMBuiltinFunctionIndex::get_externref_dec_index(), + ) } fn get_func_ref_sig(&mut self, func: &mut Function) -> ir::SigRef { @@ -567,7 +573,11 @@ impl<'module_environment> FuncEnvironment<'module_environment> { ) -> (ir::SigRef, usize, VMBuiltinFunctionIndex) { let sig = self.get_table_init_sig(func); let table_index = table_index.as_u32() as usize; - (sig, table_index, VMBuiltinFunctionIndex::get_table_init_index()) + ( + sig, + table_index, + VMBuiltinFunctionIndex::get_table_init_index(), + ) } fn get_elem_drop_sig(&mut self, func: &mut Function) -> ir::SigRef { @@ -620,9 +630,17 @@ impl<'module_environment> FuncEnvironment<'module_environment> { ) -> (ir::SigRef, usize, VMBuiltinFunctionIndex) { let sig = self.get_memory_copy_sig(func); if let Some(local_memory_index) = self.module.local_memory_index(memory_index) { - (sig, local_memory_index.index(), VMBuiltinFunctionIndex::get_memory_copy_index()) + ( + sig, + local_memory_index.index(), + VMBuiltinFunctionIndex::get_memory_copy_index(), + ) } else { - (sig, memory_index.index(), VMBuiltinFunctionIndex::get_imported_memory_copy_index()) + ( + sig, + memory_index.index(), + VMBuiltinFunctionIndex::get_imported_memory_copy_index(), + ) } } @@ -655,9 +673,17 @@ impl<'module_environment> FuncEnvironment<'module_environment> { ) -> (ir::SigRef, usize, VMBuiltinFunctionIndex) { let sig = self.get_memory_fill_sig(func); if let Some(local_memory_index) = self.module.local_memory_index(memory_index) { - (sig, local_memory_index.index(), VMBuiltinFunctionIndex::get_memory_fill_index()) + ( + sig, + local_memory_index.index(), + VMBuiltinFunctionIndex::get_memory_fill_index(), + ) } else { - (sig, memory_index.index(), VMBuiltinFunctionIndex::get_imported_memory_fill_index()) + ( + sig, + memory_index.index(), + VMBuiltinFunctionIndex::get_imported_memory_fill_index(), + ) } } @@ -759,7 +785,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let base_offset = i32::try_from(self.offsets.vmctx_vmtable_definition_base(def_index)).unwrap(); let current_elements_offset = i32::try_from( - self.offsets.vmctx_vmtable_definition_current_elements(def_index), + self.offsets + .vmctx_vmtable_definition_current_elements(def_index), ) .unwrap(); (vmctx, base_offset, current_elements_offset) @@ -815,8 +842,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (func_sig, index_arg, func_idx) = self.get_table_grow_func(&mut pos.func, table_index); let table_index = pos.ins().iconst(I32, index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - let call_inst = - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, init_value, delta, table_index]); + let call_inst = pos.ins().call_indirect( + func_sig, + func_addr, + &[vmctx, init_value, delta, table_index], + ); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -833,7 +863,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro self.get_table_get_func(&mut pos.func, table_index); let table_index = pos.ins().iconst(I32, table_index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - let call_inst = pos.ins().call_indirect(func_sig, func_addr, &[vmctx, table_index, index]); + let call_inst = pos + .ins() + .call_indirect(func_sig, func_addr, &[vmctx, table_index, index]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -851,7 +883,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro self.get_table_set_func(&mut pos.func, table_index); let table_index = pos.ins().iconst(I32, table_index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, table_index, index, value]); + pos.ins() + .call_indirect(func_sig, func_addr, &[vmctx, table_index, index, value]); Ok(()) } @@ -868,7 +901,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); let table_index_arg = pos.ins().iconst(I32, table_index_arg as i64); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, table_index_arg, dst, val, len]); + pos.ins().call_indirect( + func_sig, + func_addr, + &[vmctx, table_index_arg, dst, val, len], + ); Ok(()) } @@ -925,7 +962,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro ty if ty.is_ref() => pos.ins().is_null(value), // `funcref` ty if ty == self.pointer_type() => { - pos.ins().icmp_imm(cranelift_codegen::ir::condcodes::IntCC::Equal, value, 0) + pos.ins() + .icmp_imm(cranelift_codegen::ir::condcodes::IntCC::Equal, value, 0) } _ => unreachable!(), }; @@ -951,7 +989,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); let func_index_arg = pos.ins().iconst(I32, func_index_arg as i64); - let call_inst = pos.ins().call_indirect(func_sig, func_addr, &[vmctx, func_index_arg]); + let call_inst = pos + .ins() + .call_indirect(func_sig, func_addr, &[vmctx, func_index_arg]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -981,9 +1021,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro if let Some(def_index) = self.module.local_memory_index(index) { let base_offset = i32::try_from(self.offsets.vmctx_vmmemory_definition_base(def_index)).unwrap(); - let current_length_offset = - i32::try_from(self.offsets.vmctx_vmmemory_definition_current_length(def_index)) - .unwrap(); + let current_length_offset = i32::try_from( + self.offsets + .vmctx_vmmemory_definition_current_length(def_index), + ) + .unwrap(); (vmctx, base_offset, current_length_offset) } else { let from_offset = self.offsets.vmctx_vmmemory_import_definition(index); @@ -1012,13 +1054,20 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro }); ( Uimm64::new(offset_guard_size), - ir::HeapStyle::Dynamic { bound_gv: heap_bound }, + ir::HeapStyle::Dynamic { + bound_gv: heap_bound, + }, false, ) } - MemoryStyle::Static { bound, offset_guard_size } => ( + MemoryStyle::Static { + bound, + offset_guard_size, + } => ( Uimm64::new(offset_guard_size), - ir::HeapStyle::Static { bound: Uimm64::new(bound.bytes().0 as u64) }, + ir::HeapStyle::Static { + bound: Uimm64::new(bound.bytes().0 as u64), + }, true, ), }; @@ -1118,7 +1167,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro ); // check if the funcref is null - pos.ins().trapz(table_entry_addr, ir::TrapCode::IndirectCallToNull); + pos.ins() + .trapz(table_entry_addr, ir::TrapCode::IndirectCallToNull); let func_addr = pos.ins().load( pointer_type, @@ -1233,7 +1283,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (func_sig, index_arg, func_idx) = self.get_memory_grow_func(&mut pos.func, index); let memory_index = pos.ins().iconst(I32, index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - let call_inst = pos.ins().call_indirect(func_sig, func_addr, &[vmctx, val, memory_index]); + let call_inst = pos + .ins() + .call_indirect(func_sig, func_addr, &[vmctx, val, memory_index]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -1246,7 +1298,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (func_sig, index_arg, func_idx) = self.get_memory_size_func(&mut pos.func, index); let memory_index = pos.ins().iconst(I32, index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - let call_inst = pos.ins().call_indirect(func_sig, func_addr, &[vmctx, memory_index]); + let call_inst = pos + .ins() + .call_indirect(func_sig, func_addr, &[vmctx, memory_index]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -1267,7 +1321,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, src_index_arg, dst, src, len]); + pos.ins() + .call_indirect(func_sig, func_addr, &[vmctx, src_index_arg, dst, src, len]); Ok(()) } @@ -1288,7 +1343,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, memory_index_arg, dst, val, len]); + pos.ins().call_indirect( + func_sig, + func_addr, + &[vmctx, memory_index_arg, dst, val, len], + ); Ok(()) } @@ -1323,7 +1382,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (func_sig, func_idx) = self.get_data_drop_func(&mut pos.func); let seg_index_arg = pos.ins().iconst(I32, seg_index as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, seg_index_arg]); + pos.ins() + .call_indirect(func_sig, func_addr, &[vmctx, seg_index_arg]); Ok(()) } @@ -1336,7 +1396,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (func_sig, index_arg, func_idx) = self.get_table_size_func(&mut pos.func, table_index); let table_index = pos.ins().iconst(I32, index_arg as i64); let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - let call_inst = pos.ins().call_indirect(func_sig, func_addr, &[vmctx, table_index]); + let call_inst = pos + .ins() + .call_indirect(func_sig, func_addr, &[vmctx, table_index]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } @@ -1362,7 +1424,14 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro pos.ins().call_indirect( func_sig, func_addr, - &[vmctx, dst_table_index_arg, src_table_index_arg, dst, src, len], + &[ + vmctx, + dst_table_index_arg, + src_table_index_arg, + dst, + src, + len, + ], ); Ok(()) @@ -1402,7 +1471,8 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro let (vmctx, func_addr) = self.translate_load_builtin_function_address(&mut pos, func_idx); - pos.ins().call_indirect(func_sig, func_addr, &[vmctx, elem_index_arg]); + pos.ins() + .call_indirect(func_sig, func_addr, &[vmctx, elem_index_arg]); Ok(()) } @@ -1416,7 +1486,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro _expected: ir::Value, _timeout: ir::Value, ) -> WasmResult { - Err(WasmError::Unsupported("wasm atomics (fn translate_atomic_wait)".to_string())) + Err(WasmError::Unsupported( + "wasm atomics (fn translate_atomic_wait)".to_string(), + )) } fn translate_atomic_notify( @@ -1427,7 +1499,9 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro _addr: ir::Value, _count: ir::Value, ) -> WasmResult { - Err(WasmError::Unsupported("wasm atomics (fn translate_atomic_notify)".to_string())) + Err(WasmError::Unsupported( + "wasm atomics (fn translate_atomic_notify)".to_string(), + )) } fn get_global_type(&self, global_index: GlobalIndex) -> Option { diff --git a/lib/compiler-cranelift/src/sink.rs b/lib/compiler-cranelift/src/sink.rs index 63ea7db91..54f802912 100644 --- a/lib/compiler-cranelift/src/sink.rs +++ b/lib/compiler-cranelift/src/sink.rs @@ -75,9 +75,14 @@ impl<'a> binemit::RelocSink for RelocSink<'a> { impl<'a> RelocSink<'a> { /// Return a new `RelocSink` instance. pub fn new(module: &'a ModuleInfo, func_index: FunctionIndex) -> Self { - let local_func_index = - module.local_func_index(func_index).expect("The provided function should be local"); - Self { module, local_func_index, func_relocs: Vec::new() } + let local_func_index = module + .local_func_index(func_index) + .expect("The provided function should be local"); + Self { + module, + local_func_index, + func_relocs: Vec::new(), + } } } diff --git a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs index 2982204c4..db9d4633b 100644 --- a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs +++ b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs @@ -32,7 +32,10 @@ pub fn make_trampoline_dynamic_function( let signature = signature_to_cranelift_ir(func_type, frontend_config); let mut stub_sig = ir::Signature::new(frontend_config.default_call_conv); // Add the caller `vmctx` parameter. - stub_sig.params.push(ir::AbiParam::special(pointer_type, ir::ArgumentPurpose::VMContext)); + stub_sig.params.push(ir::AbiParam::special( + pointer_type, + ir::ArgumentPurpose::VMContext, + )); // Add the `values_vec` parameter. stub_sig.params.push(ir::AbiParam::new(pointer_type)); @@ -45,9 +48,10 @@ pub fn make_trampoline_dynamic_function( let mut context = Context::new(); context.func = Function::with_name_signature(ExternalName::user(0, 0), signature.clone()); - let ss = context - .func - .create_stack_slot(StackSlotData::new(StackSlotKind::ExplicitSlot, values_vec_len)); + let ss = context.func.create_stack_slot(StackSlotData::new( + StackSlotKind::ExplicitSlot, + values_vec_len, + )); { let mut builder = FunctionBuilder::new(&mut context.func, fn_builder_ctx); @@ -62,7 +66,12 @@ pub fn make_trampoline_dynamic_function( // We only get the non-vmctx arguments for i in 1..signature.params.len() { let val = builder.func.dfg.block_params(block0)[i]; - builder.ins().store(mflags, val, values_vec_ptr_val, ((i - 1) * value_size) as i32); + builder.ins().store( + mflags, + val, + values_vec_ptr_val, + ((i - 1) * value_size) as i32, + ); } let block_params = builder.func.dfg.block_params(block0); @@ -79,7 +88,9 @@ pub fn make_trampoline_dynamic_function( offsets.vmdynamicfunction_import_context_address() as i32, ); - builder.ins().call_indirect(new_sig, callee_value, &callee_args); + builder + .ins() + .call_indirect(new_sig, callee_value, &callee_args); let mflags = MemFlags::trusted(); let mut results = Vec::new(); @@ -101,10 +112,19 @@ pub fn make_trampoline_dynamic_function( let mut trap_sink = binemit::NullTrapSink {}; let mut stackmap_sink = binemit::NullStackMapSink {}; context - .compile_and_emit(isa, &mut code_buf, &mut reloc_sink, &mut trap_sink, &mut stackmap_sink) + .compile_and_emit( + isa, + &mut code_buf, + &mut reloc_sink, + &mut trap_sink, + &mut stackmap_sink, + ) .map_err(|error| CompileError::Codegen(pretty_error(&context.func, Some(isa), error)))?; let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind(); - Ok(FunctionBody { body: code_buf, unwind_info }) + Ok(FunctionBody { + body: code_buf, + unwind_info, + }) } diff --git a/lib/compiler-cranelift/src/trampoline/function_call.rs b/lib/compiler-cranelift/src/trampoline/function_call.rs index 318cc906e..876bc8612 100644 --- a/lib/compiler-cranelift/src/trampoline/function_call.rs +++ b/lib/compiler-cranelift/src/trampoline/function_call.rs @@ -34,7 +34,10 @@ pub fn make_trampoline_function_call( let mut wrapper_sig = ir::Signature::new(frontend_config.default_call_conv); // Add the callee `vmctx` parameter. - wrapper_sig.params.push(ir::AbiParam::special(pointer_type, ir::ArgumentPurpose::VMContext)); + wrapper_sig.params.push(ir::AbiParam::special( + pointer_type, + ir::ArgumentPurpose::VMContext, + )); // Add the `callee_address` parameter. wrapper_sig.params.push(ir::AbiParam::new(pointer_type)); @@ -84,14 +87,18 @@ pub fn make_trampoline_function_call( let new_sig = builder.import_signature(signature); - let call = builder.ins().call_indirect(new_sig, callee_value, &callee_args); + let call = builder + .ins() + .call_indirect(new_sig, callee_value, &callee_args); let results = builder.func.dfg.inst_results(call).to_vec(); // Store the return values into `values_vec`. let mflags = ir::MemFlags::trusted(); for (i, r) in results.iter().enumerate() { - builder.ins().store(mflags, *r, values_vec_ptr_val, (i * value_size) as i32); + builder + .ins() + .store(mflags, *r, values_vec_ptr_val, (i * value_size) as i32); } builder.ins().return_(&[]); @@ -104,7 +111,13 @@ pub fn make_trampoline_function_call( let mut stackmap_sink = binemit::NullStackMapSink {}; context - .compile_and_emit(isa, &mut code_buf, &mut reloc_sink, &mut trap_sink, &mut stackmap_sink) + .compile_and_emit( + isa, + &mut code_buf, + &mut reloc_sink, + &mut trap_sink, + &mut stackmap_sink, + ) .map_err(|error| CompileError::Codegen(pretty_error(&context.func, Some(isa), error)))?; let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind(); diff --git a/lib/compiler-cranelift/src/translator/code_translator.rs b/lib/compiler-cranelift/src/translator/code_translator.rs index 79f09a984..63678f201 100644 --- a/lib/compiler-cranelift/src/translator/code_translator.rs +++ b/lib/compiler-cranelift/src/translator/code_translator.rs @@ -80,7 +80,13 @@ pub fn translate_operator( let val = builder.use_var(Variable::with_u32(*local_index)); let local_type = environ.get_local_type(*local_index).unwrap(); let ref_counted = local_type == WasmerType::ExternRef; - state.push1_extra((val, ValueExtraInfo { ref_counted, ..Default::default() })); + state.push1_extra(( + val, + ValueExtraInfo { + ref_counted, + ..Default::default() + }, + )); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); @@ -145,7 +151,13 @@ pub fn translate_operator( environ.translate_externref_inc(builder.cursor(), value)?; } - (value, ValueExtraInfo { ref_counted, ..Default::default() }) + ( + value, + ValueExtraInfo { + ref_counted, + ..Default::default() + }, + ) } GlobalVariable::Custom => ( environ.translate_custom_global_get(builder.cursor(), global_index)?, @@ -204,7 +216,10 @@ pub fn translate_operator( let not_selected_ref = builder.ins().select(cond, arg2, arg1); state.push1_extra(( selected_ref, - ValueExtraInfo { ref_counted, ..Default::default() }, + ValueExtraInfo { + ref_counted, + ..Default::default() + }, )); environ.translate_externref_dec(builder.cursor(), not_selected_ref)?; } else { @@ -247,7 +262,9 @@ pub fn translate_operator( // Pop the initial `Block` actuals and replace them with the `Block`'s // params since control flow joins at the top of the loop. state.popn(params.len()); - state.stack.extend_from_slice(builder.block_params(loop_body)); + state + .stack + .extend_from_slice(builder.block_params(loop_body)); builder.switch_to_block(loop_body); environ.translate_loop_header(builder.cursor())?; @@ -385,7 +402,9 @@ pub fn translate_operator( } frame.truncate_value_stack_to_original_size(&mut state.stack); - state.stack.extend_from_slice(builder.block_params(next_block)); + state + .stack + .extend_from_slice(builder.block_params(next_block)); } /**************************** Branch instructions ********************************* * The branch instructions all have as arguments a target nesting level, which @@ -567,7 +586,10 @@ pub fn translate_operator( let mut results_metadata = Vec::with_capacity(func_type.results().len()); for result in func_type.results() { results_metadata.push(if *result == WasmerType::ExternRef { - ValueExtraInfo { ref_counted: true, ..Default::default() } + ValueExtraInfo { + ref_counted: true, + ..Default::default() + } } else { Default::default() }); @@ -612,7 +634,10 @@ pub fn translate_operator( let mut results_metadata = Vec::with_capacity(func_type.results().len()); for result in func_type.results() { results_metadata.push(if *result == WasmerType::ExternRef { - ValueExtraInfo { ref_counted: true, ..Default::default() } + ValueExtraInfo { + ref_counted: true, + ..Default::default() + } } else { Default::default() }); @@ -1361,7 +1386,10 @@ pub fn translate_operator( let (index, _) = state.pop1(); environ.translate_table_set(builder, table_index, table, value, index)?; } - Operator::TableCopy { dst_table: dst_table_index, src_table: src_table_index } => { + Operator::TableCopy { + dst_table: dst_table_index, + src_table: src_table_index, + } => { let dst_table = state.get_or_create_table(builder.func, *dst_table_index, environ)?; let src_table = state.get_or_create_table(builder.func, *src_table_index, environ)?; let (len, _) = state.pop1(); @@ -1385,7 +1413,10 @@ pub fn translate_operator( let (dest, _) = state.pop1(); environ.translate_table_fill(builder.cursor(), table_index, dest, val, len)?; } - Operator::TableInit { segment, table: table_index } => { + Operator::TableInit { + segment, + table: table_index, + } => { let table = state.get_or_create_table(builder.func, *table_index, environ)?; let (len, _) = state.pop1(); let (src, _) = state.pop1(); @@ -1412,7 +1443,9 @@ pub fn translate_operator( state.push1(value) } Operator::I8x16Splat | Operator::I16x8Splat => { - let reduced = builder.ins().ireduce(type_of(op).lane_type(), state.pop1().0); + let reduced = builder + .ins() + .ireduce(type_of(op).lane_type(), state.pop1().0); let splatted = builder.ins().splat(type_of(op), reduced); state.push1(splatted) } @@ -1653,9 +1686,12 @@ pub fn translate_operator( Operator::I8x16LeS | Operator::I16x8LeS | Operator::I32x4LeS => { translate_vector_icmp(IntCC::SignedLessThanOrEqual, type_of(op), builder, state) } - Operator::I8x16GeU | Operator::I16x8GeU | Operator::I32x4GeU => { - translate_vector_icmp(IntCC::UnsignedGreaterThanOrEqual, type_of(op), builder, state) - } + Operator::I8x16GeU | Operator::I16x8GeU | Operator::I32x4GeU => translate_vector_icmp( + IntCC::UnsignedGreaterThanOrEqual, + type_of(op), + builder, + state, + ), Operator::I8x16LeU | Operator::I16x8LeU | Operator::I32x4LeU => { translate_vector_icmp(IntCC::UnsignedLessThanOrEqual, type_of(op), builder, state) } @@ -1885,7 +1921,9 @@ fn translate_unreachable_operator( // so we don't have any branches anywhere. state.push_if( ir::Block::reserved_value(), - ElseData::NoElse { branch_inst: ir::Inst::reserved_value() }, + ElseData::NoElse { + branch_inst: ir::Inst::reserved_value(), + }, 0, 0, ty, @@ -2090,8 +2128,14 @@ fn prepare_load( let (addr32, _) = state.pop1(); let heap = state.get_heap(builder.func, memarg.memory, environ)?; - let (base, offset) = - get_heap_addr(heap, addr32, memarg.offset, loaded_bytes, environ.pointer_type(), builder); + let (base, offset) = get_heap_addr( + heap, + addr32, + memarg.offset, + loaded_bytes, + environ.pointer_type(), + builder, + ); // Note that we don't set `is_aligned` here, even if the load instruction's // alignment immediate says it's aligned, because WebAssembly's immediate @@ -2110,8 +2154,13 @@ fn translate_load( state: &mut FuncTranslationState, environ: &mut FE, ) -> WasmResult<()> { - let (flags, base, offset) = - prepare_load(memarg, mem_op_size(opcode, result_ty), builder, state, environ)?; + let (flags, base, offset) = prepare_load( + memarg, + mem_op_size(opcode, result_ty), + builder, + state, + environ, + )?; let (load, dfg) = builder.ins().Load(opcode, result_ty, flags, offset, base); state.push1(dfg.first_result(load)); Ok(()) @@ -2139,7 +2188,9 @@ fn translate_store( ); // See the comments in `prepare_load` about the flags. let flags = MemFlags::new(); - builder.ins().Store(opcode, val_ty, flags, offset.into(), val, base); + builder + .ins() + .Store(opcode, val_ty, flags, offset.into(), val, base); Ok(()) } @@ -2171,13 +2222,20 @@ fn finalise_atomic_mem_addr( ) -> WasmResult { // Check the alignment of `linear_mem_addr`. let access_ty_bytes = access_ty.bytes(); - let final_lma = builder.ins().iadd_imm(linear_mem_addr, i64::from(memarg.offset)); + let final_lma = builder + .ins() + .iadd_imm(linear_mem_addr, i64::from(memarg.offset)); if access_ty_bytes != 1 { assert!(access_ty_bytes == 2 || access_ty_bytes == 4 || access_ty_bytes == 8); - let final_lma_misalignment = - builder.ins().band_imm(final_lma, i64::from(access_ty_bytes - 1)); - let f = builder.ins().ifcmp_imm(final_lma_misalignment, i64::from(0)); - builder.ins().trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); + let final_lma_misalignment = builder + .ins() + .band_imm(final_lma, i64::from(access_ty_bytes - 1)); + let f = builder + .ins() + .ifcmp_imm(final_lma_misalignment, i64::from(0)); + builder + .ins() + .trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); } // Compute the final effective address. @@ -2211,7 +2269,12 @@ fn translate_atomic_rmw( // to type `widened_ty`. match access_ty { I8 | I16 | I32 | I64 => {} - _ => return Err(wasm_unsupported!("atomic_rmw: unsupported access type {:?}", access_ty)), + _ => { + return Err(wasm_unsupported!( + "atomic_rmw: unsupported access type {:?}", + access_ty + )) + } }; let w_ty_ok = match widened_ty { I32 | I64 => true, @@ -2229,7 +2292,9 @@ fn translate_atomic_rmw( // See the comments in `prepare_load` about the flags. let flags = MemFlags::new(); - let mut res = builder.ins().atomic_rmw(access_ty, flags, op, final_effective_address, arg2); + let mut res = builder + .ins() + .atomic_rmw(access_ty, flags, op, final_effective_address, arg2); if access_ty != widened_ty { res = builder.ins().uextend(widened_ty, res); } @@ -2253,7 +2318,12 @@ fn translate_atomic_cas( // to type `widened_ty`. match access_ty { I8 | I16 | I32 | I64 => {} - _ => return Err(wasm_unsupported!("atomic_cas: unsupported access type {:?}", access_ty)), + _ => { + return Err(wasm_unsupported!( + "atomic_cas: unsupported access type {:?}", + access_ty + )) + } }; let w_ty_ok = match widened_ty { I32 | I64 => true, @@ -2275,7 +2345,9 @@ fn translate_atomic_cas( // See the comments in `prepare_load` about the flags. let flags = MemFlags::new(); - let mut res = builder.ins().atomic_cas(flags, final_effective_address, expected, replacement); + let mut res = builder + .ins() + .atomic_cas(flags, final_effective_address, expected, replacement); if access_ty != widened_ty { res = builder.ins().uextend(widened_ty, res); } @@ -2297,7 +2369,12 @@ fn translate_atomic_load( // to `widened_ty`. match access_ty { I8 | I16 | I32 | I64 => {} - _ => return Err(wasm_unsupported!("atomic_load: unsupported access type {:?}", access_ty)), + _ => { + return Err(wasm_unsupported!( + "atomic_load: unsupported access type {:?}", + access_ty + )) + } }; let w_ty_ok = match widened_ty { I32 | I64 => true, @@ -2310,7 +2387,9 @@ fn translate_atomic_load( // See the comments in `prepare_load` about the flags. let flags = MemFlags::new(); - let mut res = builder.ins().atomic_load(access_ty, flags, final_effective_address); + let mut res = builder + .ins() + .atomic_load(access_ty, flags, final_effective_address); if access_ty != widened_ty { res = builder.ins().uextend(widened_ty, res); } @@ -2333,7 +2412,10 @@ fn translate_atomic_store( match access_ty { I8 | I16 | I32 | I64 => {} _ => { - return Err(wasm_unsupported!("atomic_store: unsupported access type {:?}", access_ty)) + return Err(wasm_unsupported!( + "atomic_store: unsupported access type {:?}", + access_ty + )) } }; let d_ty_ok = match data_ty { @@ -2351,7 +2433,9 @@ fn translate_atomic_store( // See the comments in `prepare_load` about the flags. let flags = MemFlags::new(); - builder.ins().atomic_store(flags, data, final_effective_address); + builder + .ins() + .atomic_store(flags, data, final_effective_address); Ok(()) } @@ -2411,8 +2495,11 @@ fn translate_br_if_args( // The values returned by the branch are still available for the reachable // code that comes after it frame.set_branched_to_exit(); - let return_count = - if frame.is_loop() { frame.num_param_values() } else { frame.num_return_values() }; + let return_count = if frame.is_loop() { + frame.num_param_values() + } else { + frame.num_return_values() + }; (return_count, frame.br_destination()) }; let inputs = state.peekn_mut(return_count); @@ -2621,7 +2708,10 @@ fn optionally_bitcast_vector( #[inline(always)] fn is_non_canonical_v128(ty: ir::Type) -> bool { - matches!(ty, B8X16 | B16X8 | B32X4 | B64X2 | I64X2 | I32X4 | I16X8 | F32X4 | F64X2) + matches!( + ty, + B8X16 | B16X8 | B32X4 | B64X2 | I64X2 | I32X4 | I16X8 | F32X4 | F64X2 + ) } /// Cast to I8X16, any vector values in `values` that are of "non-canonical" type (meaning, not @@ -2635,8 +2725,9 @@ fn canonicalise_v128_values<'a>( ) -> &'a [ir::Value] { debug_assert!(tmp_canonicalised.is_empty()); // First figure out if any of the parameters need to be cast. Mostly they don't need to be. - let any_non_canonical = - values.iter().any(|v| is_non_canonical_v128(builder.func.dfg.value_type(*v))); + let any_non_canonical = values + .iter() + .any(|v| is_non_canonical_v128(builder.func.dfg.value_type(*v))); // Hopefully we take this exit most of the time, hence doing no heap allocation. if !any_non_canonical { return values; diff --git a/lib/compiler-cranelift/src/translator/func_state.rs b/lib/compiler-cranelift/src/translator/func_state.rs index dad295948..6255b9e32 100644 --- a/lib/compiler-cranelift/src/translator/func_state.rs +++ b/lib/compiler-cranelift/src/translator/func_state.rs @@ -95,16 +95,28 @@ pub enum ControlStackFrame { impl ControlStackFrame { pub fn num_return_values(&self) -> usize { match *self { - Self::If { num_return_values, .. } - | Self::Block { num_return_values, .. } - | Self::Loop { num_return_values, .. } => num_return_values, + Self::If { + num_return_values, .. + } + | Self::Block { + num_return_values, .. + } + | Self::Loop { + num_return_values, .. + } => num_return_values, } } pub fn num_param_values(&self) -> usize { match *self { - Self::If { num_param_values, .. } - | Self::Block { num_param_values, .. } - | Self::Loop { num_param_values, .. } => num_param_values, + Self::If { + num_param_values, .. + } + | Self::Block { + num_param_values, .. + } + | Self::Loop { + num_param_values, .. + } => num_param_values, } } pub fn following_code(&self) -> Block { @@ -124,9 +136,18 @@ impl ControlStackFrame { /// `truncate_value_stack_to_original_size()` to restore value-stack state. fn original_stack_size(&self) -> usize { match *self { - Self::If { original_stack_size, .. } - | Self::Block { original_stack_size, .. } - | Self::Loop { original_stack_size, .. } => original_stack_size, + Self::If { + original_stack_size, + .. + } + | Self::Block { + original_stack_size, + .. + } + | Self::Loop { + original_stack_size, + .. + } => original_stack_size, } } pub fn is_loop(&self) -> bool { @@ -138,17 +159,28 @@ impl ControlStackFrame { pub fn exit_is_branched_to(&self) -> bool { match *self { - Self::If { exit_is_branched_to, .. } | Self::Block { exit_is_branched_to, .. } => { - exit_is_branched_to + Self::If { + exit_is_branched_to, + .. } + | Self::Block { + exit_is_branched_to, + .. + } => exit_is_branched_to, Self::Loop { .. } => false, } } pub fn set_branched_to_exit(&mut self) { match *self { - Self::If { ref mut exit_is_branched_to, .. } - | Self::Block { ref mut exit_is_branched_to, .. } => *exit_is_branched_to = true, + Self::If { + ref mut exit_is_branched_to, + .. + } + | Self::Block { + ref mut exit_is_branched_to, + .. + } => *exit_is_branched_to = true, Self::Loop { .. } => {} } } @@ -169,7 +201,9 @@ impl ControlStackFrame { // block can see the same number of parameters as the consequent block. As a matter of // fact, we need to substract an extra number of parameter values for if blocks. let num_duplicated_params = match self { - &ControlStackFrame::If { num_param_values, .. } => { + &ControlStackFrame::If { + num_param_values, .. + } => { debug_assert!(num_param_values <= self.original_stack_size()); num_param_values } @@ -268,7 +302,10 @@ impl FuncTranslationState { self.push_block( exit_block, 0, - sig.returns.iter().filter(|arg| arg.purpose == ir::ArgumentPurpose::Normal).count(), + sig.returns + .iter() + .filter(|arg| arg.purpose == ir::ArgumentPurpose::Normal) + .count(), ); } @@ -296,14 +333,20 @@ impl FuncTranslationState { /// Pop one value. pub(crate) fn pop1(&mut self) -> (Value, ValueExtraInfo) { - let val = self.stack.pop().expect("attempted to pop a value from an empty stack"); + let val = self + .stack + .pop() + .expect("attempted to pop a value from an empty stack"); let val_metadata = Default::default(); (val, val_metadata) } /// Peek at the top of the stack without popping it. pub(crate) fn peek1(&self) -> (Value, ValueExtraInfo) { - let val = *self.stack.last().expect("attempted to peek at a value on an empty stack"); + let val = *self + .stack + .last() + .expect("attempted to peek at a value on an empty stack"); let val_metadata = Default::default(); (val, val_metadata) } @@ -318,7 +361,11 @@ impl FuncTranslationState { /// Pop three values. Return them in the order they were pushed. pub(crate) fn pop3( &mut self, - ) -> ((Value, ValueExtraInfo), (Value, ValueExtraInfo), (Value, ValueExtraInfo)) { + ) -> ( + (Value, ValueExtraInfo), + (Value, ValueExtraInfo), + (Value, ValueExtraInfo), + ) { let v3 = self.pop1(); let v2 = self.pop1(); let v1 = self.pop1(); @@ -530,7 +577,10 @@ impl FuncTranslationState { Vacant(entry) => { let fref = environ.make_direct_func(func, index)?; let sig = func.dfg.ext_funcs[fref].signature; - Ok(*entry.insert((fref, num_wasm_parameters(environ, &func.dfg.signatures[sig])))) + Ok(*entry.insert(( + fref, + num_wasm_parameters(environ, &func.dfg.signatures[sig]), + ))) } } } @@ -540,5 +590,7 @@ fn num_wasm_parameters( environ: &FE, signature: &ir::Signature, ) -> usize { - (0..signature.params.len()).filter(|index| environ.is_wasm_parameter(signature, *index)).count() + (0..signature.params.len()) + .filter(|index| environ.is_wasm_parameter(signature, *index)) + .count() } diff --git a/lib/compiler-cranelift/src/translator/func_translator.rs b/lib/compiler-cranelift/src/translator/func_translator.rs index a93f45520..20be43ba0 100644 --- a/lib/compiler-cranelift/src/translator/func_translator.rs +++ b/lib/compiler-cranelift/src/translator/func_translator.rs @@ -37,7 +37,10 @@ pub struct FuncTranslator { impl FuncTranslator { /// Create a new translator. pub fn new() -> Self { - Self { func_ctx: FunctionBuilderContext::new(), state: FuncTranslationState::new() } + Self { + func_ctx: FunctionBuilderContext::new(), + state: FuncTranslationState::new(), + } } /// Translate a binary WebAssembly function. @@ -70,7 +73,9 @@ impl FuncTranslator { ) -> WasmResult<()> { let mut reader = MiddlewareBinaryReader::new_with_offset(code, code_offset); reader.set_middleware_chain( - config.middlewares.generate_function_middleware_chain(local_function_index), + config + .middlewares + .generate_function_middleware_chain(local_function_index), ); environ.push_params_on_stack(local_function_index); self.translate_from_reader(module_translation_state, reader, func, environ) @@ -85,7 +90,12 @@ impl FuncTranslator { environ: &mut FE, ) -> WasmResult<()> { let _tt = timing::wasm_translate_function(); - info!("translate({} bytes, {}{})", reader.bytes_remaining(), func.name, func.signature); + info!( + "translate({} bytes, {}{})", + reader.bytes_remaining(), + func.name, + func.signature + ); debug_assert_eq!(func.dfg.num_blocks(), 0, "Function must be empty"); debug_assert_eq!(func.dfg.num_insts(), 0, "Function must be empty"); diff --git a/lib/compiler-cranelift/src/translator/translation_utils.rs b/lib/compiler-cranelift/src/translator/translation_utils.rs index 62e42b79b..69d409375 100644 --- a/lib/compiler-cranelift/src/translator/translation_utils.rs +++ b/lib/compiler-cranelift/src/translator/translation_utils.rs @@ -33,8 +33,10 @@ pub fn signature_to_cranelift_ir( AbiParam::new(cret_arg) })); // The Vmctx signature - sig.params - .insert(0, AbiParam::special(target_config.pointer_type(), ir::ArgumentPurpose::VMContext)); + sig.params.insert( + 0, + AbiParam::special(target_config.pointer_type(), ir::ArgumentPurpose::VMContext), + ); sig } @@ -43,7 +45,9 @@ pub fn reference_type(target_config: TargetFrontendConfig) -> WasmResult Ok(ir::types::R32), ir::types::I64 => Ok(ir::types::R64), - _ => Err(WasmError::Unsupported("unsupported pointer type".to_string())), + _ => Err(WasmError::Unsupported( + "unsupported pointer type".to_string(), + )), } } diff --git a/lib/compiler-llvm/src/abi/aarch64_systemv.rs b/lib/compiler-llvm/src/abi/aarch64_systemv.rs index 4ab00a374..dc54a5412 100644 --- a/lib/compiler-llvm/src/abi/aarch64_systemv.rs +++ b/lib/compiler-llvm/src/abi/aarch64_systemv.rs @@ -72,7 +72,9 @@ impl Abi for Aarch64SystemV { ( context.create_enum_attribute( Attribute::get_named_enum_kind_id("align"), - std::mem::align_of::().try_into().unwrap(), + std::mem::align_of::() + .try_into() + .unwrap(), ), AttributeLoc::Param(i), ), @@ -81,7 +83,9 @@ impl Abi for Aarch64SystemV { Ok(match sig.results() { [] => ( - intrinsics.void_ty.fn_type(¶m_types.collect::, _>>()?, false), + intrinsics + .void_ty + .fn_type(¶m_types.collect::, _>>()?, false), vmctx_attributes(0), ), [_] => { @@ -221,7 +225,9 @@ impl Abi for Aarch64SystemV { let values = std::iter::once(ctx_ptr.as_basic_value_enum()).chain(values.iter().copied()); if let Some(sret) = sret { - std::iter::once(sret.as_basic_value_enum()).chain(values).collect() + std::iter::once(sret.as_basic_value_enum()) + .chain(values) + .collect() } else { values.collect() } @@ -302,9 +308,14 @@ impl Abi for Aarch64SystemV { .collect::>(); } let array_value = basic_value.into_array_value(); - let low = builder.build_extract_value(array_value, 0, "").unwrap().into_int_value(); - let high = - builder.build_extract_value(array_value, 1, "").unwrap().into_int_value(); + let low = builder + .build_extract_value(array_value, 0, "") + .unwrap() + .into_int_value(); + let high = builder + .build_extract_value(array_value, 1, "") + .unwrap() + .into_int_value(); let func_sig_returns_bitwidths = func_sig .results() .iter() @@ -462,7 +473,9 @@ impl Abi for Aarch64SystemV { if v.is_float_value() { let v = v.into_float_value(); if v.get_type() == intrinsics.f32_ty { - let v = builder.build_bitcast(v, intrinsics.i32_ty, "").into_int_value(); + let v = builder + .build_bitcast(v, intrinsics.i32_ty, "") + .into_int_value(); let v = builder.build_int_z_extend(v, intrinsics.i64_ty, ""); v.as_basic_value_enum() } else { @@ -509,7 +522,10 @@ impl Abi for Aarch64SystemV { && v2.is_float_value() && v1.into_float_value().get_type() == v2.into_float_value().get_type() => { - build_struct(func_type.get_return_type().unwrap().into_struct_type(), &[v1, v2]) + build_struct( + func_type.get_return_type().unwrap().into_struct_type(), + &[v1, v2], + ) } [v1, v2] if is_32(v1) && is_32(v2) => { let v1 = builder.build_bitcast(v1, intrinsics.i32_ty, ""); @@ -525,7 +541,10 @@ impl Abi for Aarch64SystemV { && v2.is_float_value() && v3.is_float_value() => { - build_struct(func_type.get_return_type().unwrap().into_struct_type(), &[v1, v2, v3]) + build_struct( + func_type.get_return_type().unwrap().into_struct_type(), + &[v1, v2, v3], + ) } [v1, v2, v3] if is_32(v1) && is_32(v2) => { let v1 = builder.build_bitcast(v1, intrinsics.i32_ty, ""); diff --git a/lib/compiler-llvm/src/abi/mod.rs b/lib/compiler-llvm/src/abi/mod.rs index aa43dba0f..b79f99987 100644 --- a/lib/compiler-llvm/src/abi/mod.rs +++ b/lib/compiler-llvm/src/abi/mod.rs @@ -25,7 +25,12 @@ use aarch64_systemv::Aarch64SystemV; use x86_64_systemv::X86_64SystemV; pub fn get_abi(target_machine: &TargetMachine) -> Box { - if target_machine.get_triple().as_str().to_string_lossy().starts_with("aarch64") { + if target_machine + .get_triple() + .as_str() + .to_string_lossy() + .starts_with("aarch64") + { Box::new(Aarch64SystemV {}) } else { Box::new(X86_64SystemV {}) diff --git a/lib/compiler-llvm/src/abi/x86_64_systemv.rs b/lib/compiler-llvm/src/abi/x86_64_systemv.rs index eed8b37d8..abf48b8ce 100644 --- a/lib/compiler-llvm/src/abi/x86_64_systemv.rs +++ b/lib/compiler-llvm/src/abi/x86_64_systemv.rs @@ -76,7 +76,9 @@ impl Abi for X86_64SystemV { ( context.create_enum_attribute( Attribute::get_named_enum_kind_id("align"), - std::mem::align_of::().try_into().unwrap(), + std::mem::align_of::() + .try_into() + .unwrap(), ), AttributeLoc::Param(i), ), @@ -96,7 +98,9 @@ impl Abi for X86_64SystemV { Ok(match sig_returns_bitwidths.as_slice() { [] => ( - intrinsics.void_ty.fn_type(¶m_types.collect::, _>>()?, false), + intrinsics + .void_ty + .fn_type(¶m_types.collect::, _>>()?, false), vmctx_attributes(0), ), [_] => { @@ -129,7 +133,9 @@ impl Abi for X86_64SystemV { vmctx_attributes(0), ), [32, 32] => ( - intrinsics.i64_ty.fn_type(¶m_types.collect::, _>>()?, false), + intrinsics + .i64_ty + .fn_type(¶m_types.collect::, _>>()?, false), vmctx_attributes(0), ), [32, 32, _] if sig.results()[0] == Type::F32 && sig.results()[1] == Type::F32 => ( @@ -207,7 +213,9 @@ impl Abi for X86_64SystemV { .map(|&ty| type_to_llvm(intrinsics, ty)) .collect::>()?; - let sret = context.struct_type(&basic_types, false).ptr_type(AddressSpace::Generic); + let sret = context + .struct_type(&basic_types, false) + .ptr_type(AddressSpace::Generic); let param_types = std::iter::once(Ok(sret.as_basic_type_enum())).chain(param_types); @@ -218,7 +226,9 @@ impl Abi for X86_64SystemV { attributes.append(&mut vmctx_attributes(1)); ( - intrinsics.void_ty.fn_type(¶m_types.collect::, _>>()?, false), + intrinsics + .void_ty + .fn_type(¶m_types.collect::, _>>()?, false), attributes, ) } @@ -252,7 +262,9 @@ impl Abi for X86_64SystemV { let values = std::iter::once(ctx_ptr.as_basic_value_enum()).chain(values.iter().copied()); if let Some(sret) = sret { - std::iter::once(sret.as_basic_value_enum()).chain(values).collect() + std::iter::once(sret.as_basic_value_enum()) + .chain(values) + .collect() } else { values.collect() } @@ -529,7 +541,10 @@ impl Abi for X86_64SystemV { } [v1, v2] => { assert!(!(is_32(v1) && is_32(v2))); - build_struct(func_type.get_return_type().unwrap().into_struct_type(), &[v1, v2]) + build_struct( + func_type.get_return_type().unwrap().into_struct_type(), + &[v1, v2], + ) } [v1, v2, v3] if is_f32(v1) && is_f32(v2) => build_struct( func_type.get_return_type().unwrap().into_struct_type(), diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index a696af049..a62755974 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -61,8 +61,12 @@ impl SymbolRegistry for ShortNames { match ty.chars().next().unwrap() { 'f' => Some(Symbol::LocalFunction(LocalFunctionIndex::from_u32(idx))), 's' => Some(Symbol::Section(SectionIndex::from_u32(idx))), - 't' => Some(Symbol::FunctionCallTrampoline(SignatureIndex::from_u32(idx))), - 'd' => Some(Symbol::DynamicFunctionTrampoline(FunctionIndex::from_u32(idx))), + 't' => Some(Symbol::FunctionCallTrampoline(SignatureIndex::from_u32( + idx, + ))), + 'd' => Some(Symbol::DynamicFunctionTrampoline(FunctionIndex::from_u32( + idx, + ))), _ => None, } } @@ -119,7 +123,10 @@ impl LLVMCompiler { compile_info.module.functions.iter().par_bridge().map_init( || { let target_machine = self.config().target_machine(target); - (FuncTrampoline::new(target_machine), &compile_info.module.signatures) + ( + FuncTrampoline::new(target_machine), + &compile_info.module.signatures, + ) }, |(func_trampoline, signatures), (i, sig)| { let sig = &signatures[*sig]; @@ -169,8 +176,9 @@ impl LLVMCompiler { merged_module.verify().unwrap(); } - let memory_buffer = - target_machine.write_to_memory_buffer(&merged_module, FileType::Object).unwrap(); + let memory_buffer = target_machine + .write_to_memory_buffer(&merged_module, FileType::Object) + .unwrap(); if let Some(ref callbacks) = self.config.callbacks { callbacks.obj_memory_buffer(&CompiledKind::Module, &memory_buffer); } @@ -266,7 +274,10 @@ impl Compiler for LLVMCompiler { ) } } - if compiled_function.eh_frame_section_indices.contains(§ion_index) { + if compiled_function + .eh_frame_section_indices + .contains(§ion_index) + { let offset = frame_section_bytes.len() as u32; for mut reloc in &mut custom_section.relocations { reloc.offset += offset; @@ -295,8 +306,9 @@ impl Compiler for LLVMCompiler { .collect::>(); let dwarf = if !frame_section_bytes.is_empty() { - let dwarf = - Some(Dwarf::new(SectionIndex::from_u32(module_custom_sections.len() as u32))); + let dwarf = Some(Dwarf::new(SectionIndex::from_u32( + module_custom_sections.len() as u32, + ))); // Terminating zero-length CIE. frame_section_bytes.extend(vec![ 0x00, 0x00, 0x00, 0x00, // Length diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 8410709a2..245a27e92 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -176,8 +176,10 @@ impl LLVM { // The CPU features formatted as LLVM strings // We can safely map to gcc-like features as the CPUFeatures // are compliant with the same string representations as gcc. - let llvm_cpu_features = - cpu_features.iter().map(|feature| format!("+{}", feature.to_string())).join(","); + let llvm_cpu_features = cpu_features + .iter() + .map(|feature| format!("+{}", feature.to_string())) + .join(","); let target_triple = self.target_triple(&target); let llvm_target = InkwellTarget::from_triple(&target_triple).unwrap(); diff --git a/lib/compiler-llvm/src/lib.rs b/lib/compiler-llvm/src/lib.rs index 632501c1f..db2503e9c 100644 --- a/lib/compiler-llvm/src/lib.rs +++ b/lib/compiler-llvm/src/lib.rs @@ -6,7 +6,10 @@ unused_unsafe, unreachable_patterns )] -#![cfg_attr(all(not(target_os = "windows"), not(target_arch = "aarch64")), deny(dead_code))] +#![cfg_attr( + all(not(target_os = "windows"), not(target_arch = "aarch64")), + deny(dead_code) +)] #![cfg_attr(nightly, feature(unwind_attributes))] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_logo_url = "https://github.com/wasmerio.png?size=200")] diff --git a/lib/compiler-llvm/src/object_file.rs b/lib/compiler-llvm/src/object_file.rs index e95837542..aaed70fa0 100644 --- a/lib/compiler-llvm/src/object_file.rs +++ b/lib/compiler-llvm/src/object_file.rs @@ -71,24 +71,45 @@ where libcalls.insert("wasmer_vm_f32_trunc".to_string(), LibCall::TruncF32); libcalls.insert("wasmer_vm_f64_trunc".to_string(), LibCall::TruncF64); libcalls.insert("wasmer_vm_memory32_size".to_string(), LibCall::Memory32Size); - libcalls.insert("wasmer_vm_imported_memory32_size".to_string(), LibCall::ImportedMemory32Size); + libcalls.insert( + "wasmer_vm_imported_memory32_size".to_string(), + LibCall::ImportedMemory32Size, + ); libcalls.insert("wasmer_vm_table_copy".to_string(), LibCall::TableCopy); libcalls.insert("wasmer_vm_table_init".to_string(), LibCall::TableInit); libcalls.insert("wasmer_vm_table_fill".to_string(), LibCall::TableFill); libcalls.insert("wasmer_vm_table_size".to_string(), LibCall::TableSize); - libcalls.insert("wasmer_vm_imported_table_size".to_string(), LibCall::ImportedTableSize); + libcalls.insert( + "wasmer_vm_imported_table_size".to_string(), + LibCall::ImportedTableSize, + ); libcalls.insert("wasmer_vm_table_get".to_string(), LibCall::TableGet); - libcalls.insert("wasmer_vm_imported_table_get".to_string(), LibCall::ImportedTableGet); + libcalls.insert( + "wasmer_vm_imported_table_get".to_string(), + LibCall::ImportedTableGet, + ); libcalls.insert("wasmer_vm_table_set".to_string(), LibCall::TableSet); - libcalls.insert("wasmer_vm_imported_table_set".to_string(), LibCall::ImportedTableSet); + libcalls.insert( + "wasmer_vm_imported_table_set".to_string(), + LibCall::ImportedTableSet, + ); libcalls.insert("wasmer_vm_table_grow".to_string(), LibCall::TableGrow); - libcalls.insert("wasmer_vm_imported_table_grow".to_string(), LibCall::ImportedTableGrow); + libcalls.insert( + "wasmer_vm_imported_table_grow".to_string(), + LibCall::ImportedTableGrow, + ); libcalls.insert("wasmer_vm_func_ref".to_string(), LibCall::FuncRef); libcalls.insert("wasmer_vm_elem_drop".to_string(), LibCall::ElemDrop); libcalls.insert("wasmer_vm_memory32_copy".to_string(), LibCall::Memory32Copy); - libcalls.insert("wasmer_vm_imported_memory32_copy".to_string(), LibCall::ImportedMemory32Copy); + libcalls.insert( + "wasmer_vm_imported_memory32_copy".to_string(), + LibCall::ImportedMemory32Copy, + ); libcalls.insert("wasmer_vm_memory32_fill".to_string(), LibCall::Memory32Fill); - libcalls.insert("wasmer_vm_imported_memory32_fill".to_string(), LibCall::ImportedMemory32Fill); + libcalls.insert( + "wasmer_vm_imported_memory32_fill".to_string(), + LibCall::ImportedMemory32Fill, + ); libcalls.insert("wasmer_vm_memory32_init".to_string(), LibCall::Memory32Init); libcalls.insert("wasmer_vm_data_drop".to_string(), LibCall::DataDrop); libcalls.insert("wasmer_vm_raise_trap".to_string(), LibCall::RaiseTrap); @@ -253,12 +274,15 @@ where } else { unimplemented!("unknown relocation {:?} with target {:?}", reloc, target); }; - relocations.entry(section_index).or_default().push(Relocation { - kind, - reloc_target, - offset, - addend, - }); + relocations + .entry(section_index) + .or_default() + .push(Relocation { + kind, + reloc_target, + offset, + addend, + }); } } @@ -293,10 +317,15 @@ where }) .collect::>(); custom_sections.sort_unstable_by_key(|a| a.0); - let custom_sections = - custom_sections.into_iter().map(|(_, v)| v).collect::>(); + let custom_sections = custom_sections + .into_iter() + .map(|(_, v)| v) + .collect::>(); - let function_body = FunctionBody { body: section_bytes(root_section_index), unwind_info: None }; + let function_body = FunctionBody { + body: section_bytes(root_section_index), + unwind_info: None, + }; let address_map = FunctionAddressMap { instructions: vec![InstructionAddressMap { @@ -314,8 +343,13 @@ where compiled_function: wasmer_compiler::CompiledFunction { body: function_body, jt_offsets: SecondaryMap::new(), - relocations: relocations.remove_entry(&root_section_index).map_or(vec![], |(_, v)| v), - frame_info: CompiledFunctionFrameInfo { address_map, traps: vec![] }, + relocations: relocations + .remove_entry(&root_section_index) + .map_or(vec![], |(_, v)| v), + frame_info: CompiledFunctionFrameInfo { + address_map, + traps: vec![], + }, }, custom_sections, eh_frame_section_indices, diff --git a/lib/compiler-llvm/src/trampoline/wasm.rs b/lib/compiler-llvm/src/trampoline/wasm.rs index e96c88b06..d2d921101 100644 --- a/lib/compiler-llvm/src/trampoline/wasm.rs +++ b/lib/compiler-llvm/src/trampoline/wasm.rs @@ -28,7 +28,11 @@ const FUNCTION_SECTION: &str = "__TEXT,wasmer_trmpl"; // Needs to be between 1 a impl FuncTrampoline { pub fn new(target_machine: TargetMachine) -> Self { let abi = get_abi(&target_machine); - Self { ctx: Context::create(), target_machine, abi } + Self { + ctx: Context::create(), + target_machine, + abi, + } } pub fn trampoline_to_module( @@ -47,20 +51,29 @@ impl FuncTrampoline { let intrinsics = Intrinsics::declare(&module, &self.ctx); let (callee_ty, callee_attrs) = - self.abi.func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; + self.abi + .func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; let trampoline_ty = intrinsics.void_ty.fn_type( &[ intrinsics.ctx_ptr_ty.as_basic_type_enum(), // vmctx ptr - callee_ty.ptr_type(AddressSpace::Generic).as_basic_type_enum(), // callee function address - intrinsics.i128_ptr_ty.as_basic_type_enum(), // in/out values ptr + callee_ty + .ptr_type(AddressSpace::Generic) + .as_basic_type_enum(), // callee function address + intrinsics.i128_ptr_ty.as_basic_type_enum(), // in/out values ptr ], false, ); let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External)); - trampoline_func.as_global_value().set_section(FUNCTION_SECTION); - trampoline_func.as_global_value().set_linkage(Linkage::DLLExport); - trampoline_func.as_global_value().set_dll_storage_class(DLLStorageClass::Export); + trampoline_func + .as_global_value() + .set_section(FUNCTION_SECTION); + trampoline_func + .as_global_value() + .set_linkage(Linkage::DLLExport); + trampoline_func + .as_global_value() + .set_dll_storage_class(DLLStorageClass::Export); self.generate_trampoline(trampoline_func, ty, &callee_attrs, &self.ctx, &intrinsics)?; if let Some(ref callbacks) = config.callbacks { @@ -94,26 +107,30 @@ impl FuncTrampoline { let function = CompiledKind::FunctionCallTrampoline(ty.clone()); let target_machine = &self.target_machine; - let memory_buffer = - target_machine.write_to_memory_buffer(&module, FileType::Object).unwrap(); + let memory_buffer = target_machine + .write_to_memory_buffer(&module, FileType::Object) + .unwrap(); if let Some(ref callbacks) = config.callbacks { callbacks.obj_memory_buffer(&function, &memory_buffer); } let mem_buf_slice = memory_buffer.as_slice(); - let CompiledFunction { compiled_function, custom_sections, eh_frame_section_indices } = - load_object_file( - mem_buf_slice, - FUNCTION_SECTION, - RelocationTarget::LocalFunc(LocalFunctionIndex::from_u32(0)), - |name: &String| { - Err(CompileError::Codegen(format!( - "trampoline generation produced reference to unknown function {}", - name - ))) - }, - )?; + let CompiledFunction { + compiled_function, + custom_sections, + eh_frame_section_indices, + } = load_object_file( + mem_buf_slice, + FUNCTION_SECTION, + RelocationTarget::LocalFunc(LocalFunctionIndex::from_u32(0)), + |name: &String| { + Err(CompileError::Codegen(format!( + "trampoline generation produced reference to unknown function {}", + name + ))) + }, + )?; let mut all_sections_are_eh_sections = true; if eh_frame_section_indices.len() != custom_sections.len() { all_sections_are_eh_sections = false; @@ -133,10 +150,14 @@ impl FuncTrampoline { )); } if !compiled_function.relocations.is_empty() { - return Err(CompileError::Codegen("trampoline generation produced relocations".into())); + return Err(CompileError::Codegen( + "trampoline generation produced relocations".into(), + )); } if !compiled_function.jt_offsets.is_empty() { - return Err(CompileError::Codegen("trampoline generation produced jump tables".into())); + return Err(CompileError::Codegen( + "trampoline generation produced jump tables".into(), + )); } // Ignore CompiledFunctionFrameInfo. Extra frame info isn't a problem. @@ -162,14 +183,21 @@ impl FuncTrampoline { let intrinsics = Intrinsics::declare(&module, &self.ctx); let (trampoline_ty, trampoline_attrs) = - self.abi.func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; + self.abi + .func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External)); for (attr, attr_loc) in trampoline_attrs { trampoline_func.add_attribute(attr_loc, attr); } - trampoline_func.as_global_value().set_section(FUNCTION_SECTION); - trampoline_func.as_global_value().set_linkage(Linkage::DLLExport); - trampoline_func.as_global_value().set_dll_storage_class(DLLStorageClass::Export); + trampoline_func + .as_global_value() + .set_section(FUNCTION_SECTION); + trampoline_func + .as_global_value() + .set_linkage(Linkage::DLLExport); + trampoline_func + .as_global_value() + .set_dll_storage_class(DLLStorageClass::Export); self.generate_dynamic_trampoline(trampoline_func, ty, &self.ctx, &intrinsics)?; if let Some(ref callbacks) = config.callbacks { @@ -203,26 +231,30 @@ impl FuncTrampoline { let module = self.dynamic_trampoline_to_module(ty, config, name)?; - let memory_buffer = - target_machine.write_to_memory_buffer(&module, FileType::Object).unwrap(); + let memory_buffer = target_machine + .write_to_memory_buffer(&module, FileType::Object) + .unwrap(); if let Some(ref callbacks) = config.callbacks { callbacks.obj_memory_buffer(&function, &memory_buffer); } let mem_buf_slice = memory_buffer.as_slice(); - let CompiledFunction { compiled_function, custom_sections, eh_frame_section_indices } = - load_object_file( - mem_buf_slice, - FUNCTION_SECTION, - RelocationTarget::LocalFunc(LocalFunctionIndex::from_u32(0)), - |name: &String| { - Err(CompileError::Codegen(format!( - "trampoline generation produced reference to unknown function {}", - name - ))) - }, - )?; + let CompiledFunction { + compiled_function, + custom_sections, + eh_frame_section_indices, + } = load_object_file( + mem_buf_slice, + FUNCTION_SECTION, + RelocationTarget::LocalFunc(LocalFunctionIndex::from_u32(0)), + |name: &String| { + Err(CompileError::Codegen(format!( + "trampoline generation produced reference to unknown function {}", + name + ))) + }, + )?; let mut all_sections_are_eh_sections = true; if eh_frame_section_indices.len() != custom_sections.len() { all_sections_are_eh_sections = false; @@ -242,10 +274,14 @@ impl FuncTrampoline { )); } if !compiled_function.relocations.is_empty() { - return Err(CompileError::Codegen("trampoline generation produced relocations".into())); + return Err(CompileError::Codegen( + "trampoline generation produced relocations".into(), + )); } if !compiled_function.jt_offsets.is_empty() { - return Err(CompileError::Codegen("trampoline generation produced jump tables".into())); + return Err(CompileError::Codegen( + "trampoline generation produced jump tables".into(), + )); } // Ignore CompiledFunctionFrameInfo. Extra frame info isn't a problem. @@ -267,19 +303,19 @@ impl FuncTrampoline { let builder = context.create_builder(); builder.position_at_end(entry_block); - let (callee_vmctx_ptr, func_ptr, args_rets_ptr) = match *trampoline_func - .get_params() - .as_slice() - { - [callee_vmctx_ptr, func_ptr, args_rets_ptr] => ( - callee_vmctx_ptr, - func_ptr.into_pointer_value(), - args_rets_ptr.into_pointer_value(), - ), - _ => { - return Err(CompileError::Codegen("trampoline function unimplemented".to_string())) - } - }; + let (callee_vmctx_ptr, func_ptr, args_rets_ptr) = + match *trampoline_func.get_params().as_slice() { + [callee_vmctx_ptr, func_ptr, args_rets_ptr] => ( + callee_vmctx_ptr, + func_ptr.into_pointer_value(), + args_rets_ptr.into_pointer_value(), + ), + _ => { + return Err(CompileError::Codegen( + "trampoline function unimplemented".to_string(), + )) + } + }; let mut args_vec = Vec::with_capacity(func_sig.params().len() + 1); @@ -315,11 +351,17 @@ impl FuncTrampoline { call_site.add_attribute(*attr_loc, *attr); } - let rets = self.abi.rets_from_call(&builder, intrinsics, call_site, func_sig); + let rets = self + .abi + .rets_from_call(&builder, intrinsics, call_site, func_sig); let mut idx = 0; rets.iter().for_each(|v| { let ptr = unsafe { - builder.build_gep(args_rets_ptr, &[intrinsics.i32_ty.const_int(idx, false)], "") + builder.build_gep( + args_rets_ptr, + &[intrinsics.i32_ty.const_int(idx, false)], + "", + ) }; let ptr = builder.build_pointer_cast(ptr, v.get_type().ptr_type(AddressSpace::Generic), ""); @@ -372,7 +414,9 @@ impl FuncTrampoline { .into_pointer_value(); builder.build_store( ptr, - trampoline_func.get_nth_param(i as u32 + first_user_param).unwrap(), + trampoline_func + .get_nth_param(i as u32 + first_user_param) + .unwrap(), ); } @@ -399,7 +443,10 @@ impl FuncTrampoline { let values_ptr = builder.build_pointer_cast(values, intrinsics.i128_ptr_ty, ""); builder.build_call( callee, - &[vmctx.as_basic_value_enum(), values_ptr.as_basic_value_enum()], + &[ + vmctx.as_basic_value_enum(), + values_ptr.as_basic_value_enum(), + ], "", ); @@ -428,9 +475,15 @@ impl FuncTrampoline { .collect::, CompileError>>()?; if self.abi.is_sret(func_sig)? { - let sret = trampoline_func.get_first_param().unwrap().into_pointer_value(); - let mut struct_value = - sret.get_type().get_element_type().into_struct_type().get_undef(); + let sret = trampoline_func + .get_first_param() + .unwrap() + .into_pointer_value(); + let mut struct_value = sret + .get_type() + .get_element_type() + .into_struct_type() + .get_undef(); for (idx, value) in results.iter().enumerate() { let value = builder.build_bitcast( *value, diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index 8566b68c0..0d02e0122 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -51,7 +51,11 @@ pub struct FuncTranslator { impl FuncTranslator { pub fn new(target_machine: TargetMachine) -> Self { let abi = get_abi(&target_machine); - Self { ctx: Context::create(), target_machine, abi } + Self { + ctx: Context::create(), + target_machine, + abi, + } } pub fn translate_to_module( @@ -80,13 +84,17 @@ impl FuncTranslator { let target_triple = target_machine.get_triple(); module.set_triple(&target_triple); module.set_data_layout(&target_machine.get_target_data().get_data_layout()); - let wasm_fn_type = wasm_module.signatures.get(wasm_module.functions[func_index]).unwrap(); + let wasm_fn_type = wasm_module + .signatures + .get(wasm_module.functions[func_index]) + .unwrap(); // TODO: pointer width let offsets = VMOffsets::new(8, &wasm_module); let intrinsics = Intrinsics::declare(&module, &self.ctx); let (func_type, func_attrs) = - self.abi.func_type_to_llvm(&self.ctx, &intrinsics, Some(&offsets), wasm_fn_type)?; + self.abi + .func_type_to_llvm(&self.ctx, &intrinsics, Some(&offsets), wasm_fn_type)?; let func = module.add_function(&function_name, func_type, Some(Linkage::External)); for (attr, attr_loc) in &func_attrs { @@ -97,7 +105,8 @@ impl FuncTranslator { func.set_personality_function(intrinsics.personality); func.as_global_value().set_section(FUNCTION_SECTION); func.set_linkage(Linkage::DLLExport); - func.as_global_value().set_dll_storage_class(DLLStorageClass::Export); + func.as_global_value() + .set_dll_storage_class(DLLStorageClass::Export); let entry = self.ctx.append_basic_block(func, "entry"); let start_of_code = self.ctx.append_basic_block(func, "start_of_code"); @@ -126,7 +135,9 @@ impl FuncTranslator { function_body.module_offset, ); reader.set_middleware_chain( - config.middlewares.generate_function_middleware_chain(*local_func_index), + config + .middlewares + .generate_function_middleware_chain(*local_func_index), ); let mut params = vec![]; @@ -149,7 +160,9 @@ impl FuncTranslator { for idx in 0..wasm_fn_type.params().len() { let ty = wasm_fn_type.params()[idx]; let ty = type_to_llvm(&intrinsics, ty)?; - let value = func.get_nth_param((idx as u32).checked_add(first_param).unwrap()).unwrap(); + let value = func + .get_nth_param((idx as u32).checked_add(first_param).unwrap()) + .unwrap(); let alloca = insert_alloca(ty, "param"); cache_builder.build_store(alloca, value); params.push(alloca); @@ -276,8 +289,9 @@ impl FuncTranslator { )?; let function = CompiledKind::Local(*local_func_index); let target_machine = &self.target_machine; - let memory_buffer = - target_machine.write_to_memory_buffer(&module, FileType::Object).unwrap(); + let memory_buffer = target_machine + .write_to_memory_buffer(&module, FileType::Object) + .unwrap(); if let Some(ref callbacks) = config.callbacks { callbacks.obj_memory_buffer(&function, &memory_buffer); @@ -320,7 +334,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ), vec_ty.get_undef(), - self.intrinsics.i32_ty.vec_type(vec_ty.get_size()).const_zero(), + self.intrinsics + .i32_ty + .vec_type(vec_ty.get_size()) + .const_zero(), "", ) } @@ -357,11 +374,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let is_signed = int_min_value != 0; let int_min_value = self.splat_vector( - ivec_element_ty.const_int(int_min_value, is_signed).as_basic_value_enum(), + ivec_element_ty + .const_int(int_min_value, is_signed) + .as_basic_value_enum(), ivec_ty, ); let int_max_value = self.splat_vector( - ivec_element_ty.const_int(int_max_value, is_signed).as_basic_value_enum(), + ivec_element_ty + .const_int(int_max_value, is_signed) + .as_basic_value_enum(), ivec_ty, ); let lower_bound = if is_signed { @@ -391,11 +412,16 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ) }; - let value = self.builder.build_bitcast(value, fvec_ty, "").into_vector_value(); + let value = self + .builder + .build_bitcast(value, fvec_ty, "") + .into_vector_value(); let zero = fvec_ty.const_zero(); let lower_bound = self.splat_vector(lower_bound.as_basic_value_enum(), fvec_ty); let upper_bound = self.splat_vector(upper_bound.as_basic_value_enum(), fvec_ty); - let nan_cmp = self.builder.build_float_compare(FloatPredicate::UNO, value, zero, "nan"); + let nan_cmp = self + .builder + .build_float_compare(FloatPredicate::UNO, value, zero, "nan"); let above_upper_bound_cmp = self.builder.build_float_compare( FloatPredicate::OGT, value, @@ -418,9 +444,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .build_select(not_representable, zero, value, "safe_to_convert") .into_vector_value(); let value = if is_signed { - self.builder.build_float_to_signed_int(value, ivec_ty, "as_int") + self.builder + .build_float_to_signed_int(value, ivec_ty, "as_int") } else { - self.builder.build_float_to_unsigned_int(value, ivec_ty, "as_int") + self.builder + .build_float_to_unsigned_int(value, ivec_ty, "as_int") }; let value = self .builder @@ -430,7 +458,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_select(below_lower_bound_cmp, int_min_value, value, "") .into_vector_value(); - self.builder.build_bitcast(res, self.intrinsics.i128_ty, "").into_int_value() + self.builder + .build_bitcast(res, self.intrinsics.i128_ty, "") + .into_int_value() } // Convert floating point vector to integer and saturate when out of range. @@ -492,7 +522,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let zero = value.get_type().const_zero(); - let nan_cmp = self.builder.build_float_compare(FloatPredicate::UNO, value, zero, "nan"); + let nan_cmp = self + .builder + .build_float_compare(FloatPredicate::UNO, value, zero, "nan"); let above_upper_bound_cmp = self.builder.build_float_compare( FloatPredicate::OGT, value, @@ -515,9 +547,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .build_select(not_representable, zero, value, "safe_to_convert") .into_float_value(); let value = if is_signed { - self.builder.build_float_to_signed_int(value, int_ty, "as_int") + self.builder + .build_float_to_signed_int(value, int_ty, "as_int") } else { - self.builder.build_float_to_unsigned_int(value, int_ty, "as_int") + self.builder + .build_float_to_unsigned_int(value, int_ty, "as_int") }; let value = self .builder @@ -527,7 +561,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_select(below_lower_bound_cmp, int_min_value, value, "") .into_int_value(); - self.builder.build_bitcast(value, int_ty, "").into_int_value() + self.builder + .build_bitcast(value, int_ty, "") + .into_int_value() } fn trap_if_not_representable_as_int( @@ -567,24 +603,33 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { lower_bound, "below_lower_bound", ); - let out_of_bounds = - self.builder.build_or(above_upper_bound_cmp, below_lower_bound_cmp, "out_of_bounds"); + let out_of_bounds = self.builder.build_or( + above_upper_bound_cmp, + below_lower_bound_cmp, + "out_of_bounds", + ); - let failure_block = - self.context.append_basic_block(self.function, "conversion_failure_block"); - let continue_block = - self.context.append_basic_block(self.function, "conversion_success_block"); + let failure_block = self + .context + .append_basic_block(self.function, "conversion_failure_block"); + let continue_block = self + .context + .append_basic_block(self.function, "conversion_success_block"); - self.builder.build_conditional_branch(out_of_bounds, failure_block, continue_block); + self.builder + .build_conditional_branch(out_of_bounds, failure_block, continue_block); self.builder.position_at_end(failure_block); - let is_nan = self.builder.build_float_compare(FloatPredicate::UNO, value, value, "is_nan"); + let is_nan = self + .builder + .build_float_compare(FloatPredicate::UNO, value, value, "is_nan"); let trap_code = self.builder.build_select( is_nan, self.intrinsics.trap_bad_conversion_to_integer, self.intrinsics.trap_illegal_arithmetic, "", ); - self.builder.build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); + self.builder + .build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); self.builder.build_unreachable(); self.builder.position_at_end(continue_block); } @@ -613,7 +658,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let should_trap = self.builder.build_or( divisor_is_zero, self.builder.build_and( - self.builder.build_int_compare(IntPredicate::EQ, left, min_value, "left_is_min"), + self.builder + .build_int_compare(IntPredicate::EQ, left, min_value, "left_is_min"), self.builder.build_int_compare( IntPredicate::EQ, right, @@ -640,10 +686,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap() .into_int_value(); - let shouldnt_trap_block = - self.context.append_basic_block(self.function, "shouldnt_trap_block"); - let should_trap_block = self.context.append_basic_block(self.function, "should_trap_block"); - self.builder.build_conditional_branch(should_trap, should_trap_block, shouldnt_trap_block); + let shouldnt_trap_block = self + .context + .append_basic_block(self.function, "shouldnt_trap_block"); + let should_trap_block = self + .context + .append_basic_block(self.function, "should_trap_block"); + self.builder + .build_conditional_branch(should_trap, should_trap_block, shouldnt_trap_block); self.builder.position_at_end(should_trap_block); let trap_code = self.builder.build_select( divisor_is_zero, @@ -651,7 +701,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.trap_illegal_arithmetic, "", ); - self.builder.build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); + self.builder + .build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); self.builder.build_unreachable(); self.builder.position_at_end(shouldnt_trap_block); } @@ -680,10 +731,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap() .into_int_value(); - let shouldnt_trap_block = - self.context.append_basic_block(self.function, "shouldnt_trap_block"); - let should_trap_block = self.context.append_basic_block(self.function, "should_trap_block"); - self.builder.build_conditional_branch(should_trap, should_trap_block, shouldnt_trap_block); + let shouldnt_trap_block = self + .context + .append_basic_block(self.function, "shouldnt_trap_block"); + let should_trap_block = self + .context + .append_basic_block(self.function, "should_trap_block"); + self.builder + .build_conditional_branch(should_trap, should_trap_block, shouldnt_trap_block); self.builder.position_at_end(should_trap_block); self.builder.build_call( self.intrinsics.throw_trap, @@ -701,15 +756,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { int_vec_ty: VectorType<'ctx>, ) -> (VectorValue<'ctx>, ExtraInfo) { let (value, info) = if info.has_pending_f32_nan() { - let value = self.builder.build_bitcast(value, self.intrinsics.f32x4_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f32x4_ty, ""); (self.canonicalize_nans(value), info.strip_pending()) } else if info.has_pending_f64_nan() { - let value = self.builder.build_bitcast(value, self.intrinsics.f64x2_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f64x2_ty, ""); (self.canonicalize_nans(value), info.strip_pending()) } else { (value, info) }; - (self.builder.build_bitcast(value, int_vec_ty, "").into_vector_value(), info) + ( + self.builder + .build_bitcast(value, int_vec_ty, "") + .into_vector_value(), + info, + ) } fn v128_into_i8x16( @@ -752,12 +816,19 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { info: ExtraInfo, ) -> (VectorValue<'ctx>, ExtraInfo) { let (value, info) = if info.has_pending_f64_nan() { - let value = self.builder.build_bitcast(value, self.intrinsics.f64x2_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f64x2_ty, ""); (self.canonicalize_nans(value), info.strip_pending()) } else { (value, info) }; - (self.builder.build_bitcast(value, self.intrinsics.f32x4_ty, "").into_vector_value(), info) + ( + self.builder + .build_bitcast(value, self.intrinsics.f32x4_ty, "") + .into_vector_value(), + info, + ) } // If the value is pending a 32-bit canonicalization, do it now. @@ -768,12 +839,19 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { info: ExtraInfo, ) -> (VectorValue<'ctx>, ExtraInfo) { let (value, info) = if info.has_pending_f32_nan() { - let value = self.builder.build_bitcast(value, self.intrinsics.f32x4_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f32x4_ty, ""); (self.canonicalize_nans(value), info.strip_pending()) } else { (value, info) }; - (self.builder.build_bitcast(value, self.intrinsics.f64x2_ty, "").into_vector_value(), info) + ( + self.builder + .build_bitcast(value, self.intrinsics.f64x2_ty, "") + .into_vector_value(), + info, + ) } fn apply_pending_canonicalization( @@ -786,7 +864,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { || value.get_type() == self.intrinsics.i128_ty.as_basic_type_enum() { let ty = value.get_type(); - let value = self.builder.build_bitcast(value, self.intrinsics.f32x4_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f32x4_ty, ""); let value = self.canonicalize_nans(value); self.builder.build_bitcast(value, ty, "") } else { @@ -797,7 +877,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { || value.get_type() == self.intrinsics.i128_ty.as_basic_type_enum() { let ty = value.get_type(); - let value = self.builder.build_bitcast(value, self.intrinsics.f64x2_ty, ""); + let value = self + .builder + .build_bitcast(value, self.intrinsics.f64x2_ty, ""); let value = self.canonicalize_nans(value); self.builder.build_bitcast(value, ty, "") } else { @@ -815,18 +897,28 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let value = value.into_vector_value(); let f_ty = f_ty.into_vector_type(); let zero = f_ty.const_zero(); - let nan_cmp = self.builder.build_float_compare(FloatPredicate::UNO, value, zero, "nan"); - let canonical_qnan = - f_ty.get_element_type().into_float_type().const_float(std::f64::NAN); + let nan_cmp = self + .builder + .build_float_compare(FloatPredicate::UNO, value, zero, "nan"); + let canonical_qnan = f_ty + .get_element_type() + .into_float_type() + .const_float(std::f64::NAN); let canonical_qnan = self.splat_vector(canonical_qnan.as_basic_value_enum(), f_ty); - self.builder.build_select(nan_cmp, canonical_qnan, value, "").as_basic_value_enum() + self.builder + .build_select(nan_cmp, canonical_qnan, value, "") + .as_basic_value_enum() } else { let value = value.into_float_value(); let f_ty = f_ty.into_float_type(); let zero = f_ty.const_zero(); - let nan_cmp = self.builder.build_float_compare(FloatPredicate::UNO, value, zero, "nan"); + let nan_cmp = self + .builder + .build_float_compare(FloatPredicate::UNO, value, zero, "nan"); let canonical_qnan = f_ty.const_float(std::f64::NAN); - self.builder.build_select(nan_cmp, canonical_qnan, value, "").as_basic_value_enum() + self.builder + .build_select(nan_cmp, canonical_qnan, value, "") + .as_basic_value_enum() } } @@ -838,9 +930,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { memory_index: MemoryIndex, memaccess: InstructionValue<'ctx>, ) -> Result<(), CompileError> { - if let MemoryCache::Static { base_ptr: _ } = - self.ctx.memory(memory_index, self.intrinsics, self.module, self.memory_styles) - { + if let MemoryCache::Static { base_ptr: _ } = self.ctx.memory( + memory_index, + self.intrinsics, + self.module, + self.memory_styles, + ) { // The best we've got is `volatile`. // TODO: convert unwrap fail to CompileError memaccess.set_volatile(true).unwrap(); @@ -891,8 +986,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // Look up the memory base (as pointer) and bounds (as unsigned integer). let base_ptr = - match self.ctx.memory(memory_index, intrinsics, self.module, self.memory_styles) { - MemoryCache::Dynamic { ptr_to_base_ptr, ptr_to_current_length } => { + match self + .ctx + .memory(memory_index, intrinsics, self.module, self.memory_styles) + { + MemoryCache::Dynamic { + ptr_to_base_ptr, + ptr_to_current_length, + } => { // Bounds check it. let minimum = self.wasm_module.memories[memory_index].minimum; let value_size_v = intrinsics.i64_ty.const_int(value_size as u64, false); @@ -915,8 +1016,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap_or_else(|| { let load_offset_end = builder.build_int_add(offset, value_size_v, ""); - let current_length = - builder.build_load(ptr_to_current_length, "").into_int_value(); + let current_length = builder + .build_load(ptr_to_current_length, "") + .into_int_value(); tbaa_label( self.module, self.intrinsics, @@ -985,26 +1087,34 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { MemoryCache::Static { base_ptr } => base_ptr, }; let value_ptr = unsafe { builder.build_gep(base_ptr, &[offset], "") }; - Ok(builder.build_bitcast(value_ptr, ptr_ty, "").into_pointer_value()) + Ok(builder + .build_bitcast(value_ptr, ptr_ty, "") + .into_pointer_value()) } fn trap_if_misaligned(&self, memarg: &MemoryImmediate, ptr: PointerValue<'ctx>) { let align = memarg.align; - let value = self.builder.build_ptr_to_int(ptr, self.intrinsics.i64_ty, ""); + let value = self + .builder + .build_ptr_to_int(ptr, self.intrinsics.i64_ty, ""); let and = self.builder.build_and( value, self.intrinsics.i64_ty.const_int((align - 1).into(), false), "misaligncheck", ); let aligned = - self.builder.build_int_compare(IntPredicate::EQ, and, self.intrinsics.i64_zero, ""); + self.builder + .build_int_compare(IntPredicate::EQ, and, self.intrinsics.i64_zero, ""); let aligned = self .builder .build_call( self.intrinsics.expect_i1, &[ aligned.as_basic_value_enum(), - self.intrinsics.i1_ty.const_int(1, false).as_basic_value_enum(), + self.intrinsics + .i1_ty + .const_int(1, false) + .as_basic_value_enum(), ], "", ) @@ -1013,11 +1123,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap() .into_int_value(); - let continue_block = - self.context.append_basic_block(self.function, "aligned_access_continue_block"); - let not_aligned_block = - self.context.append_basic_block(self.function, "misaligned_trap_block"); - self.builder.build_conditional_branch(aligned, continue_block, not_aligned_block); + let continue_block = self + .context + .append_basic_block(self.function, "aligned_access_continue_block"); + let not_aligned_block = self + .context + .append_basic_block(self.function, "misaligned_trap_block"); + self.builder + .build_conditional_branch(aligned, continue_block, not_aligned_block); self.builder.position_at_end(not_aligned_block); self.builder.build_call( @@ -1034,13 +1147,22 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let func_type = self.function.get_type(); let results = self.state.popn_save_extra(wasm_fn_type.results().len())?; - let results = results.into_iter().map(|(v, i)| self.apply_pending_canonicalization(v, i)); + let results = results + .into_iter() + .map(|(v, i)| self.apply_pending_canonicalization(v, i)); if wasm_fn_type.results().is_empty() { self.builder.build_return(None); } else if self.abi.is_sret(wasm_fn_type)? { - let sret = self.function.get_first_param().unwrap().into_pointer_value(); - let mut struct_value = - sret.get_type().get_element_type().into_struct_type().get_undef(); + let sret = self + .function + .get_first_param() + .unwrap() + .into_pointer_value(); + let mut struct_value = sret + .get_type() + .get_element_type() + .into_struct_type() + .get_undef(); for (idx, value) in results.enumerate() { let value = self.builder.build_bitcast( value, @@ -1056,12 +1178,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.builder.build_store(sret, struct_value); self.builder.build_return(None); } else { - self.builder.build_return(Some(&self.abi.pack_values_for_register_return( - &self.intrinsics, - &self.builder, - &results.collect::>(), - &func_type, - )?)); + self.builder + .build_return(Some(&self.abi.pack_values_for_register_return( + &self.intrinsics, + &self.builder, + &results.collect::>(), + &func_type, + )?)); } Ok(()) } @@ -1230,10 +1353,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .1 .iter() .map(|&wp_ty| { - wptype_to_type(wp_ty).map_err(to_compile_error).and_then(|wasm_ty| { - type_to_llvm(self.intrinsics, wasm_ty) - .map(|ty| self.builder.build_phi(ty, "")) - }) + wptype_to_type(wp_ty) + .map_err(to_compile_error) + .and_then(|wasm_ty| { + type_to_llvm(self.intrinsics, wasm_ty) + .map(|ty| self.builder.build_phi(ty, "")) + }) }) .collect::>()?; @@ -1253,10 +1378,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .1 .iter() .map(|&wp_ty| { - wptype_to_type(wp_ty).map_err(to_compile_error).and_then(|wasm_ty| { - type_to_llvm(self.intrinsics, wasm_ty) - .map(|ty| self.builder.build_phi(ty, "")) - }) + wptype_to_type(wp_ty) + .map_err(to_compile_error) + .and_then(|wasm_ty| { + type_to_llvm(self.intrinsics, wasm_ty) + .map(|ty| self.builder.build_phi(ty, "")) + }) }) .collect::>()?; self.builder.position_at_end(loop_body); @@ -1264,10 +1391,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .0 .iter() .map(|&wp_ty| { - wptype_to_type(wp_ty).map_err(to_compile_error).and_then(|wasm_ty| { - type_to_llvm(self.intrinsics, wasm_ty) - .map(|ty| self.builder.build_phi(ty, "")) - }) + wptype_to_type(wp_ty) + .map_err(to_compile_error) + .and_then(|wasm_ty| { + type_to_llvm(self.intrinsics, wasm_ty) + .map(|ty| self.builder.build_phi(ty, "")) + }) }) .collect::>()?; for phi in loop_phis.iter().rev() { @@ -1321,12 +1450,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .get_insert_block() .ok_or_else(|| CompileError::Codegen("not currently in a block".to_string()))?; - let phis = if frame.is_loop() { frame.loop_body_phis() } else { frame.phis() }; + let phis = if frame.is_loop() { + frame.loop_body_phis() + } else { + frame.phis() + }; let len = phis.len(); let values = self.state.peekn_extra(len)?; - let values = - values.iter().map(|(v, info)| self.apply_pending_canonicalization(*v, *info)); + let values = values + .iter() + .map(|(v, info)| self.apply_pending_canonicalization(*v, *info)); // For each result of the block we're branching to, // pop a value off the value stack and load it into @@ -1349,7 +1483,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .get_insert_block() .ok_or_else(|| CompileError::Codegen("not currently in a block".to_string()))?; - let phis = if frame.is_loop() { frame.loop_body_phis() } else { frame.phis() }; + let phis = if frame.is_loop() { + frame.loop_body_phis() + } else { + frame.phis() + }; let param_stack = self.state.peekn_extra(phis.len())?; let param_stack = param_stack @@ -1368,7 +1506,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_zero, "", ); - self.builder.build_conditional_branch(cond_value, *frame.br_dest(), else_block); + self.builder + .build_conditional_branch(cond_value, *frame.br_dest(), else_block); self.builder.position_at_end(else_block); } Operator::BrTable { ref table } => { @@ -1444,10 +1583,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .1 .iter() .map(|&wp_ty| { - wptype_to_type(wp_ty).map_err(to_compile_error).and_then(|wasm_ty| { - type_to_llvm(self.intrinsics, wasm_ty) - .map(|ty| self.builder.build_phi(ty, "")) - }) + wptype_to_type(wp_ty) + .map_err(to_compile_error) + .and_then(|wasm_ty| { + type_to_llvm(self.intrinsics, wasm_ty) + .map(|ty| self.builder.build_phi(ty, "")) + }) }) .collect::>()?; @@ -1464,7 +1605,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); - self.builder.build_conditional_branch(cond_value, if_then_block, if_else_block); + self.builder + .build_conditional_branch(cond_value, if_then_block, if_else_block); self.builder.position_at_end(if_else_block); let block_param_types = self .module_translation @@ -1477,11 +1619,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .and_then(|wasm_ty| type_to_llvm(self.intrinsics, wasm_ty)) }) .collect::, _>>()?; - let else_phis: SmallVec<[PhiValue<'ctx>; 1]> = - block_param_types.iter().map(|&ty| self.builder.build_phi(ty, "")).collect(); + let else_phis: SmallVec<[PhiValue<'ctx>; 1]> = block_param_types + .iter() + .map(|&ty| self.builder.build_phi(ty, "")) + .collect(); self.builder.position_at_end(if_then_block); - let then_phis: SmallVec<[PhiValue<'ctx>; 1]> = - block_param_types.iter().map(|&ty| self.builder.build_phi(ty, "")).collect(); + let then_phis: SmallVec<[PhiValue<'ctx>; 1]> = block_param_types + .iter() + .map(|&ty| self.builder.build_phi(ty, "")) + .collect(); for (else_phi, then_phi) in else_phis.iter().rev().zip(then_phis.iter().rev()) { let (value, info) = self.state.pop1_extra()?; let value = self.apply_pending_canonicalization(value, info); @@ -1518,14 +1664,16 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.builder.build_unconditional_branch(*frame.code_after()); } - let (if_else_block, if_else_state) = - if let ControlFrame::IfElse { if_else, if_else_state, .. } = - self.state.frame_at_depth_mut(0)? - { - (if_else, if_else_state) - } else { - unreachable!() - }; + let (if_else_block, if_else_state) = if let ControlFrame::IfElse { + if_else, + if_else_state, + .. + } = self.state.frame_at_depth_mut(0)? + { + (if_else, if_else_state) + } else { + unreachable!() + }; *if_else_state = IfElseState::Else; @@ -1557,7 +1705,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.builder.build_unconditional_branch(*frame.code_after()); } - if let ControlFrame::IfElse { if_else, next, if_else_state, else_phis, .. } = &frame + if let ControlFrame::IfElse { + if_else, + next, + if_else_state, + else_phis, + .. + } = &frame { if let IfElseState::If = if_else_state { for (phi, else_phi) in frame.phis().iter().zip(else_phis.iter()) { @@ -1685,7 +1839,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } else { Default::default() }; - let f = self.builder.build_bitcast(bits, self.intrinsics.f32_ty, "f"); + let f = self + .builder + .build_bitcast(bits, self.intrinsics.f32_ty, "f"); self.state.push1_extra(f, info); } Operator::F64Const { value } => { @@ -1695,7 +1851,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } else { Default::default() }; - let f = self.builder.build_bitcast(bits, self.intrinsics.f64_ty, "f"); + let f = self + .builder + .build_bitcast(bits, self.intrinsics.f64_ty, "f"); self.state.push1_extra(f, info); } Operator::V128Const { value } => { @@ -1704,7 +1862,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { hi.copy_from_slice(&value.bytes()[0..8]); lo.copy_from_slice(&value.bytes()[8..16]); let packed = [u64::from_le_bytes(hi), u64::from_le_bytes(lo)]; - let i = self.intrinsics.i128_ty.const_int_arbitrary_precision(&packed); + let i = self + .intrinsics + .i128_ty + .const_int_arbitrary_precision(&packed); let mut quad1: [u8; 4] = Default::default(); let mut quad2: [u8; 4] = Default::default(); let mut quad3: [u8; 4] = Default::default(); @@ -1730,7 +1891,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::I8x16Splat => { let (v, i) = self.state.pop1_extra()?; let v = v.into_int_value(); - let v = self.builder.build_int_truncate(v, self.intrinsics.i8_ty, ""); + let v = self + .builder + .build_int_truncate(v, self.intrinsics.i8_ty, ""); let res = self.splat_vector(v.as_basic_value_enum(), self.intrinsics.i8x16_ty); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1_extra(res, i); @@ -1738,7 +1901,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::I16x8Splat => { let (v, i) = self.state.pop1_extra()?; let v = v.into_int_value(); - let v = self.builder.build_int_truncate(v, self.intrinsics.i16_ty, ""); + let v = self + .builder + .build_int_truncate(v, self.intrinsics.i16_ty, ""); let res = self.splat_vector(v.as_basic_value_enum(), self.intrinsics.i16x8_ty); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1_extra(res, i); @@ -1789,19 +1954,32 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let store = self.builder.build_store(pointer_value, v); - tbaa_label(&self.module, self.intrinsics, format!("local {}", local_index), store); + tbaa_label( + &self.module, + self.intrinsics, + format!("local {}", local_index), + store, + ); } Operator::LocalTee { local_index } => { let pointer_value = self.locals[local_index as usize]; let (v, i) = self.state.peek1_extra()?; let v = self.apply_pending_canonicalization(v, i); let store = self.builder.build_store(pointer_value, v); - tbaa_label(&self.module, self.intrinsics, format!("local {}", local_index), store); + tbaa_label( + &self.module, + self.intrinsics, + format!("local {}", local_index), + store, + ); } Operator::GlobalGet { global_index } => { let global_index = GlobalIndex::from_u32(global_index); - match self.ctx.global(global_index, self.intrinsics, self.module)? { + match self + .ctx + .global(global_index, self.intrinsics, self.module)? + { GlobalCache::Const { value } => { self.state.push1(*value); } @@ -1819,7 +1997,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } Operator::GlobalSet { global_index } => { let global_index = GlobalIndex::from_u32(global_index); - match self.ctx.global(global_index, self.intrinsics, self.module)? { + match self + .ctx + .global(global_index, self.intrinsics, self.module)? + { GlobalCache::Const { value: _ } => { return Err(CompileError::Codegen(format!( "global.set on immutable global index {}", @@ -1888,23 +2069,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let sigindex = &self.wasm_module.functions[func_index]; let func_type = &self.wasm_module.signatures[*sigindex]; - let FunctionCache { func, vmctx: callee_vmctx, attrs } = - if let Some(local_func_index) = self.wasm_module.local_func_index(func_index) { - let function_name = self - .symbol_registry - .symbol_to_name(Symbol::LocalFunction(local_func_index)); - self.ctx.local_func( - local_func_index, - func_index, - self.intrinsics, - self.module, - self.context, - func_type, - &function_name, - )? - } else { - self.ctx.func(func_index, self.intrinsics, self.context, func_type)? - }; + let FunctionCache { + func, + vmctx: callee_vmctx, + attrs, + } = if let Some(local_func_index) = self.wasm_module.local_func_index(func_index) { + let function_name = self + .symbol_registry + .symbol_to_name(Symbol::LocalFunction(local_func_index)); + self.ctx.local_func( + local_func_index, + func_index, + self.intrinsics, + self.module, + self.context, + func_type, + &function_name, + )? + } else { + self.ctx + .func(func_index, self.intrinsics, self.context, func_type)? + }; let func = *func; let callee_vmctx = *callee_vmctx; let attrs = attrs.clone(); @@ -1918,8 +2103,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // Apply pending canonicalizations. let params = - params.iter().zip(func_type.params().iter()).map(|((v, info), wasm_ty)| { - match wasm_ty { + params + .iter() + .zip(func_type.params().iter()) + .map(|((v, info), wasm_ty)| match wasm_ty { Type::F32 => self.builder.build_bitcast( self.apply_pending_canonicalization(*v, *info), self.intrinsics.f32_ty, @@ -1932,8 +2119,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ), Type::V128 => self.apply_pending_canonicalization(*v, *info), _ => *v, - } - }); + }); let params = self.abi.args_to_call( &self.alloca_builder, @@ -1992,9 +2178,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let sigindex = SignatureIndex::from_u32(index); let func_type = &self.wasm_module.signatures[sigindex]; let expected_dynamic_sigindex = - self.ctx.dynamic_sigindex(sigindex, self.intrinsics, self.module); - let (table_base, table_bound) = - self.ctx.table(TableIndex::from_u32(table_index), self.intrinsics, self.module); + self.ctx + .dynamic_sigindex(sigindex, self.intrinsics, self.module); + let (table_base, table_bound) = self.ctx.table( + TableIndex::from_u32(table_index), + self.intrinsics, + self.module, + ); let func_index = self.state.pop1()?.into_int_value(); let truncated_table_bounds = self.builder.build_int_truncate( @@ -2017,7 +2207,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.expect_i1, &[ index_in_bounds.as_basic_value_enum(), - self.intrinsics.i1_ty.const_int(1, false).as_basic_value_enum(), + self.intrinsics + .i1_ty + .const_int(1, false) + .as_basic_value_enum(), ], "index_in_bounds_expect", ) @@ -2026,10 +2219,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap() .into_int_value(); - let in_bounds_continue_block = - self.context.append_basic_block(self.function, "in_bounds_continue_block"); - let not_in_bounds_block = - self.context.append_basic_block(self.function, "not_in_bounds_block"); + let in_bounds_continue_block = self + .context + .append_basic_block(self.function, "in_bounds_continue_block"); + let not_in_bounds_block = self + .context + .append_basic_block(self.function, "not_in_bounds_block"); self.builder.build_conditional_branch( index_in_bounds, in_bounds_continue_block, @@ -2061,20 +2256,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { }; // a funcref (pointer to `anyfunc`) - let anyfunc_struct_ptr = - self.builder.build_load(funcref_ptr, "anyfunc_struct_ptr").into_pointer_value(); + let anyfunc_struct_ptr = self + .builder + .build_load(funcref_ptr, "anyfunc_struct_ptr") + .into_pointer_value(); // trap if we're trying to call a null funcref { - let funcref_not_null = - self.builder.build_is_not_null(anyfunc_struct_ptr, "null funcref check"); + let funcref_not_null = self + .builder + .build_is_not_null(anyfunc_struct_ptr, "null funcref check"); let funcref_continue_deref_block = self .context .append_basic_block(self.function, "funcref_continue deref_block"); - let funcref_is_null_block = - self.context.append_basic_block(self.function, "funcref_is_null_block"); + let funcref_is_null_block = self + .context + .append_basic_block(self.function, "funcref_is_null_block"); self.builder.build_conditional_branch( funcref_not_null, funcref_continue_deref_block, @@ -2131,7 +2330,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ); let initialized_and_sigindices_match = - self.builder.build_and(elem_initialized, sigindices_equal, ""); + self.builder + .build_and(elem_initialized, sigindices_equal, ""); // Tell llvm that `expected_dynamic_sigindex` should equal `found_dynamic_sigindex`. let initialized_and_sigindices_match = self @@ -2140,7 +2340,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.expect_i1, &[ initialized_and_sigindices_match.as_basic_value_enum(), - self.intrinsics.i1_ty.const_int(1, false).as_basic_value_enum(), + self.intrinsics + .i1_ty + .const_int(1, false) + .as_basic_value_enum(), ], "initialized_and_sigindices_match_expect", ) @@ -2149,10 +2352,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .unwrap() .into_int_value(); - let continue_block = - self.context.append_basic_block(self.function, "continue_block"); - let sigindices_notequal_block = - self.context.append_basic_block(self.function, "sigindices_notequal_block"); + let continue_block = self + .context + .append_basic_block(self.function, "continue_block"); + let sigindices_notequal_block = self + .context + .append_basic_block(self.function, "sigindices_notequal_block"); self.builder.build_conditional_branch( initialized_and_sigindices_match, continue_block, @@ -2166,7 +2371,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.trap_call_indirect_null, "", ); - self.builder.build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); + self.builder + .build_call(self.intrinsics.throw_trap, &[trap_code], "throw"); self.builder.build_unreachable(); self.builder.position_at_end(continue_block); @@ -2181,8 +2387,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // Apply pending canonicalizations. let params = - params.iter().zip(func_type.params().iter()).map(|((v, info), wasm_ty)| { - match wasm_ty { + params + .iter() + .zip(func_type.params().iter()) + .map(|((v, info), wasm_ty)| match wasm_ty { Type::F32 => self.builder.build_bitcast( self.apply_pending_canonicalization(*v, *info), self.intrinsics.f32_ty, @@ -2195,8 +2403,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ), Type::V128 => self.apply_pending_canonicalization(*v, *info), _ => *v, - } - }); + }); let params = self.abi.args_to_call( &self.alloca_builder, @@ -2231,7 +2438,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } } */ - let call_site = self.builder.build_call(typed_func_ptr, ¶ms, "indirect_call"); + let call_site = self + .builder + .build_call(typed_func_ptr, ¶ms, "indirect_call"); for (attr, attr_loc) in llvm_func_attrs { call_site.add_attribute(attr_loc, attr); } @@ -2563,7 +2772,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // i32.const 0. We implement this by swapping out the left value // for 0 in this case. let will_overflow = self.builder.build_and( - self.builder.build_int_compare(IntPredicate::EQ, v1, min_value, "left_is_min"), + self.builder + .build_int_compare(IntPredicate::EQ, v1, min_value, "left_is_min"), self.builder.build_int_compare( IntPredicate::EQ, v2, @@ -2669,8 +2879,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i8x16(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); - let v2 = self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i8_ty, ""); + let v2 = self + .builder + .build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i8_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i8x16_ty); let res = self.builder.build_left_shift(v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2682,8 +2896,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i16_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i16_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i16x8_ty); let res = self.builder.build_left_shift(v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2695,7 +2912,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i32x4_ty); let res = self.builder.build_left_shift(v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2707,8 +2925,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); - let v2 = self.builder.build_int_z_extend(v2, self.intrinsics.i64_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); + let v2 = self + .builder + .build_int_z_extend(v2, self.intrinsics.i64_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i64x2_ty); let res = self.builder.build_left_shift(v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2739,8 +2960,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i8x16(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); - let v2 = self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i8_ty, ""); + let v2 = self + .builder + .build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i8_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i8x16_ty); let res = self.builder.build_right_shift(v1, v2, true, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2752,8 +2977,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i16_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i16_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i16x8_ty); let res = self.builder.build_right_shift(v1, v2, true, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2765,7 +2993,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i32x4_ty); let res = self.builder.build_right_shift(v1, v2, true, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2777,8 +3006,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); - let v2 = self.builder.build_int_z_extend(v2, self.intrinsics.i64_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); + let v2 = self + .builder + .build_int_z_extend(v2, self.intrinsics.i64_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i64x2_ty); let res = self.builder.build_right_shift(v1, v2, true, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2809,8 +3041,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i8x16(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); - let v2 = self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i8_ty, ""); + let v2 = self + .builder + .build_and(v2, self.intrinsics.i32_ty.const_int(7, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i8_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i8x16_ty); let res = self.builder.build_right_shift(v1, v2, false, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2822,8 +3058,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i16_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(15, false), ""); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i16_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i16x8_ty); let res = self.builder.build_right_shift(v1, v2, false, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2835,7 +3074,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(31, false), ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i32x4_ty); let res = self.builder.build_right_shift(v1, v2, false, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2847,8 +3087,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let v2 = v2.into_int_value(); let v2 = - self.builder.build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); - let v2 = self.builder.build_int_z_extend(v2, self.intrinsics.i64_ty, ""); + self.builder + .build_and(v2, self.intrinsics.i32_ty.const_int(63, false), ""); + let v2 = self + .builder + .build_int_z_extend(v2, self.intrinsics.i64_ty, ""); let v2 = self.splat_vector(v2.as_basic_value_enum(), self.intrinsics.i64x2_ty); let res = self.builder.build_right_shift(v1, v2, false, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); @@ -2996,7 +3239,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_zero, "", ); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); self.state.push1_extra(res, ExtraInfo::arithmetic_f32()); } Operator::I64Eqz => { @@ -3007,7 +3252,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i64_zero, "", ); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); self.state.push1_extra(res, ExtraInfo::arithmetic_f64()); } Operator::I8x16Abs => { @@ -3050,7 +3297,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3059,7 +3308,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3068,7 +3319,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3077,7 +3330,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3086,7 +3341,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3095,7 +3352,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3104,7 +3363,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3113,7 +3374,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3122,7 +3385,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3131,7 +3396,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3140,7 +3407,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3149,7 +3418,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let cmp = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); + let cmp = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); let res = self.builder.build_select(cmp, v1, v2, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); @@ -3176,9 +3447,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.builder.build_int_z_extend(v1, ext_ty, ""); let v2 = self.builder.build_int_z_extend(v2, ext_ty, ""); let res = - self.builder.build_int_add(self.builder.build_int_add(one, v1, ""), v2, ""); + self.builder + .build_int_add(self.builder.build_int_add(one, v1, ""), v2, ""); let res = self.builder.build_right_shift(res, one, false, ""); - let res = self.builder.build_int_truncate(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_truncate(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -3204,9 +3478,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.builder.build_int_z_extend(v1, ext_ty, ""); let v2 = self.builder.build_int_z_extend(v2, ext_ty, ""); let res = - self.builder.build_int_add(self.builder.build_int_add(one, v1, ""), v2, ""); + self.builder + .build_int_add(self.builder.build_int_add(one, v1, ""), v2, ""); let res = self.builder.build_right_shift(res, one, false, ""); - let res = self.builder.build_int_truncate(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_truncate(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -3392,7 +3669,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - let bits = self.builder.build_bitcast(res, self.intrinsics.i128_ty, "bits"); + let bits = self + .builder + .build_bitcast(res, self.intrinsics.i128_ty, "bits"); self.state.push1_extra(bits, ExtraInfo::pending_f32_nan()); } Operator::F64x2Sqrt => { @@ -3404,7 +3683,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - let bits = self.builder.build_bitcast(res, self.intrinsics.i128_ty, "bits"); + let bits = self + .builder + .build_bitcast(res, self.intrinsics.i128_ty, "bits"); self.state.push1(bits); } Operator::F32Min => { @@ -3433,14 +3714,23 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.f32_zero, "notnan", ); - let v1_repr = - self.builder.build_bitcast(v1, self.intrinsics.i32_ty, "").into_int_value(); - let v2_repr = - self.builder.build_bitcast(v2, self.intrinsics.i32_ty, "").into_int_value(); + let v1_repr = self + .builder + .build_bitcast(v1, self.intrinsics.i32_ty, "") + .into_int_value(); + let v2_repr = self + .builder + .build_bitcast(v2, self.intrinsics.i32_ty, "") + .into_int_value(); let repr_ne = - self.builder.build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); - let float_eq = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let min_cmp = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); + self.builder + .build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); + let float_eq = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let min_cmp = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); let negative_zero = self.intrinsics.f32_ty.const_float(-0.0); let v2 = self .builder @@ -3491,14 +3781,23 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.f64_zero, "notnan", ); - let v1_repr = - self.builder.build_bitcast(v1, self.intrinsics.i64_ty, "").into_int_value(); - let v2_repr = - self.builder.build_bitcast(v2, self.intrinsics.i64_ty, "").into_int_value(); + let v1_repr = self + .builder + .build_bitcast(v1, self.intrinsics.i64_ty, "") + .into_int_value(); + let v2_repr = self + .builder + .build_bitcast(v2, self.intrinsics.i64_ty, "") + .into_int_value(); let repr_ne = - self.builder.build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); - let float_eq = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let min_cmp = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); + self.builder + .build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); + let float_eq = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let min_cmp = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); let negative_zero = self.intrinsics.f64_ty.const_float(-0.0); let v2 = self .builder @@ -3538,12 +3837,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, i1) = self.v128_into_f32x4(v1, i1); let (v2, i2) = self.v128_into_f32x4(v2, i2); let v1 = if !i1.is_arithmetic_f32() { - self.canonicalize_nans(v1.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v1.as_basic_value_enum()) + .into_vector_value() } else { v1 }; let v2 = if !i2.is_arithmetic_f32() { - self.canonicalize_nans(v2.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v2.as_basic_value_enum()) + .into_vector_value() } else { v2 }; @@ -3575,7 +3876,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.copysign_f32x4, &[ VectorType::const_vector( - &[self.intrinsics.f32_ty.const_float(1.0).as_basic_value_enum(); + &[self + .intrinsics + .f32_ty + .const_float(1.0) + .as_basic_value_enum(); 4], ) .as_basic_value_enum(), @@ -3591,7 +3896,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "v1neg", ); - let v1_lt_v2 = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); + let v1_lt_v2 = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); let pick_v1 = self.builder.build_or( v1_is_nan, @@ -3626,12 +3933,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, i1) = self.v128_into_f64x2(v1, i1); let (v2, i2) = self.v128_into_f64x2(v2, i2); let v1 = if !i1.is_arithmetic_f64() { - self.canonicalize_nans(v1.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v1.as_basic_value_enum()) + .into_vector_value() } else { v1 }; let v2 = if !i2.is_arithmetic_f64() { - self.canonicalize_nans(v2.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v2.as_basic_value_enum()) + .into_vector_value() } else { v2 }; @@ -3663,7 +3972,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.copysign_f64x2, &[ VectorType::const_vector( - &[self.intrinsics.f64_ty.const_float(1.0).as_basic_value_enum(); + &[self + .intrinsics + .f64_ty + .const_float(1.0) + .as_basic_value_enum(); 2], ) .as_basic_value_enum(), @@ -3679,7 +3992,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "v1neg", ); - let v1_lt_v2 = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); + let v1_lt_v2 = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); let pick_v1 = self.builder.build_or( v1_is_nan, @@ -3725,14 +4040,23 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.f32_zero, "notnan", ); - let v1_repr = - self.builder.build_bitcast(v1, self.intrinsics.i32_ty, "").into_int_value(); - let v2_repr = - self.builder.build_bitcast(v2, self.intrinsics.i32_ty, "").into_int_value(); + let v1_repr = self + .builder + .build_bitcast(v1, self.intrinsics.i32_ty, "") + .into_int_value(); + let v2_repr = self + .builder + .build_bitcast(v2, self.intrinsics.i32_ty, "") + .into_int_value(); let repr_ne = - self.builder.build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); - let float_eq = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let min_cmp = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); + self.builder + .build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); + let float_eq = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let min_cmp = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); let v2 = self .builder .build_select( @@ -3782,14 +4106,23 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.f64_zero, "notnan", ); - let v1_repr = - self.builder.build_bitcast(v1, self.intrinsics.i64_ty, "").into_int_value(); - let v2_repr = - self.builder.build_bitcast(v2, self.intrinsics.i64_ty, "").into_int_value(); + let v1_repr = self + .builder + .build_bitcast(v1, self.intrinsics.i64_ty, "") + .into_int_value(); + let v2_repr = self + .builder + .build_bitcast(v2, self.intrinsics.i64_ty, "") + .into_int_value(); let repr_ne = - self.builder.build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); - let float_eq = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let min_cmp = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); + self.builder + .build_int_compare(IntPredicate::NE, v1_repr, v2_repr, ""); + let float_eq = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let min_cmp = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); let v2 = self .builder .build_select( @@ -3828,12 +4161,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, i1) = self.v128_into_f32x4(v1, i1); let (v2, i2) = self.v128_into_f32x4(v2, i2); let v1 = if !i1.is_arithmetic_f32() { - self.canonicalize_nans(v1.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v1.as_basic_value_enum()) + .into_vector_value() } else { v1 }; let v2 = if !i2.is_arithmetic_f32() { - self.canonicalize_nans(v2.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v2.as_basic_value_enum()) + .into_vector_value() } else { v2 }; @@ -3865,7 +4200,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.copysign_f32x4, &[ VectorType::const_vector( - &[self.intrinsics.f32_ty.const_float(1.0).as_basic_value_enum(); + &[self + .intrinsics + .f32_ty + .const_float(1.0) + .as_basic_value_enum(); 4], ) .as_basic_value_enum(), @@ -3881,7 +4220,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "v2neg", ); - let v1_gt_v2 = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); + let v1_gt_v2 = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); let pick_v1 = self.builder.build_or( v1_is_nan, @@ -3916,12 +4257,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, i1) = self.v128_into_f64x2(v1, i1); let (v2, i2) = self.v128_into_f64x2(v2, i2); let v1 = if !i1.is_arithmetic_f64() { - self.canonicalize_nans(v1.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v1.as_basic_value_enum()) + .into_vector_value() } else { v1 }; let v2 = if !i2.is_arithmetic_f64() { - self.canonicalize_nans(v2.as_basic_value_enum()).into_vector_value() + self.canonicalize_nans(v2.as_basic_value_enum()) + .into_vector_value() } else { v2 }; @@ -3953,7 +4296,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.copysign_f64x2, &[ VectorType::const_vector( - &[self.intrinsics.f64_ty.const_float(1.0).as_basic_value_enum(); + &[self + .intrinsics + .f64_ty + .const_float(1.0) + .as_basic_value_enum(); 2], ) .as_basic_value_enum(), @@ -3969,7 +4316,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "v2neg", ); - let v1_gt_v2 = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); + let v1_gt_v2 = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); let pick_v1 = self.builder.build_or( v1_is_nan, @@ -3997,7 +4346,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, info | ExtraInfo::pending_f32_nan()); + self.state + .push1_extra(res, info | ExtraInfo::pending_f32_nan()); } Operator::F64Ceil => { let (input, info) = self.state.pop1_extra()?; @@ -4007,7 +4357,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, info | ExtraInfo::pending_f64_nan()); + self.state + .push1_extra(res, info | ExtraInfo::pending_f64_nan()); } Operator::F32Floor => { let (input, info) = self.state.pop1_extra()?; @@ -4017,7 +4368,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, info | ExtraInfo::pending_f32_nan()); + self.state + .push1_extra(res, info | ExtraInfo::pending_f32_nan()); } Operator::F64Floor => { let (input, info) = self.state.pop1_extra()?; @@ -4027,7 +4379,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, info | ExtraInfo::pending_f64_nan()); + self.state + .push1_extra(res, info | ExtraInfo::pending_f64_nan()); } Operator::F32Trunc => { let (v, i) = self.state.pop1_extra()?; @@ -4037,7 +4390,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, i | ExtraInfo::pending_f32_nan()); + self.state + .push1_extra(res, i | ExtraInfo::pending_f32_nan()); } Operator::F64Trunc => { let (v, i) = self.state.pop1_extra()?; @@ -4047,27 +4401,38 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, i | ExtraInfo::pending_f64_nan()); + self.state + .push1_extra(res, i | ExtraInfo::pending_f64_nan()); } Operator::F32Nearest => { let (v, i) = self.state.pop1_extra()?; let res = self .builder - .build_call(self.intrinsics.nearbyint_f32, &[v.as_basic_value_enum()], "") + .build_call( + self.intrinsics.nearbyint_f32, + &[v.as_basic_value_enum()], + "", + ) .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, i | ExtraInfo::pending_f32_nan()); + self.state + .push1_extra(res, i | ExtraInfo::pending_f32_nan()); } Operator::F64Nearest => { let (v, i) = self.state.pop1_extra()?; let res = self .builder - .build_call(self.intrinsics.nearbyint_f64, &[v.as_basic_value_enum()], "") + .build_call( + self.intrinsics.nearbyint_f64, + &[v.as_basic_value_enum()], + "", + ) .try_as_basic_value() .left() .unwrap(); - self.state.push1_extra(res, i | ExtraInfo::pending_f64_nan()); + self.state + .push1_extra(res, i | ExtraInfo::pending_f64_nan()); } Operator::F32Abs => { let (v, i) = self.state.pop1_extra()?; @@ -4098,7 +4463,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F32x4Abs => { let (v, i) = self.state.pop1_extra()?; let v = - self.builder.build_bitcast(v.into_int_value(), self.intrinsics.f32x4_ty, ""); + self.builder + .build_bitcast(v.into_int_value(), self.intrinsics.f32x4_ty, ""); let v = self.apply_pending_canonicalization(v, i); let res = self .builder @@ -4114,7 +4480,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F64x2Abs => { let (v, i) = self.state.pop1_extra()?; let v = - self.builder.build_bitcast(v.into_int_value(), self.intrinsics.f64x2_ty, ""); + self.builder + .build_bitcast(v.into_int_value(), self.intrinsics.f64x2_ty, ""); let v = self.apply_pending_canonicalization(v, i); let res = self .builder @@ -4130,8 +4497,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F32x4Neg => { let (v, i) = self.state.pop1_extra()?; let v = - self.builder.build_bitcast(v.into_int_value(), self.intrinsics.f32x4_ty, ""); - let v = self.apply_pending_canonicalization(v, i).into_vector_value(); + self.builder + .build_bitcast(v.into_int_value(), self.intrinsics.f32x4_ty, ""); + let v = self + .apply_pending_canonicalization(v, i) + .into_vector_value(); let res = self.builder.build_float_neg(v, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); // The exact NaN returned by F32x4Neg is fully defined. Do not @@ -4141,8 +4511,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F64x2Neg => { let (v, i) = self.state.pop1_extra()?; let v = - self.builder.build_bitcast(v.into_int_value(), self.intrinsics.f64x2_ty, ""); - let v = self.apply_pending_canonicalization(v, i).into_vector_value(); + self.builder + .build_bitcast(v.into_int_value(), self.intrinsics.f64x2_ty, ""); + let v = self + .apply_pending_canonicalization(v, i) + .into_vector_value(); let res = self.builder.build_float_neg(v, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); // The exact NaN returned by F64x2Neg is fully defined. Do not @@ -4196,16 +4569,22 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); let cond = self.builder.build_int_compare(IntPredicate::EQ, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16Eq => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); let res = self.builder.build_int_compare(IntPredicate::EQ, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4214,7 +4593,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); let res = self.builder.build_int_compare(IntPredicate::EQ, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4223,7 +4604,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); let res = self.builder.build_int_compare(IntPredicate::EQ, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4233,16 +4616,22 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); let cond = self.builder.build_int_compare(IntPredicate::NE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16Ne => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); let res = self.builder.build_int_compare(IntPredicate::NE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4251,7 +4640,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); let res = self.builder.build_int_compare(IntPredicate::NE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4260,7 +4651,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); let res = self.builder.build_int_compare(IntPredicate::NE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4269,17 +4662,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16LtS => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4287,8 +4690,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4296,8 +4703,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4306,16 +4717,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + let cond = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I8x16LtU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4323,8 +4742,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4332,8 +4755,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4342,17 +4769,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::SLE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::SLE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16LeS => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4360,8 +4797,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4369,8 +4810,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SLE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SLE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4379,17 +4824,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::ULE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::ULE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16LeU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4397,8 +4852,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4406,8 +4865,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::ULE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::ULE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4416,17 +4879,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16GtS => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4434,8 +4907,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4443,8 +4920,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4453,17 +4934,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16GtU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4471,8 +4962,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4480,8 +4975,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4490,16 +4989,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::SGE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + let cond = self + .builder + .build_int_compare(IntPredicate::SGE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I8x16GeS => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4507,8 +5014,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4516,8 +5027,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::SGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::SGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4526,17 +5041,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let v1 = self.apply_pending_canonicalization(v1, i1); let v2 = self.apply_pending_canonicalization(v2, i2); let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); - let cond = self.builder.build_int_compare(IntPredicate::UGE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_int_compare(IntPredicate::UGE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16GeU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i8x16_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4544,8 +5069,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4553,8 +5082,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i32x4(v1, i1); let (v2, _) = self.v128_into_i32x4(v2, i2); - let res = self.builder.build_int_compare(IntPredicate::UGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_compare(IntPredicate::UGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4566,17 +5099,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F32Eq | Operator::F64Eq => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Eq => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4584,25 +5127,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OEQ, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OEQ, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32Ne | Operator::F64Ne => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::UNE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::UNE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Ne => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::UNE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::UNE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4610,25 +5167,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::UNE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::UNE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32Lt | Operator::F64Lt => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Lt => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4636,25 +5207,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OLT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OLT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32Le | Operator::F64Le => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::OLE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::OLE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Le => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OLE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OLE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4662,25 +5247,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OLE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OLE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32Gt | Operator::F64Gt => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Gt => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4688,25 +5287,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OGT, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OGT, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32Ge | Operator::F64Ge => { let (v1, v2) = self.state.pop2()?; let (v1, v2) = (v1.into_float_value(), v2.into_float_value()); - let cond = self.builder.build_float_compare(FloatPredicate::OGE, v1, v2, ""); - let res = self.builder.build_int_z_extend(cond, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let cond = self + .builder + .build_float_compare(FloatPredicate::OGE, v1, v2, ""); + let res = self + .builder + .build_int_z_extend(cond, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::F32x4Ge => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f32x4(v1, i1); let (v2, _) = self.v128_into_f32x4(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4714,8 +5327,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_f64x2(v1, i1); let (v2, _) = self.v128_into_f64x2(v2, i2); - let res = self.builder.build_float_compare(FloatPredicate::OGE, v1, v2, ""); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_float_compare(FloatPredicate::OGE, v1, v2, ""); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4728,21 +5345,27 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_int_truncate(v, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_int_truncate(v, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I64ExtendI32S => { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_int_s_extend(v, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_int_s_extend(v, self.intrinsics.i64_ty, ""); self.state.push1(res); } Operator::I64ExtendI32U => { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_int_z_extend(v, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_int_z_extend(v, self.intrinsics.i64_ty, ""); self.state.push1_extra(res, ExtraInfo::arithmetic_f64()); } Operator::I16x8WidenLowI8x16S => { @@ -4763,7 +5386,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_s_extend(low, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_s_extend(low, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4785,7 +5410,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_s_extend(low, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_s_extend(low, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4807,7 +5434,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_z_extend(low, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_z_extend(low, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4829,7 +5458,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_z_extend(low, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_z_extend(low, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4847,7 +5478,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_s_extend(low, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_s_extend(low, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4865,7 +5498,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_s_extend(low, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_s_extend(low, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4883,7 +5518,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_z_extend(low, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_z_extend(low, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4901,7 +5538,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ]), "", ); - let res = self.builder.build_int_z_extend(low, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_z_extend(low, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -4914,23 +5553,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let min = VectorType::const_vector(&[min; 8]); let max = VectorType::const_vector(&[max; 8]); let apply_min_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SLT, v1, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v1, min, ""); let apply_max_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SGT, v1, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v1, max, ""); let apply_min_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SLT, v2, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v2, min, ""); let apply_max_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SGT, v2, max, ""); - let v1 = - self.builder.build_select(apply_min_clamp_v1, min, v1, "").into_vector_value(); - let v1 = - self.builder.build_select(apply_max_clamp_v1, max, v1, "").into_vector_value(); - let v1 = self.builder.build_int_truncate(v1, self.intrinsics.i8_ty.vec_type(8), ""); - let v2 = - self.builder.build_select(apply_min_clamp_v2, min, v2, "").into_vector_value(); - let v2 = - self.builder.build_select(apply_max_clamp_v2, max, v2, "").into_vector_value(); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i8_ty.vec_type(8), ""); + self.builder + .build_int_compare(IntPredicate::SGT, v2, max, ""); + let v1 = self + .builder + .build_select(apply_min_clamp_v1, min, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_select(apply_max_clamp_v1, max, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_int_truncate(v1, self.intrinsics.i8_ty.vec_type(8), ""); + let v2 = self + .builder + .build_select(apply_min_clamp_v2, min, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_select(apply_max_clamp_v2, max, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i8_ty.vec_type(8), ""); let res = self.builder.build_shuffle_vector( v1, v2, @@ -4965,23 +5620,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let max = self.intrinsics.i16_ty.const_int(0x00ff, false); let max = VectorType::const_vector(&[max; 8]); let apply_min_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SLT, v1, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v1, min, ""); let apply_max_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SGT, v1, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v1, max, ""); let apply_min_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SLT, v2, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v2, min, ""); let apply_max_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SGT, v2, max, ""); - let v1 = - self.builder.build_select(apply_min_clamp_v1, min, v1, "").into_vector_value(); - let v1 = - self.builder.build_select(apply_max_clamp_v1, max, v1, "").into_vector_value(); - let v1 = self.builder.build_int_truncate(v1, self.intrinsics.i8_ty.vec_type(8), ""); - let v2 = - self.builder.build_select(apply_min_clamp_v2, min, v2, "").into_vector_value(); - let v2 = - self.builder.build_select(apply_max_clamp_v2, max, v2, "").into_vector_value(); - let v2 = self.builder.build_int_truncate(v2, self.intrinsics.i8_ty.vec_type(8), ""); + self.builder + .build_int_compare(IntPredicate::SGT, v2, max, ""); + let v1 = self + .builder + .build_select(apply_min_clamp_v1, min, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_select(apply_max_clamp_v1, max, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_int_truncate(v1, self.intrinsics.i8_ty.vec_type(8), ""); + let v2 = self + .builder + .build_select(apply_min_clamp_v2, min, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_select(apply_max_clamp_v2, max, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_int_truncate(v2, self.intrinsics.i8_ty.vec_type(8), ""); let res = self.builder.build_shuffle_vector( v1, v2, @@ -5017,25 +5688,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let min = VectorType::const_vector(&[min; 4]); let max = VectorType::const_vector(&[max; 4]); let apply_min_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SLT, v1, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v1, min, ""); let apply_max_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SGT, v1, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v1, max, ""); let apply_min_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SLT, v2, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v2, min, ""); let apply_max_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SGT, v2, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v2, max, ""); + let v1 = self + .builder + .build_select(apply_min_clamp_v1, min, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_select(apply_max_clamp_v1, max, v1, "") + .into_vector_value(); let v1 = - self.builder.build_select(apply_min_clamp_v1, min, v1, "").into_vector_value(); - let v1 = - self.builder.build_select(apply_max_clamp_v1, max, v1, "").into_vector_value(); - let v1 = - self.builder.build_int_truncate(v1, self.intrinsics.i16_ty.vec_type(4), ""); + self.builder + .build_int_truncate(v1, self.intrinsics.i16_ty.vec_type(4), ""); + let v2 = self + .builder + .build_select(apply_min_clamp_v2, min, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_select(apply_max_clamp_v2, max, v2, "") + .into_vector_value(); let v2 = - self.builder.build_select(apply_min_clamp_v2, min, v2, "").into_vector_value(); - let v2 = - self.builder.build_select(apply_max_clamp_v2, max, v2, "").into_vector_value(); - let v2 = - self.builder.build_int_truncate(v2, self.intrinsics.i16_ty.vec_type(4), ""); + self.builder + .build_int_truncate(v2, self.intrinsics.i16_ty.vec_type(4), ""); let res = self.builder.build_shuffle_vector( v1, v2, @@ -5062,25 +5747,39 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let max = self.intrinsics.i32_ty.const_int(0xffff, false); let max = VectorType::const_vector(&[max; 4]); let apply_min_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SLT, v1, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v1, min, ""); let apply_max_clamp_v1 = - self.builder.build_int_compare(IntPredicate::SGT, v1, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v1, max, ""); let apply_min_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SLT, v2, min, ""); + self.builder + .build_int_compare(IntPredicate::SLT, v2, min, ""); let apply_max_clamp_v2 = - self.builder.build_int_compare(IntPredicate::SGT, v2, max, ""); + self.builder + .build_int_compare(IntPredicate::SGT, v2, max, ""); + let v1 = self + .builder + .build_select(apply_min_clamp_v1, min, v1, "") + .into_vector_value(); + let v1 = self + .builder + .build_select(apply_max_clamp_v1, max, v1, "") + .into_vector_value(); let v1 = - self.builder.build_select(apply_min_clamp_v1, min, v1, "").into_vector_value(); - let v1 = - self.builder.build_select(apply_max_clamp_v1, max, v1, "").into_vector_value(); - let v1 = - self.builder.build_int_truncate(v1, self.intrinsics.i16_ty.vec_type(4), ""); + self.builder + .build_int_truncate(v1, self.intrinsics.i16_ty.vec_type(4), ""); + let v2 = self + .builder + .build_select(apply_min_clamp_v2, min, v2, "") + .into_vector_value(); + let v2 = self + .builder + .build_select(apply_max_clamp_v2, max, v2, "") + .into_vector_value(); let v2 = - self.builder.build_select(apply_min_clamp_v2, min, v2, "").into_vector_value(); - let v2 = - self.builder.build_select(apply_max_clamp_v2, max, v2, "").into_vector_value(); - let v2 = - self.builder.build_int_truncate(v2, self.intrinsics.i16_ty.vec_type(4), ""); + self.builder + .build_int_truncate(v2, self.intrinsics.i16_ty.vec_type(4), ""); let res = self.builder.build_shuffle_vector( v1, v2, @@ -5166,7 +5865,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x4effffff, // 2147483500.0 v1, ); - let res = self.builder.build_float_to_signed_int(v1, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_float_to_signed_int(v1, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I32TruncF64S => { @@ -5176,7 +5877,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x41dfffffffffffff, // 2147483647.9999998 v1, ); - let res = self.builder.build_float_to_signed_int(v1, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_float_to_signed_int(v1, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I32TruncSatF32S => { @@ -5214,7 +5917,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x5effffff, // 9223371500000000000.0 v1, ); - let res = self.builder.build_float_to_signed_int(v1, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_float_to_signed_int(v1, self.intrinsics.i64_ty, ""); self.state.push1(res); } Operator::I64TruncF64S => { @@ -5224,7 +5929,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x43dfffffffffffff, // 9223372036854775000.0 v1, ); - let res = self.builder.build_float_to_signed_int(v1, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_float_to_signed_int(v1, self.intrinsics.i64_ty, ""); self.state.push1(res); } Operator::I64TruncSatF32S => { @@ -5262,7 +5969,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x4f7fffff, // 4294967000.0 v1, ); - let res = self.builder.build_float_to_unsigned_int(v1, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_float_to_unsigned_int(v1, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I32TruncF64U => { @@ -5272,7 +5981,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x41efffffffffffff, // 4294967295.9999995 v1, ); - let res = self.builder.build_float_to_unsigned_int(v1, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_float_to_unsigned_int(v1, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I32TruncSatF32U => { @@ -5310,7 +6021,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x5f7fffff, // 18446743000000000000.0 v1, ); - let res = self.builder.build_float_to_unsigned_int(v1, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_float_to_unsigned_int(v1, self.intrinsics.i64_ty, ""); self.state.push1(res); } Operator::I64TruncF64U => { @@ -5320,7 +6033,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0x43efffffffffffff, // 18446744073709550000.0 v1, ); - let res = self.builder.build_float_to_unsigned_int(v1, self.intrinsics.i64_ty, ""); + let res = self + .builder + .build_float_to_unsigned_int(v1, self.intrinsics.i64_ty, ""); self.state.push1(res); } Operator::I64TruncSatF32U => { @@ -5354,7 +6069,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::F32DemoteF64 => { let v = self.state.pop1()?; let v = v.into_float_value(); - let res = self.builder.build_float_trunc(v, self.intrinsics.f32_ty, ""); + let res = self + .builder + .build_float_trunc(v, self.intrinsics.f32_ty, ""); self.state.push1_extra(res, ExtraInfo::pending_f32_nan()); } Operator::F64PromoteF32 => { @@ -5367,43 +6084,59 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_signed_int_to_float(v, self.intrinsics.f32_ty, ""); + let res = self + .builder + .build_signed_int_to_float(v, self.intrinsics.f32_ty, ""); self.state.push1(res); } Operator::F64ConvertI32S | Operator::F64ConvertI64S => { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_signed_int_to_float(v, self.intrinsics.f64_ty, ""); + let res = self + .builder + .build_signed_int_to_float(v, self.intrinsics.f64_ty, ""); self.state.push1(res); } Operator::F32ConvertI32U | Operator::F32ConvertI64U => { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_unsigned_int_to_float(v, self.intrinsics.f32_ty, ""); + let res = self + .builder + .build_unsigned_int_to_float(v, self.intrinsics.f32_ty, ""); self.state.push1(res); } Operator::F64ConvertI32U | Operator::F64ConvertI64U => { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i); let v = v.into_int_value(); - let res = self.builder.build_unsigned_int_to_float(v, self.intrinsics.f64_ty, ""); + let res = self + .builder + .build_unsigned_int_to_float(v, self.intrinsics.f64_ty, ""); self.state.push1(res); } Operator::F32x4ConvertI32x4S => { let v = self.state.pop1()?; - let v = - self.builder.build_bitcast(v, self.intrinsics.i32x4_ty, "").into_vector_value(); - let res = self.builder.build_signed_int_to_float(v, self.intrinsics.f32x4_ty, ""); + let v = self + .builder + .build_bitcast(v, self.intrinsics.i32x4_ty, "") + .into_vector_value(); + let res = self + .builder + .build_signed_int_to_float(v, self.intrinsics.f32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } Operator::F32x4ConvertI32x4U => { let v = self.state.pop1()?; - let v = - self.builder.build_bitcast(v, self.intrinsics.i32x4_ty, "").into_vector_value(); - let res = self.builder.build_unsigned_int_to_float(v, self.intrinsics.f32x4_ty, ""); + let v = self + .builder + .build_bitcast(v, self.intrinsics.i32x4_ty, "") + .into_vector_value(); + let res = self + .builder + .build_unsigned_int_to_float(v, self.intrinsics.f32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -5461,41 +6194,51 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::I32Extend8S => { let value = self.state.pop1()?.into_int_value(); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let extended_value = - self.builder.build_int_s_extend(narrow_value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_s_extend(narrow_value, self.intrinsics.i32_ty, ""); self.state.push1(extended_value); } Operator::I32Extend16S => { let value = self.state.pop1()?.into_int_value(); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let extended_value = - self.builder.build_int_s_extend(narrow_value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_s_extend(narrow_value, self.intrinsics.i32_ty, ""); self.state.push1(extended_value); } Operator::I64Extend8S => { let value = self.state.pop1()?.into_int_value(); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let extended_value = - self.builder.build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); + self.builder + .build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); self.state.push1(extended_value); } Operator::I64Extend16S => { let value = self.state.pop1()?.into_int_value(); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let extended_value = - self.builder.build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); + self.builder + .build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); self.state.push1(extended_value); } Operator::I64Extend32S => { let value = self.state.pop1()?.into_int_value(); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let extended_value = - self.builder.build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); + self.builder + .build_int_s_extend(narrow_value, self.intrinsics.i64_ty, ""); self.state.push1(extended_value); } @@ -5765,7 +6508,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { offset, 1, )?; - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); self.annotate_user_memaccess( memory_index, memarg, @@ -5773,7 +6519,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { narrow_result.as_instruction_value().unwrap(), )?; let result = - self.builder.build_int_s_extend(narrow_result, self.intrinsics.i64_ty, ""); + self.builder + .build_int_s_extend(narrow_result, self.intrinsics.i64_ty, ""); self.state.push1(result); } Operator::I64Load16S { ref memarg } => { @@ -5786,7 +6533,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { offset, 2, )?; - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); self.annotate_user_memaccess( memory_index, memarg, @@ -5794,7 +6544,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { narrow_result.as_instruction_value().unwrap(), )?; let result = - self.builder.build_int_s_extend(narrow_result, self.intrinsics.i64_ty, ""); + self.builder + .build_int_s_extend(narrow_result, self.intrinsics.i64_ty, ""); self.state.push1(result); } Operator::I64Load32S { ref memarg } => { @@ -5962,7 +6713,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { dead_load.as_instruction_value().unwrap(), )?; let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 1, store)?; } @@ -5985,7 +6737,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { dead_load.as_instruction_value().unwrap(), )?; let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 1, store)?; } @@ -6008,7 +6761,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { dead_load.as_instruction_value().unwrap(), )?; let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 1, store)?; } @@ -6056,9 +6810,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { v.get_type().const_zero(), "", ); - let res = self.builder.build_int_z_extend(res, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let res = self + .builder + .build_int_z_extend(res, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16AllTrue | Operator::I16x8AllTrue | Operator::I32x4AllTrue => { // | Operator::I64x2AllTrue @@ -6072,54 +6830,84 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v, i) = self.state.pop1_extra()?; let v = self.apply_pending_canonicalization(v, i).into_int_value(); let lane_int_ty = self.context.custom_width_int_type(vec_ty.get_size()); - let vec = self.builder.build_bitcast(v, vec_ty, "vec").into_vector_value(); + let vec = self + .builder + .build_bitcast(v, vec_ty, "vec") + .into_vector_value(); let mask = self.builder.build_int_compare( IntPredicate::NE, vec, vec_ty.const_zero(), "mask", ); - let cmask = self.builder.build_bitcast(mask, lane_int_ty, "cmask").into_int_value(); + let cmask = self + .builder + .build_bitcast(mask, lane_int_ty, "cmask") + .into_int_value(); let res = self.builder.build_int_compare( IntPredicate::EQ, cmask, lane_int_ty.const_int(std::u64::MAX, true), "", ); - let res = self.builder.build_int_z_extend(res, self.intrinsics.i32_ty, ""); - self.state - .push1_extra(res, ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64()); + let res = self + .builder + .build_int_z_extend(res, self.intrinsics.i32_ty, ""); + self.state.push1_extra( + res, + ExtraInfo::arithmetic_f32() | ExtraInfo::arithmetic_f64(), + ); } Operator::I8x16ExtractLaneS { lane } => { let (v, i) = self.state.pop1_extra()?; let (v, _) = self.v128_into_i8x16(v, i); let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); - let res = self.builder.build_extract_element(v, idx, "").into_int_value(); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_extract_element(v, idx, "") + .into_int_value(); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I8x16ExtractLaneU { lane } => { let (v, i) = self.state.pop1_extra()?; let (v, _) = self.v128_into_i8x16(v, i); let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); - let res = self.builder.build_extract_element(v, idx, "").into_int_value(); - let res = self.builder.build_int_z_extend(res, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_extract_element(v, idx, "") + .into_int_value(); + let res = self + .builder + .build_int_z_extend(res, self.intrinsics.i32_ty, ""); self.state.push1_extra(res, ExtraInfo::arithmetic_f32()); } Operator::I16x8ExtractLaneS { lane } => { let (v, i) = self.state.pop1_extra()?; let (v, _) = self.v128_into_i16x8(v, i); let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); - let res = self.builder.build_extract_element(v, idx, "").into_int_value(); - let res = self.builder.build_int_s_extend(res, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_extract_element(v, idx, "") + .into_int_value(); + let res = self + .builder + .build_int_s_extend(res, self.intrinsics.i32_ty, ""); self.state.push1(res); } Operator::I16x8ExtractLaneU { lane } => { let (v, i) = self.state.pop1_extra()?; let (v, _) = self.v128_into_i16x8(v, i); let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); - let res = self.builder.build_extract_element(v, idx, "").into_int_value(); - let res = self.builder.build_int_z_extend(res, self.intrinsics.i32_ty, ""); + let res = self + .builder + .build_extract_element(v, idx, "") + .into_int_value(); + let res = self + .builder + .build_int_z_extend(res, self.intrinsics.i32_ty, ""); self.state.push1_extra(res, ExtraInfo::arithmetic_f32()); } Operator::I32x4ExtractLane { lane } => { @@ -6179,7 +6967,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); let res = self.builder.build_insert_element(v1, v2, idx, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); - self.state.push1_extra(res, i1 & i2 & ExtraInfo::arithmetic_f32()); + self.state + .push1_extra(res, i1 & i2 & ExtraInfo::arithmetic_f32()); } Operator::I64x2ReplaceLane { lane } => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; @@ -6190,7 +6979,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let idx = self.intrinsics.i32_ty.const_int(lane.into(), false); let res = self.builder.build_insert_element(v1, v2, idx, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); - self.state.push1_extra(res, i1 & i2 & ExtraInfo::arithmetic_f64()); + self.state + .push1_extra(res, i1 & i2 & ExtraInfo::arithmetic_f64()); } Operator::F32x4ReplaceLane { lane } => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; @@ -6290,7 +7080,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "replace_with_zero", ) .into_int_value(); - let elem = self.builder.build_extract_element(v1, idx, "elem").into_int_value(); + let elem = self + .builder + .build_extract_element(v1, idx, "elem") + .into_int_value(); let elem_or_zero = self.builder.build_select( replace_with_zero, self.intrinsics.i8_zero, @@ -6345,7 +7138,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i8_ty.vec_type(8), "") .into_vector_value(); - let res = self.builder.build_int_s_extend(v, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_s_extend(v, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6364,7 +7159,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i8_ty.vec_type(8), "") .into_vector_value(); - let res = self.builder.build_int_z_extend(v, self.intrinsics.i16x8_ty, ""); + let res = self + .builder + .build_int_z_extend(v, self.intrinsics.i16x8_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6383,7 +7180,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i16_ty.vec_type(4), "") .into_vector_value(); - let res = self.builder.build_int_s_extend(v, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_s_extend(v, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6402,7 +7201,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i16_ty.vec_type(4), "") .into_vector_value(); - let res = self.builder.build_int_z_extend(v, self.intrinsics.i32x4_ty, ""); + let res = self + .builder + .build_int_z_extend(v, self.intrinsics.i32x4_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6421,7 +7222,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i32_ty.vec_type(2), "") .into_vector_value(); - let res = self.builder.build_int_s_extend(v, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_int_s_extend(v, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6440,7 +7243,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .builder .build_bitcast(v, self.intrinsics.i32_ty.vec_type(2), "") .into_vector_value(); - let res = self.builder.build_int_z_extend(v, self.intrinsics.i64x2_ty, ""); + let res = self + .builder + .build_int_z_extend(v, self.intrinsics.i64x2_ty, ""); let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } @@ -6599,7 +7404,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let result = self.builder.build_load(effective_address, ""); let load = result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 4, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); self.state.push1(result); } Operator::I64AtomicLoad { ref memarg } => { @@ -6616,7 +7422,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let result = self.builder.build_load(effective_address, ""); let load = result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 8, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); self.state.push1(result); } Operator::I32AtomicLoad8U { ref memarg } => { @@ -6630,12 +7437,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 1, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); let load = narrow_result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 1, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); let result = - self.builder.build_int_z_extend(narrow_result, self.intrinsics.i32_ty, ""); + self.builder + .build_int_z_extend(narrow_result, self.intrinsics.i32_ty, ""); self.state.push1_extra(result, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicLoad16U { ref memarg } => { @@ -6649,12 +7461,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 2, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); let load = narrow_result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 2, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); let result = - self.builder.build_int_z_extend(narrow_result, self.intrinsics.i32_ty, ""); + self.builder + .build_int_z_extend(narrow_result, self.intrinsics.i32_ty, ""); self.state.push1_extra(result, ExtraInfo::arithmetic_f32()); } Operator::I64AtomicLoad8U { ref memarg } => { @@ -6668,12 +7485,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 1, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); let load = narrow_result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 1, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); let result = - self.builder.build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); + self.builder + .build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); self.state.push1_extra(result, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicLoad16U { ref memarg } => { @@ -6687,12 +7509,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 2, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); let load = narrow_result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 2, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); let result = - self.builder.build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); + self.builder + .build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); self.state.push1_extra(result, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicLoad32U { ref memarg } => { @@ -6706,12 +7533,17 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 4, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_result = self.builder.build_load(effective_address, "").into_int_value(); + let narrow_result = self + .builder + .build_load(effective_address, "") + .into_int_value(); let load = narrow_result.as_instruction_value().unwrap(); self.annotate_user_memaccess(memory_index, memarg, 4, load)?; - load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); let result = - self.builder.build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); + self.builder + .build_int_z_extend(narrow_result, self.intrinsics.i64_ty, ""); self.state.push1_extra(result, ExtraInfo::arithmetic_f64()); } Operator::I32AtomicStore { ref memarg } => { @@ -6728,7 +7560,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.trap_if_misaligned(memarg, effective_address); let store = self.builder.build_store(effective_address, value); self.annotate_user_memaccess(memory_index, memarg, 4, store)?; - store.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + store + .set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); } Operator::I64AtomicStore { ref memarg } => { let value = self.state.pop1()?; @@ -6744,7 +7578,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.trap_if_misaligned(memarg, effective_address); let store = self.builder.build_store(effective_address, value); self.annotate_user_memaccess(memory_index, memarg, 8, store)?; - store.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + store + .set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); } Operator::I32AtomicStore8 { ref memarg } | Operator::I64AtomicStore8 { ref memarg } => { let value = self.state.pop1()?.into_int_value(); @@ -6759,10 +7595,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 1, store)?; - store.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + store + .set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); } Operator::I32AtomicStore16 { ref memarg } | Operator::I64AtomicStore16 { ref memarg } => { @@ -6778,10 +7617,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 2, store)?; - store.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + store + .set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); } Operator::I64AtomicStore32 { ref memarg } => { let value = self.state.pop1()?.into_int_value(); @@ -6796,10 +7638,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let store = self.builder.build_store(effective_address, narrow_value); self.annotate_user_memaccess(memory_index, memarg, 4, store)?; - store.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent).unwrap(); + store + .set_atomic_ordering(AtomicOrdering::SequentiallyConsistent) + .unwrap(); } Operator::I32AtomicRmw8AddU { ref memarg } => { let value = self.state.pop1()?.into_int_value(); @@ -6814,7 +7659,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -6830,7 +7676,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { format!("memory {}", memory_index.as_u32()), old.as_instruction_value().unwrap(), ); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16AddU { ref memarg } => { @@ -6846,7 +7694,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -6862,7 +7711,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { format!("memory {}", memory_index.as_u32()), old.as_instruction_value().unwrap(), ); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwAdd { ref memarg } => { @@ -6907,7 +7758,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -6923,7 +7775,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16AddU { ref memarg } => { @@ -6939,7 +7793,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -6955,7 +7810,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32AddU { ref memarg } => { @@ -6971,7 +7828,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -6987,7 +7845,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwAdd { ref memarg } => { @@ -7032,7 +7892,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7048,7 +7909,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16SubU { ref memarg } => { @@ -7064,7 +7927,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7080,7 +7944,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwSub { ref memarg } => { @@ -7125,7 +7991,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7141,7 +8008,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I64AtomicRmw16SubU { ref memarg } => { @@ -7157,7 +8026,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7173,7 +8043,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32SubU { ref memarg } => { @@ -7189,7 +8061,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -7205,7 +8078,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwSub { ref memarg } => { @@ -7250,7 +8125,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7266,7 +8142,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16AndU { ref memarg } => { @@ -7282,7 +8160,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7298,7 +8177,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwAnd { ref memarg } => { @@ -7343,7 +8224,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7359,7 +8241,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16AndU { ref memarg } => { @@ -7375,7 +8259,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7391,7 +8276,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32AndU { ref memarg } => { @@ -7407,7 +8294,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -7423,7 +8311,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwAnd { ref memarg } => { @@ -7468,7 +8358,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7484,7 +8375,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16OrU { ref memarg } => { @@ -7500,7 +8393,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7516,7 +8410,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwOr { ref memarg } => { @@ -7546,7 +8442,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I64AtomicRmw8OrU { ref memarg } => { @@ -7562,7 +8460,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7578,7 +8477,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16OrU { ref memarg } => { @@ -7594,7 +8495,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7610,7 +8512,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32OrU { ref memarg } => { @@ -7626,7 +8530,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -7642,7 +8547,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwOr { ref memarg } => { @@ -7687,7 +8594,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7703,7 +8611,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16XorU { ref memarg } => { @@ -7719,7 +8629,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7735,7 +8646,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwXor { ref memarg } => { @@ -7780,7 +8693,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7796,7 +8710,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16XorU { ref memarg } => { @@ -7812,7 +8728,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7828,7 +8745,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32XorU { ref memarg } => { @@ -7844,7 +8763,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -7860,7 +8780,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwXor { ref memarg } => { @@ -7905,7 +8827,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -7921,7 +8844,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16XchgU { ref memarg } => { @@ -7937,7 +8862,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -7953,7 +8879,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwXchg { ref memarg } => { @@ -7998,7 +8926,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i8_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i8_ty, ""); let old = self .builder .build_atomicrmw( @@ -8014,7 +8943,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16XchgU { ref memarg } => { @@ -8030,7 +8961,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i16_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i16_ty, ""); let old = self .builder .build_atomicrmw( @@ -8046,7 +8978,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32XchgU { ref memarg } => { @@ -8062,7 +8996,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { )?; self.trap_if_misaligned(memarg, effective_address); let narrow_value = - self.builder.build_int_truncate(value, self.intrinsics.i32_ty, ""); + self.builder + .build_int_truncate(value, self.intrinsics.i32_ty, ""); let old = self .builder .build_atomicrmw( @@ -8078,7 +9013,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwXchg { ref memarg } => { @@ -8125,8 +9062,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 1, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_cmp = self.builder.build_int_truncate(cmp, self.intrinsics.i8_ty, ""); - let narrow_new = self.builder.build_int_truncate(new, self.intrinsics.i8_ty, ""); + let narrow_cmp = self + .builder + .build_int_truncate(cmp, self.intrinsics.i8_ty, ""); + let narrow_new = self + .builder + .build_int_truncate(new, self.intrinsics.i8_ty, ""); let old = self .builder .build_cmpxchg( @@ -8143,8 +9084,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_extract_value(old, 0, "").unwrap().into_int_value(); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_extract_value(old, 0, "") + .unwrap() + .into_int_value(); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmw16CmpxchgU { ref memarg } => { @@ -8162,8 +9109,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 2, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_cmp = self.builder.build_int_truncate(cmp, self.intrinsics.i16_ty, ""); - let narrow_new = self.builder.build_int_truncate(new, self.intrinsics.i16_ty, ""); + let narrow_cmp = self + .builder + .build_int_truncate(cmp, self.intrinsics.i16_ty, ""); + let narrow_new = self + .builder + .build_int_truncate(new, self.intrinsics.i16_ty, ""); let old = self .builder .build_cmpxchg( @@ -8180,8 +9131,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_extract_value(old, 0, "").unwrap().into_int_value(); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i32_ty, ""); + let old = self + .builder + .build_extract_value(old, 0, "") + .unwrap() + .into_int_value(); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i32_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f32()); } Operator::I32AtomicRmwCmpxchg { ref memarg } => { @@ -8233,8 +9190,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 1, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_cmp = self.builder.build_int_truncate(cmp, self.intrinsics.i8_ty, ""); - let narrow_new = self.builder.build_int_truncate(new, self.intrinsics.i8_ty, ""); + let narrow_cmp = self + .builder + .build_int_truncate(cmp, self.intrinsics.i8_ty, ""); + let narrow_new = self + .builder + .build_int_truncate(new, self.intrinsics.i8_ty, ""); let old = self .builder .build_cmpxchg( @@ -8251,8 +9212,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_extract_value(old, 0, "").unwrap().into_int_value(); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_extract_value(old, 0, "") + .unwrap() + .into_int_value(); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw16CmpxchgU { ref memarg } => { @@ -8270,8 +9237,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 2, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_cmp = self.builder.build_int_truncate(cmp, self.intrinsics.i16_ty, ""); - let narrow_new = self.builder.build_int_truncate(new, self.intrinsics.i16_ty, ""); + let narrow_cmp = self + .builder + .build_int_truncate(cmp, self.intrinsics.i16_ty, ""); + let narrow_new = self + .builder + .build_int_truncate(new, self.intrinsics.i16_ty, ""); let old = self .builder .build_cmpxchg( @@ -8288,8 +9259,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_extract_value(old, 0, "").unwrap().into_int_value(); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_extract_value(old, 0, "") + .unwrap() + .into_int_value(); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmw32CmpxchgU { ref memarg } => { @@ -8307,8 +9284,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 4, )?; self.trap_if_misaligned(memarg, effective_address); - let narrow_cmp = self.builder.build_int_truncate(cmp, self.intrinsics.i32_ty, ""); - let narrow_new = self.builder.build_int_truncate(new, self.intrinsics.i32_ty, ""); + let narrow_cmp = self + .builder + .build_int_truncate(cmp, self.intrinsics.i32_ty, ""); + let narrow_new = self + .builder + .build_int_truncate(new, self.intrinsics.i32_ty, ""); let old = self .builder .build_cmpxchg( @@ -8325,8 +9306,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { 0, old.as_instruction_value().unwrap(), )?; - let old = self.builder.build_extract_value(old, 0, "").unwrap().into_int_value(); - let old = self.builder.build_int_z_extend(old, self.intrinsics.i64_ty, ""); + let old = self + .builder + .build_extract_value(old, 0, "") + .unwrap() + .into_int_value(); + let old = self + .builder + .build_int_z_extend(old, self.intrinsics.i64_ty, ""); self.state.push1_extra(old, ExtraInfo::arithmetic_f64()); } Operator::I64AtomicRmwCmpxchg { ref memarg } => { @@ -8373,7 +9360,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { &[ vmctx.as_basic_value_enum(), delta, - self.intrinsics.i32_ty.const_int(mem.into(), false).as_basic_value_enum(), + self.intrinsics + .i32_ty + .const_int(mem.into(), false) + .as_basic_value_enum(), ], "", ); @@ -8386,7 +9376,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { size_fn_ptr, &[ vmctx.as_basic_value_enum(), - self.intrinsics.i32_ty.const_int(mem.into(), false).as_basic_value_enum(), + self.intrinsics + .i32_ty + .const_int(mem.into(), false) + .as_basic_value_enum(), ], "", ); @@ -8405,7 +9398,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::RefIsNull => { let value = self.state.pop1()?.into_pointer_value(); let is_null = self.builder.build_is_null(value, ""); - let is_null = self.builder.build_int_z_extend(is_null, self.intrinsics.i32_ty, ""); + let is_null = self + .builder + .build_int_z_extend(is_null, self.intrinsics.i32_ty, ""); self.state.push1(is_null); } Operator::RefFunc { function_index } => { @@ -8423,11 +9418,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.push1(value); } Operator::TableGet { table } => { - let table_index = - self.intrinsics.i32_ty.const_int(table.into(), false).as_basic_value_enum(); + let table_index = self + .intrinsics + .i32_ty + .const_int(table.into(), false) + .as_basic_value_enum(); let elem = self.state.pop1()?; - let table_get = if let Some(_) = - self.wasm_module.local_table_index(TableIndex::from_u32(table)) + let table_get = if let Some(_) = self + .wasm_module + .local_table_index(TableIndex::from_u32(table)) { self.intrinsics.table_get } else { @@ -8443,19 +9442,29 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { value, type_to_llvm( self.intrinsics, - self.wasm_module.tables.get(TableIndex::from_u32(table)).unwrap().ty, + self.wasm_module + .tables + .get(TableIndex::from_u32(table)) + .unwrap() + .ty, )?, "", ); self.state.push1(value); } Operator::TableSet { table } => { - let table_index = - self.intrinsics.i32_ty.const_int(table.into(), false).as_basic_value_enum(); + let table_index = self + .intrinsics + .i32_ty + .const_int(table.into(), false) + .as_basic_value_enum(); let (elem, value) = self.state.pop2()?; - let value = self.builder.build_bitcast(value, self.intrinsics.anyref_ty, ""); - let table_set = if let Some(_) = - self.wasm_module.local_table_index(TableIndex::from_u32(table)) + let value = self + .builder + .build_bitcast(value, self.intrinsics.anyref_ty, ""); + let table_set = if let Some(_) = self + .wasm_module + .local_table_index(TableIndex::from_u32(table)) { self.intrinsics.table_set } else { @@ -8467,12 +9476,21 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::TableCopy { dst_table, src_table } => { + Operator::TableCopy { + dst_table, + src_table, + } => { let (dst, src, len) = self.state.pop3()?; - let dst_table = - self.intrinsics.i32_ty.const_int(dst_table as u64, false).as_basic_value_enum(); - let src_table = - self.intrinsics.i32_ty.const_int(src_table as u64, false).as_basic_value_enum(); + let dst_table = self + .intrinsics + .i32_ty + .const_int(dst_table as u64, false) + .as_basic_value_enum(); + let src_table = self + .intrinsics + .i32_ty + .const_int(src_table as u64, false) + .as_basic_value_enum(); self.builder.build_call( self.intrinsics.table_copy, &[self.ctx.basic(), dst_table, src_table, dst, src, len], @@ -8481,10 +9499,16 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } Operator::TableInit { segment, table } => { let (dst, src, len) = self.state.pop3()?; - let segment = - self.intrinsics.i32_ty.const_int(segment as u64, false).as_basic_value_enum(); - let table = - self.intrinsics.i32_ty.const_int(table as u64, false).as_basic_value_enum(); + let segment = self + .intrinsics + .i32_ty + .const_int(segment as u64, false) + .as_basic_value_enum(); + let table = self + .intrinsics + .i32_ty + .const_int(table as u64, false) + .as_basic_value_enum(); self.builder.build_call( self.intrinsics.table_init, &[self.ctx.basic(), table, segment, dst, src, len], @@ -8492,8 +9516,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ); } Operator::ElemDrop { segment } => { - let segment = - self.intrinsics.i32_ty.const_int(segment as u64, false).as_basic_value_enum(); + let segment = self + .intrinsics + .i32_ty + .const_int(segment as u64, false) + .as_basic_value_enum(); self.builder.build_call( self.intrinsics.elem_drop, &[self.ctx.basic(), segment], @@ -8501,10 +9528,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { ); } Operator::TableFill { table } => { - let table = - self.intrinsics.i32_ty.const_int(table as u64, false).as_basic_value_enum(); + let table = self + .intrinsics + .i32_ty + .const_int(table as u64, false) + .as_basic_value_enum(); let (start, elem, len) = self.state.pop3()?; - let elem = self.builder.build_bitcast(elem, self.intrinsics.anyref_ty, ""); + let elem = self + .builder + .build_bitcast(elem, self.intrinsics.anyref_ty, ""); self.builder.build_call( self.intrinsics.table_fill, &[self.ctx.basic(), table, start, elem, len], @@ -8513,9 +9545,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { } Operator::TableGrow { table } => { let (elem, delta) = self.state.pop2()?; - let elem = self.builder.build_bitcast(elem, self.intrinsics.anyref_ty, ""); - let (table_grow, table_index) = if let Some(local_table_index) = - self.wasm_module.local_table_index(TableIndex::from_u32(table)) + let elem = self + .builder + .build_bitcast(elem, self.intrinsics.anyref_ty, ""); + let (table_grow, table_index) = if let Some(local_table_index) = self + .wasm_module + .local_table_index(TableIndex::from_u32(table)) { (self.intrinsics.table_grow, local_table_index.as_u32()) } else { @@ -8528,15 +9563,20 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .as_basic_value_enum(); let size = self .builder - .build_call(table_grow, &[self.ctx.basic(), elem, delta, table_index], "") + .build_call( + table_grow, + &[self.ctx.basic(), elem, delta, table_index], + "", + ) .try_as_basic_value() .left() .unwrap(); self.state.push1(size); } Operator::TableSize { table } => { - let (table_size, table_index) = if let Some(local_table_index) = - self.wasm_module.local_table_index(TableIndex::from_u32(table)) + let (table_size, table_index) = if let Some(local_table_index) = self + .wasm_module + .local_table_index(TableIndex::from_u32(table)) { (self.intrinsics.table_size, local_table_index.as_u32()) } else { @@ -8556,7 +9596,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.push1(size); } _ => { - return Err(CompileError::Codegen(format!("Operator {:?} unimplemented", op))); + return Err(CompileError::Codegen(format!( + "Operator {:?} unimplemented", + op + ))); } } diff --git a/lib/compiler-llvm/src/translator/intrinsics.rs b/lib/compiler-llvm/src/translator/intrinsics.rs index 7611248db..a2274cac5 100644 --- a/lib/compiler-llvm/src/translator/intrinsics.rs +++ b/lib/compiler-llvm/src/translator/intrinsics.rs @@ -259,7 +259,11 @@ impl<'ctx> Intrinsics<'ctx> { let sigindex_ty = i32_ty; let anyfunc_ty = context.struct_type( - &[i8_ptr_ty_basic, sigindex_ty.as_basic_type_enum(), ctx_ptr_ty.as_basic_type_enum()], + &[ + i8_ptr_ty_basic, + sigindex_ty.as_basic_type_enum(), + ctx_ptr_ty.as_basic_type_enum(), + ], false, ); let funcref_ty = anyfunc_ty.ptr_type(AddressSpace::Generic); @@ -457,7 +461,13 @@ impl<'ctx> Intrinsics<'ctx> { experimental_stackmap: module.add_function( "llvm.experimental.stackmap", - void_ty.fn_type(&[i64_ty_basic /* id */, i32_ty_basic /* numShadowBytes */], true), + void_ty.fn_type( + &[ + i64_ty_basic, /* id */ + i32_ty_basic, /* numShadowBytes */ + ], + true, + ), None, ), @@ -518,14 +528,18 @@ impl<'ctx> Intrinsics<'ctx> { ), table_get: module.add_function( "wasmer_vm_table_get", - anyref_ty - .fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], false), + anyref_ty.fn_type( + &[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], + false, + ), None, ), imported_table_get: module.add_function( "wasmer_vm_imported_table_get", - anyref_ty - .fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], false), + anyref_ty.fn_type( + &[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], + false, + ), None, ), table_set: module.add_function( @@ -610,10 +624,16 @@ impl<'ctx> Intrinsics<'ctx> { vmmemory_definition_current_length_element: 1, memory32_grow_ptr_ty: i32_ty - .fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], false) + .fn_type( + &[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], + false, + ) .ptr_type(AddressSpace::Generic), imported_memory32_grow_ptr_ty: i32_ty - .fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], false) + .fn_type( + &[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic, i32_ty_basic], + false, + ) .ptr_type(AddressSpace::Generic), memory32_size_ptr_ty: i32_ty .fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic], false) @@ -627,8 +647,12 @@ impl<'ctx> Intrinsics<'ctx> { let noreturn = context.create_enum_attribute(Attribute::get_named_enum_kind_id("noreturn"), 0); - intrinsics.throw_trap.add_attribute(AttributeLoc::Function, noreturn); - intrinsics.func_ref.add_attribute(AttributeLoc::Function, intrinsics.readonly); + intrinsics + .throw_trap + .add_attribute(AttributeLoc::Function, noreturn); + intrinsics + .func_ref + .add_attribute(AttributeLoc::Function, intrinsics.readonly); intrinsics } @@ -637,7 +661,10 @@ impl<'ctx> Intrinsics<'ctx> { #[derive(Clone, Copy)] pub enum MemoryCache<'ctx> { /// The memory moves around. - Dynamic { ptr_to_base_ptr: PointerValue<'ctx>, ptr_to_current_length: PointerValue<'ctx> }, + Dynamic { + ptr_to_base_ptr: PointerValue<'ctx>, + ptr_to_current_length: PointerValue<'ctx>, + }, /// The memory is always in the same place. Static { base_ptr: PointerValue<'ctx> }, } @@ -725,36 +752,40 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { ); let memory_style = &memory_styles[index]; *cached_memories.entry(index).or_insert_with(|| { - let memory_definition_ptr = if let Some(local_memory_index) = - wasm_module.local_memory_index(index) - { - let offset = offsets.vmctx_vmmemory_definition(local_memory_index); - let offset = intrinsics.i32_ty.const_int(offset.into(), false); - unsafe { cache_builder.build_gep(ctx_ptr_value, &[offset], "") } - } else { - let offset = offsets.vmctx_vmmemory_import(index); - let offset = intrinsics.i32_ty.const_int(offset.into(), false); - let memory_definition_ptr_ptr = - unsafe { cache_builder.build_gep(ctx_ptr_value, &[offset], "") }; - let memory_definition_ptr_ptr = cache_builder - .build_bitcast( - memory_definition_ptr_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), - "", - ) - .into_pointer_value(); - let memory_definition_ptr = - cache_builder.build_load(memory_definition_ptr_ptr, "").into_pointer_value(); - tbaa_label( - module, - intrinsics, - format!("memory {} definition", index.as_u32()), - memory_definition_ptr.as_instruction_value().unwrap(), - ); - memory_definition_ptr - }; + let memory_definition_ptr = + if let Some(local_memory_index) = wasm_module.local_memory_index(index) { + let offset = offsets.vmctx_vmmemory_definition(local_memory_index); + let offset = intrinsics.i32_ty.const_int(offset.into(), false); + unsafe { cache_builder.build_gep(ctx_ptr_value, &[offset], "") } + } else { + let offset = offsets.vmctx_vmmemory_import(index); + let offset = intrinsics.i32_ty.const_int(offset.into(), false); + let memory_definition_ptr_ptr = + unsafe { cache_builder.build_gep(ctx_ptr_value, &[offset], "") }; + let memory_definition_ptr_ptr = cache_builder + .build_bitcast( + memory_definition_ptr_ptr, + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), + "", + ) + .into_pointer_value(); + let memory_definition_ptr = cache_builder + .build_load(memory_definition_ptr_ptr, "") + .into_pointer_value(); + tbaa_label( + module, + intrinsics, + format!("memory {} definition", index.as_u32()), + memory_definition_ptr.as_instruction_value().unwrap(), + ); + memory_definition_ptr + }; let memory_definition_ptr = cache_builder - .build_bitcast(memory_definition_ptr, intrinsics.vmmemory_definition_ptr_ty, "") + .build_bitcast( + memory_definition_ptr, + intrinsics.vmmemory_definition_ptr_ty, + "", + ) .into_pointer_value(); let base_ptr = cache_builder .build_struct_gep( @@ -801,13 +832,16 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { &self.cache_builder, &self.offsets, ); - let TableCache { ptr_to_base_ptr, ptr_to_bounds } = - *cached_tables.entry(table_index).or_insert_with(|| { - let (ptr_to_base_ptr, ptr_to_bounds) = if let Some(local_table_index) = - wasm_module.local_table_index(table_index) - { + let TableCache { + ptr_to_base_ptr, + ptr_to_bounds, + } = *cached_tables.entry(table_index).or_insert_with(|| { + let (ptr_to_base_ptr, ptr_to_bounds) = + if let Some(local_table_index) = wasm_module.local_table_index(table_index) { let offset = intrinsics.i64_ty.const_int( - offsets.vmctx_vmtable_definition_base(local_table_index).into(), + offsets + .vmctx_vmtable_definition_base(local_table_index) + .into(), false, ); let ptr_to_base_ptr = @@ -820,7 +854,9 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { ) .into_pointer_value(); let offset = intrinsics.i64_ty.const_int( - offsets.vmctx_vmtable_definition_current_elements(local_table_index).into(), + offsets + .vmctx_vmtable_definition_current_elements(local_table_index) + .into(), false, ); let ptr_to_bounds = @@ -843,8 +879,9 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { "", ) .into_pointer_value(); - let definition_ptr = - cache_builder.build_load(definition_ptr_ptr, "").into_pointer_value(); + let definition_ptr = cache_builder + .build_load(definition_ptr_ptr, "") + .into_pointer_value(); tbaa_label( module, intrinsics, @@ -874,8 +911,11 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { .into_pointer_value(); (ptr_to_base_ptr, ptr_to_bounds) }; - TableCache { ptr_to_base_ptr, ptr_to_bounds } - }); + TableCache { + ptr_to_base_ptr, + ptr_to_bounds, + } + }); (ptr_to_base_ptr, ptr_to_bounds) } @@ -887,9 +927,14 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { module: &Module<'ctx>, ) -> (PointerValue<'ctx>, IntValue<'ctx>) { let (ptr_to_base_ptr, ptr_to_bounds) = self.table_prepare(index, intrinsics, module); - let base_ptr = - self.cache_builder.build_load(ptr_to_base_ptr, "base_ptr").into_pointer_value(); - let bounds = self.cache_builder.build_load(ptr_to_bounds, "bounds").into_int_value(); + let base_ptr = self + .cache_builder + .build_load(ptr_to_base_ptr, "base_ptr") + .into_pointer_value(); + let bounds = self + .cache_builder + .build_load(ptr_to_bounds, "bounds") + .into_int_value(); tbaa_label( module, intrinsics, @@ -911,8 +956,12 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { intrinsics: &Intrinsics<'ctx>, module: &Module<'ctx>, ) -> IntValue<'ctx> { - let (cached_sigindices, ctx_ptr_value, cache_builder, offsets) = - (&mut self.cached_sigindices, self.ctx_ptr_value, &self.cache_builder, &self.offsets); + let (cached_sigindices, ctx_ptr_value, cache_builder, offsets) = ( + &mut self.cached_sigindices, + self.ctx_ptr_value, + &self.cache_builder, + &self.offsets, + ); *cached_sigindices.entry(index).or_insert_with(|| { let byte_offset = intrinsics .i64_ty @@ -924,7 +973,9 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { .build_bitcast(sigindex_ptr, intrinsics.i32_ptr_ty, "") .into_pointer_value(); - let sigindex = cache_builder.build_load(sigindex_ptr, "sigindex").into_int_value(); + let sigindex = cache_builder + .build_load(sigindex_ptr, "sigindex") + .into_int_value(); tbaa_label( module, intrinsics, @@ -972,8 +1023,9 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { "", ) .into_pointer_value(); - let global_ptr = - cache_builder.build_load(global_ptr_ptr, "").into_pointer_value(); + let global_ptr = cache_builder + .build_load(global_ptr_ptr, "") + .into_pointer_value(); tbaa_label( module, intrinsics, @@ -1001,7 +1053,9 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { ); GlobalCache::Const { value } } - Mutability::Var => GlobalCache::Mut { ptr_to_value: global_ptr }, + Mutability::Var => GlobalCache::Mut { + ptr_to_value: global_ptr, + }, }) } }) @@ -1017,7 +1071,11 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { match self.cached_functions.entry(function_index) { Entry::Occupied(_) => unreachable!("duplicate function"), Entry::Vacant(entry) => { - entry.insert(FunctionCache { func, vmctx, attrs: attrs.to_vec() }); + entry.insert(FunctionCache { + func, + vmctx, + attrs: attrs.to_vec(), + }); } } } @@ -1032,14 +1090,18 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { func_type: &FuncType, function_name: &str, ) -> Result<&FunctionCache<'ctx>, CompileError> { - let (cached_functions, ctx_ptr_value, offsets) = - (&mut self.cached_functions, &self.ctx_ptr_value, &self.offsets); + let (cached_functions, ctx_ptr_value, offsets) = ( + &mut self.cached_functions, + &self.ctx_ptr_value, + &self.offsets, + ); Ok(match cached_functions.entry(function_index) { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => { debug_assert!(module.get_function(function_name).is_none()); let (llvm_func_type, llvm_func_attrs) = - self.abi.func_type_to_llvm(context, intrinsics, Some(offsets), func_type)?; + self.abi + .func_type_to_llvm(context, intrinsics, Some(offsets), func_type)?; let func = module.add_function(function_name, llvm_func_type, Some(Linkage::External)); for (attr, attr_loc) in &llvm_func_attrs { @@ -1072,14 +1134,19 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => { let (llvm_func_type, llvm_func_attrs) = - self.abi.func_type_to_llvm(context, intrinsics, Some(offsets), func_type)?; + self.abi + .func_type_to_llvm(context, intrinsics, Some(offsets), func_type)?; debug_assert!(wasm_module.local_func_index(function_index).is_none()); let offset = offsets.vmctx_vmfunction_import(function_index); let offset = intrinsics.i32_ty.const_int(offset.into(), false); let vmfunction_import_ptr = unsafe { cache_builder.build_gep(*ctx_ptr_value, &[offset], "") }; let vmfunction_import_ptr = cache_builder - .build_bitcast(vmfunction_import_ptr, intrinsics.vmfunction_import_ptr_ty, "") + .build_bitcast( + vmfunction_import_ptr, + intrinsics.vmfunction_import_ptr_ty, + "", + ) .into_pointer_value(); let body_ptr_ptr = cache_builder @@ -1124,7 +1191,10 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { ); *cached_memory_grow.entry(memory_index).or_insert_with(|| { let (grow_fn, grow_fn_ty) = if wasm_module.local_memory_index(memory_index).is_some() { - (VMBuiltinFunctionIndex::get_memory32_grow_index(), intrinsics.memory32_grow_ptr_ty) + ( + VMBuiltinFunctionIndex::get_memory32_grow_index(), + intrinsics.memory32_grow_ptr_ty, + ) } else { ( VMBuiltinFunctionIndex::get_imported_memory32_grow_index(), @@ -1136,9 +1206,15 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let grow_fn_ptr_ptr = unsafe { cache_builder.build_gep(*ctx_ptr_value, &[offset], "") }; let grow_fn_ptr_ptr = cache_builder - .build_bitcast(grow_fn_ptr_ptr, grow_fn_ty.ptr_type(AddressSpace::Generic), "") + .build_bitcast( + grow_fn_ptr_ptr, + grow_fn_ty.ptr_type(AddressSpace::Generic), + "", + ) .into_pointer_value(); - cache_builder.build_load(grow_fn_ptr_ptr, "").into_pointer_value() + cache_builder + .build_load(grow_fn_ptr_ptr, "") + .into_pointer_value() }) } @@ -1156,7 +1232,10 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { ); *cached_memory_size.entry(memory_index).or_insert_with(|| { let (size_fn, size_fn_ty) = if wasm_module.local_memory_index(memory_index).is_some() { - (VMBuiltinFunctionIndex::get_memory32_size_index(), intrinsics.memory32_size_ptr_ty) + ( + VMBuiltinFunctionIndex::get_memory32_size_index(), + intrinsics.memory32_size_ptr_ty, + ) } else { ( VMBuiltinFunctionIndex::get_imported_memory32_size_index(), @@ -1168,10 +1247,16 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = unsafe { cache_builder.build_gep(*ctx_ptr_value, &[offset], "") }; let size_fn_ptr_ptr = cache_builder - .build_bitcast(size_fn_ptr_ptr, size_fn_ty.ptr_type(AddressSpace::Generic), "") + .build_bitcast( + size_fn_ptr_ptr, + size_fn_ty.ptr_type(AddressSpace::Generic), + "", + ) .into_pointer_value(); - cache_builder.build_load(size_fn_ptr_ptr, "").into_pointer_value() + cache_builder + .build_load(size_fn_ptr_ptr, "") + .into_pointer_value() }) } @@ -1211,21 +1296,27 @@ pub fn tbaa_label<'ctx>( }; // `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer. - let tbaa_root = module.get_global_metadata("wasmer_tbaa_root").pop().unwrap_or_else(|| { - module.add_global_metadata("wasmer_tbaa_root", &context.metadata_node(&[])); - module.get_global_metadata("wasmer_tbaa_root")[0] - }); + let tbaa_root = module + .get_global_metadata("wasmer_tbaa_root") + .pop() + .unwrap_or_else(|| { + module.add_global_metadata("wasmer_tbaa_root", &context.metadata_node(&[])); + module.get_global_metadata("wasmer_tbaa_root")[0] + }); // Construct (or look up) the type descriptor, for example // `!"local 0" = !{!"local 0", !wasmer_tbaa_root}`. let type_label = context.metadata_string(label.as_str()); - let type_tbaa = module.get_global_metadata(label.as_str()).pop().unwrap_or_else(|| { - module.add_global_metadata( - label.as_str(), - &context.metadata_node(&[type_label.into(), tbaa_root.into()]), - ); - module.get_global_metadata(label.as_str())[0] - }); + let type_tbaa = module + .get_global_metadata(label.as_str()) + .pop() + .unwrap_or_else(|| { + module.add_global_metadata( + label.as_str(), + &context.metadata_node(&[type_label.into(), tbaa_root.into()]), + ); + module.get_global_metadata(label.as_str())[0] + }); // Construct (or look up) the access tag, which is a struct of the form // (base type, access type, offset). @@ -1234,17 +1325,20 @@ pub fn tbaa_label<'ctx>( // must be the same". // -- https://llvm.org/docs/LangRef.html#tbaa-metadata let label = label + "_memop"; - let type_tbaa = module.get_global_metadata(label.as_str()).pop().unwrap_or_else(|| { - module.add_global_metadata( - label.as_str(), - &context.metadata_node(&[ - type_tbaa.into(), - type_tbaa.into(), - intrinsics.i64_zero.into(), - ]), - ); - module.get_global_metadata(label.as_str())[0] - }); + let type_tbaa = module + .get_global_metadata(label.as_str()) + .pop() + .unwrap_or_else(|| { + module.add_global_metadata( + label.as_str(), + &context.metadata_node(&[ + type_tbaa.into(), + type_tbaa.into(), + intrinsics.i64_zero.into(), + ]), + ); + module.get_global_metadata(label.as_str())[0] + }); // Attach the access tag to the instruction. let tbaa_kind = context.get_kind_id("tbaa"); diff --git a/lib/compiler-llvm/src/translator/state.rs b/lib/compiler-llvm/src/translator/state.rs index bb9e04a88..e3046a09d 100644 --- a/lib/compiler-llvm/src/translator/state.rs +++ b/lib/compiler-llvm/src/translator/state.rs @@ -67,7 +67,9 @@ impl<'ctx> ControlFrame<'ctx> { pub fn loop_body_phis(&self) -> &[PhiValue<'ctx>] { match self { ControlFrame::Block { .. } | ControlFrame::IfElse { .. } => &[], - ControlFrame::Loop { ref loop_body_phis, .. } => loop_body_phis.as_slice(), + ControlFrame::Loop { + ref loop_body_phis, .. + } => loop_body_phis.as_slice(), } } @@ -209,7 +211,11 @@ pub struct State<'ctx> { impl<'ctx> State<'ctx> { pub fn new() -> Self { - Self { stack: vec![], control_stack: vec![], reachable: true } + Self { + stack: vec![], + control_stack: vec![], + reachable: true, + } } pub fn has_control_frames(&self) -> bool { @@ -218,9 +224,18 @@ impl<'ctx> State<'ctx> { pub fn reset_stack(&mut self, frame: &ControlFrame<'ctx>) { let stack_size_snapshot = match frame { - ControlFrame::Block { stack_size_snapshot, .. } - | ControlFrame::Loop { stack_size_snapshot, .. } - | ControlFrame::IfElse { stack_size_snapshot, .. } => *stack_size_snapshot, + ControlFrame::Block { + stack_size_snapshot, + .. + } + | ControlFrame::Loop { + stack_size_snapshot, + .. + } + | ControlFrame::IfElse { + stack_size_snapshot, + .. + } => *stack_size_snapshot, }; self.stack.truncate(stack_size_snapshot); } @@ -232,8 +247,11 @@ impl<'ctx> State<'ctx> { } pub fn frame_at_depth(&self, depth: u32) -> Result<&ControlFrame<'ctx>, CompileError> { - let index = - self.control_stack.len().checked_sub(1 + (depth as usize)).ok_or_else(|| { + let index = self + .control_stack + .len() + .checked_sub(1 + (depth as usize)) + .ok_or_else(|| { CompileError::Codegen("frame_at_depth: invalid control stack depth".to_string()) })?; Ok(&self.control_stack[index]) @@ -243,8 +261,11 @@ impl<'ctx> State<'ctx> { &mut self, depth: u32, ) -> Result<&mut ControlFrame<'ctx>, CompileError> { - let index = - self.control_stack.len().checked_sub(1 + (depth as usize)).ok_or_else(|| { + let index = self + .control_stack + .len() + .checked_sub(1 + (depth as usize)) + .ok_or_else(|| { CompileError::Codegen("frame_at_depth_mut: invalid control stack depth".to_string()) })?; Ok(&mut self.control_stack[index]) @@ -282,8 +303,13 @@ impl<'ctx> State<'ctx> { pub fn pop2_extra( &mut self, - ) -> Result<((BasicValueEnum<'ctx>, ExtraInfo), (BasicValueEnum<'ctx>, ExtraInfo)), CompileError> - { + ) -> Result< + ( + (BasicValueEnum<'ctx>, ExtraInfo), + (BasicValueEnum<'ctx>, ExtraInfo), + ), + CompileError, + > { let v2 = self.pop1_extra()?; let v1 = self.pop1_extra()?; Ok((v1, v2)) @@ -291,8 +317,14 @@ impl<'ctx> State<'ctx> { pub fn pop3( &mut self, - ) -> Result<(BasicValueEnum<'ctx>, BasicValueEnum<'ctx>, BasicValueEnum<'ctx>), CompileError> - { + ) -> Result< + ( + BasicValueEnum<'ctx>, + BasicValueEnum<'ctx>, + BasicValueEnum<'ctx>, + ), + CompileError, + > { let v3 = self.pop1()?; let v2 = self.pop1()?; let v1 = self.pop1()?; diff --git a/lib/compiler-singlepass/src/address_map.rs b/lib/compiler-singlepass/src/address_map.rs index 0456e2451..abe18209f 100644 --- a/lib/compiler-singlepass/src/address_map.rs +++ b/lib/compiler-singlepass/src/address_map.rs @@ -10,5 +10,11 @@ pub fn get_function_address_map<'data>( let start_srcloc = SourceLoc::new(data.module_offset as u32); let end_srcloc = SourceLoc::new((data.module_offset + data.data.len()) as u32); - FunctionAddressMap { instructions, start_srcloc, end_srcloc, body_offset: 0, body_len } + FunctionAddressMap { + instructions, + start_srcloc, + end_srcloc, + body_offset: 0, + body_len, + } } diff --git a/lib/compiler-singlepass/src/codegen_x64.rs b/lib/compiler-singlepass/src/codegen_x64.rs index ebac3ba33..4b5c30b0d 100644 --- a/lib/compiler-singlepass/src/codegen_x64.rs +++ b/lib/compiler-singlepass/src/codegen_x64.rs @@ -118,15 +118,24 @@ struct FloatValue { impl FloatValue { fn new(depth: usize) -> Self { - FloatValue { canonicalization: None, depth } + FloatValue { + canonicalization: None, + depth, + } } fn cncl_f32(depth: usize) -> Self { - FloatValue { canonicalization: Some(CanonicalizeType::F32), depth } + FloatValue { + canonicalization: Some(CanonicalizeType::F32), + depth, + } } fn cncl_f64(depth: usize) -> Self { - FloatValue { canonicalization: Some(CanonicalizeType::F64), depth } + FloatValue { + canonicalization: Some(CanonicalizeType::F64), + depth, + } } fn promote(self, depth: usize) -> FloatValue { @@ -177,16 +186,20 @@ trait PopMany { impl PopMany for Vec { fn peek1(&self) -> Result<&T, CodegenError> { - self.last() - .ok_or_else(|| CodegenError { message: "peek1() expects at least 1 element".into() }) + self.last().ok_or_else(|| CodegenError { + message: "peek1() expects at least 1 element".into(), + }) } fn pop1(&mut self) -> Result { - self.pop() - .ok_or_else(|| CodegenError { message: "pop1() expects at least 1 element".into() }) + self.pop().ok_or_else(|| CodegenError { + message: "pop1() expects at least 1 element".into(), + }) } fn pop2(&mut self) -> Result<(T, T), CodegenError> { if self.len() < 2 { - return Err(CodegenError { message: "pop2() expects at least 2 elements".into() }); + return Err(CodegenError { + message: "pop2() expects at least 2 elements".into(), + }); } let right = self.pop().unwrap(); @@ -252,7 +265,10 @@ impl<'a> FuncGen<'a> { } fn pop_value_released(&mut self) -> Location { - let loc = self.value_stack.pop().expect("pop_value_released: value stack is empty"); + let loc = self + .value_stack + .pop() + .expect("pop_value_released: value stack is empty"); self.get_location_released(loc) } @@ -274,11 +290,16 @@ impl<'a> FuncGen<'a> { let offset = self.assembler.get_offset().0; self.fsm.trappable_offsets.insert( offset, - OffsetInfo { end_offset: offset + 1, activate_offset: offset, diff_id: state_diff_id }, + OffsetInfo { + end_offset: offset + 1, + activate_offset: offset, + diff_id: state_diff_id, + }, + ); + self.fsm.wasm_offset_to_target_offset.insert( + self.machine.state.wasm_inst_offset, + SuspendOffset::Trappable(offset), ); - self.fsm - .wasm_offset_to_target_offset - .insert(self.machine.state.wasm_inst_offset, SuspendOffset::Trappable(offset)); } /// Marks each address in the code range emitted by `f` with the trap code `code`. @@ -315,24 +336,30 @@ impl<'a> FuncGen<'a> { match sz { Size::S32 => { - self.assembler.emit_vcmpunordss(tmp1, XMMOrMemory::XMM(tmp1), tmp2); + self.assembler + .emit_vcmpunordss(tmp1, XMMOrMemory::XMM(tmp1), tmp2); self.assembler.emit_mov( Size::S32, Location::Imm32(0x7FC0_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(tmp3)); - self.assembler.emit_vblendvps(tmp2, XMMOrMemory::XMM(tmp3), tmp1, tmp1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(tmp3)); + self.assembler + .emit_vblendvps(tmp2, XMMOrMemory::XMM(tmp3), tmp1, tmp1); } Size::S64 => { - self.assembler.emit_vcmpunordsd(tmp1, XMMOrMemory::XMM(tmp1), tmp2); + self.assembler + .emit_vcmpunordsd(tmp1, XMMOrMemory::XMM(tmp1), tmp2); self.assembler.emit_mov( Size::S64, Location::Imm64(0x7FF8_0000_0000_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(tmp3)); - self.assembler.emit_vblendvpd(tmp2, XMMOrMemory::XMM(tmp3), tmp1, tmp1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(tmp3)); + self.assembler + .emit_vblendvpd(tmp2, XMMOrMemory::XMM(tmp3), tmp1, tmp1); } _ => unreachable!(), } @@ -353,21 +380,28 @@ impl<'a> FuncGen<'a> { loc: Location, ) { self.assembler.emit_cmp(sz, Location::Imm32(0), loc); - self.assembler.emit_jmp(Condition::Equal, self.special_labels.integer_division_by_zero); + self.assembler.emit_jmp( + Condition::Equal, + self.special_labels.integer_division_by_zero, + ); match loc { Location::Imm64(_) | Location::Imm32(_) => { self.assembler.emit_mov(sz, loc, Location::GPR(GPR::RCX)); // must not be used during div (rax, rdx) self.mark_trappable(); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::IntegerOverflow); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::IntegerOverflow); op(&mut self.assembler, sz, Location::GPR(GPR::RCX)); self.mark_instruction_address_end(offset); } _ => { self.mark_trappable(); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::IntegerOverflow); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::IntegerOverflow); op(&mut self.assembler, sz, loc); self.mark_instruction_address_end(offset); } @@ -411,7 +445,8 @@ impl<'a> FuncGen<'a> { match src { Location::Imm32(_) | Location::Imm64(_) => { let tmp_src = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, src, Location::GPR(tmp_src)); + self.assembler + .emit_mov(Size::S64, src, Location::GPR(tmp_src)); src = Location::GPR(tmp_src); inner(&mut self.machine, &mut self.assembler, src)?; @@ -485,7 +520,12 @@ impl<'a> FuncGen<'a> { let temp_dst = self.machine.acquire_temp_gpr().unwrap(); self.assembler.emit_mov(sz, src, Location::GPR(temp_src)); self.assembler.emit_mov(sz, dst, Location::GPR(temp_dst)); - op(&mut self.assembler, sz, Location::GPR(temp_src), Location::GPR(temp_dst)); + op( + &mut self.assembler, + sz, + Location::GPR(temp_src), + Location::GPR(temp_dst), + ); match dst { Location::Memory(_, _) | Location::GPR(_) => { self.assembler.emit_mov(sz, Location::GPR(temp_dst), dst); @@ -534,17 +574,22 @@ impl<'a> FuncGen<'a> { let src1 = match src1 { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, src1, Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, src1, Location::XMM(tmp1)); tmp1 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, src1, Location::GPR(tmpg)); - self.assembler.emit_mov(Size::S32, Location::GPR(tmpg), Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S32, src1, Location::GPR(tmpg)); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmpg), Location::XMM(tmp1)); tmp1 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, src1, Location::GPR(tmpg)); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg), Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, src1, Location::GPR(tmpg)); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg), Location::XMM(tmp1)); tmp1 } _ => { @@ -558,17 +603,22 @@ impl<'a> FuncGen<'a> { Location::XMM(x) => XMMOrMemory::XMM(x), Location::Memory(base, disp) => XMMOrMemory::Memory(base, disp), Location::GPR(_) => { - self.assembler.emit_mov(Size::S64, src2, Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, src2, Location::XMM(tmp2)); XMMOrMemory::XMM(tmp2) } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, src2, Location::GPR(tmpg)); - self.assembler.emit_mov(Size::S32, Location::GPR(tmpg), Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S32, src2, Location::GPR(tmpg)); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmpg), Location::XMM(tmp2)); XMMOrMemory::XMM(tmp2) } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, src2, Location::GPR(tmpg)); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg), Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, src2, Location::GPR(tmpg)); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg), Location::XMM(tmp2)); XMMOrMemory::XMM(tmp2) } _ => { @@ -649,13 +699,15 @@ impl<'a> FuncGen<'a> { Location::GPR(x) => { self.emit_relaxed_binop(Assembler::emit_cmp, Size::S32, loc_b, loc_a); self.assembler.emit_set(c, x); - self.assembler.emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x)); + self.assembler + .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x)); } Location::Memory(_, _) => { let tmp = self.machine.acquire_temp_gpr().unwrap(); self.emit_relaxed_binop(Assembler::emit_cmp, Size::S32, loc_b, loc_a); self.assembler.emit_set(c, tmp); - self.assembler.emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(tmp)); + self.assembler + .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(tmp)); self.assembler.emit_mov(Size::S32, Location::GPR(tmp), ret); self.machine.release_temp_gpr(tmp); } @@ -694,13 +746,15 @@ impl<'a> FuncGen<'a> { Location::GPR(x) => { self.emit_relaxed_binop(Assembler::emit_cmp, Size::S64, loc_b, loc_a); self.assembler.emit_set(c, x); - self.assembler.emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x)); + self.assembler + .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x)); } Location::Memory(_, _) => { let tmp = self.machine.acquire_temp_gpr().unwrap(); self.emit_relaxed_binop(Assembler::emit_cmp, Size::S64, loc_b, loc_a); self.assembler.emit_set(c, tmp); - self.assembler.emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(tmp)); + self.assembler + .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(tmp)); self.assembler.emit_mov(Size::S32, Location::GPR(tmp), ret); self.machine.release_temp_gpr(tmp); } @@ -739,8 +793,14 @@ impl<'a> FuncGen<'a> { self.assembler.emit_mov(Size::S32, loc, Location::GPR(tmp)); if let Location::Memory(_, _) = ret { let out_tmp = self.machine.acquire_temp_gpr().unwrap(); - f(&mut self.assembler, Size::S32, Location::GPR(tmp), Location::GPR(out_tmp)); - self.assembler.emit_mov(Size::S32, Location::GPR(out_tmp), ret); + f( + &mut self.assembler, + Size::S32, + Location::GPR(tmp), + Location::GPR(out_tmp), + ); + self.assembler + .emit_mov(Size::S32, Location::GPR(out_tmp), ret); self.machine.release_temp_gpr(out_tmp); } else { f(&mut self.assembler, Size::S32, Location::GPR(tmp), ret); @@ -751,7 +811,8 @@ impl<'a> FuncGen<'a> { if let Location::Memory(_, _) = ret { let out_tmp = self.machine.acquire_temp_gpr().unwrap(); f(&mut self.assembler, Size::S32, loc, Location::GPR(out_tmp)); - self.assembler.emit_mov(Size::S32, Location::GPR(out_tmp), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(out_tmp), ret); self.machine.release_temp_gpr(out_tmp); } else { f(&mut self.assembler, Size::S32, loc, ret); @@ -785,8 +846,14 @@ impl<'a> FuncGen<'a> { self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp)); if let Location::Memory(_, _) = ret { let out_tmp = self.machine.acquire_temp_gpr().unwrap(); - f(&mut self.assembler, Size::S64, Location::GPR(tmp), Location::GPR(out_tmp)); - self.assembler.emit_mov(Size::S64, Location::GPR(out_tmp), ret); + f( + &mut self.assembler, + Size::S64, + Location::GPR(tmp), + Location::GPR(out_tmp), + ); + self.assembler + .emit_mov(Size::S64, Location::GPR(out_tmp), ret); self.machine.release_temp_gpr(out_tmp); } else { f(&mut self.assembler, Size::S64, Location::GPR(tmp), ret); @@ -797,7 +864,8 @@ impl<'a> FuncGen<'a> { if let Location::Memory(_, _) = ret { let out_tmp = self.machine.acquire_temp_gpr().unwrap(); f(&mut self.assembler, Size::S64, loc, Location::GPR(out_tmp)); - self.assembler.emit_mov(Size::S64, Location::GPR(out_tmp), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(out_tmp), ret); self.machine.release_temp_gpr(out_tmp); } else { f(&mut self.assembler, Size::S64, loc, ret); @@ -817,7 +885,8 @@ impl<'a> FuncGen<'a> { fn emit_shift_i32(&mut self, f: fn(&mut Assembler, Size, Location, Location)) { let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I32); - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(GPR::RCX)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(GPR::RCX)); if loc_a != ret { self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc_a, ret); @@ -829,7 +898,8 @@ impl<'a> FuncGen<'a> { /// I64 shift with both operands popped from the virtual stack. fn emit_shift_i64(&mut self, f: fn(&mut Assembler, Size, Location, Location)) { let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I64); - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(GPR::RCX)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(GPR::RCX)); if loc_a != ret { self.emit_relaxed_binop(Assembler::emit_mov, Size::S64, loc_a, ret); @@ -892,7 +962,10 @@ impl<'a> FuncGen<'a> { params: I, ) -> Result<(), CodegenError> { // Values pushed in this function are above the shadow region. - self.machine.state.stack_values.push(MachineValue::ExplicitShadow); + self.machine + .state + .stack_values + .push(MachineValue::ExplicitShadow); let params: Vec<_> = params.collect(); @@ -955,9 +1028,13 @@ impl<'a> FuncGen<'a> { % 16 != 0 { - self.assembler.emit_sub(Size::S64, Location::Imm32(8), Location::GPR(GPR::RSP)); + self.assembler + .emit_sub(Size::S64, Location::Imm32(8), Location::GPR(GPR::RSP)); stack_offset += 8; - self.machine.state.stack_values.push(MachineValue::Undefined); + self.machine + .state + .stack_values + .push(MachineValue::Undefined); } let mut call_movs: Vec<(Location, GPR)> = vec![]; @@ -1002,7 +1079,10 @@ impl<'a> FuncGen<'a> { // TODO: Read value at this offset } _ => { - self.machine.state.stack_values.push(MachineValue::Undefined); + self.machine + .state + .stack_values + .push(MachineValue::Undefined); } } match *param { @@ -1014,7 +1094,8 @@ impl<'a> FuncGen<'a> { // - It is a temporary register that is not used for any persistent value. // - This register as an argument location is only written to after `sort_call_movs`.' self.machine.reserve_unused_temp_gpr(GPR::RCX); - self.assembler.emit_mov(Size::S64, *param, Location::GPR(GPR::RCX)); + self.assembler + .emit_mov(Size::S64, *param, Location::GPR(GPR::RCX)); self.assembler.emit_mov( Size::S64, Location::GPR(GPR::RCX), @@ -1082,9 +1163,10 @@ impl<'a> FuncGen<'a> { diff_id: state_diff_id, }, ); - self.fsm - .wasm_offset_to_target_offset - .insert(self.machine.state.wasm_inst_offset, SuspendOffset::Call(offset)); + self.fsm.wasm_offset_to_target_offset.insert( + self.machine.state.wasm_inst_offset, + SuspendOffset::Call(offset), + ); } // Restore stack. @@ -1165,7 +1247,9 @@ impl<'a> FuncGen<'a> { // Reusing `tmp_addr` for temporary indirection here, since it's not used before the last reference to `{base,bound}_loc`. let (base_loc, bound_loc) = if self.module.num_imported_memories != 0 { // Imported memories require one level of indirection. - let offset = self.vmoffsets.vmctx_vmmemory_import_definition(MemoryIndex::new(0)); + let offset = self + .vmoffsets + .vmctx_vmmemory_import_definition(MemoryIndex::new(0)); self.emit_relaxed_binop( Assembler::emit_mov, Size::S64, @@ -1174,7 +1258,9 @@ impl<'a> FuncGen<'a> { ); (Location::Memory(tmp_addr, 0), Location::Memory(tmp_addr, 8)) } else { - let offset = self.vmoffsets.vmctx_vmmemory_definition(LocalMemoryIndex::new(0)); + let offset = self + .vmoffsets + .vmctx_vmmemory_definition(LocalMemoryIndex::new(0)); ( Location::Memory(Machine::get_vmctx_reg(), offset as i32), Location::Memory(Machine::get_vmctx_reg(), (offset + 8) as i32), @@ -1185,11 +1271,13 @@ impl<'a> FuncGen<'a> { let tmp_bound = self.machine.acquire_temp_gpr().unwrap(); // Load base into temporary register. - self.assembler.emit_mov(Size::S64, base_loc, Location::GPR(tmp_base)); + self.assembler + .emit_mov(Size::S64, base_loc, Location::GPR(tmp_base)); // Load bound into temporary register, if needed. if need_check { - self.assembler.emit_mov(Size::S32, bound_loc, Location::GPR(tmp_bound)); + self.assembler + .emit_mov(Size::S32, bound_loc, Location::GPR(tmp_bound)); // Wasm -> Effective. // Assuming we never underflow - should always be true on Linux/macOS and Windows >=8, @@ -1209,7 +1297,8 @@ impl<'a> FuncGen<'a> { // Load effective address. // `base_loc` and `bound_loc` becomes INVALID after this line, because `tmp_addr` // might be reused. - self.assembler.emit_mov(Size::S32, addr, Location::GPR(tmp_addr)); + self.assembler + .emit_mov(Size::S32, addr, Location::GPR(tmp_addr)); // Add offset to memory address. if memarg.offset != 0 { @@ -1220,18 +1309,22 @@ impl<'a> FuncGen<'a> { ); // Trap if offset calculation overflowed. - self.assembler.emit_jmp(Condition::Carry, self.special_labels.heap_access_oob); + self.assembler + .emit_jmp(Condition::Carry, self.special_labels.heap_access_oob); } // Wasm linear memory -> real memory - self.assembler.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr)); + self.assembler + .emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr)); if need_check { // Trap if the end address of the requested area is above that of the linear memory. - self.assembler.emit_cmp(Size::S64, Location::GPR(tmp_bound), Location::GPR(tmp_addr)); + self.assembler + .emit_cmp(Size::S64, Location::GPR(tmp_bound), Location::GPR(tmp_addr)); // `tmp_bound` is inclusive. So trap only if `tmp_addr > tmp_bound`. - self.assembler.emit_jmp(Condition::Above, self.special_labels.heap_access_oob); + self.assembler + .emit_jmp(Condition::Above, self.special_labels.heap_access_oob); } self.machine.release_temp_gpr(tmp_bound); @@ -1250,7 +1343,8 @@ impl<'a> FuncGen<'a> { Location::Imm32((align - 1).into()), Location::GPR(tmp_aligncheck), ); - self.assembler.emit_jmp(Condition::NotEqual, self.special_labels.heap_access_oob); + self.assembler + .emit_jmp(Condition::NotEqual, self.special_labels.heap_access_oob); self.machine.release_temp_gpr(tmp_aligncheck); } @@ -1279,7 +1373,11 @@ impl<'a> FuncGen<'a> { } let compare = self.machine.reserve_unused_temp_gpr(GPR::RAX); - let value = if loc == Location::GPR(GPR::R14) { GPR::R13 } else { GPR::R14 }; + let value = if loc == Location::GPR(GPR::R14) { + GPR::R13 + } else { + GPR::R14 + }; self.assembler.emit_push(Size::S64, Location::GPR(value)); self.assembler.emit_mov(stack_sz, loc, Location::GPR(value)); @@ -1290,10 +1388,13 @@ impl<'a> FuncGen<'a> { self.emit_memory_op(target, memarg, true, value_size, |this, addr| { // Memory moves with size < 32b do not zero upper bits. if memory_sz < Size::S32 { - this.assembler.emit_xor(Size::S32, Location::GPR(compare), Location::GPR(compare)); + this.assembler + .emit_xor(Size::S32, Location::GPR(compare), Location::GPR(compare)); } - this.assembler.emit_mov(memory_sz, Location::Memory(addr, 0), Location::GPR(compare)); - this.assembler.emit_mov(stack_sz, Location::GPR(compare), ret); + this.assembler + .emit_mov(memory_sz, Location::Memory(addr, 0), Location::GPR(compare)); + this.assembler + .emit_mov(stack_sz, Location::GPR(compare), ret); cb(this, compare, value); this.assembler.emit_lock_cmpxchg( memory_sz, @@ -1328,25 +1429,39 @@ impl<'a> FuncGen<'a> { let tmp_x = self.machine.acquire_temp_xmm().unwrap(); // Underflow. - self.assembler.emit_mov(Size::S32, Location::Imm32(lower_bound), Location::GPR(tmp)); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x)); - self.assembler.emit_vcmpless(reg, XMMOrMemory::XMM(tmp_x), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); - self.assembler.emit_jmp(Condition::NotEqual, underflow_label); + self.assembler + .emit_mov(Size::S32, Location::Imm32(lower_bound), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x)); + self.assembler + .emit_vcmpless(reg, XMMOrMemory::XMM(tmp_x), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_jmp(Condition::NotEqual, underflow_label); // Overflow. - self.assembler.emit_mov(Size::S32, Location::Imm32(upper_bound), Location::GPR(tmp)); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x)); - self.assembler.emit_vcmpgess(reg, XMMOrMemory::XMM(tmp_x), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S32, Location::Imm32(upper_bound), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x)); + self.assembler + .emit_vcmpgess(reg, XMMOrMemory::XMM(tmp_x), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); self.assembler.emit_jmp(Condition::NotEqual, overflow_label); // NaN. - self.assembler.emit_vcmpeqss(reg, XMMOrMemory::XMM(reg), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_vcmpeqss(reg, XMMOrMemory::XMM(reg), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); self.assembler.emit_jmp(Condition::Equal, nan_label); self.assembler.emit_jmp(Condition::None, succeed_label); @@ -1373,14 +1488,18 @@ impl<'a> FuncGen<'a> { self.assembler.emit_label(trap_overflow); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::IntegerOverflow); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::IntegerOverflow); self.assembler.emit_ud2(); self.mark_instruction_address_end(offset); self.assembler.emit_label(trap_badconv); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::BadConversionToInteger); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::BadConversionToInteger); self.assembler.emit_ud2(); self.mark_instruction_address_end(offset); @@ -1408,7 +1527,11 @@ impl<'a> FuncGen<'a> { let underflow = self.assembler.get_label(); let overflow = self.assembler.get_label(); - let nan = if nan_cb.is_some() { self.assembler.get_label() } else { underflow }; + let nan = if nan_cb.is_some() { + self.assembler.get_label() + } else { + underflow + }; let convert = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -1459,25 +1582,39 @@ impl<'a> FuncGen<'a> { let tmp_x = self.machine.acquire_temp_xmm().unwrap(); // Underflow. - self.assembler.emit_mov(Size::S64, Location::Imm64(lower_bound), Location::GPR(tmp)); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x)); - self.assembler.emit_vcmplesd(reg, XMMOrMemory::XMM(tmp_x), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); - self.assembler.emit_jmp(Condition::NotEqual, underflow_label); + self.assembler + .emit_mov(Size::S64, Location::Imm64(lower_bound), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x)); + self.assembler + .emit_vcmplesd(reg, XMMOrMemory::XMM(tmp_x), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_jmp(Condition::NotEqual, underflow_label); // Overflow. - self.assembler.emit_mov(Size::S64, Location::Imm64(upper_bound), Location::GPR(tmp)); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x)); - self.assembler.emit_vcmpgesd(reg, XMMOrMemory::XMM(tmp_x), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S64, Location::Imm64(upper_bound), Location::GPR(tmp)); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x)); + self.assembler + .emit_vcmpgesd(reg, XMMOrMemory::XMM(tmp_x), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); self.assembler.emit_jmp(Condition::NotEqual, overflow_label); // NaN. - self.assembler.emit_vcmpeqsd(reg, XMMOrMemory::XMM(reg), tmp_x); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); - self.assembler.emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); + self.assembler + .emit_vcmpeqsd(reg, XMMOrMemory::XMM(reg), tmp_x); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_x), Location::GPR(tmp)); + self.assembler + .emit_cmp(Size::S32, Location::Imm32(0), Location::GPR(tmp)); self.assembler.emit_jmp(Condition::Equal, nan_label); self.assembler.emit_jmp(Condition::None, succeed_label); @@ -1504,13 +1641,17 @@ impl<'a> FuncGen<'a> { self.assembler.emit_label(trap_overflow); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::IntegerOverflow); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::IntegerOverflow); self.assembler.emit_ud2(); self.mark_instruction_address_end(offset); self.assembler.emit_label(trap_badconv); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::BadConversionToInteger); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::BadConversionToInteger); self.assembler.emit_ud2(); self.mark_instruction_address_end(offset); @@ -1538,7 +1679,11 @@ impl<'a> FuncGen<'a> { let underflow = self.assembler.get_label(); let overflow = self.assembler.get_label(); - let nan = if nan_cb.is_some() { self.assembler.get_label() } else { underflow }; + let nan = if nan_cb.is_some() { + self.assembler.get_label() + } else { + underflow + }; let convert = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -1590,7 +1735,8 @@ impl<'a> FuncGen<'a> { // Normal x86 entry prologue. self.assembler.emit_push(Size::S64, Location::GPR(GPR::RBP)); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RSP), Location::GPR(GPR::RBP)); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RSP), Location::GPR(GPR::RBP)); // Initialize locals. self.locals = self.machine.init_locals( @@ -1608,13 +1754,19 @@ impl<'a> FuncGen<'a> { let state_diff_id = self.fsm.diffs.len(); self.fsm.diffs.push(diff); - self.assembler.emit_sub(Size::S64, Location::Imm32(32), Location::GPR(GPR::RSP)); // simulate "red zone" if not supported by the platform + self.assembler + .emit_sub(Size::S64, Location::Imm32(32), Location::GPR(GPR::RSP)); // simulate "red zone" if not supported by the platform self.control_stack.push(ControlFrame { label: self.assembler.get_label(), loop_like: false, if_else: IfElseState::None, - returns: self.signature.results().iter().map(|&x| type_to_wp_type(x)).collect(), + returns: self + .signature + .results() + .iter() + .map(|&x| type_to_wp_type(x)) + .collect(), value_stack_depth: 0, fp_stack_depth: 0, state: self.machine.state.clone(), @@ -1626,7 +1778,9 @@ impl<'a> FuncGen<'a> { // We insert set StackOverflow as the default trap that can happen // anywhere in the function prologue. let offset = 0; - self.trap_table.offset_to_code.insert(offset, TrapCode::StackOverflow); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::StackOverflow); self.mark_instruction_address_end(offset); if self.machine.state.wasm_inst_offset != std::usize::MAX { @@ -1660,15 +1814,20 @@ impl<'a> FuncGen<'a> { let sig_index = module.functions[func_index]; let signature = module.signatures[sig_index].clone(); - let mut local_types: Vec<_> = - signature.params().iter().map(|&x| type_to_wp_type(x)).collect(); + let mut local_types: Vec<_> = signature + .params() + .iter() + .map(|&x| type_to_wp_type(x)) + .collect(); local_types.extend_from_slice(&local_types_excluding_arguments); let fsm = FunctionStateMap::new( new_machine_state(), local_func_index.index() as usize, 32, - (0..local_types.len()).map(|_| WasmAbstractValue::Runtime).collect(), + (0..local_types.len()) + .map(|_| WasmAbstractValue::Runtime) + .collect(), ); let mut assembler = Assembler::new().unwrap(); @@ -1777,7 +1936,9 @@ impl<'a> FuncGen<'a> { Location::Memory(tmp, 0) } else { // Imported globals require one level of indirection. - let offset = self.vmoffsets.vmctx_vmglobal_import_definition(global_index); + let offset = self + .vmoffsets + .vmctx_vmglobal_import_definition(global_index); self.emit_relaxed_binop( Assembler::emit_mov, Size::S64, @@ -1807,7 +1968,9 @@ impl<'a> FuncGen<'a> { Location::Memory(tmp, 0) } else { // Imported globals require one level of indirection. - let offset = self.vmoffsets.vmctx_vmglobal_import_definition(global_index); + let offset = self + .vmoffsets + .vmctx_vmglobal_import_definition(global_index); self.emit_relaxed_binop( Assembler::emit_mov, Size::S64, @@ -1856,7 +2019,8 @@ impl<'a> FuncGen<'a> { ); self.value_stack.push(ret); if self.local_types[local_index].is_float() { - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); } } Operator::LocalSet { local_index } => { @@ -1933,7 +2097,10 @@ impl<'a> FuncGen<'a> { } Operator::I32Const { value } => { self.value_stack.push(Location::Imm32(value as u32)); - self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value as u32 as u64)); + self.machine + .state + .wasm_stack + .push(WasmAbstractValue::Const(value as u32 as u64)); } Operator::I32Add => self.emit_binop_i32(Assembler::emit_add), Operator::I32Sub => self.emit_binop_i32(Assembler::emit_sub), @@ -1941,34 +2108,40 @@ impl<'a> FuncGen<'a> { Operator::I32DivU => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I32); - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_xor( Size::S32, Location::GPR(GPR::RDX), Location::GPR(GPR::RDX), ); self.emit_relaxed_xdiv(Assembler::emit_div, Size::S32, loc_b); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); } Operator::I32DivS => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I32); - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_cdq(); self.emit_relaxed_xdiv(Assembler::emit_idiv, Size::S32, loc_b); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); } Operator::I32RemU => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I32); - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_xor( Size::S32, Location::GPR(GPR::RDX), Location::GPR(GPR::RDX), ); self.emit_relaxed_xdiv(Assembler::emit_div, Size::S32, loc_b); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RDX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RDX), ret); } Operator::I32RemS => { // We assume that RAX and RDX are temporary registers here. @@ -1995,10 +2168,12 @@ impl<'a> FuncGen<'a> { self.assembler.emit_jmp(Condition::None, end); self.assembler.emit_label(normal_path); - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_cdq(); self.emit_relaxed_xdiv(Assembler::emit_idiv, Size::S32, loc_b); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RDX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RDX), ret); self.assembler.emit_label(end); } @@ -2055,11 +2230,14 @@ impl<'a> FuncGen<'a> { self.assembler.emit_test_gpr_64(src); self.assembler.emit_jmp(Condition::Equal, zero_path); - self.assembler.emit_bsr(Size::S32, Location::GPR(src), Location::GPR(dst)); - self.assembler.emit_xor(Size::S32, Location::Imm32(31), Location::GPR(dst)); + self.assembler + .emit_bsr(Size::S32, Location::GPR(src), Location::GPR(dst)); + self.assembler + .emit_xor(Size::S32, Location::Imm32(31), Location::GPR(dst)); self.assembler.emit_jmp(Condition::None, end); self.assembler.emit_label(zero_path); - self.assembler.emit_mov(Size::S32, Location::Imm32(32), Location::GPR(dst)); + self.assembler + .emit_mov(Size::S32, Location::Imm32(32), Location::GPR(dst)); self.assembler.emit_label(end); } @@ -2119,10 +2297,12 @@ impl<'a> FuncGen<'a> { self.assembler.emit_test_gpr_64(src); self.assembler.emit_jmp(Condition::Equal, zero_path); - self.assembler.emit_bsf(Size::S32, Location::GPR(src), Location::GPR(dst)); + self.assembler + .emit_bsf(Size::S32, Location::GPR(src), Location::GPR(dst)); self.assembler.emit_jmp(Condition::None, end); self.assembler.emit_label(zero_path); - self.assembler.emit_mov(Size::S32, Location::Imm32(32), Location::GPR(dst)); + self.assembler + .emit_mov(Size::S32, Location::Imm32(32), Location::GPR(dst)); self.assembler.emit_label(end); } @@ -2156,7 +2336,10 @@ impl<'a> FuncGen<'a> { Operator::I64Const { value } => { let value = value as u64; self.value_stack.push(Location::Imm64(value)); - self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value)); + self.machine + .state + .wasm_stack + .push(WasmAbstractValue::Const(value)); } Operator::I64Add => self.emit_binop_i64(Assembler::emit_add), Operator::I64Sub => self.emit_binop_i64(Assembler::emit_sub), @@ -2164,34 +2347,40 @@ impl<'a> FuncGen<'a> { Operator::I64DivU => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I64); - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_xor( Size::S64, Location::GPR(GPR::RDX), Location::GPR(GPR::RDX), ); self.emit_relaxed_xdiv(Assembler::emit_div, Size::S64, loc_b); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::I64DivS => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I64); - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_cqo(); self.emit_relaxed_xdiv(Assembler::emit_idiv, Size::S64, loc_b); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::I64RemU => { // We assume that RAX and RDX are temporary registers here. let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::I64); - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_xor( Size::S64, Location::GPR(GPR::RDX), Location::GPR(GPR::RDX), ); self.emit_relaxed_xdiv(Assembler::emit_div, Size::S64, loc_b); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RDX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RDX), ret); } Operator::I64RemS => { // We assume that RAX and RDX are temporary registers here. @@ -2219,10 +2408,12 @@ impl<'a> FuncGen<'a> { self.assembler.emit_label(normal_path); - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX)); self.assembler.emit_cqo(); self.emit_relaxed_xdiv(Assembler::emit_idiv, Size::S64, loc_b); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RDX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RDX), ret); self.assembler.emit_label(end); } Operator::I64And => self.emit_binop_i64(Assembler::emit_and), @@ -2278,11 +2469,14 @@ impl<'a> FuncGen<'a> { self.assembler.emit_test_gpr_64(src); self.assembler.emit_jmp(Condition::Equal, zero_path); - self.assembler.emit_bsr(Size::S64, Location::GPR(src), Location::GPR(dst)); - self.assembler.emit_xor(Size::S64, Location::Imm32(63), Location::GPR(dst)); + self.assembler + .emit_bsr(Size::S64, Location::GPR(src), Location::GPR(dst)); + self.assembler + .emit_xor(Size::S64, Location::Imm32(63), Location::GPR(dst)); self.assembler.emit_jmp(Condition::None, end); self.assembler.emit_label(zero_path); - self.assembler.emit_mov(Size::S64, Location::Imm32(64), Location::GPR(dst)); + self.assembler + .emit_mov(Size::S64, Location::Imm32(64), Location::GPR(dst)); self.assembler.emit_label(end); } @@ -2342,10 +2536,12 @@ impl<'a> FuncGen<'a> { self.assembler.emit_test_gpr_64(src); self.assembler.emit_jmp(Condition::Equal, zero_path); - self.assembler.emit_bsf(Size::S64, Location::GPR(src), Location::GPR(dst)); + self.assembler + .emit_bsf(Size::S64, Location::GPR(src), Location::GPR(dst)); self.assembler.emit_jmp(Condition::None, end); self.assembler.emit_label(zero_path); - self.assembler.emit_mov(Size::S64, Location::Imm32(64), Location::GPR(dst)); + self.assembler + .emit_mov(Size::S64, Location::Imm32(64), Location::GPR(dst)); self.assembler.emit_label(end); } @@ -2475,32 +2671,41 @@ impl<'a> FuncGen<'a> { Operator::F32Const { value } => { self.value_stack.push(Location::Imm32(value.bits())); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); - self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value.bits() as u64)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); + self.machine + .state + .wasm_stack + .push(WasmAbstractValue::Const(value.bits() as u64)); } Operator::F32Add => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vaddss)?; } Operator::F32Sub => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vsubss)? } Operator::F32Mul => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vmulss)? } Operator::F32Div => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vdivss)? } Operator::F32Max => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 2)); if !self.assembler.arch_supports_canonicalize_nan() { self.emit_fp_binop_avx(Assembler::emit_vmaxss)?; } else { @@ -2514,11 +2719,13 @@ impl<'a> FuncGen<'a> { let src1 = match loc_a { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); tmp1 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2527,7 +2734,8 @@ impl<'a> FuncGen<'a> { tmp1 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -2544,11 +2752,13 @@ impl<'a> FuncGen<'a> { let src2 = match loc_b { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); tmp2 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2557,7 +2767,8 @@ impl<'a> FuncGen<'a> { tmp2 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -2576,10 +2787,14 @@ impl<'a> FuncGen<'a> { let tmp_xmm2 = XMM::XMM9; let tmp_xmm3 = XMM::XMM10; - self.assembler.emit_mov(Size::S32, Location::XMM(src1), Location::GPR(tmpg1)); - self.assembler.emit_mov(Size::S32, Location::XMM(src2), Location::GPR(tmpg2)); - self.assembler.emit_cmp(Size::S32, Location::GPR(tmpg2), Location::GPR(tmpg1)); - self.assembler.emit_vmaxss(src1, XMMOrMemory::XMM(src2), tmp_xmm1); + self.assembler + .emit_mov(Size::S32, Location::XMM(src1), Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, Location::XMM(src2), Location::GPR(tmpg2)); + self.assembler + .emit_cmp(Size::S32, Location::GPR(tmpg2), Location::GPR(tmpg1)); + self.assembler + .emit_vmaxss(src1, XMMOrMemory::XMM(src2), tmp_xmm1); let label1 = self.assembler.get_label(); let label2 = self.assembler.get_label(); self.assembler.emit_jmp(Condition::NotEqual, label1); @@ -2587,24 +2802,29 @@ impl<'a> FuncGen<'a> { .emit_vmovaps(XMMOrMemory::XMM(tmp_xmm1), XMMOrMemory::XMM(tmp_xmm2)); self.assembler.emit_jmp(Condition::None, label2); self.assembler.emit_label(label1); - self.assembler.emit_vxorps(tmp_xmm2, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm2); + self.assembler + .emit_vxorps(tmp_xmm2, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm2); self.assembler.emit_label(label2); - self.assembler.emit_vcmpeqss(src1, XMMOrMemory::XMM(src2), tmp_xmm3); + self.assembler + .emit_vcmpeqss(src1, XMMOrMemory::XMM(src2), tmp_xmm3); self.assembler.emit_vblendvps( tmp_xmm3, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm1, tmp_xmm1, ); - self.assembler.emit_vcmpunordss(src1, XMMOrMemory::XMM(src2), src1); + self.assembler + .emit_vcmpunordss(src1, XMMOrMemory::XMM(src2), src1); // load float canonical nan self.assembler.emit_mov( Size::S64, Location::Imm32(0x7FC0_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); - self.assembler.emit_vblendvps(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); + self.assembler + .emit_vblendvps(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); match ret { Location::XMM(x) => { self.assembler @@ -2628,7 +2848,8 @@ impl<'a> FuncGen<'a> { } Operator::F32Min => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 2)); if !self.assembler.arch_supports_canonicalize_nan() { self.emit_fp_binop_avx(Assembler::emit_vminss)?; } else { @@ -2642,11 +2863,13 @@ impl<'a> FuncGen<'a> { let src1 = match loc_a { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); tmp1 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2655,7 +2878,8 @@ impl<'a> FuncGen<'a> { tmp1 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -2672,11 +2896,13 @@ impl<'a> FuncGen<'a> { let src2 = match loc_b { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); tmp2 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2685,7 +2911,8 @@ impl<'a> FuncGen<'a> { tmp2 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -2704,10 +2931,14 @@ impl<'a> FuncGen<'a> { let tmp_xmm2 = XMM::XMM9; let tmp_xmm3 = XMM::XMM10; - self.assembler.emit_mov(Size::S32, Location::XMM(src1), Location::GPR(tmpg1)); - self.assembler.emit_mov(Size::S32, Location::XMM(src2), Location::GPR(tmpg2)); - self.assembler.emit_cmp(Size::S32, Location::GPR(tmpg2), Location::GPR(tmpg1)); - self.assembler.emit_vminss(src1, XMMOrMemory::XMM(src2), tmp_xmm1); + self.assembler + .emit_mov(Size::S32, Location::XMM(src1), Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, Location::XMM(src2), Location::GPR(tmpg2)); + self.assembler + .emit_cmp(Size::S32, Location::GPR(tmpg2), Location::GPR(tmpg1)); + self.assembler + .emit_vminss(src1, XMMOrMemory::XMM(src2), tmp_xmm1); let label1 = self.assembler.get_label(); let label2 = self.assembler.get_label(); self.assembler.emit_jmp(Condition::NotEqual, label1); @@ -2727,22 +2958,26 @@ impl<'a> FuncGen<'a> { Location::XMM(tmp_xmm2), ); self.assembler.emit_label(label2); - self.assembler.emit_vcmpeqss(src1, XMMOrMemory::XMM(src2), tmp_xmm3); + self.assembler + .emit_vcmpeqss(src1, XMMOrMemory::XMM(src2), tmp_xmm3); self.assembler.emit_vblendvps( tmp_xmm3, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm1, tmp_xmm1, ); - self.assembler.emit_vcmpunordss(src1, XMMOrMemory::XMM(src2), src1); + self.assembler + .emit_vcmpunordss(src1, XMMOrMemory::XMM(src2), src1); // load float canonical nan self.assembler.emit_mov( Size::S64, Location::Imm32(0x7FC0_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); - self.assembler.emit_vblendvps(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); + self.assembler + .emit_vblendvps(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); match ret { Location::XMM(x) => { self.assembler @@ -2790,27 +3025,32 @@ impl<'a> FuncGen<'a> { } Operator::F32Nearest => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundss_nearest)? } Operator::F32Floor => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundss_floor)? } Operator::F32Ceil => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundss_ceil)? } Operator::F32Trunc => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundss_trunc)? } Operator::F32Sqrt => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f32(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f32(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vsqrtss)? } @@ -2818,7 +3058,8 @@ impl<'a> FuncGen<'a> { let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::F32); let (fp_src1, fp_src2) = self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); let tmp1 = self.machine.acquire_temp_gpr().unwrap(); let tmp2 = self.machine.acquire_temp_gpr().unwrap(); @@ -2832,13 +3073,16 @@ impl<'a> FuncGen<'a> { self.canonicalize_nan(Size::S32, *loc, Location::GPR(*tmp)); } None => { - self.assembler.emit_mov(Size::S32, *loc, Location::GPR(*tmp)); + self.assembler + .emit_mov(Size::S32, *loc, Location::GPR(*tmp)); } } } } else { - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(tmp1)); - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(tmp2)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(tmp1)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(tmp2)); } self.assembler.emit_and( Size::S32, @@ -2850,7 +3094,8 @@ impl<'a> FuncGen<'a> { Location::Imm32(0x80000000u32), Location::GPR(tmp2), ); - self.assembler.emit_or(Size::S32, Location::GPR(tmp2), Location::GPR(tmp1)); + self.assembler + .emit_or(Size::S32, Location::GPR(tmp2), Location::GPR(tmp1)); self.assembler.emit_mov(Size::S32, Location::GPR(tmp1), ret); self.machine.release_temp_gpr(tmp2); self.machine.release_temp_gpr(tmp1); @@ -2915,32 +3160,41 @@ impl<'a> FuncGen<'a> { Operator::F64Const { value } => { self.value_stack.push(Location::Imm64(value.bits())); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); - self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value.bits())); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); + self.machine + .state + .wasm_stack + .push(WasmAbstractValue::Const(value.bits())); } Operator::F64Add => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vaddsd)? } Operator::F64Sub => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vsubsd)? } Operator::F64Mul => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vmulsd)? } Operator::F64Div => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 2)); self.emit_fp_binop_avx(Assembler::emit_vdivsd)? } Operator::F64Max => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 2)); if !self.assembler.arch_supports_canonicalize_nan() { self.emit_fp_binop_avx(Assembler::emit_vmaxsd)?; @@ -2955,11 +3209,13 @@ impl<'a> FuncGen<'a> { let src1 = match loc_a { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); tmp1 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2968,7 +3224,8 @@ impl<'a> FuncGen<'a> { tmp1 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -2985,11 +3242,13 @@ impl<'a> FuncGen<'a> { let src2 = match loc_b { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); tmp2 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -2998,7 +3257,8 @@ impl<'a> FuncGen<'a> { tmp2 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -3017,10 +3277,14 @@ impl<'a> FuncGen<'a> { let tmp_xmm2 = XMM::XMM9; let tmp_xmm3 = XMM::XMM10; - self.assembler.emit_mov(Size::S64, Location::XMM(src1), Location::GPR(tmpg1)); - self.assembler.emit_mov(Size::S64, Location::XMM(src2), Location::GPR(tmpg2)); - self.assembler.emit_cmp(Size::S64, Location::GPR(tmpg2), Location::GPR(tmpg1)); - self.assembler.emit_vmaxsd(src1, XMMOrMemory::XMM(src2), tmp_xmm1); + self.assembler + .emit_mov(Size::S64, Location::XMM(src1), Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, Location::XMM(src2), Location::GPR(tmpg2)); + self.assembler + .emit_cmp(Size::S64, Location::GPR(tmpg2), Location::GPR(tmpg1)); + self.assembler + .emit_vmaxsd(src1, XMMOrMemory::XMM(src2), tmp_xmm1); let label1 = self.assembler.get_label(); let label2 = self.assembler.get_label(); self.assembler.emit_jmp(Condition::NotEqual, label1); @@ -3028,24 +3292,29 @@ impl<'a> FuncGen<'a> { .emit_vmovapd(XMMOrMemory::XMM(tmp_xmm1), XMMOrMemory::XMM(tmp_xmm2)); self.assembler.emit_jmp(Condition::None, label2); self.assembler.emit_label(label1); - self.assembler.emit_vxorpd(tmp_xmm2, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm2); + self.assembler + .emit_vxorpd(tmp_xmm2, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm2); self.assembler.emit_label(label2); - self.assembler.emit_vcmpeqsd(src1, XMMOrMemory::XMM(src2), tmp_xmm3); + self.assembler + .emit_vcmpeqsd(src1, XMMOrMemory::XMM(src2), tmp_xmm3); self.assembler.emit_vblendvpd( tmp_xmm3, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm1, tmp_xmm1, ); - self.assembler.emit_vcmpunordsd(src1, XMMOrMemory::XMM(src2), src1); + self.assembler + .emit_vcmpunordsd(src1, XMMOrMemory::XMM(src2), src1); // load float canonical nan self.assembler.emit_mov( Size::S64, Location::Imm64(0x7FF8_0000_0000_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); - self.assembler.emit_vblendvpd(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); + self.assembler + .emit_vblendvpd(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); match ret { Location::XMM(x) => { self.assembler @@ -3069,7 +3338,8 @@ impl<'a> FuncGen<'a> { } Operator::F64Min => { self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 2)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 2)); if !self.assembler.arch_supports_canonicalize_nan() { self.emit_fp_binop_avx(Assembler::emit_vminsd)?; @@ -3084,11 +3354,13 @@ impl<'a> FuncGen<'a> { let src1 = match loc_a { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::XMM(tmp1)); tmp1 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -3097,7 +3369,8 @@ impl<'a> FuncGen<'a> { tmp1 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -3114,11 +3387,13 @@ impl<'a> FuncGen<'a> { let src2 = match loc_b { Location::XMM(x) => x, Location::GPR(_) | Location::Memory(_, _) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::XMM(tmp2)); tmp2 } Location::Imm32(_) => { - self.assembler.emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S32, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S32, Location::GPR(tmpg1), @@ -3127,7 +3402,8 @@ impl<'a> FuncGen<'a> { tmp2 } Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(tmpg1)); self.assembler.emit_mov( Size::S64, Location::GPR(tmpg1), @@ -3146,10 +3422,14 @@ impl<'a> FuncGen<'a> { let tmp_xmm2 = XMM::XMM9; let tmp_xmm3 = XMM::XMM10; - self.assembler.emit_mov(Size::S64, Location::XMM(src1), Location::GPR(tmpg1)); - self.assembler.emit_mov(Size::S64, Location::XMM(src2), Location::GPR(tmpg2)); - self.assembler.emit_cmp(Size::S64, Location::GPR(tmpg2), Location::GPR(tmpg1)); - self.assembler.emit_vminsd(src1, XMMOrMemory::XMM(src2), tmp_xmm1); + self.assembler + .emit_mov(Size::S64, Location::XMM(src1), Location::GPR(tmpg1)); + self.assembler + .emit_mov(Size::S64, Location::XMM(src2), Location::GPR(tmpg2)); + self.assembler + .emit_cmp(Size::S64, Location::GPR(tmpg2), Location::GPR(tmpg1)); + self.assembler + .emit_vminsd(src1, XMMOrMemory::XMM(src2), tmp_xmm1); let label1 = self.assembler.get_label(); let label2 = self.assembler.get_label(); self.assembler.emit_jmp(Condition::NotEqual, label1); @@ -3169,22 +3449,26 @@ impl<'a> FuncGen<'a> { Location::XMM(tmp_xmm2), ); self.assembler.emit_label(label2); - self.assembler.emit_vcmpeqsd(src1, XMMOrMemory::XMM(src2), tmp_xmm3); + self.assembler + .emit_vcmpeqsd(src1, XMMOrMemory::XMM(src2), tmp_xmm3); self.assembler.emit_vblendvpd( tmp_xmm3, XMMOrMemory::XMM(tmp_xmm2), tmp_xmm1, tmp_xmm1, ); - self.assembler.emit_vcmpunordsd(src1, XMMOrMemory::XMM(src2), src1); + self.assembler + .emit_vcmpunordsd(src1, XMMOrMemory::XMM(src2), src1); // load float canonical nan self.assembler.emit_mov( Size::S64, Location::Imm64(0x7FF8_0000_0000_0000), // Canonical NaN Location::GPR(tmpg1), ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); - self.assembler.emit_vblendvpd(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmpg1), Location::XMM(src2)); + self.assembler + .emit_vblendvpd(src1, XMMOrMemory::XMM(src2), tmp_xmm1, src1); match ret { Location::XMM(x) => { self.assembler @@ -3232,27 +3516,32 @@ impl<'a> FuncGen<'a> { } Operator::F64Nearest => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundsd_nearest)? } Operator::F64Floor => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundsd_floor)? } Operator::F64Ceil => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundsd_ceil)? } Operator::F64Trunc => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vroundsd_trunc)? } Operator::F64Sqrt => { self.fp_stack.pop1()?; - self.fp_stack.push(FloatValue::cncl_f64(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::cncl_f64(self.value_stack.len() - 1)); self.emit_fp_unop_avx(Assembler::emit_vsqrtsd)? } @@ -3260,7 +3549,8 @@ impl<'a> FuncGen<'a> { let I2O1 { loc_a, loc_b, ret } = self.i2o1_prepare(WpType::F64); let (fp_src1, fp_src2) = self.fp_stack.pop2()?; - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); let tmp1 = self.machine.acquire_temp_gpr().unwrap(); let tmp2 = self.machine.acquire_temp_gpr().unwrap(); @@ -3274,13 +3564,16 @@ impl<'a> FuncGen<'a> { self.canonicalize_nan(Size::S64, *loc, Location::GPR(*tmp)); } None => { - self.assembler.emit_mov(Size::S64, *loc, Location::GPR(*tmp)); + self.assembler + .emit_mov(Size::S64, *loc, Location::GPR(*tmp)); } } } } else { - self.assembler.emit_mov(Size::S64, loc_a, Location::GPR(tmp1)); - self.assembler.emit_mov(Size::S64, loc_b, Location::GPR(tmp2)); + self.assembler + .emit_mov(Size::S64, loc_a, Location::GPR(tmp1)); + self.assembler + .emit_mov(Size::S64, loc_b, Location::GPR(tmp2)); } let c = self.machine.acquire_temp_gpr().unwrap(); @@ -3290,16 +3583,19 @@ impl<'a> FuncGen<'a> { Location::Imm64(0x7fffffffffffffffu64), Location::GPR(c), ); - self.assembler.emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp1)); + self.assembler + .emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp1)); self.assembler.emit_mov( Size::S64, Location::Imm64(0x8000000000000000u64), Location::GPR(c), ); - self.assembler.emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp2)); + self.assembler + .emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp2)); - self.assembler.emit_or(Size::S64, Location::GPR(tmp2), Location::GPR(tmp1)); + self.assembler + .emit_or(Size::S64, Location::GPR(tmp2), Location::GPR(tmp1)); self.assembler.emit_mov(Size::S64, Location::GPR(tmp1), ret); self.machine.release_temp_gpr(c); @@ -3327,7 +3623,8 @@ impl<'a> FuncGen<'a> { Location::Imm64(0x7fffffffffffffffu64), Location::GPR(c), ); - self.assembler.emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp)); + self.assembler + .emit_and(Size::S64, Location::GPR(c), Location::GPR(tmp)); self.assembler.emit_mov(Size::S64, Location::GPR(tmp), ret); self.machine.release_temp_gpr(c); @@ -3409,7 +3706,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); if loc != ret { self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc, ret); @@ -3445,7 +3743,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); if loc != ret { self.emit_relaxed_binop(Assembler::emit_mov, Size::S64, loc, ret); @@ -3491,8 +3790,10 @@ impl<'a> FuncGen<'a> { ); self.emit_f32_int_conv_check_trap(tmp_in, GEF32_LT_U32_MIN, LEF32_GT_U32_MAX); - self.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -3535,12 +3836,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_uf32(tmp_in, tmp_out); } else { - this.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -3585,8 +3888,10 @@ impl<'a> FuncGen<'a> { ); self.emit_f32_int_conv_check_trap(tmp_in, GEF32_LT_I32_MIN, LEF32_GT_I32_MAX); - self.assembler.emit_cvttss2si_32(XMMOrMemory::XMM(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttss2si_32(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -3635,12 +3940,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_sf32(tmp_in, tmp_out); } else { - this.assembler.emit_cvttss2si_32(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_cvttss2si_32(XMMOrMemory::XMM(tmp_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -3684,8 +3991,10 @@ impl<'a> FuncGen<'a> { Location::XMM(tmp_in), ); self.emit_f32_int_conv_check_trap(tmp_in, GEF32_LT_I64_MIN, LEF32_GT_I64_MAX); - self.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -3735,12 +4044,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i64_trunc_sf32(tmp_in, tmp_out); } else { - this.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -3794,24 +4105,31 @@ impl<'a> FuncGen<'a> { Location::Imm32(1593835520u32), Location::GPR(tmp), ); //float 9.22337203E+18 - self.assembler.emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x1)); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp), Location::XMM(tmp_x1)); self.assembler.emit_mov( Size::S32, Location::XMM(tmp_in), Location::XMM(tmp_x2), ); - self.assembler.emit_vsubss(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); - self.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_vsubss(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); + self.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); self.assembler.emit_mov( Size::S64, Location::Imm64(0x8000000000000000u64), Location::GPR(tmp), ); - self.assembler.emit_xor(Size::S64, Location::GPR(tmp_out), Location::GPR(tmp)); - self.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); - self.assembler.emit_ucomiss(XMMOrMemory::XMM(tmp_x1), tmp_x2); + self.assembler + .emit_xor(Size::S64, Location::GPR(tmp_out), Location::GPR(tmp)); + self.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); + self.assembler + .emit_ucomiss(XMMOrMemory::XMM(tmp_x1), tmp_x2); self.assembler.emit_cmovae_gpr_64(tmp, tmp_out); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_x2); self.machine.release_temp_xmm(tmp_x1); @@ -3876,8 +4194,10 @@ impl<'a> FuncGen<'a> { Location::XMM(tmp_in), Location::XMM(tmp_x2), ); - this.assembler.emit_vsubss(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); - this.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_vsubss(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); + this.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); this.assembler.emit_mov( Size::S64, Location::Imm64(0x8000000000000000u64), @@ -3888,8 +4208,10 @@ impl<'a> FuncGen<'a> { Location::GPR(tmp_out), Location::GPR(tmp), ); - this.assembler.emit_cvttss2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); - this.assembler.emit_ucomiss(XMMOrMemory::XMM(tmp_x1), tmp_x2); + this.assembler + .emit_cvttss2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); + this.assembler + .emit_ucomiss(XMMOrMemory::XMM(tmp_x1), tmp_x2); this.assembler.emit_cmovae_gpr_64(tmp, tmp_out); this.machine.release_temp_xmm(tmp_x2); @@ -3899,7 +4221,8 @@ impl<'a> FuncGen<'a> { }, ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -3944,8 +4267,10 @@ impl<'a> FuncGen<'a> { ); self.emit_f64_int_conv_check_trap(tmp_in, GEF64_LT_U32_MIN, LEF64_GT_U32_MAX); - self.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -3989,12 +4314,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_uf64(tmp_in, tmp_out); } else { - this.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -4033,7 +4360,8 @@ impl<'a> FuncGen<'a> { let real_in = match loc { Location::Imm32(_) | Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_out)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_out)); self.assembler.emit_mov( Size::S64, Location::GPR(tmp_out), @@ -4043,15 +4371,18 @@ impl<'a> FuncGen<'a> { } Location::XMM(x) => x, _ => { - self.assembler.emit_mov(Size::S64, loc, Location::XMM(tmp_in)); + self.assembler + .emit_mov(Size::S64, loc, Location::XMM(tmp_in)); tmp_in } }; self.emit_f64_int_conv_check_trap(real_in, GEF64_LT_I32_MIN, LEF64_GT_I32_MAX); - self.assembler.emit_cvttsd2si_32(XMMOrMemory::XMM(real_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttsd2si_32(XMMOrMemory::XMM(real_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -4073,7 +4404,8 @@ impl<'a> FuncGen<'a> { let real_in = match loc { Location::Imm32(_) | Location::Imm64(_) => { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_out)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_out)); self.assembler.emit_mov( Size::S64, Location::GPR(tmp_out), @@ -4083,7 +4415,8 @@ impl<'a> FuncGen<'a> { } Location::XMM(x) => x, _ => { - self.assembler.emit_mov(Size::S64, loc, Location::XMM(tmp_in)); + self.assembler + .emit_mov(Size::S64, loc, Location::XMM(tmp_in)); tmp_in } }; @@ -4117,12 +4450,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_sf64(tmp_in, tmp_out); } else { - this.assembler.emit_cvttsd2si_32(XMMOrMemory::XMM(real_in), tmp_out); + this.assembler + .emit_cvttsd2si_32(XMMOrMemory::XMM(real_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S32, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -4167,8 +4502,10 @@ impl<'a> FuncGen<'a> { ); self.emit_f64_int_conv_check_trap(tmp_in, GEF64_LT_I64_MIN, LEF64_GT_I64_MAX); - self.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); @@ -4218,12 +4555,14 @@ impl<'a> FuncGen<'a> { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i64_trunc_sf64(tmp_in, tmp_out); } else { - this.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); } }, ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -4277,24 +4616,31 @@ impl<'a> FuncGen<'a> { Location::Imm64(4890909195324358656u64), Location::GPR(tmp), ); //double 9.2233720368547758E+18 - self.assembler.emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x1)); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp), Location::XMM(tmp_x1)); self.assembler.emit_mov( Size::S64, Location::XMM(tmp_in), Location::XMM(tmp_x2), ); - self.assembler.emit_vsubsd(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); - self.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + self.assembler + .emit_vsubsd(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); + self.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); self.assembler.emit_mov( Size::S64, Location::Imm64(0x8000000000000000u64), Location::GPR(tmp), ); - self.assembler.emit_xor(Size::S64, Location::GPR(tmp_out), Location::GPR(tmp)); - self.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); - self.assembler.emit_ucomisd(XMMOrMemory::XMM(tmp_x1), tmp_x2); + self.assembler + .emit_xor(Size::S64, Location::GPR(tmp_out), Location::GPR(tmp)); + self.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); + self.assembler + .emit_ucomisd(XMMOrMemory::XMM(tmp_x1), tmp_x2); self.assembler.emit_cmovae_gpr_64(tmp, tmp_out); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_x2); self.machine.release_temp_xmm(tmp_x1); @@ -4360,8 +4706,10 @@ impl<'a> FuncGen<'a> { Location::XMM(tmp_in), Location::XMM(tmp_x2), ); - this.assembler.emit_vsubsd(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); - this.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); + this.assembler + .emit_vsubsd(tmp_in, XMMOrMemory::XMM(tmp_x1), tmp_in); + this.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_in), tmp_out); this.assembler.emit_mov( Size::S64, Location::Imm64(0x8000000000000000u64), @@ -4372,8 +4720,10 @@ impl<'a> FuncGen<'a> { Location::GPR(tmp_out), Location::GPR(tmp), ); - this.assembler.emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); - this.assembler.emit_ucomisd(XMMOrMemory::XMM(tmp_x1), tmp_x2); + this.assembler + .emit_cvttsd2si_64(XMMOrMemory::XMM(tmp_x2), tmp_out); + this.assembler + .emit_ucomisd(XMMOrMemory::XMM(tmp_x1), tmp_x2); this.assembler.emit_cmovae_gpr_64(tmp, tmp_out); this.machine.release_temp_xmm(tmp_x2); @@ -4383,7 +4733,8 @@ impl<'a> FuncGen<'a> { }, ); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_out), ret); self.machine.release_temp_xmm(tmp_in); self.machine.release_temp_gpr(tmp_out); } @@ -4396,7 +4747,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f32 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f32 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4420,9 +4772,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2ss_32(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2ss_32(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4436,7 +4791,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f32 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f32 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4460,9 +4816,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4476,7 +4835,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f32 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f32 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4500,9 +4860,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4516,7 +4879,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f32 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f32 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4544,20 +4908,29 @@ impl<'a> FuncGen<'a> { let do_convert = self.assembler.get_label(); let end_convert = self.assembler.get_label(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_in)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_in)); self.assembler.emit_test_gpr_64(tmp_in); self.assembler.emit_jmp(Condition::Signed, do_convert); - self.assembler.emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); self.assembler.emit_jmp(Condition::None, end_convert); self.assembler.emit_label(do_convert); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_in), Location::GPR(tmp)); - self.assembler.emit_and(Size::S64, Location::Imm32(1), Location::GPR(tmp)); - self.assembler.emit_shr(Size::S64, Location::Imm8(1), Location::GPR(tmp_in)); - self.assembler.emit_or(Size::S64, Location::GPR(tmp), Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_vaddss(tmp_out, XMMOrMemory::XMM(tmp_out), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_in), Location::GPR(tmp)); + self.assembler + .emit_and(Size::S64, Location::Imm32(1), Location::GPR(tmp)); + self.assembler + .emit_shr(Size::S64, Location::Imm8(1), Location::GPR(tmp_in)); + self.assembler + .emit_or(Size::S64, Location::GPR(tmp), Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_vaddss(tmp_out, XMMOrMemory::XMM(tmp_out), tmp_out); self.assembler.emit_label(end_convert); - self.assembler.emit_mov(Size::S32, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp); self.machine.release_temp_gpr(tmp_in); @@ -4573,7 +4946,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f64 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f64 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4597,9 +4971,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2sd_32(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S64, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2sd_32(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4613,7 +4990,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f64 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i32 to f64 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4637,9 +5015,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S64, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4653,7 +5034,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f64 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f64 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4677,9 +5059,12 @@ impl<'a> FuncGen<'a> { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); let tmp_in = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_mov(Size::S64, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp_in); self.machine.release_temp_xmm(tmp_out); @@ -4693,7 +5078,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f64 never results in NaN. + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // Converting i64 to f64 never results in NaN. if self.assembler.arch_has_fconverti() { let tmp_out = self.machine.acquire_temp_xmm().unwrap(); @@ -4721,20 +5107,29 @@ impl<'a> FuncGen<'a> { let do_convert = self.assembler.get_label(); let end_convert = self.assembler.get_label(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(tmp_in)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(tmp_in)); self.assembler.emit_test_gpr_64(tmp_in); self.assembler.emit_jmp(Condition::Signed, do_convert); - self.assembler.emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); self.assembler.emit_jmp(Condition::None, end_convert); self.assembler.emit_label(do_convert); - self.assembler.emit_mov(Size::S64, Location::GPR(tmp_in), Location::GPR(tmp)); - self.assembler.emit_and(Size::S64, Location::Imm32(1), Location::GPR(tmp)); - self.assembler.emit_shr(Size::S64, Location::Imm8(1), Location::GPR(tmp_in)); - self.assembler.emit_or(Size::S64, Location::GPR(tmp), Location::GPR(tmp_in)); - self.assembler.emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); - self.assembler.emit_vaddsd(tmp_out, XMMOrMemory::XMM(tmp_out), tmp_out); + self.assembler + .emit_mov(Size::S64, Location::GPR(tmp_in), Location::GPR(tmp)); + self.assembler + .emit_and(Size::S64, Location::Imm32(1), Location::GPR(tmp)); + self.assembler + .emit_shr(Size::S64, Location::Imm8(1), Location::GPR(tmp_in)); + self.assembler + .emit_or(Size::S64, Location::GPR(tmp), Location::GPR(tmp_in)); + self.assembler + .emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out); + self.assembler + .emit_vaddsd(tmp_out, XMMOrMemory::XMM(tmp_out), tmp_out); self.assembler.emit_label(end_convert); - self.assembler.emit_mov(Size::S64, Location::XMM(tmp_out), ret); + self.assembler + .emit_mov(Size::S64, Location::XMM(tmp_out), ret); self.machine.release_temp_gpr(tmp); self.machine.release_temp_gpr(tmp_in); @@ -4745,16 +5140,21 @@ impl<'a> FuncGen<'a> { Operator::Call { function_index } => { let function_index = function_index as usize; - let sig_index = - *self.module.functions.get(FunctionIndex::new(function_index)).unwrap(); + let sig_index = *self + .module + .functions + .get(FunctionIndex::new(function_index)) + .unwrap(); let sig = self.module.signatures.get(sig_index).unwrap(); let param_types: SmallVec<[WpType; 8]> = sig.params().iter().cloned().map(type_to_wp_type).collect(); let return_types: SmallVec<[WpType; 1]> = sig.results().iter().cloned().map(type_to_wp_type).collect(); - let params: SmallVec<[_; 8]> = - self.value_stack.drain(self.value_stack.len() - param_types.len()..).collect(); + let params: SmallVec<[_; 8]> = self + .value_stack + .drain(self.value_stack.len() - param_types.len()..) + .collect(); self.machine.release_locations_only_regs(¶ms); self.machine.release_locations_only_osr_state(params.len()); @@ -4807,27 +5207,36 @@ impl<'a> FuncGen<'a> { self.emit_call_sysv( |this| { let offset = this.assembler.get_offset().0; - this.trap_table.offset_to_code.insert(offset, TrapCode::StackOverflow); + this.trap_table + .offset_to_code + .insert(offset, TrapCode::StackOverflow); this.assembler.emit_call_location(Location::GPR(GPR::RAX)); this.mark_instruction_address_end(offset); }, params.iter().copied(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, ¶ms); + self.machine + .release_locations_only_stack(&mut self.assembler, ¶ms); if !return_types.is_empty() { let ret = self.machine.acquire_locations( &mut self.assembler, - &[(return_types[0], MachineValue::WasmStack(self.value_stack.len()))], + &[( + return_types[0], + MachineValue::WasmStack(self.value_stack.len()), + )], false, )[0]; self.value_stack.push(ret); if return_types[0].is_float() { - self.assembler.emit_mov(Size::S64, Location::XMM(XMM::XMM0), ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.assembler + .emit_mov(Size::S64, Location::XMM(XMM::XMM0), ret); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); } else { - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } } } @@ -4844,8 +5253,10 @@ impl<'a> FuncGen<'a> { let func_index = self.pop_value_released(); - let params: SmallVec<[_; 8]> = - self.value_stack.drain(self.value_stack.len() - param_types.len()..).collect(); + let params: SmallVec<[_; 8]> = self + .value_stack + .drain(self.value_stack.len() - param_types.len()..) + .collect(); self.machine.release_locations_only_regs(¶ms); // Pop arguments off the FP stack and canonicalize them if needed. @@ -4875,7 +5286,8 @@ impl<'a> FuncGen<'a> { if let Some(local_table_index) = self.module.local_table_index(table_index) { let (vmctx_offset_base, vmctx_offset_len) = ( self.vmoffsets.vmctx_vmtable_definition(local_table_index), - self.vmoffsets.vmctx_vmtable_definition_current_elements(local_table_index), + self.vmoffsets + .vmctx_vmtable_definition_current_elements(local_table_index), ); self.assembler.emit_mov( Size::S64, @@ -4914,10 +5326,12 @@ impl<'a> FuncGen<'a> { ); } - self.assembler.emit_cmp(Size::S32, func_index, Location::GPR(table_count)); + self.assembler + .emit_cmp(Size::S32, func_index, Location::GPR(table_count)); self.assembler .emit_jmp(Condition::BelowEqual, self.special_labels.table_access_oob); - self.assembler.emit_mov(Size::S32, func_index, Location::GPR(table_count)); + self.assembler + .emit_mov(Size::S32, func_index, Location::GPR(table_count)); self.assembler .emit_imul_imm32_gpr64(self.vmoffsets.size_of_vm_funcref() as u32, table_count); self.assembler.emit_add( @@ -4933,8 +5347,10 @@ impl<'a> FuncGen<'a> { Location::GPR(table_count), ); // Trap if the FuncRef is null - self.assembler.emit_cmp(Size::S64, Location::Imm32(0), Location::GPR(table_count)); - self.assembler.emit_jmp(Condition::Equal, self.special_labels.indirect_call_null); + self.assembler + .emit_cmp(Size::S64, Location::Imm32(0), Location::GPR(table_count)); + self.assembler + .emit_jmp(Condition::Equal, self.special_labels.indirect_call_null); self.assembler.emit_mov( Size::S64, Location::Memory( @@ -4953,7 +5369,8 @@ impl<'a> FuncGen<'a> { (self.vmoffsets.vmcaller_checked_anyfunc_type_index() as usize) as i32, ), ); - self.assembler.emit_jmp(Condition::NotEqual, self.special_labels.bad_signature); + self.assembler + .emit_jmp(Condition::NotEqual, self.special_labels.bad_signature); self.machine.release_temp_gpr(sigidx); self.machine.release_temp_gpr(table_count); @@ -4983,7 +5400,9 @@ impl<'a> FuncGen<'a> { ); } else { let offset = this.assembler.get_offset().0; - this.trap_table.offset_to_code.insert(offset, TrapCode::StackOverflow); + this.trap_table + .offset_to_code + .insert(offset, TrapCode::StackOverflow); this.assembler.emit_call_location(Location::Memory( GPR::RAX, vmcaller_checked_anyfunc_func_ptr as i32, @@ -4994,20 +5413,27 @@ impl<'a> FuncGen<'a> { params.iter().copied(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, ¶ms); + self.machine + .release_locations_only_stack(&mut self.assembler, ¶ms); if !return_types.is_empty() { let ret = self.machine.acquire_locations( &mut self.assembler, - &[(return_types[0], MachineValue::WasmStack(self.value_stack.len()))], + &[( + return_types[0], + MachineValue::WasmStack(self.value_stack.len()), + )], false, )[0]; self.value_stack.push(ret); if return_types[0].is_float() { - self.assembler.emit_mov(Size::S64, Location::XMM(XMM::XMM0), ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.assembler + .emit_mov(Size::S64, Location::XMM(XMM::XMM0), ret); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); } else { - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } } } @@ -5081,7 +5507,8 @@ impl<'a> FuncGen<'a> { let mut frame = self.control_stack.last_mut().unwrap(); let released: &[Location] = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations(&mut self.assembler, released); + self.machine + .release_locations(&mut self.assembler, released); self.value_stack.truncate(frame.value_stack_depth); self.fp_stack.truncate(frame.fp_stack_depth); @@ -5247,7 +5674,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::MemoryGrow { mem, mem_byte: _ } => { let memory_index = MemoryIndex::new(mem as usize); @@ -5281,7 +5709,8 @@ impl<'a> FuncGen<'a> { .chain(iter::once(Location::Imm32(memory_index.index() as u32))), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[param_pages]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[param_pages]); let ret = self.machine.acquire_locations( &mut self.assembler, @@ -5289,7 +5718,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::I32Load { ref memarg } => { let target = self.pop_value_released(); @@ -5318,7 +5748,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); self.emit_memory_op(target, memarg, false, 4, |this, addr| { this.emit_relaxed_binop( @@ -5503,7 +5934,8 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); self.emit_memory_op(target, memarg, false, 8, |this, addr| { this.emit_relaxed_binop( @@ -5731,7 +6163,9 @@ impl<'a> FuncGen<'a> { Operator::Unreachable => { self.mark_trappable(); let offset = self.assembler.get_offset().0; - self.trap_table.offset_to_code.insert(offset, TrapCode::UnreachableCodeReached); + self.trap_table + .offset_to_code + .insert(offset, TrapCode::UnreachableCodeReached); self.assembler.emit_ud2(); self.mark_instruction_address_end(offset); self.unreachable_depth = 1; @@ -5780,7 +6214,8 @@ impl<'a> FuncGen<'a> { } let frame = &self.control_stack[0]; let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations_keep_state(&mut self.assembler, released); + self.machine + .release_locations_keep_state(&mut self.assembler, released); self.assembler.emit_jmp(Condition::None, frame.label); self.unreachable_depth = 1; } @@ -5820,14 +6255,16 @@ impl<'a> FuncGen<'a> { ); } } else { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); } } let frame = &self.control_stack[self.control_stack.len() - 1 - (relative_depth as usize)]; let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations_keep_state(&mut self.assembler, released); + self.machine + .release_locations_keep_state(&mut self.assembler, released); self.assembler.emit_jmp(Condition::None, frame.label); self.unreachable_depth = 1; } @@ -5872,21 +6309,26 @@ impl<'a> FuncGen<'a> { ); } } else { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); } } let frame = &self.control_stack[self.control_stack.len() - 1 - (relative_depth as usize)]; let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations_keep_state(&mut self.assembler, released); + self.machine + .release_locations_keep_state(&mut self.assembler, released); self.assembler.emit_jmp(Condition::None, frame.label); self.assembler.emit_label(after); } Operator::BrTable { ref table } => { - let mut targets = table.targets().collect::, _>>().map_err(|e| { - CodegenError { message: format!("BrTable read_table: {:?}", e) } - })?; + let mut targets = table + .targets() + .collect::, _>>() + .map_err(|e| CodegenError { + message: format!("BrTable read_table: {:?}", e), + })?; let default_target = targets.pop().unwrap().0; let cond = self.pop_value_released(); let table_label = self.assembler.get_label(); @@ -5900,11 +6342,14 @@ impl<'a> FuncGen<'a> { ); self.assembler.emit_jmp(Condition::AboveEqual, default_br); - self.assembler.emit_lea_label(table_label, Location::GPR(GPR::RCX)); - self.assembler.emit_mov(Size::S32, cond, Location::GPR(GPR::RDX)); + self.assembler + .emit_lea_label(table_label, Location::GPR(GPR::RCX)); + self.assembler + .emit_mov(Size::S32, cond, Location::GPR(GPR::RDX)); let instr_size = self.assembler.get_jmp_instr_size(); - self.assembler.emit_imul_imm32_gpr64(instr_size as _, GPR::RDX); + self.assembler + .emit_imul_imm32_gpr64(instr_size as _, GPR::RDX); self.assembler.emit_add( Size::S64, Location::GPR(GPR::RCX), @@ -5954,13 +6399,15 @@ impl<'a> FuncGen<'a> { ); } } else { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); } } let frame = &self.control_stack[self.control_stack.len() - 1 - (*target as usize)]; let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations_keep_state(&mut self.assembler, released); + self.machine + .release_locations_keep_state(&mut self.assembler, released); self.assembler.emit_jmp(Condition::None, frame.label); } self.assembler.emit_label(default_br); @@ -6001,13 +6448,15 @@ impl<'a> FuncGen<'a> { ); } } else { - self.assembler.emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(GPR::RAX)); } } let frame = &self.control_stack [self.control_stack.len() - 1 - (default_target as usize)]; let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations_keep_state(&mut self.assembler, released); + self.machine + .release_locations_keep_state(&mut self.assembler, released); self.assembler.emit_jmp(Condition::None, frame.label); } @@ -6065,7 +6514,8 @@ impl<'a> FuncGen<'a> { if self.control_stack.is_empty() { self.assembler.emit_label(frame.label); - self.machine.finalize_locals(&mut self.assembler, &self.locals); + self.machine + .finalize_locals(&mut self.assembler, &self.locals); self.assembler.emit_mov( Size::S64, Location::GPR(GPR::RBP), @@ -6087,7 +6537,8 @@ impl<'a> FuncGen<'a> { self.assembler.emit_ret(); } else { let released = &self.value_stack[frame.value_stack_depth..]; - self.machine.release_locations(&mut self.assembler, released); + self.machine + .release_locations(&mut self.assembler, released); self.value_stack.truncate(frame.value_stack_depth); self.fp_stack.truncate(frame.fp_stack_depth); @@ -6107,13 +6558,18 @@ impl<'a> FuncGen<'a> { } let loc = self.machine.acquire_locations( &mut self.assembler, - &[(frame.returns[0], MachineValue::WasmStack(self.value_stack.len()))], + &[( + frame.returns[0], + MachineValue::WasmStack(self.value_stack.len()), + )], false, )[0]; - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), loc); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), loc); self.value_stack.push(loc); if frame.returns[0].is_float() { - self.fp_stack.push(FloatValue::new(self.value_stack.len() - 1)); + self.fp_stack + .push(FloatValue::new(self.value_stack.len() - 1)); // we already canonicalized at the `Br*` instruction or here previously. } } @@ -6389,7 +6845,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_lock_xadd( Size::S32, @@ -6398,7 +6855,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmwAdd { ref memarg } => { @@ -6412,7 +6870,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 8, |this, addr| { this.assembler.emit_lock_xadd( Size::S64, @@ -6421,7 +6880,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw8AddU { ref memarg } => { @@ -6435,7 +6895,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_xadd( Size::S8, @@ -6444,7 +6905,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw16AddU { ref memarg } => { @@ -6458,7 +6920,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_lock_xadd( Size::S16, @@ -6467,7 +6930,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw8AddU { ref memarg } => { @@ -6481,7 +6945,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_xadd( Size::S8, @@ -6490,7 +6955,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw16AddU { ref memarg } => { @@ -6504,7 +6970,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_lock_xadd( Size::S16, @@ -6513,7 +6980,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw32AddU { ref memarg } => { @@ -6527,7 +6995,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_lock_xadd( Size::S32, @@ -6536,7 +7005,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmwSub { ref memarg } => { @@ -6550,7 +7020,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.assembler.emit_neg(Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_lock_xadd( @@ -6560,7 +7031,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmwSub { ref memarg } => { @@ -6574,7 +7046,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(value)); self.assembler.emit_neg(Size::S64, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 8, |this, addr| { this.assembler.emit_lock_xadd( @@ -6584,7 +7057,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw8SubU { ref memarg } => { @@ -6598,7 +7072,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); self.assembler.emit_neg(Size::S8, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_xadd( @@ -6608,7 +7083,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw16SubU { ref memarg } => { @@ -6622,7 +7098,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); self.assembler.emit_neg(Size::S16, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_lock_xadd( @@ -6632,7 +7109,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw8SubU { ref memarg } => { @@ -6646,7 +7124,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); self.assembler.emit_neg(Size::S8, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_xadd( @@ -6656,7 +7135,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw16SubU { ref memarg } => { @@ -6670,7 +7150,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); self.assembler.emit_neg(Size::S16, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_lock_xadd( @@ -6680,7 +7161,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw32SubU { ref memarg } => { @@ -6694,7 +7176,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.assembler.emit_neg(Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_lock_xadd( @@ -6704,7 +7187,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmwAnd { ref memarg } => { @@ -6726,7 +7210,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S32, |this, src, dst| { - this.assembler.emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6749,7 +7234,8 @@ impl<'a> FuncGen<'a> { Size::S64, Size::S64, |this, src, dst| { - this.assembler.emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6772,7 +7258,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S32, |this, src, dst| { - this.assembler.emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6795,7 +7282,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S32, |this, src, dst| { - this.assembler.emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6818,7 +7306,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S64, |this, src, dst| { - this.assembler.emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6841,7 +7330,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S64, |this, src, dst| { - this.assembler.emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6864,7 +7354,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S64, |this, src, dst| { - this.assembler.emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_and(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6887,7 +7378,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S32, |this, src, dst| { - this.assembler.emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6910,7 +7402,8 @@ impl<'a> FuncGen<'a> { Size::S64, Size::S64, |this, src, dst| { - this.assembler.emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6933,7 +7426,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S32, |this, src, dst| { - this.assembler.emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6956,7 +7450,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S32, |this, src, dst| { - this.assembler.emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -6979,7 +7474,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S64, |this, src, dst| { - this.assembler.emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7002,7 +7498,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S64, |this, src, dst| { - this.assembler.emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7025,7 +7522,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S64, |this, src, dst| { - this.assembler.emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_or(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7048,7 +7546,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S32, |this, src, dst| { - this.assembler.emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7071,7 +7570,8 @@ impl<'a> FuncGen<'a> { Size::S64, Size::S64, |this, src, dst| { - this.assembler.emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7094,7 +7594,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S32, |this, src, dst| { - this.assembler.emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7117,7 +7618,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S32, |this, src, dst| { - this.assembler.emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S32, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7140,7 +7642,8 @@ impl<'a> FuncGen<'a> { Size::S8, Size::S64, |this, src, dst| { - this.assembler.emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7163,7 +7666,8 @@ impl<'a> FuncGen<'a> { Size::S16, Size::S64, |this, src, dst| { - this.assembler.emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7186,7 +7690,8 @@ impl<'a> FuncGen<'a> { Size::S32, Size::S64, |this, src, dst| { - this.assembler.emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); + this.assembler + .emit_xor(Size::S64, Location::GPR(src), Location::GPR(dst)); }, )?; } @@ -7201,7 +7706,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_xchg( Size::S32, @@ -7210,7 +7716,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmwXchg { ref memarg } => { @@ -7224,7 +7731,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S64, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 8, |this, addr| { this.assembler.emit_xchg( Size::S64, @@ -7233,7 +7741,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw8XchgU { ref memarg } => { @@ -7247,7 +7756,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_xchg( Size::S8, @@ -7256,7 +7766,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmw16XchgU { ref memarg } => { @@ -7270,7 +7781,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_xchg( Size::S16, @@ -7279,7 +7791,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S32, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw8XchgU { ref memarg } => { @@ -7293,7 +7806,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_xchg( Size::S8, @@ -7302,7 +7816,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw16XchgU { ref memarg } => { @@ -7316,7 +7831,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); + self.assembler + .emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 2, |this, addr| { this.assembler.emit_xchg( Size::S16, @@ -7325,7 +7841,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I64AtomicRmw32XchgU { ref memarg } => { @@ -7339,7 +7856,8 @@ impl<'a> FuncGen<'a> { self.value_stack.push(ret); let value = self.machine.acquire_temp_gpr().unwrap(); - self.assembler.emit_mov(Size::S32, loc, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, loc, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_xchg( Size::S32, @@ -7348,7 +7866,8 @@ impl<'a> FuncGen<'a> { ); Ok(()) })?; - self.assembler.emit_mov(Size::S64, Location::GPR(value), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(value), ret); self.machine.release_temp_gpr(value); } Operator::I32AtomicRmwCmpxchg { ref memarg } => { @@ -7373,8 +7892,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S32, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S32, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S32, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 4, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7382,7 +7903,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_mov(Size::S32, Location::GPR(compare), ret); + this.assembler + .emit_mov(Size::S32, Location::GPR(compare), ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7410,8 +7932,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S64, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S64, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S64, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 8, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7419,7 +7943,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_mov(Size::S64, Location::GPR(compare), ret); + this.assembler + .emit_mov(Size::S64, Location::GPR(compare), ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7447,8 +7972,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S32, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S32, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S32, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7456,7 +7983,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_movzx(Size::S8, Location::GPR(compare), Size::S32, ret); + this.assembler + .emit_movzx(Size::S8, Location::GPR(compare), Size::S32, ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7484,8 +8012,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S32, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S32, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S32, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S32, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7493,7 +8023,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_movzx(Size::S16, Location::GPR(compare), Size::S32, ret); + this.assembler + .emit_movzx(Size::S16, Location::GPR(compare), Size::S32, ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7521,8 +8052,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S64, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S64, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S64, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7530,7 +8063,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_movzx(Size::S8, Location::GPR(compare), Size::S64, ret); + this.assembler + .emit_movzx(Size::S8, Location::GPR(compare), Size::S64, ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7558,8 +8092,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S64, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S64, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S64, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7567,7 +8103,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_movzx(Size::S16, Location::GPR(compare), Size::S64, ret); + this.assembler + .emit_movzx(Size::S16, Location::GPR(compare), Size::S64, ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7595,8 +8132,10 @@ impl<'a> FuncGen<'a> { GPR::R14 }; self.assembler.emit_push(Size::S64, Location::GPR(value)); - self.assembler.emit_mov(Size::S64, cmp, Location::GPR(compare)); - self.assembler.emit_mov(Size::S64, new, Location::GPR(value)); + self.assembler + .emit_mov(Size::S64, cmp, Location::GPR(compare)); + self.assembler + .emit_mov(Size::S64, new, Location::GPR(value)); self.emit_memory_op(target, memarg, true, 1, |this, addr| { this.assembler.emit_lock_cmpxchg( @@ -7604,7 +8143,8 @@ impl<'a> FuncGen<'a> { Location::GPR(value), Location::Memory(addr, 0), ); - this.assembler.emit_mov(Size::S32, Location::GPR(compare), ret); + this.assembler + .emit_mov(Size::S32, Location::GPR(compare), ret); Ok(()) })?; self.assembler.emit_pop(Size::S64, Location::GPR(value)); @@ -7613,7 +8153,10 @@ impl<'a> FuncGen<'a> { Operator::RefNull { .. } => { self.value_stack.push(Location::Imm64(0)); - self.machine.state.wasm_stack.push(WasmAbstractValue::Const(0)); + self.machine + .state + .wasm_stack + .push(WasmAbstractValue::Const(0)); } Operator::RefFunc { function_index } => { self.assembler.emit_mov( @@ -7639,11 +8182,15 @@ impl<'a> FuncGen<'a> { let ret = self.machine.acquire_locations( &mut self.assembler, - &[(WpType::FuncRef, MachineValue::WasmStack(self.value_stack.len()))], + &[( + WpType::FuncRef, + MachineValue::WasmStack(self.value_stack.len()), + )], false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::RefIsNull => { self.emit_cmpop_i64_dynamic_b(Condition::Equal, Location::Imm64(0))?; @@ -7677,10 +8224,13 @@ impl<'a> FuncGen<'a> { this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, table_index, elem_index, reftype] - [Location::Imm32(table_index.index() as u32), index, value].iter().cloned(), + [Location::Imm32(table_index.index() as u32), index, value] + .iter() + .cloned(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[index, value]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[index, value]); } Operator::TableGet { table: index } => { let table_index = TableIndex::new(index as _); @@ -7708,18 +8258,25 @@ impl<'a> FuncGen<'a> { this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, table_index, elem_index] -> reftype - [Location::Imm32(table_index.index() as u32), index].iter().cloned(), + [Location::Imm32(table_index.index() as u32), index] + .iter() + .cloned(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[index]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[index]); let ret = self.machine.acquire_locations( &mut self.assembler, - &[(WpType::FuncRef, MachineValue::WasmStack(self.value_stack.len()))], + &[( + WpType::FuncRef, + MachineValue::WasmStack(self.value_stack.len()), + )], false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S64, Location::GPR(GPR::RAX), ret); } Operator::TableSize { table: index } => { let table_index = TableIndex::new(index as _); @@ -7753,13 +8310,15 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); } Operator::TableGrow { table: index } => { let table_index = TableIndex::new(index as _); let delta = self.value_stack.pop().unwrap(); let init_value = self.value_stack.pop().unwrap(); - self.machine.release_locations_only_regs(&[delta, init_value]); + self.machine + .release_locations_only_regs(&[delta, init_value]); self.assembler.emit_mov( Size::S64, @@ -7783,9 +8342,13 @@ impl<'a> FuncGen<'a> { this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, init_value, delta, table_index] -> u32 - [init_value, delta, Location::Imm32(table_index.index() as u32)] - .iter() - .cloned(), + [ + init_value, + delta, + Location::Imm32(table_index.index() as u32), + ] + .iter() + .cloned(), )?; self.machine @@ -7797,9 +8360,13 @@ impl<'a> FuncGen<'a> { false, )[0]; self.value_stack.push(ret); - self.assembler.emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); + self.assembler + .emit_mov(Size::S32, Location::GPR(GPR::RAX), ret); } - Operator::TableCopy { dst_table, src_table } => { + Operator::TableCopy { + dst_table, + src_table, + } => { let len = self.value_stack.pop().unwrap(); let src = self.value_stack.pop().unwrap(); let dest = self.value_stack.pop().unwrap(); @@ -7823,12 +8390,19 @@ impl<'a> FuncGen<'a> { this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, dst_table_index, src_table_index, dst, src, len] - [Location::Imm32(dst_table), Location::Imm32(src_table), dest, src, len] - .iter() - .cloned(), + [ + Location::Imm32(dst_table), + Location::Imm32(src_table), + dest, + src, + len, + ] + .iter() + .cloned(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[dest, src, len]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[dest, src, len]); } Operator::TableFill { table } => { @@ -7858,7 +8432,8 @@ impl<'a> FuncGen<'a> { [Location::Imm32(table), dest, val, len].iter().cloned(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[dest, val, len]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[dest, val, len]); } Operator::TableInit { segment, table } => { let len = self.value_stack.pop().unwrap(); @@ -7884,12 +8459,19 @@ impl<'a> FuncGen<'a> { this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, table_index, elem_index, dst, src, len] - [Location::Imm32(table), Location::Imm32(segment), dest, src, len] - .iter() - .cloned(), + [ + Location::Imm32(table), + Location::Imm32(segment), + dest, + src, + len, + ] + .iter() + .cloned(), )?; - self.machine.release_locations_only_stack(&mut self.assembler, &[dest, src, len]); + self.machine + .release_locations_only_stack(&mut self.assembler, &[dest, src, len]); } Operator::ElemDrop { segment } => { self.assembler.emit_mov( @@ -7914,7 +8496,9 @@ impl<'a> FuncGen<'a> { )?; } _ => { - return Err(CodegenError { message: format!("not yet implemented: {:?}", op) }); + return Err(CodegenError { + message: format!("not yet implemented: {:?}", op), + }); } } @@ -7923,19 +8507,23 @@ impl<'a> FuncGen<'a> { pub fn finalize(mut self, data: &FunctionBodyData) -> CompiledFunction { // Generate actual code for special labels. - self.assembler.emit_label(self.special_labels.integer_division_by_zero); + self.assembler + .emit_label(self.special_labels.integer_division_by_zero); self.mark_address_with_trap_code(TrapCode::IntegerDivisionByZero); self.assembler.emit_ud2(); - self.assembler.emit_label(self.special_labels.heap_access_oob); + self.assembler + .emit_label(self.special_labels.heap_access_oob); self.mark_address_with_trap_code(TrapCode::HeapAccessOutOfBounds); self.assembler.emit_ud2(); - self.assembler.emit_label(self.special_labels.table_access_oob); + self.assembler + .emit_label(self.special_labels.table_access_oob); self.mark_address_with_trap_code(TrapCode::TableAccessOutOfBounds); self.assembler.emit_ud2(); - self.assembler.emit_label(self.special_labels.indirect_call_null); + self.assembler + .emit_label(self.special_labels.indirect_call_null); self.mark_address_with_trap_code(TrapCode::IndirectCallToNull); self.assembler.emit_ud2(); @@ -8056,11 +8644,23 @@ pub fn gen_std_trampoline(sig: &FunctionType) -> FunctionBody { a.emit_push(Size::S64, Location::GPR(GPR::R14)); // Prepare stack space. - a.emit_sub(Size::S64, Location::Imm32(stack_offset), Location::GPR(GPR::RSP)); + a.emit_sub( + Size::S64, + Location::Imm32(stack_offset), + Location::GPR(GPR::RSP), + ); // Arguments - a.emit_mov(Size::S64, Machine::get_param_location(1), Location::GPR(GPR::R15)); // func_ptr - a.emit_mov(Size::S64, Machine::get_param_location(2), Location::GPR(GPR::R14)); // args_rets + a.emit_mov( + Size::S64, + Machine::get_param_location(1), + Location::GPR(GPR::R15), + ); // func_ptr + a.emit_mov( + Size::S64, + Machine::get_param_location(2), + Location::GPR(GPR::R14), + ); // args_rets // Move arguments to their locations. // `callee_vmctx` is already in the first argument register, so no need to move. @@ -8094,11 +8694,19 @@ pub fn gen_std_trampoline(sig: &FunctionType) -> FunctionBody { a.emit_call_location(Location::GPR(GPR::R15)); // Restore stack. - a.emit_add(Size::S64, Location::Imm32(stack_offset), Location::GPR(GPR::RSP)); + a.emit_add( + Size::S64, + Location::Imm32(stack_offset), + Location::GPR(GPR::RSP), + ); // Write return value. if !sig.results().is_empty() { - a.emit_mov(Size::S64, Location::GPR(GPR::RAX), Location::Memory(GPR::R14, 0)); + a.emit_mov( + Size::S64, + Location::GPR(GPR::RAX), + Location::Memory(GPR::R14, 0), + ); } // Restore callee-saved registers. @@ -8107,7 +8715,10 @@ pub fn gen_std_trampoline(sig: &FunctionType) -> FunctionBody { a.emit_ret(); - FunctionBody { body: a.finalize().unwrap().to_vec(), unwind_info: None } + FunctionBody { + body: a.finalize().unwrap().to_vec(), + unwind_info: None, + } } /// Generates dynamic import function call trampoline for a function type. @@ -8119,7 +8730,11 @@ pub fn gen_std_dynamic_import_trampoline( // Allocate argument array. let stack_offset: usize = 16 * std::cmp::max(sig.params().len(), sig.results().len()) + 8; // 16 bytes each + 8 bytes sysv call padding - a.emit_sub(Size::S64, Location::Imm32(stack_offset as _), Location::GPR(GPR::RSP)); + a.emit_sub( + Size::S64, + Location::Imm32(stack_offset as _), + Location::GPR(GPR::RSP), + ); // Copy arguments. if !sig.params().is_empty() { @@ -8142,7 +8757,11 @@ pub fn gen_std_dynamic_import_trampoline( Location::GPR(GPR::RAX) } }; - a.emit_mov(Size::S64, source_loc, Location::Memory(GPR::RSP, (i * 16) as _)); + a.emit_mov( + Size::S64, + source_loc, + Location::Memory(GPR::RSP, (i * 16) as _), + ); // Zero upper 64 bits. a.emit_mov( @@ -8156,7 +8775,10 @@ pub fn gen_std_dynamic_import_trampoline( // Load target address. a.emit_mov( Size::S64, - Location::Memory(GPR::RDI, vmoffsets.vmdynamicfunction_import_context_address() as i32), + Location::Memory( + GPR::RDI, + vmoffsets.vmdynamicfunction_import_context_address() as i32, + ), Location::GPR(GPR::RAX), ); @@ -8169,16 +8791,27 @@ pub fn gen_std_dynamic_import_trampoline( // Fetch return value. if !sig.results().is_empty() { assert_eq!(sig.results().len(), 1); - a.emit_mov(Size::S64, Location::Memory(GPR::RSP, 0), Location::GPR(GPR::RAX)); + a.emit_mov( + Size::S64, + Location::Memory(GPR::RSP, 0), + Location::GPR(GPR::RAX), + ); } // Release values array. - a.emit_add(Size::S64, Location::Imm32(stack_offset as _), Location::GPR(GPR::RSP)); + a.emit_add( + Size::S64, + Location::Imm32(stack_offset as _), + Location::GPR(GPR::RSP), + ); // Return. a.emit_ret(); - FunctionBody { body: a.finalize().unwrap().to_vec(), unwind_info: None } + FunctionBody { + body: a.finalize().unwrap().to_vec(), + unwind_info: None, + } } // Singlepass calls import functions through a trampoline. @@ -8197,14 +8830,25 @@ pub fn gen_import_call_trampoline( // FIXME: This is only a workaround. We should fix singlepass to use the standard CC. // Translation is expensive, so only do it if needed. - if sig.params().iter().any(|&x| x == Type::F32 || x == Type::F64) { + if sig + .params() + .iter() + .any(|&x| x == Type::F32 || x == Type::F64) + { let mut param_locations: Vec = vec![]; // Allocate stack space for arguments. - let stack_offset: i32 = - if sig.params().len() > 5 { 5 * 8 } else { (sig.params().len() as i32) * 8 }; + let stack_offset: i32 = if sig.params().len() > 5 { + 5 * 8 + } else { + (sig.params().len() as i32) * 8 + }; if stack_offset > 0 { - a.emit_sub(Size::S64, Location::Imm32(stack_offset as u32), Location::GPR(GPR::RSP)); + a.emit_sub( + Size::S64, + Location::Imm32(stack_offset as u32), + Location::GPR(GPR::RSP), + ); } // Store all arguments to the stack to prevent overwrite. @@ -8251,7 +8895,11 @@ pub fn gen_import_call_trampoline( // Restore stack pointer. if stack_offset > 0 { - a.emit_add(Size::S64, Location::Imm32(stack_offset as u32), Location::GPR(GPR::RSP)); + a.emit_add( + Size::S64, + Location::Imm32(stack_offset as u32), + Location::GPR(GPR::RSP), + ); } } diff --git a/lib/compiler-singlepass/src/common_decl.rs b/lib/compiler-singlepass/src/common_decl.rs index 4164c0baa..e59095822 100644 --- a/lib/compiler-singlepass/src/common_decl.rs +++ b/lib/compiler-singlepass/src/common_decl.rs @@ -174,15 +174,13 @@ impl MachineState { let prev_frame_diff: BTreeMap> = self .prev_frame .iter() - .filter( - |(k, v)| { - if let Some(ref old_v) = old.prev_frame.get(k) { - v != old_v - } else { - true - } - }, - ) + .filter(|(k, v)| { + if let Some(ref old_v) = old.prev_frame.get(k) { + v != old_v + } else { + true + } + }) .map(|(&k, v)| (k, Some(v.clone()))) .chain( old.prev_frame diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index a6df0621d..edc1d93a4 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -51,7 +51,9 @@ impl Compiler for SinglepassCompiler { function_body_inputs: PrimaryMap>, ) -> Result { if target.triple().operating_system == OperatingSystem::Windows { - return Err(CompileError::UnsupportedTarget(OperatingSystem::Windows.to_string())); + return Err(CompileError::UnsupportedTarget( + OperatingSystem::Windows.to_string(), + )); } if let Architecture::X86_32(arch) = target.triple().architecture { return Err(CompileError::UnsupportedTarget(arch.to_string())); @@ -81,8 +83,10 @@ impl Compiler for SinglepassCompiler { .collect::)>>() .par_iter() .map(|(i, input)| { - let middleware_chain = - self.config.middlewares.generate_function_middleware_chain(*i); + let middleware_chain = self + .config + .middlewares + .generate_function_middleware_chain(*i); let mut reader = MiddlewareBinaryReader::new_with_offset(input.data, input.module_offset); reader.set_middleware_chain(middleware_chain); diff --git a/lib/compiler-singlepass/src/config.rs b/lib/compiler-singlepass/src/config.rs index a4c0e298a..d788478a9 100644 --- a/lib/compiler-singlepass/src/config.rs +++ b/lib/compiler-singlepass/src/config.rs @@ -19,7 +19,11 @@ impl Singlepass { /// Creates a new configuration object with the default configuration /// specified. pub fn new() -> Self { - Self { enable_nan_canonicalization: true, enable_stack_check: false, middlewares: vec![] } + Self { + enable_nan_canonicalization: true, + enable_stack_check: false, + middlewares: vec![], + } } /// Enable stack check. diff --git a/lib/compiler-singlepass/src/emitter_x64.rs b/lib/compiler-singlepass/src/emitter_x64.rs index 8713a8222..b5f4f2349 100644 --- a/lib/compiler-singlepass/src/emitter_x64.rs +++ b/lib/compiler-singlepass/src/emitter_x64.rs @@ -1051,7 +1051,10 @@ impl Emitter for Assembler { dynasm!(self ; movzx Rq(dst as u8), WORD [Rq(src as u8) + disp]); } _ => { - panic!("singlepass can't emit MOVZX {:?} {:?} {:?} {:?}", sz_src, src, sz_dst, dst) + panic!( + "singlepass can't emit MOVZX {:?} {:?} {:?} {:?}", + sz_src, src, sz_dst, dst + ) } } } @@ -1088,7 +1091,10 @@ impl Emitter for Assembler { dynasm!(self ; movsx Rq(dst as u8), DWORD [Rq(src as u8) + disp]); } _ => { - panic!("singlepass can't emit MOVSX {:?} {:?} {:?} {:?}", sz_src, src, sz_dst, dst) + panic!( + "singlepass can't emit MOVSX {:?} {:?} {:?} {:?}", + sz_src, src, sz_dst, dst + ) } } } @@ -1149,7 +1155,10 @@ impl Emitter for Assembler { (Size::S64, Location::GPR(src), Location::Memory(dst, disp)) => { dynasm!(self ; lock xadd [Rq(dst as u8) + disp], Rq(src as u8)); } - _ => panic!("singlepass can't emit LOCK XADD {:?} {:?} {:?}", sz, src, dst), + _ => panic!( + "singlepass can't emit LOCK XADD {:?} {:?} {:?}", + sz, src, dst + ), } } @@ -1167,7 +1176,10 @@ impl Emitter for Assembler { (Size::S64, Location::GPR(src), Location::Memory(dst, disp)) => { dynasm!(self ; lock cmpxchg [Rq(dst as u8) + disp], Rq(src as u8)); } - _ => panic!("singlepass can't emit LOCK CMPXCHG {:?} {:?} {:?}", sz, src, dst), + _ => panic!( + "singlepass can't emit LOCK CMPXCHG {:?} {:?} {:?}", + sz, src, dst + ), } } diff --git a/lib/compiler-singlepass/src/machine.rs b/lib/compiler-singlepass/src/machine.rs index 74fe8a541..3cf01512f 100644 --- a/lib/compiler-singlepass/src/machine.rs +++ b/lib/compiler-singlepass/src/machine.rs @@ -371,14 +371,19 @@ impl Machine { let callee_saved_regs_size = static_area_size; // Now we can determine concrete locations for locals. - let locations: Vec = - (0..n).map(|i| get_local_location(i, callee_saved_regs_size)).collect(); + let locations: Vec = (0..n) + .map(|i| get_local_location(i, callee_saved_regs_size)) + .collect(); // Add size of locals on stack. static_area_size += num_mem_slots * 8; // Allocate save area, without actually writing to it. - a.emit_sub(Size::S64, Location::Imm32(static_area_size as _), Location::GPR(GPR::RSP)); + a.emit_sub( + Size::S64, + Location::Imm32(static_area_size as _), + Location::GPR(GPR::RSP), + ); // Save callee-saved registers. for loc in locations.iter() { @@ -389,9 +394,9 @@ impl Machine { *loc, Location::Memory(GPR::RBP, -(self.stack_offset.0 as i32)), ); - self.state - .stack_values - .push(MachineValue::PreserveRegister(X64Register::GPR(x).to_index())); + self.state.stack_values.push(MachineValue::PreserveRegister( + X64Register::GPR(x).to_index(), + )); } } @@ -402,9 +407,9 @@ impl Machine { Location::GPR(GPR::R15), Location::Memory(GPR::RBP, -(self.stack_offset.0 as i32)), ); - self.state - .stack_values - .push(MachineValue::PreserveRegister(X64Register::GPR(GPR::R15).to_index())); + self.state.stack_values.push(MachineValue::PreserveRegister( + X64Register::GPR(GPR::R15).to_index(), + )); // Save the offset of register save area. self.save_area_offset = Some(MachineStackOffset(self.stack_offset.0)); @@ -447,7 +452,11 @@ impl Machine { } // Load vmctx into R15. - a.emit_mov(Size::S64, Self::get_param_location(0), Location::GPR(GPR::R15)); + a.emit_mov( + Size::S64, + Self::get_param_location(0), + Location::GPR(GPR::R15), + ); // Stack probe. // @@ -494,7 +503,10 @@ impl Machine { // Unwind stack to the "save area". a.emit_lea( Size::S64, - Location::Memory(GPR::RBP, -(self.save_area_offset.as_ref().unwrap().0 as i32)), + Location::Memory( + GPR::RBP, + -(self.save_area_offset.as_ref().unwrap().0 as i32), + ), Location::GPR(GPR::RSP), ); @@ -533,7 +545,9 @@ mod test { let mut assembler = Assembler::new().unwrap(); let locs = machine.acquire_locations( &mut assembler, - &(0..10).map(|_| (WpType::I32, MachineValue::Undefined)).collect::>(), + &(0..10) + .map(|_| (WpType::I32, MachineValue::Undefined)) + .collect::>(), false, ); diff --git a/lib/compiler-singlepass/src/x64_decl.rs b/lib/compiler-singlepass/src/x64_decl.rs index e51f03208..935090694 100644 --- a/lib/compiler-singlepass/src/x64_decl.rs +++ b/lib/compiler-singlepass/src/x64_decl.rs @@ -202,7 +202,10 @@ impl ArgumentRegisterAllocator { None } } - _ => todo!("ArgumentRegisterAllocator::next: Unsupported type: {:?}", ty), + _ => todo!( + "ArgumentRegisterAllocator::next: Unsupported type: {:?}", + ty + ), } } } diff --git a/lib/compiler/src/compiler.rs b/lib/compiler/src/compiler.rs index 5f153c9df..eff21365c 100644 --- a/lib/compiler/src/compiler.rs +++ b/lib/compiler/src/compiler.rs @@ -83,7 +83,9 @@ pub trait Compiler: Send + MemoryUsage { deterministic_only: false, }; validator.wasm_features(wasm_features); - validator.validate_all(data).map_err(|e| CompileError::Validate(format!("{}", e)))?; + validator + .validate_all(data) + .map_err(|e| CompileError::Validate(format!("{}", e)))?; Ok(()) } diff --git a/lib/compiler/src/error.rs b/lib/compiler/src/error.rs index 47dfd0a6f..cf107ad63 100644 --- a/lib/compiler/src/error.rs +++ b/lib/compiler/src/error.rs @@ -62,7 +62,10 @@ pub struct MiddlewareError { impl MiddlewareError { /// Create a new `MiddlewareError` pub fn new, B: Into>(name: A, message: B) -> Self { - Self { name: name.into(), message: message.into() } + Self { + name: name.into(), + message: message.into(), + } } } diff --git a/lib/compiler/src/function.rs b/lib/compiler/src/function.rs index 45575610d..e431f3bb7 100644 --- a/lib/compiler/src/function.rs +++ b/lib/compiler/src/function.rs @@ -242,7 +242,9 @@ impl<'a> IntoIterator for &'a Compilation { type Item = ::Item; fn into_iter(self) -> Self::IntoIter { - Iter { iterator: self.functions.iter() } + Iter { + iterator: self.functions.iter(), + } } } diff --git a/lib/compiler/src/module.rs b/lib/compiler/src/module.rs index 68d8af115..347003fb6 100644 --- a/lib/compiler/src/module.rs +++ b/lib/compiler/src/module.rs @@ -15,7 +15,10 @@ use wasmer_vm::{MemoryStyle, ModuleInfo, TableStyle}; /// or the `MemoryStyle` and `TableStyle`). #[derive(Debug, MemoryUsage, PartialEq, Eq)] #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct CompileModuleInfo { /// The features used for compiling the module pub features: Features, diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index 911153131..25cec340a 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -116,7 +116,9 @@ impl Relocation { RelocationKind::Abs8 => { let reloc_address = start + self.offset as usize; let reloc_addend = self.addend as isize; - let reloc_abs = target_func_address.checked_add(reloc_addend as u64).unwrap(); + let reloc_abs = target_func_address + .checked_add(reloc_addend as u64) + .unwrap(); (reloc_address, reloc_abs) } RelocationKind::X86PCRel4 => { diff --git a/lib/compiler/src/sourceloc.rs b/lib/compiler/src/sourceloc.rs index d1a6b446c..fa61e4ab8 100644 --- a/lib/compiler/src/sourceloc.rs +++ b/lib/compiler/src/sourceloc.rs @@ -16,7 +16,11 @@ use serde::{Deserialize, Serialize}; /// /// The default source location uses the all-ones bit pattern `!0`. It is used for instructions /// that can't be given a real source location. -#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize), serde(transparent))] +#[cfg_attr( + feature = "enable-serde", + derive(Serialize, Deserialize), + serde(transparent) +)] #[repr(transparent)] #[derive(Debug, Clone, Copy, PartialEq, Eq, MemoryUsage)] pub struct SourceLoc(u32); diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 25df7fcfa..12b2b06f1 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -172,7 +172,10 @@ pub struct Target { impl Target { /// Creates a new target given a triple pub fn new(triple: Triple, cpu_features: EnumSet) -> Self { - Self { triple, cpu_features } + Self { + triple, + cpu_features, + } } /// The triple associated for the target. @@ -189,6 +192,9 @@ impl Target { /// The default for the Target will use the HOST as the triple impl Default for Target { fn default() -> Self { - Self { triple: Triple::host(), cpu_features: CpuFeature::for_host() } + Self { + triple: Triple::host(), + cpu_features: CpuFeature::for_host(), + } } } diff --git a/lib/compiler/src/translator/environ.rs b/lib/compiler/src/translator/environ.rs index dc11d1893..2996c6d67 100644 --- a/lib/compiler/src/translator/environ.rs +++ b/lib/compiler/src/translator/environ.rs @@ -78,7 +78,10 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn declare_export(&mut self, export: ExportIndex, name: &str) -> WasmResult<()> { - self.result.module.exports.insert(String::from(name), export); + self.result + .module + .exports + .insert(String::from(name), export); Ok(()) } @@ -88,15 +91,18 @@ impl<'data> ModuleEnvironment<'data> { module: &str, field: &str, ) -> WasmResult<()> { - self.result - .module - .imports - .insert((String::from(module), String::from(field), self.imports), import); + self.result.module.imports.insert( + (String::from(module), String::from(field), self.imports), + import, + ); Ok(()) } pub(crate) fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> { - self.result.module.signatures.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .signatures + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -142,7 +148,9 @@ impl<'data> ModuleEnvironment<'data> { "Imported tables must be declared first" ); self.declare_import( - ImportIndex::Table(TableIndex::from_u32(self.result.module.num_imported_tables as _)), + ImportIndex::Table(TableIndex::from_u32( + self.result.module.num_imported_tables as _, + )), module, field, )?; @@ -205,8 +213,13 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn reserve_func_types(&mut self, num: u32) -> WasmResult<()> { - self.result.module.functions.reserve_exact(usize::try_from(num).unwrap()); - self.result.function_body_inputs.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .functions + .reserve_exact(usize::try_from(num).unwrap()); + self.result + .function_body_inputs + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -216,7 +229,10 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn reserve_tables(&mut self, num: u32) -> WasmResult<()> { - self.result.module.tables.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .tables + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -226,20 +242,28 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn reserve_memories(&mut self, num: u32) -> WasmResult<()> { - self.result.module.memories.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .memories + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } pub(crate) fn declare_memory(&mut self, memory: MemoryType) -> WasmResult<()> { if memory.shared { - return Err(WasmError::Unsupported("shared memories are not supported yet".to_owned())); + return Err(WasmError::Unsupported( + "shared memories are not supported yet".to_owned(), + )); } self.result.module.memories.push(memory); Ok(()) } pub(crate) fn reserve_globals(&mut self, num: u32) -> WasmResult<()> { - self.result.module.globals.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .globals + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -254,7 +278,10 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn reserve_exports(&mut self, num: u32) -> WasmResult<()> { - self.result.module.exports.reserve(usize::try_from(num).unwrap()); + self.result + .module + .exports + .reserve(usize::try_from(num).unwrap()); Ok(()) } @@ -297,7 +324,10 @@ impl<'data> ModuleEnvironment<'data> { } pub(crate) fn reserve_table_initializers(&mut self, num: u32) -> WasmResult<()> { - self.result.module.table_initializers.reserve_exact(usize::try_from(num).unwrap()); + self.result + .module + .table_initializers + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -308,12 +338,15 @@ impl<'data> ModuleEnvironment<'data> { offset: usize, elements: Box<[FunctionIndex]>, ) -> WasmResult<()> { - self.result.module.table_initializers.push(TableInitializer { - table_index, - base, - offset, - elements, - }); + self.result + .module + .table_initializers + .push(TableInitializer { + table_index, + base, + offset, + elements, + }); Ok(()) } @@ -322,7 +355,11 @@ impl<'data> ModuleEnvironment<'data> { elem_index: ElemIndex, segments: Box<[FunctionIndex]>, ) -> WasmResult<()> { - let old = self.result.module.passive_elements.insert(elem_index, segments); + let old = self + .result + .module + .passive_elements + .insert(elem_index, segments); debug_assert!( old.is_none(), "should never get duplicate element indices, that would be a bug in `wasmer_compiler`'s \ @@ -337,14 +374,17 @@ impl<'data> ModuleEnvironment<'data> { body_bytes: &'data [u8], body_offset: usize, ) -> WasmResult<()> { - self.result - .function_body_inputs - .push(FunctionBodyData { data: body_bytes, module_offset: body_offset }); + self.result.function_body_inputs.push(FunctionBodyData { + data: body_bytes, + module_offset: body_offset, + }); Ok(()) } pub(crate) fn reserve_data_initializers(&mut self, num: u32) -> WasmResult<()> { - self.result.data_initializers.reserve_exact(usize::try_from(num).unwrap()); + self.result + .data_initializers + .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } @@ -356,7 +396,11 @@ impl<'data> ModuleEnvironment<'data> { data: &'data [u8], ) -> WasmResult<()> { self.result.data_initializers.push(DataInitializer { - location: DataInitializerLocation { memory_index, base, offset }, + location: DataInitializerLocation { + memory_index, + base, + offset, + }, data, }); Ok(()) @@ -373,7 +417,11 @@ impl<'data> ModuleEnvironment<'data> { data_index: DataIndex, data: &'data [u8], ) -> WasmResult<()> { - let old = self.result.module.passive_data.insert(data_index, Arc::from(data)); + let old = self + .result + .module + .passive_data + .insert(data_index, Arc::from(data)); debug_assert!( old.is_none(), "a module can't have duplicate indices, this would be a wasmer-compiler bug" @@ -391,7 +439,10 @@ impl<'data> ModuleEnvironment<'data> { func_index: FunctionIndex, name: &'data str, ) -> WasmResult<()> { - self.result.module.function_names.insert(func_index, name.to_string()); + self.result + .module + .function_names + .insert(func_index, name.to_string()); Ok(()) } @@ -409,10 +460,21 @@ impl<'data> ModuleEnvironment<'data> { /// Indicates that a custom section has been found in the wasm file pub(crate) fn custom_section(&mut self, name: &'data str, data: &'data [u8]) -> WasmResult<()> { let custom_section = CustomSectionIndex::from_u32( - self.result.module.custom_sections_data.len().try_into().unwrap(), + self.result + .module + .custom_sections_data + .len() + .try_into() + .unwrap(), ); - self.result.module.custom_sections.insert(String::from(name), custom_section); - self.result.module.custom_sections_data.push(Arc::from(data)); + self.result + .module + .custom_sections + .insert(String::from(name), custom_section); + self.result + .module + .custom_sections_data + .push(Arc::from(data)); Ok(()) } } diff --git a/lib/compiler/src/translator/error.rs b/lib/compiler/src/translator/error.rs index d3847b4f4..07a6397d5 100644 --- a/lib/compiler/src/translator/error.rs +++ b/lib/compiler/src/translator/error.rs @@ -10,7 +10,10 @@ macro_rules! wasm_unsupported { impl From for WasmError { fn from(original: BinaryReaderError) -> Self { - Self::InvalidWebAssembly { message: original.message().into(), offset: original.offset() } + Self::InvalidWebAssembly { + message: original.message().into(), + offset: original.offset(), + } } } diff --git a/lib/compiler/src/translator/middleware.rs b/lib/compiler/src/translator/middleware.rs index 4b911403d..3dd8c6aed 100644 --- a/lib/compiler/src/translator/middleware.rs +++ b/lib/compiler/src/translator/middleware.rs @@ -79,7 +79,9 @@ impl> ModuleMiddlewareChain for [T] { &self, local_function_index: LocalFunctionIndex, ) -> Vec> { - self.iter().map(|x| x.generate_function_middleware(local_function_index)).collect() + self.iter() + .map(|x| x.generate_function_middleware(local_function_index)) + .collect() } /// Applies the chain on a `ModuleInfo` struct. @@ -114,7 +116,10 @@ impl<'a> MiddlewareBinaryReader<'a> { pub fn new_with_offset(data: &'a [u8], original_offset: usize) -> Self { let inner = BinaryReader::new_with_offset(data, original_offset); Self { - state: MiddlewareReaderState { inner, pending_operations: VecDeque::new() }, + state: MiddlewareReaderState { + inner, + pending_operations: VecDeque::new(), + }, chain: vec![], } } diff --git a/lib/compiler/src/translator/module.rs b/lib/compiler/src/translator/module.rs index 437edd814..5f75aa5fe 100644 --- a/lib/compiler/src/translator/module.rs +++ b/lib/compiler/src/translator/module.rs @@ -89,9 +89,11 @@ pub fn translate_module<'data>( unimplemented!("module linking not implemented yet") } - Payload::CustomSection { name: "name", data, data_offset } => { - parse_name_section(NameSectionReader::new(data, data_offset)?, environ)? - } + Payload::CustomSection { + name: "name", + data, + data_offset, + } => parse_name_section(NameSectionReader::new(data, data_offset)?, environ)?, Payload::CustomSection { name, data, .. } => environ.custom_section(name, data)?, diff --git a/lib/compiler/src/translator/sections.rs b/lib/compiler/src/translator/sections.rs index ea24df8e8..0cd234a57 100644 --- a/lib/compiler/src/translator/sections.rs +++ b/lib/compiler/src/translator/sections.rs @@ -42,7 +42,10 @@ pub fn wptype_to_type(ty: wasmparser::Type) -> WasmResult { wasmparser::Type::V128 => Ok(Type::V128), wasmparser::Type::ExternRef => Ok(Type::ExternRef), wasmparser::Type::FuncRef => Ok(Type::FuncRef), - ty => Err(wasm_unsupported!("wptype_to_type: wasmparser type {:?}", ty)), + ty => Err(wasm_unsupported!( + "wptype_to_type: wasmparser type {:?}", + ty + )), } } @@ -107,7 +110,10 @@ pub fn parse_import_section<'data>( | ImportSectionEntryType::Event(_) => { unimplemented!("module linking not implemented yet") } - ImportSectionEntryType::Memory(WPMemoryType::M32 { limits: ref memlimits, shared }) => { + ImportSectionEntryType::Memory(WPMemoryType::M32 { + limits: ref memlimits, + shared, + }) => { environ.declare_memory_import( MemoryType { minimum: Pages(memlimits.initial), @@ -221,7 +227,13 @@ pub fn parse_global_section( environ.reserve_globals(globals.get_count())?; for entry in globals { - let wasmparser::Global { ty: WPGlobalType { content_type, mutable }, init_expr } = entry?; + let wasmparser::Global { + ty: WPGlobalType { + content_type, + mutable, + }, + init_expr, + } = entry?; let mut init_expr_reader = init_expr.get_binary_reader(); let initializer = match init_expr_reader.read_operator()? { Operator::I32Const { value } => GlobalInit::I32Const(value), @@ -237,11 +249,16 @@ pub fn parse_global_section( GlobalInit::GetGlobal(GlobalIndex::from_u32(global_index)) } ref s => { - return Err(wasm_unsupported!("unsupported init expr in global section: {:?}", s)); + return Err(wasm_unsupported!( + "unsupported init expr in global section: {:?}", + s + )); } }; - let global = - GlobalType { ty: wptype_to_type(content_type).unwrap(), mutability: mutable.into() }; + let global = GlobalType { + ty: wptype_to_type(content_type).unwrap(), + mutability: mutable.into(), + }; environ.declare_global(global, initializer)?; } @@ -256,7 +273,11 @@ pub fn parse_export_section<'data>( environ.reserve_exports(exports.get_count())?; for entry in exports { - let Export { field, ref kind, index } = entry?; + let Export { + field, + ref kind, + index, + } = entry?; // The input has already been validated, so we should be able to // assume valid UTF-8 and use `from_utf8_unchecked` if performance @@ -315,11 +336,17 @@ pub fn parse_element_section<'data>( for (index, entry) in elements.into_iter().enumerate() { let Element { kind, items, ty } = entry?; if ty != wasmparser::Type::FuncRef { - return Err(wasm_unsupported!("unsupported table element type: {:?}", ty)); + return Err(wasm_unsupported!( + "unsupported table element type: {:?}", + ty + )); } let segments = read_elems(&items)?; match kind { - ElementKind::Active { table_index, init_expr } => { + ElementKind::Active { + table_index, + init_expr, + } => { let mut init_expr_reader = init_expr.get_binary_reader(); let (base, offset) = match init_expr_reader.read_operator()? { Operator::I32Const { value } => (None, value as u32 as usize), @@ -360,7 +387,10 @@ pub fn parse_data_section<'data>( for (index, entry) in data.into_iter().enumerate() { let Data { kind, data } = entry?; match kind { - DataKind::Active { memory_index, init_expr } => { + DataKind::Active { + memory_index, + init_expr, + } => { let mut init_expr_reader = init_expr.get_binary_reader(); let (base, offset) = match init_expr_reader.read_operator()? { Operator::I32Const { value } => (None, value as u32 as usize), @@ -399,8 +429,10 @@ pub fn parse_name_section<'data>( while let Ok(subsection) = names.read() { match subsection { wasmparser::Name::Function(function_subsection) => { - if let Some(function_names) = - function_subsection.get_map().ok().and_then(parse_function_name_subsection) + if let Some(function_names) = function_subsection + .get_map() + .ok() + .and_then(parse_function_name_subsection) { for (index, name) in function_names { environ.declare_function_name(index, name)?; @@ -429,7 +461,10 @@ fn parse_function_name_subsection( return None; } - if function_names.insert(FunctionIndex::from_u32(index), name).is_some() { + if function_names + .insert(FunctionIndex::from_u32(index), name) + .is_some() + { // If the function index has been previously seen, then we // break out of the loop and early return `None`, because these // should be unique. diff --git a/lib/compiler/src/translator/state.rs b/lib/compiler/src/translator/state.rs index 76f51f3da..2d72168cb 100644 --- a/lib/compiler/src/translator/state.rs +++ b/lib/compiler/src/translator/state.rs @@ -28,7 +28,9 @@ pub struct ModuleTranslationState { impl ModuleTranslationState { /// Creates a new empty ModuleTranslationState. pub fn new() -> Self { - Self { wasm_types: PrimaryMap::new() } + Self { + wasm_types: PrimaryMap::new(), + } } /// Get the parameter and result types for the given Wasm blocktype. diff --git a/lib/derive/src/lib.rs b/lib/derive/src/lib.rs index 57fa5637a..22fcca782 100644 --- a/lib/derive/src/lib.rs +++ b/lib/derive/src/lib.rs @@ -124,7 +124,12 @@ fn derive_struct_fields(data: &DataStruct) -> (TokenStream, TokenStream) { helpers.push(helper_tokens); } match wasmer_attr { - WasmerAttr::Export { identifier, optional, aliases, span } => { + WasmerAttr::Export { + identifier, + optional, + aliases, + span, + } => { let finish_tokens = if let Some(name) = name { let name_str = name.to_string(); let item_name = @@ -216,7 +221,10 @@ fn derive_struct_fields(data: &DataStruct) -> (TokenStream, TokenStream) { // TODO: name this something that makes sense fn get_identifier(ty: &Type) -> TokenStream { match ty { - Type::Path(TypePath { path: Path { segments, .. }, .. }) => { + Type::Path(TypePath { + path: Path { segments, .. }, + .. + }) => { if let Some(PathSegment { ident, arguments }) = segments.last() { if ident != "LazyInit" { abort!( diff --git a/lib/derive/src/parse.rs b/lib/derive/src/parse.rs index 077d988f9..a8feb9e94 100644 --- a/lib/derive/src/parse.rs +++ b/lib/derive/src/parse.rs @@ -66,7 +66,11 @@ impl Parse for ExportOptions { } } - Ok(ExportOptions { name, optional, aliases }) + Ok(ExportOptions { + name, + optional, + aliases, + }) } } @@ -85,7 +89,11 @@ impl Parse for ExportExpr { optional = false; aliases = vec![]; } - Ok(Self { name, optional, aliases }) + Ok(Self { + name, + optional, + aliases, + }) } } @@ -109,9 +117,18 @@ impl Parse for WasmerAttrInner { (None, false, vec![]) }; - WasmerAttr::Export { identifier: name, optional, aliases, span } + WasmerAttr::Export { + identifier: name, + optional, + aliases, + span, + } } - otherwise => abort!(ident, "Unexpected identifier `{}`. Expected `export`.", otherwise), + otherwise => abort!( + ident, + "Unexpected identifier `{}`. Expected `export`.", + otherwise + ), }; Ok(WasmerAttrInner(out)) } diff --git a/lib/derive/tests/basic.rs b/lib/derive/tests/basic.rs index d25d1b9c7..4302253eb 100644 --- a/lib/derive/tests/basic.rs +++ b/lib/derive/tests/basic.rs @@ -14,7 +14,10 @@ fn impls_wasmer_env() -> bool { #[test] fn test_derive() { - let _my_env = MyEnv { num: 3, nums: vec![1, 2, 3] }; + let _my_env = MyEnv { + num: 3, + nums: vec![1, 2, 3], + }; assert!(impls_wasmer_env::()); } diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index d7d6a54fd..790e1dd3e 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -209,7 +209,16 @@ pub fn invoke_viii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32) { } pub fn invoke_viiii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { debug!("emscripten::invoke_viiii"); - invoke_no_return!(ctx, dyn_call_viiii, dyn_call_viiii_ref, index, a1, a2, a3, a4); + invoke_no_return!( + ctx, + dyn_call_viiii, + dyn_call_viiii_ref, + index, + a1, + a2, + a3, + a4 + ); } pub fn invoke_dii(ctx: &EmEnv, index: i32, a1: i32, a2: i32) -> f64 { debug!("emscripten::invoke_dii"); @@ -217,15 +226,43 @@ pub fn invoke_dii(ctx: &EmEnv, index: i32, a1: i32, a2: i32) -> f64 { } pub fn invoke_diiii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> f64 { debug!("emscripten::invoke_diiii"); - invoke!(ctx, dyn_call_diiii, dyn_call_diiii_ref, index, a1, a2, a3, a4) + invoke!( + ctx, + dyn_call_diiii, + dyn_call_diiii_ref, + index, + a1, + a2, + a3, + a4 + ) } pub fn invoke_iiiii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { debug!("emscripten::invoke_iiiii"); - invoke!(ctx, dyn_call_iiiii, dyn_call_iiiii_ref, index, a1, a2, a3, a4) + invoke!( + ctx, + dyn_call_iiiii, + dyn_call_iiiii_ref, + index, + a1, + a2, + a3, + a4 + ) } pub fn invoke_iiiiii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) -> i32 { debug!("emscripten::invoke_iiiiii"); - invoke!(ctx, dyn_call_iiiiii, dyn_call_iiiiii_ref, index, a1, a2, a3, a4, a5) + invoke!( + ctx, + dyn_call_iiiiii, + dyn_call_iiiiii_ref, + index, + a1, + a2, + a3, + a4, + a5 + ) } pub fn invoke_iiiiiii( ctx: &EmEnv, @@ -238,7 +275,18 @@ pub fn invoke_iiiiiii( a6: i32, ) -> i32 { debug!("emscripten::invoke_iiiiiii"); - invoke!(ctx, dyn_call_iiiiiii, dyn_call_iiiiiii_ref, index, a1, a2, a3, a4, a5, a6) + invoke!( + ctx, + dyn_call_iiiiiii, + dyn_call_iiiiiii_ref, + index, + a1, + a2, + a3, + a4, + a5, + a6 + ) } pub fn invoke_iiiiiiii( ctx: &EmEnv, @@ -252,7 +300,19 @@ pub fn invoke_iiiiiiii( a7: i32, ) -> i32 { debug!("emscripten::invoke_iiiiiiii"); - invoke!(ctx, dyn_call_iiiiiiii, dyn_call_iiiiiiii_ref, index, a1, a2, a3, a4, a5, a6, a7) + invoke!( + ctx, + dyn_call_iiiiiiii, + dyn_call_iiiiiiii_ref, + index, + a1, + a2, + a3, + a4, + a5, + a6, + a7 + ) } pub fn invoke_iiiiiiiii( ctx: &EmEnv, @@ -267,7 +327,20 @@ pub fn invoke_iiiiiiiii( a8: i32, ) -> i32 { debug!("emscripten::invoke_iiiiiiiii"); - invoke!(ctx, dyn_call_iiiiiiiii, dyn_call_iiiiiiiii_ref, index, a1, a2, a3, a4, a5, a6, a7, a8) + invoke!( + ctx, + dyn_call_iiiiiiiii, + dyn_call_iiiiiiiii_ref, + index, + a1, + a2, + a3, + a4, + a5, + a6, + a7, + a8 + ) } pub fn invoke_iiiiiiiiii( ctx: &EmEnv, @@ -337,7 +410,17 @@ pub fn invoke_vd(ctx: &EmEnv, index: i32, a1: f64) { } pub fn invoke_viiiii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_viiiii"); - invoke_no_return!(ctx, dyn_call_viiiii, dyn_call_viiiii_ref, index, a1, a2, a3, a4, a5) + invoke_no_return!( + ctx, + dyn_call_viiiii, + dyn_call_viiiii_ref, + index, + a1, + a2, + a3, + a4, + a5 + ) } pub fn invoke_viiiiii( ctx: &EmEnv, @@ -350,7 +433,18 @@ pub fn invoke_viiiiii( a6: i32, ) { debug!("emscripten::invoke_viiiiii"); - invoke_no_return!(ctx, dyn_call_viiiiii, dyn_call_viiiiii_ref, index, a1, a2, a3, a4, a5, a6) + invoke_no_return!( + ctx, + dyn_call_viiiiii, + dyn_call_viiiiii_ref, + index, + a1, + a2, + a3, + a4, + a5, + a6 + ) } pub fn invoke_viiiiiii( ctx: &EmEnv, @@ -495,7 +589,18 @@ pub fn invoke_iiijj( a6: i32, ) -> i32 { debug!("emscripten::invoke_iiijj"); - invoke!(ctx, dyn_call_iiijj, dyn_call_iiijj_ref, index, a1, a2, a3, a4, a5, a6) + invoke!( + ctx, + dyn_call_iiijj, + dyn_call_iiijj_ref, + index, + a1, + a2, + a3, + a4, + a5, + a6 + ) } pub fn invoke_j(ctx: &EmEnv, index: i32) -> i32 { debug!("emscripten::invoke_j"); @@ -561,7 +666,9 @@ pub fn invoke_viiijiiii( ) { debug!("emscripten::invoke_viiijiiii"); if let Some(dyn_call_viiijiiii) = get_emscripten_data(ctx).dyn_call_viiijiiii_ref() { - dyn_call_viiijiiii.call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9).unwrap(); + dyn_call_viiijiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9) + .unwrap(); } else { panic!("dyn_call_viiijiiii is set to None"); } @@ -583,7 +690,9 @@ pub fn invoke_viiijiiiiii( ) { debug!("emscripten::invoke_viiijiiiiii"); if let Some(dyn_call_viiijiiiiii) = get_emscripten_data(ctx).dyn_call_viiijiiiiii_ref() { - dyn_call_viiijiiiiii.call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11).unwrap(); + dyn_call_viiijiiiiii + .call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) + .unwrap(); } else { panic!("dyn_call_viiijiiiiii is set to None"); } @@ -617,7 +726,9 @@ pub fn invoke_viijiii( ) { debug!("emscripten::invoke_viijiii"); if let Some(dyn_call_viijiii) = get_emscripten_data(ctx).dyn_call_viijiii_ref() { - dyn_call_viijiii.call(index, a1, a2, a3, a4, a5, a6, a7).unwrap(); + dyn_call_viijiii + .call(index, a1, a2, a3, a4, a5, a6, a7) + .unwrap(); } else { panic!("dyn_call_viijiii is set to None"); } @@ -640,7 +751,17 @@ pub fn invoke_vj(ctx: &EmEnv, index: i32, a1: i32, a2: i32) { } pub fn invoke_vjji(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32, a4: i32, a5: i32) { debug!("emscripten::invoke_vjji"); - invoke_no_return!(ctx, dyn_call_vjji, dyn_call_vjji_ref, index, a1, a2, a3, a4, a5) + invoke_no_return!( + ctx, + dyn_call_vjji, + dyn_call_vjji_ref, + index, + a1, + a2, + a3, + a4, + a5 + ) } pub fn invoke_vij(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: i32) { debug!("emscripten::invoke_vij"); @@ -693,7 +814,17 @@ pub fn invoke_viid(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: f64) { } pub fn invoke_viidii(ctx: &EmEnv, index: i32, a1: i32, a2: i32, a3: f64, a4: i32, a5: i32) { debug!("emscripten::invoke_viidii"); - invoke_no_return!(ctx, dyn_call_viidii, dyn_call_viidii_ref, index, a1, a2, a3, a4, a5); + invoke_no_return!( + ctx, + dyn_call_viidii, + dyn_call_viidii_ref, + index, + a1, + a2, + a3, + a4, + a5 + ); } pub fn invoke_viidddddddd( ctx: &EmEnv, diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index a74b92772..4cbc9479d 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -25,7 +25,11 @@ use crate::EmEnv; use wasmer::ValueType; pub fn call_malloc(ctx: &EmEnv, size: u32) -> u32 { - get_emscripten_data(ctx).malloc_ref().unwrap().call(size).unwrap() + get_emscripten_data(ctx) + .malloc_ref() + .unwrap() + .call(size) + .unwrap() } #[warn(dead_code)] @@ -42,7 +46,11 @@ pub fn call_memalign(ctx: &EmEnv, alignment: u32, size: u32) -> u32 { } pub fn call_memset(ctx: &EmEnv, pointer: u32, value: u32, size: u32) -> u32 { - get_emscripten_data(ctx).memset_ref().unwrap().call(pointer, value, size).unwrap() + get_emscripten_data(ctx) + .memset_ref() + .unwrap() + .call(pointer, value, size) + .unwrap() } pub(crate) fn get_emscripten_data(ctx: &EmEnv) -> MutexGuard { @@ -121,7 +129,10 @@ pub fn ___assert_fail(_ctx: &EmEnv, _a: c_int, _b: c_int, _c: c_int, _d: c_int) } pub fn _pathconf(ctx: &EmEnv, path_addr: c_int, name: c_int) -> c_int { - debug!("emscripten::_pathconf {} {} - UNIMPLEMENTED", path_addr, name); + debug!( + "emscripten::_pathconf {} {} - UNIMPLEMENTED", + path_addr, name + ); let _path = emscripten_memory_pointer!(ctx.memory(0), path_addr) as *const c_char; match name { 0 => 32000, diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index ed7370aef..6355fb3ec 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -152,7 +152,11 @@ pub fn _gai_strerror(ctx: &EmEnv, ecode: i32) -> i32 { let string_on_guest: WasmPtr = call_malloc_with_cast(ctx, bytes.len() as _); let memory = ctx.memory(0); - let writer = unsafe { string_on_guest.deref_mut(&memory, 0, bytes.len() as _).unwrap() }; + let writer = unsafe { + string_on_guest + .deref_mut(&memory, 0, bytes.len() as _) + .unwrap() + }; for (i, byte) in bytes.iter().enumerate() { writer[i].set(*byte as _); } @@ -208,13 +212,18 @@ pub fn _getaddrinfo( // allocate equivalent memory for res_val_ptr let result = unsafe { libc::getaddrinfo( - (node_ptr.deref(&memory).map(|m| m as *const Cell as *const c_char)) - .unwrap_or(std::ptr::null()), + (node_ptr + .deref(&memory) + .map(|m| m as *const Cell as *const c_char)) + .unwrap_or(std::ptr::null()), service_str_ptr .deref(&memory) .map(|m| m as *const Cell as *const c_char) .unwrap_or(std::ptr::null()), - hints.as_ref().map(|h| h as *const addrinfo).unwrap_or(std::ptr::null()), + hints + .as_ref() + .map(|h| h as *const addrinfo) + .unwrap_or(std::ptr::null()), &mut out_ptr as *mut *mut addrinfo, ) }; diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index 4772d5fa1..9a2d00f7c 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -49,7 +49,9 @@ pub fn _putenv(ctx: &EmEnv, name: c_int) -> c_int { debug!("emscripten::_putenv"); let memory = ctx.memory(0); let name_addr = emscripten_memory_pointer!(&memory, name) as *const c_char; - debug!("=> name({:?})", unsafe { std::ffi::CStr::from_ptr(name_addr) }); + debug!("=> name({:?})", unsafe { + std::ffi::CStr::from_ptr(name_addr) + }); unsafe { putenv(name_addr) } } diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 8fa32c12b..62190653f 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -47,7 +47,10 @@ pub fn getpwuid(ctx: &EmEnv, uid: i32) -> i32 { let passwd_struct_offset = call_malloc(ctx, mem::size_of::() as _); let passwd_struct_ptr = emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd; - assert_eq!(passwd_struct_ptr as usize % std::mem::align_of::(), 0); + assert_eq!( + passwd_struct_ptr as usize % std::mem::align_of::(), + 0 + ); (*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name); (*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd); (*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos); diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 0e0169007..0785627d8 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -280,7 +280,12 @@ impl EmscriptenData { globals: EmscriptenGlobalsData, mapped_dirs: HashMap, ) -> EmscriptenData { - EmscriptenData { globals, temp_ret_0: 0, mapped_dirs, ..Default::default() } + EmscriptenData { + globals, + temp_ret_0: 0, + mapped_dirs, + ..Default::default() + } } } @@ -296,7 +301,10 @@ pub fn set_up_emscripten(instance: &mut Instance) -> Result<(), RuntimeError> { func.call(&[])?; } - if let Ok(func) = instance.exports.get::("___emscripten_environ_constructor") { + if let Ok(func) = instance + .exports + .get::("___emscripten_environ_constructor") + { func.call(&[])?; } Ok(()) @@ -314,7 +322,10 @@ pub fn emscripten_call_main( ) -> Result<(), RuntimeError> { let (function_name, main_func) = match instance.exports.get::("_main") { Ok(func) => Ok(("_main", func)), - Err(_e) => instance.exports.get::("main").map(|func| ("main", func)), + Err(_e) => instance + .exports + .get::("main") + .map(|func| ("main", func)), } .map_err(|e| RuntimeError::new(e.to_string()))?; let num_params = main_func.ty().params().len(); @@ -365,8 +376,10 @@ pub fn run_emscripten_instance( debug!("Running entry point: {}", &ep); let arg = unsafe { allocate_cstr_on_stack(env, args[0]).0 }; //let (argc, argv) = store_module_arguments(instance.context_mut(), args); - let func: &Function = - instance.exports.get(&ep).map_err(|e| RuntimeError::new(e.to_string()))?; + let func: &Function = instance + .exports + .get(&ep) + .map_err(|e| RuntimeError::new(e.to_string()))?; func.call(&[Val::I32(arg as i32)])?; } else { emscripten_call_main(instance, env, path, &args)?; @@ -457,7 +470,11 @@ impl EmscriptenGlobals { let memory_type = MemoryType::new(memory_min, memory_max, shared); let memory = Memory::new(store, memory_type).unwrap(); - let table_type = TableType { ty: ValType::FuncRef, minimum: table_min, maximum: table_max }; + let table_type = TableType { + ty: ValType::FuncRef, + minimum: table_min, + maximum: table_max, + }; let table = Table::new(store, table_type, Val::FuncRef(None)).unwrap(); let data = { @@ -474,7 +491,10 @@ impl EmscriptenGlobals { let (dynamic_base, dynamictop_ptr) = get_emscripten_metadata(&module)?.unwrap_or_else(|| { let dynamictop_ptr = static_alloc(&mut static_top, 4); - (align_memory(align_memory(static_top) + TOTAL_STACK), dynamictop_ptr) + ( + align_memory(align_memory(static_top) + TOTAL_STACK), + dynamictop_ptr, + ) }); let stacktop = align_memory(static_top); @@ -505,7 +525,14 @@ impl EmscriptenGlobals { } } - Ok(Self { data, memory, table, memory_min, memory_max, null_function_names }) + Ok(Self { + data, + memory, + table, + memory_min, + memory_max, + null_function_names, + }) } } diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index 42693d1a7..1be26f85f 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -7,7 +7,10 @@ use wasmer::{Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE}; /// emscripten: _emscripten_memcpy_big pub fn _emscripten_memcpy_big(ctx: &EmEnv, dest: u32, src: u32, len: u32) -> u32 { - debug!("emscripten::_emscripten_memcpy_big {}, {}, {}", dest, src, len); + debug!( + "emscripten::_emscripten_memcpy_big {}, {}, {}", + dest, src, len + ); let dest_addr = emscripten_memory_pointer!(ctx.memory(0), dest) as *mut c_void; let src_addr = emscripten_memory_pointer!(ctx.memory(0), src) as *mut c_void; unsafe { @@ -41,8 +44,10 @@ pub fn _emscripten_resize_heap(ctx: &EmEnv, requested_size: u32) -> u32 { let current_memory = current_memory_pages.bytes().0 as u32; // implementation from emscripten - let mut new_size = - usize::max(current_memory as usize, WASM_MIN_PAGES as usize * WASM_PAGE_SIZE); + let mut new_size = usize::max( + current_memory as usize, + WASM_MIN_PAGES as usize * WASM_PAGE_SIZE, + ); while new_size < requested_size as usize { if new_size <= 0x2000_0000 { new_size = align_up(new_size * 2, WASM_PAGE_SIZE); @@ -111,7 +116,10 @@ pub fn enlarge_memory(_ctx: &EmEnv) -> u32 { /// emscripten: abortOnCannotGrowMemory pub fn abort_on_cannot_grow_memory(ctx: &EmEnv, _requested_size: u32) -> u32 { - debug!("emscripten::abort_on_cannot_grow_memory {}", _requested_size); + debug!( + "emscripten::abort_on_cannot_grow_memory {}", + _requested_size + ); abort_with_message(ctx, "Cannot enlarge memory arrays!"); 0 } diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index bfa6c1539..f5fe4eb07 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -169,7 +169,10 @@ pub fn _waitpid(_ctx: &EmEnv, _one: i32, _two: i32, _three: i32) -> i32 { pub fn abort_stack_overflow(ctx: &EmEnv, _what: c_int) { debug!("emscripten::abort_stack_overflow"); // TODO: Message incomplete. Need to finish em runtime data first - abort_with_message(ctx, "Stack overflow! Attempted to allocate some bytes on the stack"); + abort_with_message( + ctx, + "Stack overflow! Attempted to allocate some bytes on the stack", + ); } pub fn _llvm_trap(ctx: &EmEnv) { diff --git a/lib/emscripten/src/pthread.rs b/lib/emscripten/src/pthread.rs index ff52d2bc9..c4ab3d6b1 100644 --- a/lib/emscripten/src/pthread.rs +++ b/lib/emscripten/src/pthread.rs @@ -6,7 +6,12 @@ pub fn _pthread_attr_destroy(_ctx: &EmEnv, _a: i32) -> i32 { } pub fn _pthread_attr_getstack(_ctx: &EmEnv, _stackaddr: i32, _stacksize: i32, _other: i32) -> i32 { - trace!("emscripten::_pthread_attr_getstack({}, {}, {})", _stackaddr, _stacksize, _other); + trace!( + "emscripten::_pthread_attr_getstack({}, {}, {})", + _stackaddr, + _stacksize, + _other + ); // TODO: Translate from Emscripten // HEAP32[stackaddr >> 2] = STACK_BASE; // HEAP32[stacksize >> 2] = TOTAL_STACK; diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 43356f7e2..5210da764 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -98,10 +98,17 @@ pub fn ___syscall12(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall12 (chdir) {}", _which); let path_ptr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, path_ptr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { path_ptr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + path_ptr + }; let ret = unsafe { chdir(real_path) }; - debug!("=> path: {:?}, ret: {}", unsafe { std::ffi::CStr::from_ptr(real_path) }, ret); + debug!( + "=> path: {:?}, ret: {}", + unsafe { std::ffi::CStr::from_ptr(real_path) }, + ret + ); ret } @@ -162,11 +169,17 @@ pub fn ___syscall38(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { let old_path = varargs.get_str(ctx); let new_path = varargs.get_str(ctx); let real_old_path_owned = get_cstr_path(ctx, old_path as *const _); - let real_old_path = - if let Some(ref rp) = real_old_path_owned { rp.as_c_str().as_ptr() } else { old_path }; + let real_old_path = if let Some(ref rp) = real_old_path_owned { + rp.as_c_str().as_ptr() + } else { + old_path + }; let real_new_path_owned = get_cstr_path(ctx, new_path as *const _); - let real_new_path = - if let Some(ref rp) = real_new_path_owned { rp.as_c_str().as_ptr() } else { new_path }; + let real_new_path = if let Some(ref rp) = real_new_path_owned { + rp.as_c_str().as_ptr() + } else { + new_path + }; let result = unsafe { rename(real_old_path, real_new_path) }; debug!( "=> old_path: {}, new_path: {}, result: {}", @@ -182,8 +195,11 @@ pub fn ___syscall40(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall40 (rmdir)"); let pathname_addr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; unsafe { rmdir(real_path) } } @@ -495,7 +511,10 @@ pub fn ___syscall146(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { pub fn ___syscall191(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let _resource: i32 = varargs.get(ctx); - debug!("emscripten::___syscall191 - mostly stub, resource: {}", _resource); + debug!( + "emscripten::___syscall191 - mostly stub, resource: {}", + _resource + ); let rlim_emptr: i32 = varargs.get(ctx); let rlim_ptr = emscripten_memory_pointer!(ctx.memory(0), rlim_emptr) as *mut u8; let rlim = unsafe { slice::from_raw_parts_mut(rlim_ptr, 16) }; @@ -519,8 +538,11 @@ pub fn ___syscall195(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let buf: u32 = varargs.get(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; unsafe { let mut _stat: stat = std::mem::zeroed(); diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index c059d7f80..69ac5a2f4 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -162,11 +162,17 @@ pub fn ___syscall5(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { let flags: i32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx); let real_path_owned = utils::get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; let _path_str = unsafe { std::ffi::CStr::from_ptr(real_path).to_str().unwrap() }; let fd = unsafe { open(real_path, flags, mode) }; - debug!("=> path: {}, flags: {}, mode: {} = fd: {}", _path_str, flags, mode, fd,); + debug!( + "=> path: {}, flags: {}, mode: {} = fd: {}", + _path_str, flags, mode, fd, + ); if fd == -1 { debug!("=> last os error: {}", Error::last_os_error(),); } @@ -208,11 +214,17 @@ pub fn ___syscall83(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { let path1 = varargs.get_str(ctx); let path2 = varargs.get_str(ctx); let real_path1_owned = utils::get_cstr_path(ctx, path1 as *const _); - let real_path1 = - if let Some(ref rp) = real_path1_owned { rp.as_c_str().as_ptr() } else { path1 }; + let real_path1 = if let Some(ref rp) = real_path1_owned { + rp.as_c_str().as_ptr() + } else { + path1 + }; let real_path2_owned = utils::get_cstr_path(ctx, path2 as *const _); - let real_path2 = - if let Some(ref rp) = real_path2_owned { rp.as_c_str().as_ptr() } else { path2 }; + let real_path2 = if let Some(ref rp) = real_path2_owned { + rp.as_c_str().as_ptr() + } else { + path2 + }; let result = unsafe { symlink(real_path1, real_path2) }; debug!( "=> path1: {}, path2: {}, result: {}", @@ -231,8 +243,11 @@ pub fn ___syscall85(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> i32 { // let buf_addr: i32 = varargs.get(ctx); let buf_size: i32 = varargs.get(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; let ret = unsafe { libc::readlink(real_path, buf as _, buf_size as _) as i32 }; if ret == -1 { @@ -271,8 +286,11 @@ pub fn ___syscall198(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int debug!("emscripten::___syscall198 (lchown) {}", _which); let path_ptr = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path_ptr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { path_ptr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + path_ptr + }; let uid: uid_t = varargs.get(ctx); let gid: gid_t = varargs.get(ctx); let result = unsafe { lchown(real_path, uid, gid) }; @@ -296,7 +314,10 @@ pub fn ___syscall205(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let gid_ptr = emscripten_memory_pointer!(ctx.memory(0), groups) as *mut gid_t; assert_eq!(4, mem::align_of_val(&gid_ptr)); let result = unsafe { getgroups(ngroups_max, gid_ptr) }; - debug!("=> ngroups_max: {}, gid_ptr: {:?}, result: {}", ngroups_max, gid_ptr, result,); + debug!( + "=> ngroups_max: {}, gid_ptr: {:?}, result: {}", + ngroups_max, gid_ptr, result, + ); result } @@ -306,8 +327,11 @@ pub fn ___syscall212(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let pathname_addr = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; let owner: u32 = varargs.get(ctx); let group: u32 = varargs.get(ctx); @@ -332,7 +356,11 @@ pub fn ___syscall33(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall33 (access) {}", _which); let path = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path as *const _); - let real_path = if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { path }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + path + }; let amode: c_int = varargs.get(ctx); let result = unsafe { access(real_path, amode) }; debug!( @@ -356,8 +384,11 @@ pub fn ___syscall39(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall39 (mkdir) {}", _which); let pathname_addr = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, pathname_addr as *const _); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; let mode: u32 = varargs.get(ctx); unsafe { mkdir(real_path, mode as _) } } @@ -430,7 +461,10 @@ pub fn ___syscall330(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> pid_t fcntl(newfd, F_SETFD, old_flags); } - debug!("=> oldfd: {}, newfd: {}, flags: {} = pid: {}", oldfd, newfd, flags, res); + debug!( + "=> oldfd: {}, newfd: {}, flags: {} = pid: {}", + oldfd, newfd, flags, res + ); res } @@ -450,7 +484,10 @@ pub fn ___syscall54(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void; let translated_request = translate_ioctl(request); let ret = unsafe { ioctl(fd, translated_request as _, argp_ptr) }; - debug!(" => request: {}, translated: {}, return: {}", request, translated_request, ret); + debug!( + " => request: {}, translated: {}, return: {}", + request, translated_request, ret + ); // TODO: We hardcode the value to have emscripten tests pass, as for some reason // when the capturer is active, ioctl returns -1 instead of 0 @@ -460,7 +497,10 @@ pub fn ___syscall54(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int { ret } _ => { - debug!(" => not implemented case {} (noop, hardcoded to 0)", request); + debug!( + " => not implemented case {} (noop, hardcoded to 0)", + request + ); 0 } } @@ -518,10 +558,19 @@ pub fn ___syscall102(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int type T = u32; let payload = 1 as *const T as _; unsafe { - setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, payload, mem::size_of::() as socklen_t); + setsockopt( + fd, + SOL_SOCKET, + SO_NOSIGPIPE, + payload, + mem::size_of::() as socklen_t, + ); }; - debug!("=> domain: {}, type: {}, protocol: {} = fd: {}", domain, ty, protocol, fd); + debug!( + "=> domain: {}, type: {}, protocol: {} = fd: {}", + domain, ty, protocol, fd + ); fd as _ } 2 => { @@ -565,7 +614,10 @@ pub fn ___syscall102(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let socket = socket_varargs.get(ctx); let backlog: i32 = socket_varargs.get(ctx); let status = unsafe { listen(socket, backlog) }; - debug!("=> socketfd: {}, backlog: {} = status: {}", socket, backlog, status); + debug!( + "=> socketfd: {}, backlog: {} = status: {}", + socket, backlog, status + ); status } 5 => { @@ -602,7 +654,10 @@ pub fn ___syscall102(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int ioctl(fd, translate_ioctl(WASM_FIOCLEX) as _); }; - debug!("address: {:?}, len: {}, result fd = {}", address_addr, address_len_addr, fd); + debug!( + "address: {:?}, len: {}, result fd = {}", + address_addr, address_len_addr, fd + ); fd as _ } @@ -677,7 +732,14 @@ pub fn ___syscall102(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let address_len_addr = emscripten_memory_pointer!(memory, address_len) as *mut socklen_t; unsafe { - recvfrom(socket, buf_addr, len as usize, flags, address, address_len_addr) as i32 + recvfrom( + socket, + buf_addr, + len as usize, + flags, + address, + address_len_addr, + ) as i32 } } 14 => { @@ -797,8 +859,13 @@ pub fn ___syscall168(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let fds_mut = unsafe { fds.deref_mut(&memory).unwrap().get_mut() }; - let ret = - unsafe { libc::poll(fds_mut as *mut EmPollFd as *mut libc::pollfd, nfds as _, timeout) }; + let ret = unsafe { + libc::poll( + fds_mut as *mut EmPollFd as *mut libc::pollfd, + nfds as _, + timeout, + ) + }; ret } @@ -834,7 +901,10 @@ pub fn ___syscall181(ctx: &EmEnv, _which: c_int, mut varargs: VarArgs) -> c_int let buf_ptr = emscripten_memory_pointer!(ctx.memory(0), buf) as _; let status = unsafe { pwrite(fd, buf_ptr, count as _, offset) as _ }; - debug!("=> fd: {}, buf: {}, count: {}, offset: {} = status:{}", fd, buf, count, offset, status); + debug!( + "=> fd: {}, buf: {}, count: {}, offset: {} = status:{}", + fd, buf, count, offset, status + ); status } @@ -934,7 +1004,11 @@ pub fn ___syscall196(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall196 (lstat64) {}", _which); let path = varargs.get_str(ctx); let real_path_owned = utils::get_cstr_path(ctx, path as *const _); - let real_path = if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { path }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + path + }; let buf_ptr: u32 = varargs.get(ctx); unsafe { let mut stat: stat = std::mem::zeroed(); @@ -975,7 +1049,10 @@ pub fn ___syscall220(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { let fd: i32 = varargs.get(ctx); let dirp_addr: i32 = varargs.get(ctx); let count: u32 = varargs.get(ctx); - debug!("emscripten::___syscall220 (getdents) {} {} {}", fd, dirp_addr, count); + debug!( + "emscripten::___syscall220 (getdents) {} {} {}", + fd, dirp_addr, count + ); let dirp = emscripten_memory_pointer!(ctx.memory(0), dirp_addr) as *mut u8; @@ -1019,7 +1096,9 @@ pub fn ___syscall220(ctx: &EmEnv, _which: i32, mut varargs: VarArgs) -> i32 { *(dirp.add(pos + 11 + i) as *mut c_char) = 0 as c_char; debug!( " => file {}", - CStr::from_ptr(dirp.add(pos + 11) as *const c_char).to_str().unwrap() + CStr::from_ptr(dirp.add(pos + 11) as *const c_char) + .to_str() + .unwrap() ); } pos += offset; diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index 2ea3ad7bd..169b5f836 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -19,8 +19,11 @@ pub fn ___syscall5(ctx: &EmEnv, which: c_int, mut varargs: VarArgs) -> c_int { let _ = which; let pathname_addr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; let flags: i32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx); let path_str = unsafe { std::ffi::CStr::from_ptr(real_path).to_str().unwrap() }; @@ -45,7 +48,10 @@ pub fn ___syscall5(ctx: &EmEnv, which: c_int, mut varargs: VarArgs) -> c_int { let raw_pointer_to_urandom_file = emscripten_memory_pointer!(&memory, urandom_file_offset) as *const i8; let fd = unsafe { open(raw_pointer_to_urandom_file, flags, mode) }; - debug!("=> pathname: {}, flags: {}, mode: {} = fd: {}", path_str, flags, mode, fd); + debug!( + "=> pathname: {}, flags: {}, mode: {} = fd: {}", + path_str, flags, mode, fd + ); fd } _ => { @@ -98,8 +104,11 @@ pub fn ___syscall39(ctx: &EmEnv, which: c_int, mut varargs: VarArgs) -> c_int { let _ = which; let pathname_addr = varargs.get_str(ctx); let real_path_owned = get_cstr_path(ctx, pathname_addr); - let real_path = - if let Some(ref rp) = real_path_owned { rp.as_c_str().as_ptr() } else { pathname_addr }; + let real_path = if let Some(ref rp) = real_path_owned { + rp.as_c_str().as_ptr() + } else { + pathname_addr + }; unsafe { mkdir(real_path) } } diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index eae019c2b..1827b89b1 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -60,7 +60,10 @@ pub fn _gettimeofday(ctx: &EmEnv, tp: c_int, tz: c_int) -> c_int { tv_usec: i32, } - assert!(tz == 0, "the timezone argument of `_gettimeofday` must be null"); + assert!( + tz == 0, + "the timezone argument of `_gettimeofday` must be null" + ); unsafe { let now = SystemTime::now(); let since_epoch = now.duration_since(SystemTime::UNIX_EPOCH).unwrap(); @@ -95,7 +98,10 @@ pub fn _clock_gettime(ctx: &EmEnv, clk_id: clockid_t, tp: c_int) -> c_int { CLOCK_MONOTONIC | CLOCK_MONOTONIC_COARSE => { let precise_ns = time::precise_time_ns(); - time::Timespec::new((precise_ns / 1000000000) as i64, (precise_ns % 1000000000) as i32) + time::Timespec::new( + (precise_ns / 1000000000) as i64, + (precise_ns % 1000000000) as i32, + ) } _ => panic!("Clock with id \"{}\" is not supported.", clk_id), }; @@ -174,8 +180,9 @@ unsafe fn fmt_time(ctx: &EmEnv, time: u32) -> *const c_char { let date = &*(emscripten_memory_pointer!(ctx.memory(0), time) as *mut guest_tm); let days = vec!["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - let months = - vec!["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + let months = vec![ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + ]; let year = 1900 + date.tm_year; let time_str = format!( @@ -372,13 +379,19 @@ pub fn _timegm(ctx: &EmEnv, time_ptr: u32) -> i32 { #[cfg(target_os = "windows")] pub fn _timegm(_ctx: &EmEnv, _time_ptr: c_int) -> i32 { - debug!("emscripten::_timegm - UNIMPLEMENTED IN WINDOWS {}", _time_ptr); + debug!( + "emscripten::_timegm - UNIMPLEMENTED IN WINDOWS {}", + _time_ptr + ); -1 } /// emscripten: _strftime pub fn _strftime(ctx: &EmEnv, s_ptr: c_int, maxsize: u32, format_ptr: c_int, tm_ptr: c_int) -> i32 { - debug!("emscripten::_strftime {} {} {} {}", s_ptr, maxsize, format_ptr, tm_ptr); + debug!( + "emscripten::_strftime {} {} {} {}", + s_ptr, maxsize, format_ptr, tm_ptr + ); #[allow(clippy::cast_ptr_alignment)] let s = emscripten_memory_pointer!(ctx.memory(0), s_ptr) as *mut c_char; @@ -436,7 +449,10 @@ pub fn _strftime_l( tm_ptr: c_int, _last: c_int, ) -> i32 { - debug!("emscripten::_strftime_l {} {} {} {}", s_ptr, maxsize, format_ptr, tm_ptr); + debug!( + "emscripten::_strftime_l {} {} {} {}", + s_ptr, maxsize, format_ptr, tm_ptr + ); _strftime(ctx, s_ptr, maxsize, format_ptr, tm_ptr) } diff --git a/lib/emscripten/src/ucontext.rs b/lib/emscripten/src/ucontext.rs index 9971e84a7..7fda8656e 100644 --- a/lib/emscripten/src/ucontext.rs +++ b/lib/emscripten/src/ucontext.rs @@ -5,7 +5,10 @@ pub fn _getcontext(_ctx: &EmEnv, _ucp: i32) -> i32 { 0 } pub fn _makecontext(_ctx: &EmEnv, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { - debug!("emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv); + debug!( + "emscripten::_makecontext({}, {}, {}, {})", + _ucp, _func, _argc, _argv + ); } pub fn _setcontext(_ctx: &EmEnv, _ucp: i32) -> i32 { debug!("emscripten::_setcontext({})", _ucp); diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index af6123533..7ad250ddd 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -49,7 +49,13 @@ pub fn get_emscripten_memory_size(module: &Module) -> Result<(Pages, Option Result, String> { - let max_idx = match module.info().global_initializers.iter().map(|(k, _)| k).max() { + let max_idx = match module + .info() + .global_initializers + .iter() + .map(|(k, _)| k) + .max() + { Some(x) => x, None => return Ok(None), }; @@ -70,13 +76,18 @@ pub fn get_emscripten_metadata(module: &Module) -> Result, St &module.info().global_initializers[max_idx], &module.info().global_initializers[snd_max_idx], ) { - let dynamic_base = (*dynamic_base as u32) - .checked_sub(32) - .ok_or(format!("emscripten unexpected dynamic_base {}", *dynamic_base as u32))?; - let dynamictop_ptr = (*dynamictop_ptr as u32) - .checked_sub(32) - .ok_or(format!("emscripten unexpected dynamictop_ptr {}", *dynamictop_ptr as u32))?; - Ok(Some((align_memory(dynamic_base), align_memory(dynamictop_ptr)))) + let dynamic_base = (*dynamic_base as u32).checked_sub(32).ok_or(format!( + "emscripten unexpected dynamic_base {}", + *dynamic_base as u32 + ))?; + let dynamictop_ptr = (*dynamictop_ptr as u32).checked_sub(32).ok_or(format!( + "emscripten unexpected dynamictop_ptr {}", + *dynamictop_ptr as u32 + ))?; + Ok(Some(( + align_memory(dynamic_base), + align_memory(dynamictop_ptr), + ))) } else { Ok(None) } @@ -146,7 +157,10 @@ pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &EmEnv, cstrs: *mut *mut c_ch } counter }; - debug!("emscripten::copy_terminated_array_of_cstrs::total_num: {}", _total_num); + debug!( + "emscripten::copy_terminated_array_of_cstrs::total_num: {}", + _total_num + ); 0 } @@ -228,9 +242,15 @@ pub fn get_cstr_path(ctx: &EmEnv, path: *const i8) -> Option let mut cumulative_path = PathBuf::new(); for c in components.into_iter() { cumulative_path.push(c); - if let Some(val) = data.mapped_dirs.get(&cumulative_path.to_string_lossy().to_string()) { - let rest_of_path = - if !prefix_added { path.strip_prefix(cumulative_path).ok()? } else { &path }; + if let Some(val) = data + .mapped_dirs + .get(&cumulative_path.to_string_lossy().to_string()) + { + let rest_of_path = if !prefix_added { + path.strip_prefix(cumulative_path).ok()? + } else { + &path + }; let rebased_path = val.join(rest_of_path); return std::ffi::CString::new(rebased_path.to_string_lossy().as_bytes()).ok(); } @@ -246,8 +266,9 @@ pub fn get_current_directory(ctx: &EmEnv) -> Option { } std::env::current_dir() .map(|cwd| { - if let Some(val) = - get_emscripten_data(ctx).mapped_dirs.get(&cwd.to_string_lossy().to_string()) + if let Some(val) = get_emscripten_data(ctx) + .mapped_dirs + .get(&cwd.to_string_lossy().to_string()) { val.clone() } else { diff --git a/lib/engine-jit/src/artifact.rs b/lib/engine-jit/src/artifact.rs index 66681f941..a83e026e5 100644 --- a/lib/engine-jit/src/artifact.rs +++ b/lib/engine-jit/src/artifact.rs @@ -132,7 +132,9 @@ impl JITArtifact { /// Compile a data buffer into a `JITArtifact`, which may then be instantiated. #[cfg(not(feature = "compiler"))] pub fn new(_jit: &JITEngine, _data: &[u8]) -> Result { - Err(CompileError::Codegen("Compilation is not enabled in the engine".to_string())) + Err(CompileError::Codegen( + "Compilation is not enabled in the engine".to_string(), + )) } /// Deserialize a JITArtifact @@ -195,8 +197,10 @@ impl JITArtifact { let eh_frame = match &serializable.compilation.debug { Some(debug) => { - let eh_frame_section_size = - serializable.compilation.custom_sections[debug.eh_frame].bytes.len(); + let eh_frame_section_size = serializable.compilation.custom_sections + [debug.eh_frame] + .bytes + .len(); let eh_frame_section_pointer = custom_sections[debug.eh_frame]; Some(unsafe { std::slice::from_raw_parts(*eh_frame_section_pointer, eh_frame_section_size) diff --git a/lib/engine-jit/src/builder.rs b/lib/engine-jit/src/builder.rs index a8515b137..254f9d8bf 100644 --- a/lib/engine-jit/src/builder.rs +++ b/lib/engine-jit/src/builder.rs @@ -15,12 +15,20 @@ impl JIT { where T: Into>, { - Self { compiler_config: Some(compiler_config.into()), target: None, features: None } + Self { + compiler_config: Some(compiler_config.into()), + target: None, + features: None, + } } /// Create a new headless JIT pub fn headless() -> Self { - Self { compiler_config: None, target: None, features: None } + Self { + compiler_config: None, + target: None, + features: None, + } } /// Set the target diff --git a/lib/engine-jit/src/code_memory.rs b/lib/engine-jit/src/code_memory.rs index dd88d6a36..1498a23ea 100644 --- a/lib/engine-jit/src/code_memory.rs +++ b/lib/engine-jit/src/code_memory.rs @@ -66,14 +66,17 @@ impl CodeMemory { let total_len = round_up( functions.iter().fold(0, |acc, func| { - round_up(acc + Self::function_allocation_size(func), ARCH_FUNCTION_ALIGNMENT) - }) + executable_sections - .iter() - .fold(0, |acc, exec| round_up(acc + exec.bytes.len(), ARCH_FUNCTION_ALIGNMENT)), + round_up( + acc + Self::function_allocation_size(func), + ARCH_FUNCTION_ALIGNMENT, + ) + }) + executable_sections.iter().fold(0, |acc, exec| { + round_up(acc + exec.bytes.len(), ARCH_FUNCTION_ALIGNMENT) + }), page_size, - ) + data_sections - .iter() - .fold(0, |acc, data| round_up(acc + data.bytes.len(), DATA_SECTION_ALIGNMENT)); + ) + data_sections.iter().fold(0, |acc, data| { + round_up(acc + data.bytes.len(), DATA_SECTION_ALIGNMENT) + }); // 2. Allocate the pages. Mark them all read-write. @@ -85,7 +88,10 @@ impl CodeMemory { let mut bytes = 0; let mut buf = self.mmap.as_mut_slice(); for func in functions { - let len = round_up(Self::function_allocation_size(func), ARCH_FUNCTION_ALIGNMENT); + let len = round_up( + Self::function_allocation_size(func), + ARCH_FUNCTION_ALIGNMENT, + ); let (func_buf, next_buf) = buf.split_at_mut(len); buf = next_buf; bytes += len; @@ -124,7 +130,11 @@ impl CodeMemory { } } - Ok((function_result, executable_section_result, data_section_result)) + Ok(( + function_result, + executable_section_result, + data_section_result, + )) } /// Apply the page permissions. diff --git a/lib/engine-jit/src/engine.rs b/lib/engine-jit/src/engine.rs index a1f47c189..b089bb1ff 100644 --- a/lib/engine-jit/src/engine.rs +++ b/lib/engine-jit/src/engine.rs @@ -295,9 +295,14 @@ impl JITEngineInner { /// Register DWARF-type exception handling information associated with the code. pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> { - self.code_memory.last_mut().unwrap().unwind_registry_mut().publish(eh_frame).map_err( - |e| CompileError::Resource(format!("Error while publishing the unwind code: {}", e)), - )?; + self.code_memory + .last_mut() + .unwrap() + .unwind_registry_mut() + .publish(eh_frame) + .map_err(|e| { + CompileError::Resource(format!("Error while publishing the unwind code: {}", e)) + })?; Ok(()) } diff --git a/lib/engine-jit/src/link.rs b/lib/engine-jit/src/link.rs index 811a88ff6..fdd2b5691 100644 --- a/lib/engine-jit/src/link.rs +++ b/lib/engine-jit/src/link.rs @@ -55,7 +55,10 @@ fn apply_relocation( write_unaligned(reloc_address as *mut u32, reloc_delta as _); }, RelocationKind::X86PCRelRodata4 => {} - kind => panic!("Relocation kind unsupported in the current architecture {}", kind), + kind => panic!( + "Relocation kind unsupported in the current architecture {}", + kind + ), } } diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-native/src/artifact.rs index ca126cd3a..d1a03268d 100644 --- a/lib/engine-native/src/artifact.rs +++ b/lib/engine-native/src/artifact.rs @@ -258,7 +258,10 @@ impl NativeArtifact { .suffix(&suffix) .tempfile() .map_err(to_compile_error)?; - shared_file.into_temp_path().keep().map_err(to_compile_error)? + shared_file + .into_temp_path() + .keep() + .map_err(to_compile_error)? }; let is_cross_compiling = engine_inner.is_cross_compiling(); @@ -380,10 +383,12 @@ impl NativeArtifact { unsafe { // We use a fake function signature `fn()` because we just // want to get the function address. - let func: LibrarySymbol = - lib.get(function_name.as_bytes()).map_err(to_compile_error)?; - finished_functions - .push(FunctionBodyPtr(func.into_raw().into_raw() as *const VMFunctionBody)); + let func: LibrarySymbol = lib + .get(function_name.as_bytes()) + .map_err(to_compile_error)?; + finished_functions.push(FunctionBodyPtr( + func.into_raw().into_raw() as *const VMFunctionBody + )); } } @@ -395,8 +400,9 @@ impl NativeArtifact { .get_symbol_registry() .symbol_to_name(Symbol::FunctionCallTrampoline(sig_index)); unsafe { - let trampoline: LibrarySymbol = - lib.get(function_name.as_bytes()).map_err(to_compile_error)?; + let trampoline: LibrarySymbol = lib + .get(function_name.as_bytes()) + .map_err(to_compile_error)?; let raw = *trampoline.into_raw(); finished_function_call_trampolines.push(raw); } @@ -416,8 +422,9 @@ impl NativeArtifact { .get_symbol_registry() .symbol_to_name(Symbol::DynamicFunctionTrampoline(func_index)); unsafe { - let trampoline: LibrarySymbol = - lib.get(function_name.as_bytes()).map_err(to_compile_error)?; + let trampoline: LibrarySymbol = lib + .get(function_name.as_bytes()) + .map_err(to_compile_error)?; finished_dynamic_function_trampolines.push(FunctionBodyPtr( trampoline.into_raw().into_raw() as *const VMFunctionBody, )); @@ -467,7 +474,9 @@ impl NativeArtifact { /// Compile a data buffer into a `NativeArtifact`, which may then be instantiated. #[cfg(not(feature = "compiler"))] pub fn new(_engine: &NativeEngine, _data: &[u8]) -> Result { - Err(CompileError::Codegen("Compilation is not enabled in the engine".to_string())) + Err(CompileError::Codegen( + "Compilation is not enabled in the engine".to_string(), + )) } /// Deserialize a `NativeArtifact` from bytes. diff --git a/lib/engine-native/src/builder.rs b/lib/engine-native/src/builder.rs index 8d89a24ed..889fc26a9 100644 --- a/lib/engine-native/src/builder.rs +++ b/lib/engine-native/src/builder.rs @@ -18,12 +18,20 @@ impl Native { let mut compiler_config = compiler_config.into(); compiler_config.enable_pic(); - Self { compiler_config: Some(compiler_config), target: None, features: None } + Self { + compiler_config: Some(compiler_config), + target: None, + features: None, + } } /// Create a new headless Native pub fn headless() -> Self { - Self { compiler_config: None, target: None, features: None } + Self { + compiler_config: None, + target: None, + features: None, + } } /// Set the target diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 9f42490e5..196f743a0 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -170,7 +170,9 @@ impl Engine for NativeEngine { &self, file_ref: &Path, ) -> Result, DeserializeError> { - Ok(Arc::new(NativeArtifact::deserialize_from_file(&self, &file_ref)?)) + Ok(Arc::new(NativeArtifact::deserialize_from_file( + &self, &file_ref, + )?)) } fn id(&self) -> &EngineId { @@ -270,7 +272,10 @@ impl NativeEngineInner { if self.compiler.is_none() { return Err(CompileError::Codegen("The `NativeEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); } - Ok(&**self.compiler.as_ref().expect("Can't get compiler reference")) + Ok(&**self + .compiler + .as_ref() + .expect("Can't get compiler reference")) } #[cfg(feature = "compiler")] diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs index 57281e917..feea4c3c8 100644 --- a/lib/engine-native/src/serialize.rs +++ b/lib/engine-native/src/serialize.rs @@ -46,12 +46,16 @@ impl ModuleMetadata { &'a mut self, ) -> (&'a mut CompileModuleInfo, ModuleMetadataSymbolRegistry<'a>) { let compile_info = &mut self.compile_info; - let symbol_registry = ModuleMetadataSymbolRegistry { prefix: &self.prefix }; + let symbol_registry = ModuleMetadataSymbolRegistry { + prefix: &self.prefix, + }; (compile_info, symbol_registry) } pub fn get_symbol_registry<'a>(&'a self) -> ModuleMetadataSymbolRegistry<'a> { - ModuleMetadataSymbolRegistry { prefix: &self.prefix } + ModuleMetadataSymbolRegistry { + prefix: &self.prefix, + } } pub fn serialize(&mut self) -> Result, CompileError> { @@ -107,10 +111,18 @@ impl<'a> SymbolRegistry for ModuleMetadataSymbolRegistry<'a> { } Symbol::Section(index) => format!("wasmer_section_{}_{}", self.prefix, index.index()), Symbol::FunctionCallTrampoline(index) => { - format!("wasmer_trampoline_function_call_{}_{}", self.prefix, index.index()) + format!( + "wasmer_trampoline_function_call_{}_{}", + self.prefix, + index.index() + ) } Symbol::DynamicFunctionTrampoline(index) => { - format!("wasmer_trampoline_dynamic_function_{}_{}", self.prefix, index.index()) + format!( + "wasmer_trampoline_dynamic_function_{}_{}", + self.prefix, + index.index() + ) } } } @@ -122,7 +134,10 @@ impl<'a> SymbolRegistry for ModuleMetadataSymbolRegistry<'a> { .ok() .map(|index| Symbol::LocalFunction(LocalFunctionIndex::from_u32(index))) } else if let Some(index) = name.strip_prefix(&format!("wasmer_section_{}_", self.prefix)) { - index.parse::().ok().map(|index| Symbol::Section(SectionIndex::from_u32(index))) + index + .parse::() + .ok() + .map(|index| Symbol::Section(SectionIndex::from_u32(index))) } else if let Some(index) = name.strip_prefix(&format!("wasmer_trampoline_function_call_{}_", self.prefix)) { @@ -130,9 +145,10 @@ impl<'a> SymbolRegistry for ModuleMetadataSymbolRegistry<'a> { .parse::() .ok() .map(|index| Symbol::FunctionCallTrampoline(SignatureIndex::from_u32(index))) - } else if let Some(index) = - name.strip_prefix(&format!("wasmer_trampoline_dynamic_function_{}_", self.prefix)) - { + } else if let Some(index) = name.strip_prefix(&format!( + "wasmer_trampoline_dynamic_function_{}_", + self.prefix + )) { index .parse::() .ok() diff --git a/lib/engine-object-file/src/artifact.rs b/lib/engine-object-file/src/artifact.rs index 7e050f2ee..9b5b384de 100644 --- a/lib/engine-object-file/src/artifact.rs +++ b/lib/engine-object-file/src/artifact.rs @@ -289,7 +289,9 @@ impl ObjectFileArtifact { /// Compile a data buffer into a `ObjectFileArtifact`, which may then be instantiated. #[cfg(not(feature = "compiler"))] pub fn new(_engine: &ObjectFileEngine, _data: &[u8]) -> Result { - Err(CompileError::Codegen("Compilation is not enabled in the engine".to_string())) + Err(CompileError::Codegen( + "Compilation is not enabled in the engine".to_string(), + )) } /// Deserialize a `ObjectFileArtifact` from bytes. diff --git a/lib/engine-object-file/src/builder.rs b/lib/engine-object-file/src/builder.rs index 0d0ce3a73..41fa5e919 100644 --- a/lib/engine-object-file/src/builder.rs +++ b/lib/engine-object-file/src/builder.rs @@ -18,12 +18,20 @@ impl ObjectFile { let mut compiler_config = compiler_config.into(); compiler_config.enable_pic(); - Self { compiler_config: Some(compiler_config), target: None, features: None } + Self { + compiler_config: Some(compiler_config), + target: None, + features: None, + } } /// Create a new headless ObjectFile pub fn headless() -> Self { - Self { compiler_config: None, target: None, features: None } + Self { + compiler_config: None, + target: None, + features: None, + } } /// Set the target diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-object-file/src/engine.rs index c4d8d7875..2a15137bf 100644 --- a/lib/engine-object-file/src/engine.rs +++ b/lib/engine-object-file/src/engine.rs @@ -208,7 +208,10 @@ impl ObjectFileEngineInner { if self.compiler.is_none() { return Err(CompileError::Codegen("The `ObjectFileEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); } - Ok(&**self.compiler.as_ref().expect("Can't get compiler reference")) + Ok(&**self + .compiler + .as_ref() + .expect("Can't get compiler reference")) } #[cfg(feature = "compiler")] diff --git a/lib/engine-object-file/src/serialize.rs b/lib/engine-object-file/src/serialize.rs index 470915b68..cee443a45 100644 --- a/lib/engine-object-file/src/serialize.rs +++ b/lib/engine-object-file/src/serialize.rs @@ -22,12 +22,16 @@ pub struct ModuleMetadataSymbolRegistry { impl ModuleMetadata { pub fn split(&mut self) -> (&mut CompileModuleInfo, ModuleMetadataSymbolRegistry) { let compile_info = &mut self.compile_info; - let symbol_registry = ModuleMetadataSymbolRegistry { prefix: self.prefix.clone() }; + let symbol_registry = ModuleMetadataSymbolRegistry { + prefix: self.prefix.clone(), + }; (compile_info, symbol_registry) } pub fn get_symbol_registry(&self) -> ModuleMetadataSymbolRegistry { - ModuleMetadataSymbolRegistry { prefix: self.prefix.clone() } + ModuleMetadataSymbolRegistry { + prefix: self.prefix.clone(), + } } } @@ -39,10 +43,18 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry { } Symbol::Section(index) => format!("wasmer_section_{}_{}", self.prefix, index.index()), Symbol::FunctionCallTrampoline(index) => { - format!("wasmer_trampoline_function_call_{}_{}", self.prefix, index.index()) + format!( + "wasmer_trampoline_function_call_{}_{}", + self.prefix, + index.index() + ) } Symbol::DynamicFunctionTrampoline(index) => { - format!("wasmer_trampoline_dynamic_function_{}_{}", self.prefix, index.index()) + format!( + "wasmer_trampoline_dynamic_function_{}_{}", + self.prefix, + index.index() + ) } } } @@ -54,7 +66,10 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry { .ok() .map(|index| Symbol::LocalFunction(LocalFunctionIndex::from_u32(index))) } else if let Some(index) = name.strip_prefix(&format!("wasmer_section_{}_", self.prefix)) { - index.parse::().ok().map(|index| Symbol::Section(SectionIndex::from_u32(index))) + index + .parse::() + .ok() + .map(|index| Symbol::Section(SectionIndex::from_u32(index))) } else if let Some(index) = name.strip_prefix(&format!("wasmer_trampoline_function_call_{}_", self.prefix)) { @@ -62,9 +77,10 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry { .parse::() .ok() .map(|index| Symbol::FunctionCallTrampoline(SignatureIndex::from_u32(index))) - } else if let Some(index) = - name.strip_prefix(&format!("wasmer_trampoline_dynamic_function_{}_", self.prefix)) - { + } else if let Some(index) = name.strip_prefix(&format!( + "wasmer_trampoline_dynamic_function_{}_", + self.prefix + )) { index .parse::() .ok() diff --git a/lib/engine/src/artifact.rs b/lib/engine/src/artifact.rs index 08843c87f..a706dbdd7 100644 --- a/lib/engine/src/artifact.rs +++ b/lib/engine/src/artifact.rs @@ -129,8 +129,10 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage { .create_tables(&module, self.table_styles(), &table_definition_locations) .map_err(InstantiationError::Link)? .into_boxed_slice(); - let finished_globals = - tunables.create_globals(&module).map_err(InstantiationError::Link)?.into_boxed_slice(); + let finished_globals = tunables + .create_globals(&module) + .map_err(InstantiationError::Link)? + .into_boxed_slice(); self.register_frame_info(); @@ -164,7 +166,10 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage { let data_initializers = self .data_initializers() .iter() - .map(|init| DataInitializer { location: init.location.clone(), data: &*init.data }) + .map(|init| DataInitializer { + location: init.location.clone(), + data: &*init.data, + }) .collect::>(); handle .finish_instantiation(&data_initializers) diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 0e297f663..b321c5c4b 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -95,6 +95,8 @@ impl Clone for EngineId { impl Default for EngineId { fn default() -> Self { static NEXT_ID: AtomicUsize = AtomicUsize::new(0); - Self { id: NEXT_ID.fetch_add(1, SeqCst) } + Self { + id: NEXT_ID.fetch_add(1, SeqCst), + } } } diff --git a/lib/engine/src/export.rs b/lib/engine/src/export.rs index ae0a78e0f..d0014eb8c 100644 --- a/lib/engine/src/export.rs +++ b/lib/engine/src/export.rs @@ -35,9 +35,10 @@ impl From for VMExport { impl From for Export { fn from(other: VMExport) -> Self { match other { - VMExport::Function(vm_function) => { - Self::Function(ExportFunction { vm_function, metadata: None }) - } + VMExport::Function(vm_function) => Self::Function(ExportFunction { + vm_function, + metadata: None, + }), VMExport::Memory(vm_memory) => Self::Memory(ExportMemory { vm_memory }), VMExport::Table(vm_table) => Self::Table(ExportTable { vm_table }), VMExport::Global(vm_global) => Self::Global(ExportGlobal { vm_global }), @@ -111,7 +112,12 @@ impl ExportFunctionMetadata { host_env_clone_fn: fn(*mut std::ffi::c_void) -> *mut std::ffi::c_void, host_env_drop_fn: fn(*mut std::ffi::c_void), ) -> Self { - Self { host_env, import_init_function_ptr, host_env_clone_fn, host_env_drop_fn } + Self { + host_env, + import_init_function_ptr, + host_env_clone_fn, + host_env_drop_fn, + } } } diff --git a/lib/engine/src/resolver.rs b/lib/engine/src/resolver.rs index d9cca77ce..cc0123015 100644 --- a/lib/engine/src/resolver.rs +++ b/lib/engine/src/resolver.rs @@ -180,8 +180,10 @@ pub fn resolve_imports( }; // Clone the host env for this `Instance`. - let env = if let Some(ExportFunctionMetadata { host_env_clone_fn: clone, .. }) = - f.metadata.as_deref() + let env = if let Some(ExportFunctionMetadata { + host_env_clone_fn: clone, + .. + }) = f.metadata.as_deref() { // TODO: maybe start adding asserts in all these // unsafe blocks to prevent future changes from @@ -207,7 +209,12 @@ pub fn resolve_imports( let destructor = f.metadata.as_ref().map(|m| m.host_env_drop_fn); let import_function_env = if let (Some(clone), Some(destructor)) = (clone, destructor) { - ImportFunctionEnv::Env { env, clone, initializer, destructor } + ImportFunctionEnv::Env { + env, + clone, + initializer, + destructor, + } } else { ImportFunctionEnv::NoEnv }; @@ -229,7 +236,10 @@ pub fn resolve_imports( let import_memory_style = &memory_styles[*index]; if let ( MemoryStyle::Static { bound, .. }, - MemoryStyle::Static { bound: import_bound, .. }, + MemoryStyle::Static { + bound: import_bound, + .. + }, ) = (export_memory_style.clone(), &import_memory_style) { assert_ge!(bound, *import_bound); @@ -341,7 +351,9 @@ where B: NamedResolver, { fn resolve_by_name(&self, module: &str, field: &str) -> Option { - self.a.resolve_by_name(module, field).or_else(|| self.b.resolve_by_name(module, field)) + self.a + .resolve_by_name(module, field) + .or_else(|| self.b.resolve_by_name(module, field)) } } @@ -351,6 +363,9 @@ where B: NamedResolver + Clone, { fn clone(&self) -> Self { - Self { a: self.a.clone(), b: self.b.clone() } + Self { + a: self.a.clone(), + b: self.b.clone(), + } } } diff --git a/lib/engine/src/serialize.rs b/lib/engine/src/serialize.rs index 9ef2f0fc9..a36b47da3 100644 --- a/lib/engine/src/serialize.rs +++ b/lib/engine/src/serialize.rs @@ -98,6 +98,8 @@ impl<'de> Deserialize<'de> for SerializableFunctionFrameInfo { where D: Deserializer<'de>, { - Ok(Self::Unprocessed(deserializer.deserialize_byte_buf(FunctionFrameInfoVisitor)?)) + Ok(Self::Unprocessed( + deserializer.deserialize_byte_buf(FunctionFrameInfoVisitor)?, + )) } } diff --git a/lib/engine/src/trap/error.rs b/lib/engine/src/trap/error.rs index 65ebf125a..36cdb7e49 100644 --- a/lib/engine/src/trap/error.rs +++ b/lib/engine/src/trap/error.rs @@ -80,7 +80,11 @@ impl RuntimeError { } } // A trap caused by an error on the generated machine code for a Wasm function - Trap::Wasm { pc, signal_trap, backtrace } => { + Trap::Wasm { + pc, + signal_trap, + backtrace, + } => { let info = if info.should_process_frame(pc).unwrap_or(false) { drop(info); let mut info = FRAME_INFO.write().unwrap(); @@ -92,13 +96,16 @@ impl RuntimeError { }; let code = info .lookup_trap_info(pc) - .map_or(signal_trap.unwrap_or(TrapCode::StackOverflow), |info| info.trap_code); + .map_or(signal_trap.unwrap_or(TrapCode::StackOverflow), |info| { + info.trap_code + }); Self::new_with_trace(info, Some(pc), RuntimeErrorSource::Trap(code), backtrace) } // A trap triggered manually from the Wasmer runtime - Trap::Runtime { trap_code, backtrace } => { - Self::new_with_trace(info, None, RuntimeErrorSource::Trap(trap_code), backtrace) - } + Trap::Runtime { + trap_code, + backtrace, + } => Self::new_with_trace(info, None, RuntimeErrorSource::Trap(trap_code), backtrace), } } @@ -139,7 +146,10 @@ impl RuntimeError { // If any of the frames is not processed, we adquire the lock to // modify the GlobalFrameInfo module. - let info = if frames.iter().any(|pc| info.should_process_frame(*pc).unwrap_or(false)) { + let info = if frames + .iter() + .any(|pc| info.should_process_frame(*pc).unwrap_or(false)) + { // We drop the read lock, to get a write one. // Note: this is not guaranteed because it's a RwLock: // the following code may cause deadlocks. @@ -157,10 +167,18 @@ impl RuntimeError { }; // Let's construct the trace - let wasm_trace = - frames.into_iter().filter_map(|pc| info.lookup_frame_info(pc)).collect::>(); + let wasm_trace = frames + .into_iter() + .filter_map(|pc| info.lookup_frame_info(pc)) + .collect::>(); - Self { inner: Arc::new(RuntimeErrorInner { source, wasm_trace, native_trace }) } + Self { + inner: Arc::new(RuntimeErrorInner { + source, + wasm_trace, + native_trace, + }), + } } /// Returns a reference the `message` stored in `Trap`. @@ -178,12 +196,13 @@ impl RuntimeError { pub fn downcast(self) -> Result { match Arc::try_unwrap(self.inner) { // We only try to downcast user errors - Ok(RuntimeErrorInner { source: RuntimeErrorSource::User(err), .. }) - if err.is::() => - { - Ok(*err.downcast::().unwrap()) - } - Ok(inner) => Err(Self { inner: Arc::new(inner) }), + Ok(RuntimeErrorInner { + source: RuntimeErrorSource::User(err), + .. + }) if err.is::() => Ok(*err.downcast::().unwrap()), + Ok(inner) => Err(Self { + inner: Arc::new(inner), + }), Err(inner) => Err(Self { inner }), } } @@ -235,7 +254,13 @@ impl fmt::Display for RuntimeError { }, None => write!(f, "")?, } - write!(f, " ({}[{}]:0x{:x})", name, func_index, frame.module_offset())?; + write!( + f, + " ({}[{}]:0x{:x})", + name, + func_index, + frame.module_offset() + )?; } Ok(()) } diff --git a/lib/engine/src/trap/frame_info.rs b/lib/engine/src/trap/frame_info.rs index af87447d6..3407ab742 100644 --- a/lib/engine/src/trap/frame_info.rs +++ b/lib/engine/src/trap/frame_info.rs @@ -118,8 +118,12 @@ impl GlobalFrameInfo { // machine instruction that corresponds to `pc`, which then allows us to // map that to a wasm original source location. let rel_pos = pc - func.start; - let instr_map = &module.processed_function_frame_info(func.local_index).address_map; - let pos = match instr_map.instructions.binary_search_by_key(&rel_pos, |map| map.code_offset) + let instr_map = &module + .processed_function_frame_info(func.local_index) + .address_map; + let pos = match instr_map + .instructions + .binary_search_by_key(&rel_pos, |map| map.code_offset) { // Exact hit! Ok(pos) => Some(pos), @@ -244,12 +248,22 @@ pub fn register( let mut min = usize::max_value(); let mut max = 0; let mut functions = BTreeMap::new(); - for (i, FunctionExtent { ptr: start, length: len }) in finished_functions.iter() { + for ( + i, + FunctionExtent { + ptr: start, + length: len, + }, + ) in finished_functions.iter() + { let start = **start as usize; let end = start + len; min = cmp::min(min, start); max = cmp::max(max, end); - let func = FunctionInfo { start, local_index: i }; + let func = FunctionInfo { + start, + local_index: i, + }; assert!(functions.insert(end, func).is_none()); } if functions.is_empty() { @@ -267,8 +281,15 @@ pub fn register( } // ... then insert our range and assert nothing was there previously - let prev = - info.ranges.insert(max, ModuleInfoFrameInfo { start: min, functions, module, frame_infos }); + let prev = info.ranges.insert( + max, + ModuleInfoFrameInfo { + start: min, + functions, + module, + frame_infos, + }, + ); assert!(prev.is_none()); Some(GlobalFrameInfoRegistration { key: max }) } diff --git a/lib/engine/src/tunables.rs b/lib/engine/src/tunables.rs index 7ad2ef894..adad964c6 100644 --- a/lib/engine/src/tunables.rs +++ b/lib/engine/src/tunables.rs @@ -100,7 +100,10 @@ pub trait Tunables: MemoryUsage { let ty = &module.tables[ti]; let style = &table_styles[ti]; let tdl = table_definition_locations[index]; - tables.push(self.create_vm_table(ty, style, tdl).map_err(LinkError::Resource)?); + tables.push( + self.create_vm_table(ty, style, tdl) + .map_err(LinkError::Resource)?, + ); } Ok(tables) } @@ -115,7 +118,10 @@ pub trait Tunables: MemoryUsage { let mut vmctx_globals = PrimaryMap::with_capacity(module.globals.len() - num_imports); for &global_type in module.globals.values().skip(num_imports) { - vmctx_globals.push(self.create_global(global_type).map_err(LinkError::Resource)?); + vmctx_globals.push( + self.create_global(global_type) + .map_err(LinkError::Resource)?, + ); } Ok(vmctx_globals) diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 63bd12c63..faea363e0 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -122,10 +122,13 @@ impl u64 + Send + Sync + 'static> ModuleMiddleware for Meter } // Append a global for remaining points and initialize it. - let remaining_points_global_index = - module_info.globals.push(GlobalType::new(Type::I64, Mutability::Var)); + let remaining_points_global_index = module_info + .globals + .push(GlobalType::new(Type::I64, Mutability::Var)); - module_info.global_initializers.push(GlobalInit::I64Const(self.initial_limit as i64)); + module_info + .global_initializers + .push(GlobalInit::I64Const(self.initial_limit as i64)); module_info.exports.insert( "wasmer_metering_remaining_points".to_string(), @@ -133,10 +136,13 @@ impl u64 + Send + Sync + 'static> ModuleMiddleware for Meter ); // Append a global for the exhausted points boolean and initialize it. - let points_exhausted_global_index = - module_info.globals.push(GlobalType::new(Type::I32, Mutability::Var)); + let points_exhausted_global_index = module_info + .globals + .push(GlobalType::new(Type::I32, Mutability::Var)); - module_info.global_initializers.push(GlobalInit::I32Const(0)); + module_info + .global_initializers + .push(GlobalInit::I32Const(0)); module_info.exports.insert( "wasmer_metering_points_exhausted".to_string(), @@ -318,7 +324,10 @@ mod tests { // Instantiate let instance = Instance::new(&module, &imports! {}).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(10)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(10) + ); // First call // @@ -326,14 +335,24 @@ mod tests { // * `local.get $value` is a `Operator::LocalGet` which costs 1 point; // * `i32.const` is a `Operator::I32Const` which costs 1 point; // * `i32.add` is a `Operator::I32Add` which costs 2 points. - let add_one = - instance.exports.get_function("add_one").unwrap().native::().unwrap(); + let add_one = instance + .exports + .get_function("add_one") + .unwrap() + .native::() + .unwrap(); add_one.call(1).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(6)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(6) + ); // Second call add_one.call(1).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(2)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(2) + ); // Third call fails due to limit assert!(add_one.call(1).is_err()); @@ -350,28 +369,47 @@ mod tests { // Instantiate let instance = Instance::new(&module, &imports! {}).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(10)); - let add_one = - instance.exports.get_function("add_one").unwrap().native::().unwrap(); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(10) + ); + let add_one = instance + .exports + .get_function("add_one") + .unwrap() + .native::() + .unwrap(); // Increase a bit to have enough for 3 calls set_remaining_points(&instance, 12); // Ensure we can use the new points now add_one.call(1).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(8)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(8) + ); add_one.call(1).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(4)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(4) + ); add_one.call(1).unwrap(); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(0)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(0) + ); assert!(add_one.call(1).is_err()); assert_eq!(get_remaining_points(&instance), MeteringPoints::Exhausted); // Add some points for another call set_remaining_points(&instance, 4); - assert_eq!(get_remaining_points(&instance), MeteringPoints::Remaining(4)); + assert_eq!( + get_remaining_points(&instance), + MeteringPoints::Remaining(4) + ); } } diff --git a/lib/object/src/module.rs b/lib/object/src/module.rs index f85517727..b824403e3 100644 --- a/lib/object/src/module.rs +++ b/lib/object/src/module.rs @@ -27,22 +27,35 @@ pub fn get_object_for_target(triple: &Triple) -> Result { BinaryFormat::Macho => object::BinaryFormat::MachO, BinaryFormat::Coff => object::BinaryFormat::Coff, binary_format => { - return Err(ObjectError::UnsupportedBinaryFormat(format!("{}", binary_format))); + return Err(ObjectError::UnsupportedBinaryFormat(format!( + "{}", + binary_format + ))); } }; let obj_architecture = match triple.architecture { Architecture::X86_64 => object::Architecture::X86_64, Architecture::Aarch64(_) => object::Architecture::Aarch64, architecture => { - return Err(ObjectError::UnsupportedArchitecture(format!("{}", architecture))); + return Err(ObjectError::UnsupportedArchitecture(format!( + "{}", + architecture + ))); } }; - let obj_endianness = match triple.endianness().map_err(|_| ObjectError::UnknownEndianness)? { + let obj_endianness = match triple + .endianness() + .map_err(|_| ObjectError::UnknownEndianness)? + { Endianness::Little => object::Endianness::Little, Endianness::Big => object::Endianness::Big, }; - Ok(Object::new(obj_binary_format, obj_architecture, obj_endianness)) + Ok(Object::new( + obj_binary_format, + obj_architecture, + obj_endianness, + )) } /// Write data into an existing object. @@ -196,14 +209,22 @@ pub fn emit_compilation( // Add relocations (function and sections) let (relocation_size, relocation_kind, relocation_encoding) = match triple.architecture { - Architecture::X86_64 => (32, RelocationKind::PltRelative, RelocationEncoding::X86Branch), + Architecture::X86_64 => ( + 32, + RelocationKind::PltRelative, + RelocationEncoding::X86Branch, + ), // Object doesn't fully support it yet // Architecture::Aarch64(_) => ( // 32, // RelocationKind::PltRelative, // RelocationEncoding::Generic, // ), - architecture => return Err(ObjectError::UnsupportedArchitecture(architecture.to_string())), + architecture => { + return Err(ObjectError::UnsupportedArchitecture( + architecture.to_string(), + )) + } }; let mut all_relocations = Vec::new(); diff --git a/lib/types/src/archives.rs b/lib/types/src/archives.rs index ce6cff2a7..ce9e40cad 100644 --- a/lib/types/src/archives.rs +++ b/lib/types/src/archives.rs @@ -48,7 +48,10 @@ where { fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { let elems: Vec<_> = self.0.deserialize(deserializer)?; - Ok(PrimaryMap { elems, unused: PhantomData }) + Ok(PrimaryMap { + elems, + unused: PhantomData, + }) } } @@ -61,7 +64,10 @@ pub struct ArchivableIndexMap { impl From> for ArchivableIndexMap { fn from(it: IndexMap) -> ArchivableIndexMap { - let mut r = ArchivableIndexMap { indices: HashMap::new(), entries: Vec::new() }; + let mut r = ArchivableIndexMap { + indices: HashMap::new(), + entries: Vec::new(), + }; let mut i: u64 = 0; for (k, v) in it.into_iter() { r.indices.insert(k.clone(), i); diff --git a/lib/types/src/entity/boxed_slice.rs b/lib/types/src/entity/boxed_slice.rs index 346438570..19fdd4b45 100644 --- a/lib/types/src/entity/boxed_slice.rs +++ b/lib/types/src/entity/boxed_slice.rs @@ -37,7 +37,10 @@ where /// /// This relies on `raw` pointing to a valid slice of `V`s. pub unsafe fn from_raw(raw: *mut [V]) -> Self { - Self { elems: Box::from_raw(raw), unused: PhantomData } + Self { + elems: Box::from_raw(raw), + unused: PhantomData, + } } /// Check if `k` is a valid key in the map. diff --git a/lib/types/src/entity/iter.rs b/lib/types/src/entity/iter.rs index 1e770325c..a157abef8 100644 --- a/lib/types/src/entity/iter.rs +++ b/lib/types/src/entity/iter.rs @@ -22,7 +22,10 @@ impl<'a, K: EntityRef, V> Iter<'a, K, V> { /// Create an `Iter` iterator that visits the `PrimaryMap` keys and values /// of `iter`. pub fn new(iter: slice::Iter<'a, V>) -> Self { - Self { enumerate: iter.enumerate(), unused: PhantomData } + Self { + enumerate: iter.enumerate(), + unused: PhantomData, + } } } @@ -59,7 +62,10 @@ impl<'a, K: EntityRef, V> IterMut<'a, K, V> { /// Create an `IterMut` iterator that visits the `PrimaryMap` keys and values /// of `iter`. pub fn new(iter: slice::IterMut<'a, V>) -> Self { - Self { enumerate: iter.enumerate(), unused: PhantomData } + Self { + enumerate: iter.enumerate(), + unused: PhantomData, + } } } @@ -93,7 +99,10 @@ impl IntoIter { /// Create an `IntoIter` iterator that visits the `PrimaryMap` keys and values /// of `iter`. pub fn new(iter: vec::IntoIter) -> Self { - Self { enumerate: iter.enumerate(), unused: PhantomData } + Self { + enumerate: iter.enumerate(), + unused: PhantomData, + } } } diff --git a/lib/types/src/entity/keys.rs b/lib/types/src/entity/keys.rs index 9e15157fe..08d5a225c 100644 --- a/lib/types/src/entity/keys.rs +++ b/lib/types/src/entity/keys.rs @@ -19,7 +19,11 @@ pub struct Keys { impl Keys { /// Create a `Keys` iterator that visits `len` entities starting from 0. pub fn with_len(len: usize) -> Self { - Self { pos: 0, rev_pos: len, unused: PhantomData } + Self { + pos: 0, + rev_pos: len, + unused: PhantomData, + } } } diff --git a/lib/types/src/entity/packed_option.rs b/lib/types/src/entity/packed_option.rs index 2097660f8..a391f31fd 100644 --- a/lib/types/src/entity/packed_option.rs +++ b/lib/types/src/entity/packed_option.rs @@ -83,7 +83,10 @@ impl Default for PackedOption { impl From for PackedOption { /// Convert `t` into a packed `Some(x)`. fn from(t: T) -> Self { - debug_assert!(!t.is_reserved_value(), "Can't make a PackedOption from the reserved value."); + debug_assert!( + !t.is_reserved_value(), + "Can't make a PackedOption from the reserved value." + ); Self(t) } } diff --git a/lib/types/src/entity/primary_map.rs b/lib/types/src/entity/primary_map.rs index e6a6d4a81..a5827cad6 100644 --- a/lib/types/src/entity/primary_map.rs +++ b/lib/types/src/entity/primary_map.rs @@ -48,12 +48,18 @@ where { /// Create a new empty map. pub fn new() -> Self { - Self { elems: Vec::new(), unused: PhantomData } + Self { + elems: Vec::new(), + unused: PhantomData, + } } /// Create a new empty map with the given capacity. pub fn with_capacity(capacity: usize) -> Self { - Self { elems: Vec::with_capacity(capacity), unused: PhantomData } + Self { + elems: Vec::with_capacity(capacity), + unused: PhantomData, + } } /// Check if `k` is a valid key in the map. @@ -225,7 +231,10 @@ where where T: IntoIterator, { - Self { elems: Vec::from_iter(iter), unused: PhantomData } + Self { + elems: Vec::from_iter(iter), + unused: PhantomData, + } } } diff --git a/lib/types/src/entity/secondary_map.rs b/lib/types/src/entity/secondary_map.rs index 987a30070..ac19c432f 100644 --- a/lib/types/src/entity/secondary_map.rs +++ b/lib/types/src/entity/secondary_map.rs @@ -50,7 +50,11 @@ where where V: Default, { - Self { elems: Vec::new(), default: Default::default(), unused: PhantomData } + Self { + elems: Vec::new(), + default: Default::default(), + unused: PhantomData, + } } /// Create a new, empty map with the specified capacity. @@ -71,7 +75,11 @@ where /// /// This constructor does not require V to implement Default. pub fn with_default(default: V) -> Self { - Self { elems: Vec::new(), default, unused: PhantomData } + Self { + elems: Vec::new(), + default, + unused: PhantomData, + } } /// Returns the number of elements the map can hold without reallocating. @@ -267,7 +275,9 @@ where } } - deserializer.deserialize_seq(SecondaryMapVisitor { unused: PhantomData {} }) + deserializer.deserialize_seq(SecondaryMapVisitor { + unused: PhantomData {}, + }) } } diff --git a/lib/types/src/extern_ref.rs b/lib/types/src/extern_ref.rs index dccc08a2a..85494baf6 100644 --- a/lib/types/src/extern_ref.rs +++ b/lib/types/src/extern_ref.rs @@ -75,7 +75,11 @@ impl VMExternRef { // bug on systems that can address `usize` sized memory blocks or smaller because // the reference itself is at least `usize` in size and all virtual memory would be // taken by references to the data leaving no room for the data itself. - if old_size.checked_add(growth_amount).map(|v| v > Self::MAX_REFCOUNT).unwrap_or(true) { + if old_size + .checked_add(growth_amount) + .map(|v| v > Self::MAX_REFCOUNT) + .unwrap_or(true) + { panic!("Too many references to `ExternRef`"); } } @@ -157,7 +161,10 @@ impl VMExternRefInner { where T: Any + Send + Sync + Sized + 'static, { - Self { strong: atomic::AtomicUsize::new(1), data: Box::new(value) } + Self { + strong: atomic::AtomicUsize::new(1), + data: Box::new(value), + } } /// Increments the reference count. @@ -220,7 +227,9 @@ pub struct ExternRef { impl Clone for ExternRef { fn clone(&self) -> Self { - Self { inner: self.inner.ref_clone() } + Self { + inner: self.inner.ref_clone(), + } } } @@ -238,7 +247,9 @@ impl ExternRef { /// New null extern ref pub fn null() -> Self { - Self { inner: VMExternRef::null() } + Self { + inner: VMExternRef::null(), + } } #[cfg(feature = "experimental-reference-types-extern-ref")] @@ -247,7 +258,9 @@ impl ExternRef { where T: Any + Send + Sync + 'static + Sized, { - Self { inner: VMExternRef::new(value) } + Self { + inner: VMExternRef::new(value), + } } #[cfg(feature = "experimental-reference-types-extern-ref")] diff --git a/lib/types/src/features.rs b/lib/types/src/features.rs index 9a92e273e..ca779ac88 100644 --- a/lib/types/src/features.rs +++ b/lib/types/src/features.rs @@ -10,7 +10,10 @@ use serde::{Deserialize, Serialize}; /// [WebAssembly proposal]: https://github.com/WebAssembly/proposals #[derive(Clone, Debug, Eq, PartialEq, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct Features { /// Threads proposal should be enabled pub threads: bool, @@ -298,7 +301,10 @@ mod test_features { #[test] fn disable_bulk_memory() { let mut features = Features::new(); - features.threads(true).reference_types(true).bulk_memory(false); + features + .threads(true) + .reference_types(true) + .bulk_memory(false); assert!(!features.bulk_memory); assert!(!features.reference_types); } diff --git a/lib/types/src/indexes.rs b/lib/types/src/indexes.rs index bea024f79..af1975ecc 100644 --- a/lib/types/src/indexes.rs +++ b/lib/types/src/indexes.rs @@ -10,7 +10,10 @@ use serde::{Deserialize, Serialize}; /// Index type of a function defined locally inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -35,7 +38,10 @@ entity_impl!(LocalMemoryIndex); /// Index type of a global defined locally inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -48,7 +54,10 @@ entity_impl!(ArchivedLocalGlobalIndex); /// Index type of a function (imported or local) inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -61,7 +70,10 @@ entity_impl!(ArchivedFunctionIndex); /// Index type of a table (imported or local) inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -74,7 +86,10 @@ entity_impl!(ArchivedTableIndex); /// Index type of a global variable (imported or local) inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -87,7 +102,10 @@ entity_impl!(ArchivedGlobalIndex); /// Index type of a linear memory (imported or local) inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -100,7 +118,10 @@ entity_impl!(ArchivedMemoryIndex); /// Index type of a signature (imported or local) inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -113,7 +134,10 @@ entity_impl!(ArchivedSignatureIndex); /// Index type of a passive data segment inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -126,7 +150,10 @@ entity_impl!(ArchivedDataIndex); /// Index type of a passive element segment inside the WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -139,7 +166,10 @@ entity_impl!(ArchivedElemIndex); /// Index type of a custom section inside a WebAssembly module. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -152,7 +182,10 @@ entity_impl!(ArchivedCustomSectionIndex); /// An entity to export. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) @@ -171,7 +204,10 @@ pub enum ExportIndex { /// An entity to import. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] #[cfg_attr( feature = "enable-rkyv", archive(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)) diff --git a/lib/types/src/initializers.rs b/lib/types/src/initializers.rs index a46b6ea29..1809eddd0 100644 --- a/lib/types/src/initializers.rs +++ b/lib/types/src/initializers.rs @@ -9,7 +9,10 @@ use serde::{Deserialize, Serialize}; /// A WebAssembly table initializer. #[derive(Clone, Debug, Hash, Serialize, Deserialize, MemoryUsage, PartialEq, Eq)] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct TableInitializer { /// The index of a table to initialize. pub table_index: TableIndex, @@ -25,7 +28,10 @@ pub struct TableInitializer { /// should be performed. #[derive(Clone, Debug, MemoryUsage, PartialEq, Eq)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct DataInitializerLocation { /// The index of the memory to initialize. pub memory_index: MemoryIndex, @@ -52,7 +58,10 @@ pub struct DataInitializer<'data> { /// holding a reference to it #[derive(Debug, Clone, MemoryUsage, PartialEq, Eq)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct OwnedDataInitializer { /// The location where the initialization is to be performed. pub location: DataInitializerLocation, diff --git a/lib/types/src/memory_view.rs b/lib/types/src/memory_view.rs index a7d39c753..907f7d8e0 100644 --- a/lib/types/src/memory_view.rs +++ b/lib/types/src/memory_view.rs @@ -58,14 +58,22 @@ where { /// Creates a new MemoryView given a `pointer` and `length`. pub unsafe fn new(ptr: *mut T, length: u32) -> Self { - Self { ptr, length: length as usize, _phantom: PhantomData } + Self { + ptr, + length: length as usize, + _phantom: PhantomData, + } } } impl<'a, T: Atomic> MemoryView<'a, T> { /// Get atomic access to a memory view. pub fn atomically(&self) -> MemoryView<'a, T::Output, Atomically> { - MemoryView { ptr: self.ptr as *mut T::Output, length: self.length, _phantom: PhantomData } + MemoryView { + ptr: self.ptr as *mut T::Output, + length: self.length, + _phantom: PhantomData, + } } } diff --git a/lib/types/src/types.rs b/lib/types/src/types.rs index 18ad2b20e..c246dfc8a 100644 --- a/lib/types/src/types.rs +++ b/lib/types/src/types.rs @@ -20,7 +20,10 @@ use serde::{Deserialize, Serialize}; /// A list of all possible value types in WebAssembly. #[derive(Copy, Debug, Clone, Eq, PartialEq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub enum Type { /// Signed 32 bit integer. I32, @@ -42,7 +45,10 @@ impl Type { /// Returns true if `Type` matches any of the numeric types. (e.g. `I32`, /// `I64`, `F32`, `F64`, `V128`). pub fn is_num(self) -> bool { - matches!(self, Self::I32 | Self::I64 | Self::F32 | Self::F64 | Self::V128) + matches!( + self, + Self::I32 | Self::I64 | Self::F32 | Self::F64 | Self::V128 + ) } /// Returns true if `Type` matches either of the reference types. @@ -59,7 +65,10 @@ impl fmt::Display for Type { #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] /// The WebAssembly V128 type pub struct V128(pub(crate) [u8; 16]); @@ -126,8 +135,14 @@ pub enum ExternType { } fn is_global_compatible(exported: GlobalType, imported: GlobalType) -> bool { - let GlobalType { ty: exported_ty, mutability: exported_mutability } = exported; - let GlobalType { ty: imported_ty, mutability: imported_mutability } = imported; + let GlobalType { + ty: exported_ty, + mutability: exported_mutability, + } = exported; + let GlobalType { + ty: imported_ty, + mutability: imported_mutability, + } = imported; exported_ty == imported_ty && imported_mutability == exported_mutability } @@ -140,10 +155,16 @@ fn is_table_element_type_compatible(exported_type: Type, imported_type: Type) -> } fn is_table_compatible(exported: &TableType, imported: &TableType) -> bool { - let TableType { ty: exported_ty, minimum: exported_minimum, maximum: exported_maximum } = - exported; - let TableType { ty: imported_ty, minimum: imported_minimum, maximum: imported_maximum } = - imported; + let TableType { + ty: exported_ty, + minimum: exported_minimum, + maximum: exported_maximum, + } = exported; + let TableType { + ty: imported_ty, + minimum: imported_minimum, + maximum: imported_maximum, + } = imported; is_table_element_type_compatible(*exported_ty, *imported_ty) && imported_minimum <= exported_minimum @@ -223,7 +244,10 @@ impl ExternType { /// WebAssembly functions can have 0 or more parameters and results. #[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct FunctionType { /// The parameters of the function params: Box<[Type]>, @@ -238,7 +262,10 @@ impl FunctionType { Params: Into>, Returns: Into>, { - Self { params: params.into(), results: returns.into() } + Self { + params: params.into(), + results: returns.into(), + } } /// Parameter types. @@ -254,9 +281,18 @@ impl FunctionType { impl fmt::Display for FunctionType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let params = self.params.iter().map(|p| format!("{:?}", p)).collect::>().join(", "); - let results = - self.results.iter().map(|p| format!("{:?}", p)).collect::>().join(", "); + let params = self + .params + .iter() + .map(|p| format!("{:?}", p)) + .collect::>() + .join(", "); + let results = self + .results + .iter() + .map(|p| format!("{:?}", p)) + .collect::>() + .join(", "); write!(f, "[{}] -> [{}]", params, results) } } @@ -297,7 +333,10 @@ impl From<&FunctionType> for FunctionType { /// Indicator of whether a global is mutable or not #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub enum Mutability { /// The global is constant and its value does not change Const, @@ -334,7 +373,10 @@ impl From for bool { /// WebAssembly global. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct GlobalType { /// The type of the value stored in the global. pub ty: Type, @@ -378,7 +420,10 @@ impl fmt::Display for GlobalType { /// Globals are initialized via the `const` operators or by referring to another import. #[derive(Debug, Clone, Copy, MemoryUsage, PartialEq)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub enum GlobalInit { /// An `i32.const`. I32Const(i32), @@ -435,7 +480,10 @@ impl GlobalInit { /// which `call_indirect` can invoke other functions. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct TableType { /// The type of data stored in elements of the table. pub ty: Type, @@ -449,7 +497,11 @@ impl TableType { /// Creates a new table descriptor which will contain the specified /// `element` and have the `limits` applied to its length. pub fn new(ty: Type, minimum: u32, maximum: Option) -> Self { - Self { ty, minimum, maximum } + Self { + ty, + minimum, + maximum, + } } } @@ -471,7 +523,10 @@ impl fmt::Display for TableType { /// chunks of addressable memory. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct MemoryType { /// The minimum number of pages in the memory. pub minimum: Pages, @@ -488,7 +543,11 @@ impl MemoryType { where IntoPages: Into, { - Self { minimum: minimum.into(), maximum: maximum.map(Into::into), shared } + Self { + minimum: minimum.into(), + maximum: maximum.map(Into::into), + shared, + } } } @@ -523,7 +582,11 @@ impl ImportType { /// Creates a new import descriptor which comes from `module` and `name` and /// is of type `ty`. pub fn new(module: &str, name: &str, ty: T) -> Self { - Self { module: module.to_owned(), name: name.to_owned(), ty } + Self { + module: module.to_owned(), + name: name.to_owned(), + ty, + } } /// Returns the module name that this import is expected to come from. @@ -565,7 +628,10 @@ impl ExportType { /// Creates a new export which is exported with the given `name` and has the /// given `ty`. pub fn new(name: &str, ty: T) -> Self { - Self { name: name.to_string(), ty } + Self { + name: name.to_string(), + ty, + } } /// Returns the name by which this export is known by. diff --git a/lib/types/src/units.rs b/lib/types/src/units.rs index a2fccdcdd..6ab314ddc 100644 --- a/lib/types/src/units.rs +++ b/lib/types/src/units.rs @@ -24,7 +24,10 @@ pub const WASM_MIN_PAGES: u32 = 0x100; /// Units of WebAssembly pages (as specified to be 65,536 bytes). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct Pages(pub u32); impl Pages { @@ -123,7 +126,9 @@ impl TryFrom for Pages { type Error = PageCountOutOfRange; fn try_from(bytes: Bytes) -> Result { - let pages: u32 = (bytes.0 / WASM_PAGE_SIZE).try_into().or(Err(PageCountOutOfRange))?; + let pages: u32 = (bytes.0 / WASM_PAGE_SIZE) + .try_into() + .or(Err(PageCountOutOfRange))?; Ok(Self(pages)) } } diff --git a/lib/vm/build.rs b/lib/vm/build.rs index e263c6fd4..206d99276 100644 --- a/lib/vm/build.rs +++ b/lib/vm/build.rs @@ -2,5 +2,8 @@ fn main() { println!("cargo:rerun-if-changed=src/trap/helpers.c"); - cc::Build::new().warnings(true).file("src/trap/helpers.c").compile("helpers"); + cc::Build::new() + .warnings(true) + .file("src/trap/helpers.c") + .compile("helpers"); } diff --git a/lib/vm/src/func_data_registry.rs b/lib/vm/src/func_data_registry.rs index d14636e4e..7fc9fc24d 100644 --- a/lib/vm/src/func_data_registry.rs +++ b/lib/vm/src/func_data_registry.rs @@ -96,7 +96,9 @@ struct Inner { impl FuncDataRegistry { /// Create a new `FuncDataRegistry`. pub fn new() -> Self { - Self { inner: Default::default() } + Self { + inner: Default::default(), + } } /// Register a signature and return its unique index. diff --git a/lib/vm/src/global.rs b/lib/vm/src/global.rs index 2e5073a63..9917c06be 100644 --- a/lib/vm/src/global.rs +++ b/lib/vm/src/global.rs @@ -102,7 +102,10 @@ impl Global { return Err(GlobalError::ImmutableGlobalCannotBeSet); } if val.ty() != self.ty().ty { - return Err(GlobalError::IncorrectType { expected: self.ty.ty, found: val.ty() }); + return Err(GlobalError::IncorrectType { + expected: self.ty.ty, + found: val.ty(), + }); } self.set_unchecked(val) } diff --git a/lib/vm/src/instance/allocator.rs b/lib/vm/src/instance/allocator.rs index eb852800b..fa2618fac 100644 --- a/lib/vm/src/instance/allocator.rs +++ b/lib/vm/src/instance/allocator.rs @@ -69,7 +69,11 @@ impl InstanceAllocator { /// [`InstanceHandle::new`]: super::InstanceHandle::new pub fn new( module: &ModuleInfo, - ) -> (Self, Vec>, Vec>) { + ) -> ( + Self, + Vec>, + Vec>, + ) { let offsets = VMOffsets::new(mem::size_of::() as u8, module); let instance_layout = Self::instance_layout(&offsets); @@ -82,7 +86,12 @@ impl InstanceAllocator { alloc::handle_alloc_error(instance_layout); }; - let allocator = Self { instance_ptr, instance_layout, offsets, consumed: false }; + let allocator = Self { + instance_ptr, + instance_layout, + offsets, + consumed: false, + }; // # Safety // Both of these calls are safe because we allocate the pointer @@ -130,7 +139,9 @@ impl InstanceAllocator { let base_ptr = ptr.add(mem::size_of::()); for i in 0..num_memories { - let mem_offset = self.offsets.vmctx_vmmemory_definition(LocalMemoryIndex::new(i)); + let mem_offset = self + .offsets + .vmctx_vmmemory_definition(LocalMemoryIndex::new(i)); let mem_offset = usize::try_from(mem_offset).unwrap(); let new_ptr = NonNull::new_unchecked(base_ptr.add(mem_offset)); @@ -162,7 +173,9 @@ impl InstanceAllocator { let base_ptr = ptr.add(std::mem::size_of::()); for i in 0..num_tables { - let table_offset = self.offsets.vmctx_vmtable_definition(LocalTableIndex::new(i)); + let table_offset = self + .offsets + .vmctx_vmtable_definition(LocalTableIndex::new(i)); let table_offset = usize::try_from(table_offset).unwrap(); let new_ptr = NonNull::new_unchecked(base_ptr.add(table_offset)); diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index a2c63932b..4108e63d3 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -163,7 +163,12 @@ impl Clone for ImportFunctionEnv { fn clone(&self) -> Self { match &self { Self::NoEnv => Self::NoEnv, - Self::Env { env, clone, destructor, initializer } => { + Self::Env { + env, + clone, + destructor, + initializer, + } => { let new_env = (*clone)(*env); Self::Env { env: new_env, @@ -179,7 +184,9 @@ impl Clone for ImportFunctionEnv { impl Drop for ImportFunctionEnv { fn drop(&mut self) { match self { - Self::Env { env, destructor, .. } => { + Self::Env { + env, destructor, .. + } => { // # Safety // - This is correct because we know no other references // to this data can exist if we're dropping it. @@ -209,7 +216,9 @@ impl Instance { /// Helper function to access various locations offset from our `*mut /// VMContext` object. unsafe fn vmctx_plus_offset(&self, offset: u32) -> *mut T { - (self.vmctx_ptr() as *mut u8).add(usize::try_from(offset).unwrap()).cast() + (self.vmctx_ptr() as *mut u8) + .add(usize::try_from(offset).unwrap()) + .cast() } fn module(&self) -> &Arc { @@ -396,9 +405,17 @@ impl Instance { let (callee_address, callee_vmctx) = match self.module.local_func_index(start_index) { Some(local_index) => { - let body = - self.functions.get(local_index).expect("function index is out of bounds").0; - (body as *const _, VMFunctionEnvironment { vmctx: self.vmctx_ptr() }) + let body = self + .functions + .get(local_index) + .expect("function index is out of bounds") + .0; + ( + body as *const _, + VMFunctionEnvironment { + vmctx: self.vmctx_ptr(), + }, + ) } None => { assert_lt!(start_index.index(), self.module.num_imported_functions); @@ -643,9 +660,13 @@ impl Instance { let table = self.get_table(table_index); let passive_elements = self.passive_elements.borrow(); - let elem = passive_elements.get(&elem_index).map_or::<&[VMFuncRef], _>(&[], |e| &**e); + let elem = passive_elements + .get(&elem_index) + .map_or::<&[VMFuncRef], _>(&[], |e| &**e); - if src.checked_add(len).map_or(true, |n| n as usize > elem.len()) + if src + .checked_add(len) + .map_or(true, |n| n as usize > elem.len()) || dst.checked_add(len).map_or(true, |m| m > table.size()) { return Err(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)); @@ -677,7 +698,10 @@ impl Instance { let table = self.get_table(table_index); let table_size = table.size() as usize; - if start_index.checked_add(len).map_or(true, |n| n as usize > table_size) { + if start_index + .checked_add(len) + .map_or(true, |n| n as usize > table_size) + { return Err(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)); } @@ -790,8 +814,12 @@ impl Instance { let passive_data = self.passive_data.borrow(); let data = passive_data.get(&data_index).map_or(&[][..], |d| &**d); - if src.checked_add(len).map_or(true, |n| n as usize > data.len()) - || dst.checked_add(len).map_or(true, |m| m > memory.current_length) + if src + .checked_add(len) + .map_or(true, |n| n as usize > data.len()) + || dst + .checked_add(len) + .map_or(true, |m| m > memory.current_length) { return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds)); } @@ -928,7 +956,9 @@ impl InstanceHandle { ); } - Self { instance: instance_ref } + Self { + instance: instance_ref, + } }; let instance = handle.instance().as_ref(); @@ -1056,7 +1086,9 @@ impl InstanceHandle { if let Some(def_index) = instance_ref.module.local_func_index(*index) { ( instance_ref.functions[def_index].0 as *const _, - VMFunctionEnvironment { vmctx: instance_ref.vmctx_ptr() }, + VMFunctionEnvironment { + vmctx: instance_ref.vmctx_ptr(), + }, None, ) } else { @@ -1088,7 +1120,11 @@ impl InstanceHandle { let import = instance_ref.imported_table(*index); import.from.clone() }; - VMExportTable { from, instance_ref: Some(instance) }.into() + VMExportTable { + from, + instance_ref: Some(instance), + } + .into() } ExportIndex::Memory(index) => { let from = if let Some(def_index) = instance_ref.module.local_memory_index(*index) { @@ -1097,7 +1133,11 @@ impl InstanceHandle { let import = instance_ref.imported_memory(*index); import.from.clone() }; - VMExportMemory { from, instance_ref: Some(instance) }.into() + VMExportMemory { + from, + instance_ref: Some(instance), + } + .into() } ExportIndex::Global(index) => { let from = { @@ -1108,7 +1148,11 @@ impl InstanceHandle { import.from.clone() } }; - VMExportGlobal { from, instance_ref: Some(instance) }.into() + VMExportGlobal { + from, + instance_ref: Some(instance), + } + .into() } } } @@ -1162,7 +1206,9 @@ impl InstanceHandle { delta: u32, init_value: TableElement, ) -> Option { - self.instance().as_ref().table_grow(table_index, delta, init_value) + self.instance() + .as_ref() + .table_grow(table_index, delta, init_value) } /// Get table element reference. @@ -1204,7 +1250,11 @@ impl InstanceHandle { for import_function_env in instance_ref.imported_function_envs.values_mut() { match import_function_env { - ImportFunctionEnv::Env { env, ref mut initializer, .. } => { + ImportFunctionEnv::Env { + env, + ref mut initializer, + .. + } => { if let Some(f) = initializer { // transmute our function pointer into one with the correct error type let f = mem::transmute::< @@ -1289,8 +1339,9 @@ unsafe fn get_memory_slice<'instance>( init: &DataInitializer<'_>, instance: &'instance Instance, ) -> &'instance mut [u8] { - let memory = if let Some(local_memory_index) = - instance.module.local_memory_index(init.location.memory_index) + let memory = if let Some(local_memory_index) = instance + .module + .local_memory_index(init.location.memory_index) { instance.memory(local_memory_index) } else { @@ -1342,13 +1393,21 @@ fn initialize_tables(instance: &Instance) -> Result<(), Trap> { let start = get_table_init_start(init, instance); let table = instance.get_table(init.table_index); - if start.checked_add(init.elements.len()).map_or(true, |end| end > table.size() as usize) { + if start + .checked_add(init.elements.len()) + .map_or(true, |end| end > table.size() as usize) + { return Err(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)); } for (i, func_idx) in init.elements.iter().enumerate() { let anyfunc = instance.get_vm_funcref(*func_idx); - table.set(u32::try_from(start + i).unwrap(), TableElement::FuncRef(anyfunc)).unwrap(); + table + .set( + u32::try_from(start + i).unwrap(), + TableElement::FuncRef(anyfunc), + ) + .unwrap(); } } @@ -1366,11 +1425,20 @@ fn initialize_passive_elements(instance: &Instance) { ); passive_elements.extend( - instance.module.passive_elements.iter().filter(|(_, segments)| !segments.is_empty()).map( - |(idx, segments)| { - (*idx, segments.iter().map(|s| instance.get_vm_funcref(*s)).collect()) - }, - ), + instance + .module + .passive_elements + .iter() + .filter(|(_, segments)| !segments.is_empty()) + .map(|(idx, segments)| { + ( + *idx, + segments + .iter() + .map(|s| instance.get_vm_funcref(*s)) + .collect(), + ) + }), ); } @@ -1447,8 +1515,11 @@ fn build_funcrefs( for (index, import) in imports.functions.iter() { let sig_index = module_info.functions[index]; let type_index = vmshared_signatures[sig_index]; - let anyfunc = - VMCallerCheckedAnyfunc { func_ptr: import.body, type_index, vmctx: import.environment }; + let anyfunc = VMCallerCheckedAnyfunc { + func_ptr: import.body, + type_index, + vmctx: import.environment, + }; let func_ref = func_data_registry.register(anyfunc); func_refs.push(func_ref); } diff --git a/lib/vm/src/instance/ref.rs b/lib/vm/src/instance/ref.rs index fdeeb6ab1..77daeddc6 100644 --- a/lib/vm/src/instance/ref.rs +++ b/lib/vm/src/instance/ref.rs @@ -67,7 +67,11 @@ impl InstanceRef { /// [`InstanceAllocator`] for an example of how to correctly use /// this API. pub(super) unsafe fn new(instance: NonNull, instance_layout: Layout) -> Self { - Self { strong: Arc::new(atomic::AtomicUsize::new(1)), instance_layout, instance } + Self { + strong: Arc::new(atomic::AtomicUsize::new(1)), + instance_layout, + instance, + } } /// A soft limit on the amount of references that may be made to an `InstanceRef`. diff --git a/lib/vm/src/libcalls.rs b/lib/vm/src/libcalls.rs index 1ec550aa4..f03fc2447 100644 --- a/lib/vm/src/libcalls.rs +++ b/lib/vm/src/libcalls.rs @@ -153,7 +153,10 @@ pub unsafe extern "C" fn wasmer_vm_memory32_grow( let instance = (&*vmctx).instance(); let memory_index = LocalMemoryIndex::from_u32(memory_index); - instance.memory_grow(memory_index, delta).map(|pages| pages.0).unwrap_or(u32::max_value()) + instance + .memory_grow(memory_index, delta) + .map(|pages| pages.0) + .unwrap_or(u32::max_value()) } /// Implementation of memory.grow for imported 32-bit memories. @@ -374,7 +377,10 @@ pub unsafe extern "C" fn wasmer_vm_table_set( ) { let instance = (&*vmctx).instance(); let table_index = TableIndex::from_u32(table_index); - let table_index = instance.module_ref().local_table_index(table_index).unwrap(); + let table_index = instance + .module_ref() + .local_table_index(table_index) + .unwrap(); let elem = match instance.get_local_table(table_index).ty().ty { Type::ExternRef => TableElement::ExternRef(value.extern_ref.into()), @@ -438,7 +444,9 @@ pub unsafe extern "C" fn wasmer_vm_table_grow( _ => panic!("Unrecognized table type: does not contain references"), }; - instance.table_grow(table_index, delta, init_value).unwrap_or(u32::max_value()) + instance + .table_grow(table_index, delta, init_value) + .unwrap_or(u32::max_value()) } /// Implementation of `table.grow` for imported tables. @@ -461,7 +469,9 @@ pub unsafe extern "C" fn wasmer_vm_imported_table_grow( _ => panic!("Unrecognized table type: does not contain references"), }; - instance.imported_table_grow(table_index, delta, init_value).unwrap_or(u32::max_value()) + instance + .imported_table_grow(table_index, delta, init_value) + .unwrap_or(u32::max_value()) } /// Implementation of `func.ref`. diff --git a/lib/vm/src/memory.rs b/lib/vm/src/memory.rs index 35ea74117..78eddaef5 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -65,7 +65,10 @@ pub enum MemoryError { /// Implementation styles for WebAssembly linear memory. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, MemoryUsage)] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub enum MemoryStyle { /// The actual memory can be resized and moved. Dynamic { @@ -92,7 +95,9 @@ impl MemoryStyle { pub fn offset_guard_size(&self) -> u64 { match self { Self::Dynamic { offset_guard_size } => *offset_guard_size, - Self::Static { offset_guard_size, .. } => *offset_guard_size, + Self::Static { + offset_guard_size, .. + } => *offset_guard_size, } } } @@ -277,7 +282,10 @@ impl LinearMemory { VMMemoryDefinitionOwnership::VMOwned(mem_loc) } else { VMMemoryDefinitionOwnership::HostOwned(Box::new(UnsafeCell::new( - VMMemoryDefinition { base: base_ptr, current_length: mem_length }, + VMMemoryDefinition { + base: base_ptr, + current_length: mem_length, + }, ))) }, memory: *memory, @@ -336,7 +344,10 @@ impl Memory for LinearMemory { let new_pages = mmap .size .checked_add(delta) - .ok_or(MemoryError::CouldNotGrow { current: mmap.size, attempted_delta: delta })?; + .ok_or(MemoryError::CouldNotGrow { + current: mmap.size, + attempted_delta: delta, + })?; let prev_pages = mmap.size; if let Some(maximum) = self.maximum { @@ -353,7 +364,10 @@ impl Memory for LinearMemory { // limit here. if new_pages >= Pages::max_value() { // Linear memory size would exceed the index range. - return Err(MemoryError::CouldNotGrow { current: mmap.size, attempted_delta: delta }); + return Err(MemoryError::CouldNotGrow { + current: mmap.size, + attempted_delta: delta, + }); } let delta_bytes = delta.bytes().0; @@ -365,10 +379,12 @@ impl Memory for LinearMemory { // have on hand, it's a dynamic heap and it can move. let guard_bytes = self.offset_guard_size; let request_bytes = - new_bytes.checked_add(guard_bytes).ok_or_else(|| MemoryError::CouldNotGrow { - current: new_pages, - attempted_delta: Bytes(guard_bytes).try_into().unwrap(), - })?; + new_bytes + .checked_add(guard_bytes) + .ok_or_else(|| MemoryError::CouldNotGrow { + current: new_pages, + attempted_delta: Bytes(guard_bytes).try_into().unwrap(), + })?; let mut new_mmap = Mmap::accessible_reserved(new_bytes, request_bytes).map_err(MemoryError::Region)?; @@ -379,7 +395,9 @@ impl Memory for LinearMemory { mmap.alloc = new_mmap; } else if delta_bytes > 0 { // Make the newly allocated pages accessible. - mmap.alloc.make_accessible(prev_bytes, delta_bytes).map_err(MemoryError::Region)?; + mmap.alloc + .make_accessible(prev_bytes, delta_bytes) + .map_err(MemoryError::Region)?; } mmap.size = new_pages; diff --git a/lib/vm/src/mmap.rs b/lib/vm/src/mmap.rs index 1edf714fa..7f33e8862 100644 --- a/lib/vm/src/mmap.rs +++ b/lib/vm/src/mmap.rs @@ -35,7 +35,10 @@ impl Mmap { // contains code to create a non-null dangling pointer value when // constructed empty, so we reuse that here. let empty = Vec::::new(); - Self { ptr: empty.as_ptr() as usize, len: 0 } + Self { + ptr: empty.as_ptr() as usize, + len: 0, + } } /// Create a new `Mmap` pointing to at least `size` bytes of page-aligned accessible memory. @@ -80,7 +83,10 @@ impl Mmap { return Err(io::Error::last_os_error().to_string()); } - Self { ptr: ptr as usize, len: mapping_size } + Self { + ptr: ptr as usize, + len: mapping_size, + } } else { // Reserve the mapping size. let ptr = unsafe { @@ -97,7 +103,10 @@ impl Mmap { return Err(io::Error::last_os_error().to_string()); } - let mut result = Self { ptr: ptr as usize, len: mapping_size }; + let mut result = Self { + ptr: ptr as usize, + len: mapping_size, + }; if accessible_size != 0 { // Commit the accessible size. @@ -144,7 +153,10 @@ impl Mmap { return Err(io::Error::last_os_error().to_string()); } - Self { ptr: ptr as usize, len: mapping_size } + Self { + ptr: ptr as usize, + len: mapping_size, + } } else { // Reserve the mapping size. let ptr = @@ -153,7 +165,10 @@ impl Mmap { return Err(io::Error::last_os_error().to_string()); } - let mut result = Self { ptr: ptr as usize, len: mapping_size }; + let mut result = Self { + ptr: ptr as usize, + len: mapping_size, + }; if accessible_size != 0 { // Commit the accessible size. @@ -197,8 +212,15 @@ impl Mmap { // Commit the accessible size. let ptr = self.ptr as *const u8; - if unsafe { VirtualAlloc(ptr.add(start) as *mut c_void, len, MEM_COMMIT, PAGE_READWRITE) } - .is_null() + if unsafe { + VirtualAlloc( + ptr.add(start) as *mut c_void, + len, + MEM_COMMIT, + PAGE_READWRITE, + ) + } + .is_null() { return Err(io::Error::last_os_error().to_string()); } diff --git a/lib/vm/src/module.rs b/lib/vm/src/module.rs index c365cf236..a31b61f95 100644 --- a/lib/vm/src/module.rs +++ b/lib/vm/src/module.rs @@ -28,7 +28,10 @@ use wasmer_types::{ }; #[derive(Debug, Clone, MemoryUsage)] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub struct ModuleId { id: usize, } @@ -42,7 +45,9 @@ impl ModuleId { impl Default for ModuleId { fn default() -> Self { static NEXT_ID: AtomicUsize = AtomicUsize::new(0); - Self { id: NEXT_ID.fetch_add(1, SeqCst) } + Self { + id: NEXT_ID.fetch_add(1, SeqCst), + } } } @@ -342,44 +347,55 @@ impl ModuleInfo { }; ExportType::new(name, extern_type) }); - ExportsIterator { iter, size: self.exports.len() } + ExportsIterator { + iter, + size: self.exports.len(), + } } /// Get the export types of the module pub fn imports<'a>(&'a self) -> ImportsIterator + 'a> { - let iter = self.imports.iter().map(move |((module, field, _), import_index)| { - let extern_type = match import_index { - ImportIndex::Function(i) => { - let signature = self.functions.get(*i).unwrap(); - let func_type = self.signatures.get(*signature).unwrap(); - ExternType::Function(func_type.clone()) - } - ImportIndex::Table(i) => { - let table_type = self.tables.get(*i).unwrap(); - ExternType::Table(*table_type) - } - ImportIndex::Memory(i) => { - let memory_type = self.memories.get(*i).unwrap(); - ExternType::Memory(*memory_type) - } - ImportIndex::Global(i) => { - let global_type = self.globals.get(*i).unwrap(); - ExternType::Global(*global_type) - } - }; - ImportType::new(module, field, extern_type) - }); - ImportsIterator { iter, size: self.imports.len() } + let iter = self + .imports + .iter() + .map(move |((module, field, _), import_index)| { + let extern_type = match import_index { + ImportIndex::Function(i) => { + let signature = self.functions.get(*i).unwrap(); + let func_type = self.signatures.get(*signature).unwrap(); + ExternType::Function(func_type.clone()) + } + ImportIndex::Table(i) => { + let table_type = self.tables.get(*i).unwrap(); + ExternType::Table(*table_type) + } + ImportIndex::Memory(i) => { + let memory_type = self.memories.get(*i).unwrap(); + ExternType::Memory(*memory_type) + } + ImportIndex::Global(i) => { + let global_type = self.globals.get(*i).unwrap(); + ExternType::Global(*global_type) + } + }; + ImportType::new(module, field, extern_type) + }); + ImportsIterator { + iter, + size: self.imports.len(), + } } /// Get the custom sections of the module given a `name`. pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator> + 'a { - self.custom_sections.iter().filter_map(move |(section_name, section_index)| { - if name != section_name { - return None; - } - Some(self.custom_sections_data[*section_index].clone()) - }) + self.custom_sections + .iter() + .filter_map(move |(section_name, section_index)| { + if name != section_name { + return None; + } + Some(self.custom_sections_data[*section_index].clone()) + }) } /// Convert a `LocalFunctionIndex` into a `FunctionIndex`. @@ -390,7 +406,9 @@ impl ModuleInfo { /// Convert a `FunctionIndex` into a `LocalFunctionIndex`. Returns None if the /// index is an imported function. pub fn local_func_index(&self, func: FunctionIndex) -> Option { - func.index().checked_sub(self.num_imported_functions).map(LocalFunctionIndex::new) + func.index() + .checked_sub(self.num_imported_functions) + .map(LocalFunctionIndex::new) } /// Test whether the given function index is for an imported function. @@ -406,7 +424,10 @@ impl ModuleInfo { /// Convert a `TableIndex` into a `LocalTableIndex`. Returns None if the /// index is an imported table. pub fn local_table_index(&self, table: TableIndex) -> Option { - table.index().checked_sub(self.num_imported_tables).map(LocalTableIndex::new) + table + .index() + .checked_sub(self.num_imported_tables) + .map(LocalTableIndex::new) } /// Test whether the given table index is for an imported table. @@ -422,7 +443,10 @@ impl ModuleInfo { /// Convert a `MemoryIndex` into a `LocalMemoryIndex`. Returns None if the /// index is an imported memory. pub fn local_memory_index(&self, memory: MemoryIndex) -> Option { - memory.index().checked_sub(self.num_imported_memories).map(LocalMemoryIndex::new) + memory + .index() + .checked_sub(self.num_imported_memories) + .map(LocalMemoryIndex::new) } /// Test whether the given memory index is for an imported memory. @@ -438,7 +462,10 @@ impl ModuleInfo { /// Convert a `GlobalIndex` into a `LocalGlobalIndex`. Returns None if the /// index is an imported global. pub fn local_global_index(&self, global: GlobalIndex) -> Option { - global.index().checked_sub(self.num_imported_globals).map(LocalGlobalIndex::new) + global + .index() + .checked_sub(self.num_imported_globals) + .map(LocalGlobalIndex::new) } /// Test whether the given global index is for an imported global. @@ -542,9 +569,11 @@ impl + Sized> ImportsIterator { /// Get only the functions pub fn functions(self) -> impl Iterator> + Sized { self.iter.filter_map(|extern_| match extern_.ty() { - ExternType::Function(ty) => { - Some(ImportType::new(extern_.module(), extern_.name(), ty.clone())) - } + ExternType::Function(ty) => Some(ImportType::new( + extern_.module(), + extern_.name(), + ty.clone(), + )), _ => None, }) } diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs index 5cba647af..051006bc9 100644 --- a/lib/vm/src/sig_registry.rs +++ b/lib/vm/src/sig_registry.rs @@ -35,7 +35,9 @@ struct Inner { impl SignatureRegistry { /// Create a new `SignatureRegistry`. pub fn new() -> Self { - Self { inner: Default::default() } + Self { + inner: Default::default(), + } } /// Register a signature and return its unique index. @@ -65,6 +67,11 @@ impl SignatureRegistry { /// Note that for this operation to be semantically correct the `idx` must /// have previously come from a call to `register` of this same object. pub fn lookup(&self, idx: VMSharedSignatureIndex) -> Option { - self.inner.read().unwrap().index2signature.get(&idx).cloned() + self.inner + .read() + .unwrap() + .index2signature + .get(&idx) + .cloned() } } diff --git a/lib/vm/src/table.rs b/lib/vm/src/table.rs index b554be687..c4960abb5 100644 --- a/lib/vm/src/table.rs +++ b/lib/vm/src/table.rs @@ -23,7 +23,10 @@ use wasmer_types::{ExternRef, TableType, Type as ValType}; /// Implementation styles for WebAssembly tables. #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, MemoryUsage)] -#[cfg_attr(feature = "enable-rkyv", derive(RkyvSerialize, RkyvDeserialize, Archive))] +#[cfg_attr( + feature = "enable-rkyv", + derive(RkyvSerialize, RkyvDeserialize, Archive) +)] pub enum TableStyle { /// Signatures are stored in the table and checked in the caller. CallerChecksSignature, @@ -76,7 +79,10 @@ pub trait Table: fmt::Debug + Send + Sync + MemoryUsage { ) -> Result<(), Trap> { // https://webassembly.github.io/bulk-memory-operations/core/exec/instructions.html#exec-table-copy - if src_index.checked_add(len).map_or(true, |n| n > src_table.size()) { + if src_index + .checked_add(len) + .map_or(true, |n| n > src_table.size()) + { return Err(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)); } @@ -119,7 +125,9 @@ pub enum TableElement { impl From for RawTableElement { fn from(other: TableElement) -> Self { match other { - TableElement::ExternRef(extern_ref) => Self { extern_ref: extern_ref.into() }, + TableElement::ExternRef(extern_ref) => Self { + extern_ref: extern_ref.into(), + }, TableElement::FuncRef(func_ref) => Self { func_ref }, } } @@ -154,7 +162,9 @@ impl fmt::Debug for RawTableElement { impl Default for RawTableElement { fn default() -> Self { - Self { func_ref: VMFuncRef::null() } + Self { + func_ref: VMFuncRef::null(), + } } } @@ -227,7 +237,12 @@ impl LinearTable { ) -> Result { match table.ty { ValType::FuncRef | ValType::ExternRef => (), - ty => return Err(format!("tables of types other than funcref or externref ({})", ty)), + ty => { + return Err(format!( + "tables of types other than funcref or externref ({})", + ty + )) + } }; if let Some(max) = table.maximum { if max < table.minimum { @@ -257,7 +272,10 @@ impl LinearTable { VMTableDefinitionOwnership::VMOwned(table_loc) } else { VMTableDefinitionOwnership::HostOwned(Box::new(UnsafeCell::new( - VMTableDefinition { base: base as _, current_elements: table_minimum as _ }, + VMTableDefinition { + base: base as _, + current_elements: table_minimum as _, + }, ))) }, }), @@ -384,7 +402,10 @@ impl Table for LinearTable { // This path should never be hit by the generated code due to Wasm // validation. (ty, v) => { - panic!("Attempted to set a table of type {} with the value {:?}", ty, v) + panic!( + "Attempted to set a table of type {} with the value {:?}", + ty, v + ) } }; diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index a85334550..be2b68ff5 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -452,7 +452,11 @@ impl Trap { /// Wasm traps are Traps that are triggered by the chip when running generated /// code for a Wasm function. pub fn new_from_wasm(pc: usize, backtrace: Backtrace, signal_trap: Option) -> Self { - Self::Wasm { pc, backtrace, signal_trap } + Self::Wasm { + pc, + backtrace, + signal_trap, + } } /// Construct a new runtime `Trap` with the given trap code. @@ -461,7 +465,10 @@ impl Trap { /// Internally saves a backtrace when constructed. pub fn new_from_runtime(trap_code: TrapCode) -> Self { let backtrace = Backtrace::new_unresolved(); - Self::Runtime { trap_code, backtrace } + Self::Runtime { + trap_code, + backtrace, + } } /// Construct a new Out of Memory (OOM) `Trap`. @@ -515,7 +522,11 @@ where setup_unix_sigaltstack()?; return CallThreadState::new(vmctx).with(|cx| { - RegisterSetjmp(cx.jmp_buf.as_ptr(), call_closure::, &mut closure as *mut F as *mut u8) + RegisterSetjmp( + cx.jmp_buf.as_ptr(), + call_closure::, + &mut closure as *mut F as *mut u8, + ) }); extern "C" fn call_closure(payload: *mut u8) @@ -565,7 +576,11 @@ enum UnwindReason { Panic(Box), UserTrap(Box), LibTrap(Trap), - RuntimeTrap { backtrace: Backtrace, pc: usize, signal_trap: Option }, + RuntimeTrap { + backtrace: Backtrace, + pc: usize, + signal_trap: Option, + }, } impl CallThreadState { @@ -594,7 +609,11 @@ impl CallThreadState { Err(Trap::new_from_user(data)) } UnwindReason::LibTrap(trap) => Err(trap), - UnwindReason::RuntimeTrap { backtrace, pc, signal_trap } => { + UnwindReason::RuntimeTrap { + backtrace, + pc, + signal_trap, + } => { debug_assert_eq!(ret, 0); Err(Trap::new_from_wasm(pc, backtrace, signal_trap)) } @@ -695,7 +714,11 @@ impl CallThreadState { } let backtrace = Backtrace::new_unresolved(); self.reset_guard_page.set(reset_guard_page); - self.unwind.replace(UnwindReason::RuntimeTrap { backtrace, signal_trap, pc: pc as usize }); + self.unwind.replace(UnwindReason::RuntimeTrap { + backtrace, + signal_trap, + pc: pc as usize, + }); self.handling_trap.set(false); self.jmp_buf.get() } @@ -772,7 +795,10 @@ fn setup_unix_sigaltstack() -> Result<(), Trap> { enum Tls { None, - Allocated { mmap_ptr: *mut libc::c_void, mmap_size: usize }, + Allocated { + mmap_ptr: *mut libc::c_void, + mmap_size: usize, + }, BigEnough, } @@ -814,20 +840,34 @@ fn setup_unix_sigaltstack() -> Result<(), Trap> { // Prepare the stack with readable/writable memory and then register it // with `sigaltstack`. let stack_ptr = (ptr as usize + guard_size) as *mut libc::c_void; - let r = libc::mprotect(stack_ptr, MIN_STACK_SIZE, libc::PROT_READ | libc::PROT_WRITE); + let r = libc::mprotect( + stack_ptr, + MIN_STACK_SIZE, + libc::PROT_READ | libc::PROT_WRITE, + ); assert_eq!(r, 0, "mprotect to configure memory for sigaltstack failed"); - let new_stack = libc::stack_t { ss_sp: stack_ptr, ss_flags: 0, ss_size: MIN_STACK_SIZE }; + let new_stack = libc::stack_t { + ss_sp: stack_ptr, + ss_flags: 0, + ss_size: MIN_STACK_SIZE, + }; let r = libc::sigaltstack(&new_stack, ptr::null_mut()); assert_eq!(r, 0, "registering new sigaltstack failed"); - *slot = Tls::Allocated { mmap_ptr: ptr, mmap_size: alloc_size }; + *slot = Tls::Allocated { + mmap_ptr: ptr, + mmap_size: alloc_size, + }; Ok(()) }); impl Drop for Tls { fn drop(&mut self) { let (ptr, size) = match self { - Self::Allocated { mmap_ptr, mmap_size } => (*mmap_ptr, *mmap_size), + Self::Allocated { + mmap_ptr, + mmap_size, + } => (*mmap_ptr, *mmap_size), _ => return, }; unsafe { diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 5b4beca2f..9d294e9fc 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -89,7 +89,10 @@ mod test_vmfunction_import { fn check_vmfunction_import_offsets() { let module = ModuleInfo::new(); let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); - assert_eq!(size_of::(), usize::from(offsets.size_of_vmfunction_import())); + assert_eq!( + size_of::(), + usize::from(offsets.size_of_vmfunction_import()) + ); assert_eq!( offset_of!(VMFunctionImport, body), usize::from(offsets.vmfunction_import_body()) @@ -130,7 +133,10 @@ unsafe impl Sync for VMDynamicFunctionContext {} impl Clone for VMDynamicFunctionContext { fn clone(&self) -> Self { - Self { address: self.address, ctx: self.ctx.clone() } + Self { + address: self.address, + ctx: self.ctx.clone(), + } } } @@ -221,12 +227,18 @@ mod test_vmtable_import { fn check_vmtable_import_offsets() { let module = ModuleInfo::new(); let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); - assert_eq!(size_of::(), usize::from(offsets.size_of_vmtable_import())); + assert_eq!( + size_of::(), + usize::from(offsets.size_of_vmtable_import()) + ); assert_eq!( offset_of!(VMTableImport, definition), usize::from(offsets.vmtable_import_definition()) ); - assert_eq!(offset_of!(VMTableImport, from), usize::from(offsets.vmtable_import_from())); + assert_eq!( + offset_of!(VMTableImport, from), + usize::from(offsets.vmtable_import_from()) + ); } } @@ -253,12 +265,18 @@ mod test_vmmemory_import { fn check_vmmemory_import_offsets() { let module = ModuleInfo::new(); let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); - assert_eq!(size_of::(), usize::from(offsets.size_of_vmmemory_import())); + assert_eq!( + size_of::(), + usize::from(offsets.size_of_vmmemory_import()) + ); assert_eq!( offset_of!(VMMemoryImport, definition), usize::from(offsets.vmmemory_import_definition()) ); - assert_eq!(offset_of!(VMMemoryImport, from), usize::from(offsets.vmmemory_import_from())); + assert_eq!( + offset_of!(VMMemoryImport, from), + usize::from(offsets.vmmemory_import_from()) + ); } } @@ -297,12 +315,18 @@ mod test_vmglobal_import { fn check_vmglobal_import_offsets() { let module = ModuleInfo::new(); let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); - assert_eq!(size_of::(), usize::from(offsets.size_of_vmglobal_import())); + assert_eq!( + size_of::(), + usize::from(offsets.size_of_vmglobal_import()) + ); assert_eq!( offset_of!(VMGlobalImport, definition), usize::from(offsets.vmglobal_import_definition()) ); - assert_eq!(offset_of!(VMGlobalImport, from), usize::from(offsets.vmglobal_import_from())); + assert_eq!( + offset_of!(VMGlobalImport, from), + usize::from(offsets.vmglobal_import_from()) + ); } } @@ -353,8 +377,12 @@ impl VMMemoryDefinition { /// caller's responsibility to synchronize. pub(crate) unsafe fn memory_copy(&self, dst: u32, src: u32, len: u32) -> Result<(), Trap> { // https://webassembly.github.io/reference-types/core/exec/instructions.html#exec-memory-copy - if src.checked_add(len).map_or(true, |n| n > self.current_length) - || dst.checked_add(len).map_or(true, |m| m > self.current_length) + if src + .checked_add(len) + .map_or(true, |n| n > self.current_length) + || dst + .checked_add(len) + .map_or(true, |m| m > self.current_length) { return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds)); } @@ -382,7 +410,10 @@ impl VMMemoryDefinition { /// The memory is not filled atomically and is not synchronized: it's the /// caller's responsibility to synchronize. pub(crate) unsafe fn memory_fill(&self, dst: u32, val: u32, len: u32) -> Result<(), Trap> { - if dst.checked_add(len).map_or(true, |m| m > self.current_length) { + if dst + .checked_add(len) + .map_or(true, |m| m > self.current_length) + { return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds)); } @@ -502,7 +533,9 @@ pub union VMGlobalDefinitionStorage { impl fmt::Debug for VMGlobalDefinitionStorage { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("VMGlobalDefinitionStorage").field("bytes", unsafe { &self.bytes }).finish() + f.debug_struct("VMGlobalDefinitionStorage") + .field("bytes", unsafe { &self.bytes }) + .finish() } } @@ -561,7 +594,9 @@ mod test_vmglobal_definition { impl VMGlobalDefinition { /// Construct a `VMGlobalDefinition`. pub fn new() -> Self { - Self { storage: VMGlobalDefinitionStorage { bytes: [0; 16] } } + Self { + storage: VMGlobalDefinitionStorage { bytes: [0; 16] }, + } } /// Return the value as an i32. @@ -777,7 +812,10 @@ mod test_vmshared_signature_index { #[test] fn check_target_shared_signature_index() { - assert_eq!(size_of::(), size_of::()); + assert_eq!( + size_of::(), + size_of::() + ); } } @@ -844,7 +882,9 @@ impl Default for VMCallerCheckedAnyfunc { Self { func_ptr: ptr::null_mut(), type_index: Default::default(), - vmctx: VMFunctionEnvironment { vmctx: ptr::null_mut() }, + vmctx: VMFunctionEnvironment { + vmctx: ptr::null_mut(), + }, } } } diff --git a/lib/vm/src/vmoffsets.rs b/lib/vm/src/vmoffsets.rs index 090f47daa..7d849e88e 100644 --- a/lib/vm/src/vmoffsets.rs +++ b/lib/vm/src/vmoffsets.rs @@ -489,7 +489,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_imported_functions); self.vmctx_imported_functions_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmfunction_import())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmfunction_import())) + .unwrap(), ) .unwrap() } @@ -501,7 +504,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_imported_tables); self.vmctx_imported_tables_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmtable_import())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmtable_import())) + .unwrap(), ) .unwrap() } @@ -513,7 +519,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_imported_memories); self.vmctx_imported_memories_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmmemory_import())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmmemory_import())) + .unwrap(), ) .unwrap() } @@ -525,7 +534,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_imported_globals); self.vmctx_imported_globals_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmglobal_import())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmglobal_import())) + .unwrap(), ) .unwrap() } @@ -537,7 +549,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_local_tables); self.vmctx_tables_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmtable_definition())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmtable_definition())) + .unwrap(), ) .unwrap() } @@ -549,7 +564,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_local_memories); self.vmctx_memories_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmmemory_definition())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmmemory_definition())) + .unwrap(), ) .unwrap() } @@ -561,7 +579,10 @@ impl VMOffsets { assert_lt!(index.as_u32(), self.num_local_globals); self.vmctx_globals_begin() .checked_add( - index.as_u32().checked_mul(u32::from(self.size_of_vmglobal_local())).unwrap(), + index + .as_u32() + .checked_mul(u32::from(self.size_of_vmglobal_local())) + .unwrap(), ) .unwrap() } @@ -655,7 +676,12 @@ impl VMOffsets { /// Return the offset to builtin function in `VMBuiltinFunctionsArray` index `index`. pub fn vmctx_builtin_function(&self, index: VMBuiltinFunctionIndex) -> u32 { self.vmctx_builtin_functions_begin() - .checked_add(index.index().checked_mul(u32::from(self.pointer_size)).unwrap()) + .checked_add( + index + .index() + .checked_mul(u32::from(self.pointer_size)) + .unwrap(), + ) .unwrap() } } diff --git a/lib/wasi-experimental-io-devices/src/lib.rs b/lib/wasi-experimental-io-devices/src/lib.rs index a90777212..8c78aff07 100644 --- a/lib/wasi-experimental-io-devices/src/lib.rs +++ b/lib/wasi-experimental-io-devices/src/lib.rs @@ -77,7 +77,11 @@ impl FrameBufferState { "Wasmer Experimental FrameBuffer", x, y, - WindowOptions { resize: true, scale: Scale::FitScreen, ..WindowOptions::default() }, + WindowOptions { + resize: true, + scale: Scale::FitScreen, + ..WindowOptions::default() + }, ) .unwrap() } @@ -161,7 +165,11 @@ impl FrameBufferState { pub fn draw(&mut self) { self.window .update_with_buffer( - if self.front_buffer { &self.data_1[..] } else { &self.data_2[..] }, + if self.front_buffer { + &self.data_1[..] + } else { + &self.data_2[..] + }, self.x_size.try_into().unwrap(), self.y_size.try_into().unwrap(), ) @@ -421,16 +429,32 @@ impl WasiFile for FrameBuffer { } pub fn initialize(fs: &mut WasiFs) -> Result<(), String> { - let frame_buffer_file = - Box::new(FrameBuffer { fb_type: FrameBufferFileType::Buffer, cursor: 0 }); - let resolution_file = - Box::new(FrameBuffer { fb_type: FrameBufferFileType::Resolution, cursor: 0 }); - let draw_file = Box::new(FrameBuffer { fb_type: FrameBufferFileType::Draw, cursor: 0 }); - let input_file = Box::new(FrameBuffer { fb_type: FrameBufferFileType::Input, cursor: 0 }); + let frame_buffer_file = Box::new(FrameBuffer { + fb_type: FrameBufferFileType::Buffer, + cursor: 0, + }); + let resolution_file = Box::new(FrameBuffer { + fb_type: FrameBufferFileType::Resolution, + cursor: 0, + }); + let draw_file = Box::new(FrameBuffer { + fb_type: FrameBufferFileType::Draw, + cursor: 0, + }); + let input_file = Box::new(FrameBuffer { + fb_type: FrameBufferFileType::Input, + cursor: 0, + }); let base_dir_fd = unsafe { - fs.open_dir_all(VIRTUAL_ROOT_FD, "_wasmer/dev/fb0".to_string(), ALL_RIGHTS, ALL_RIGHTS, 0) - .map_err(|e| format!("fb: Failed to create dev folder {:?}", e))? + fs.open_dir_all( + VIRTUAL_ROOT_FD, + "_wasmer/dev/fb0".to_string(), + ALL_RIGHTS, + ALL_RIGHTS, + 0, + ) + .map_err(|e| format!("fb: Failed to create dev folder {:?}", e))? }; let _fd = fs diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 5b46bd0d5..628863d0a 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -61,12 +61,19 @@ pub struct WasiEnv { impl WasiEnv { pub fn new(state: WasiState) -> Self { - Self { state: Arc::new(Mutex::new(state)), memory: LazyInit::new() } + Self { + state: Arc::new(Mutex::new(state)), + memory: LazyInit::new(), + } } pub fn import_object(&mut self, module: &Module) -> Result { let wasi_version = get_wasi_version(module, false).ok_or(WasiError::UnknownWasiVersion)?; - Ok(generate_import_object_from_env(module.store(), self.clone(), wasi_version)) + Ok(generate_import_object_from_env( + module.store(), + self.clone(), + wasi_version, + )) } /// Get the WASI state @@ -87,7 +94,8 @@ impl WasiEnv { /// Get a reference to the memory pub fn memory(&self) -> &Memory { - self.memory_ref().expect("Memory should be set on `WasiEnv` first") + self.memory_ref() + .expect("Memory should be set on `WasiEnv` first") } pub(crate) fn get_memory_and_wasi_state( diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index b65a59cc7..3422601cd 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -10,7 +10,10 @@ use thiserror::Error; /// /// Internal method only, users should call [`WasiState::new`]. pub(crate) fn create_wasi_state(program_name: &str) -> WasiStateBuilder { - WasiStateBuilder { args: vec![program_name.bytes().collect()], ..WasiStateBuilder::default() } + WasiStateBuilder { + args: vec![program_name.bytes().collect()], + ..WasiStateBuilder::default() + } } /// Convenient builder API for configuring WASI via [`WasiState`]. @@ -78,10 +81,9 @@ pub enum WasiStateCreationError { fn validate_mapped_dir_alias(alias: &str) -> Result<(), WasiStateCreationError> { if !alias.bytes().all(|b| b != b'\0') { - return Err(WasiStateCreationError::MappedDirAliasFormattingError(format!( - "Alias \"{}\" contains a nul byte", - alias - ))); + return Err(WasiStateCreationError::MappedDirAliasFormattingError( + format!("Alias \"{}\" contains a nul byte", alias), + )); } Ok(()) @@ -100,7 +102,8 @@ impl WasiStateBuilder { Key: AsRef<[u8]>, Value: AsRef<[u8]>, { - self.envs.push((key.as_ref().to_vec(), value.as_ref().to_vec())); + self.envs + .push((key.as_ref().to_vec(), value.as_ref().to_vec())); self } @@ -227,7 +230,11 @@ impl WasiStateBuilder { { let mut pdb = PreopenDirBuilder::new(); let path = po_dir.as_ref(); - pdb.directory(path).alias(alias).read(true).write(true).create(true); + pdb.directory(path) + .alias(alias) + .read(true) + .write(true) + .create(true); let preopen = pdb.build()?; self.preopens.push(preopen); @@ -322,27 +329,33 @@ impl WasiStateBuilder { } }) { Some(InvalidCharacter::Nul) => { - return Err(WasiStateCreationError::EnvironmentVariableFormatError(format!( - "found nul byte in env var key \"{}\" (key=value)", - String::from_utf8_lossy(env_key) - ))) + return Err(WasiStateCreationError::EnvironmentVariableFormatError( + format!( + "found nul byte in env var key \"{}\" (key=value)", + String::from_utf8_lossy(env_key) + ), + )) } Some(InvalidCharacter::Equal) => { - return Err(WasiStateCreationError::EnvironmentVariableFormatError(format!( - "found equal sign in env var key \"{}\" (key=value)", - String::from_utf8_lossy(env_key) - ))) + return Err(WasiStateCreationError::EnvironmentVariableFormatError( + format!( + "found equal sign in env var key \"{}\" (key=value)", + String::from_utf8_lossy(env_key) + ), + )) } None => (), } if env_value.iter().any(|&ch| ch == 0) { - return Err(WasiStateCreationError::EnvironmentVariableFormatError(format!( - "found nul byte in env var value \"{}\" (key=value)", - String::from_utf8_lossy(env_value) - ))); + return Err(WasiStateCreationError::EnvironmentVariableFormatError( + format!( + "found nul byte in env var value \"{}\" (key=value)", + String::from_utf8_lossy(env_value) + ), + )); } } @@ -509,25 +522,37 @@ mod test { fn env_var_errors() { // `=` in the key is invalid. assert!( - create_wasi_state("test_prog").env("HOM=E", "/home/home").build().is_err(), + create_wasi_state("test_prog") + .env("HOM=E", "/home/home") + .build() + .is_err(), "equal sign in key must be invalid" ); // `\0` in the key is invalid. assert!( - create_wasi_state("test_prog").env("HOME\0", "/home/home").build().is_err(), + create_wasi_state("test_prog") + .env("HOME\0", "/home/home") + .build() + .is_err(), "nul in key must be invalid" ); // `=` in the value is valid. assert!( - create_wasi_state("test_prog").env("HOME", "/home/home=home").build().is_ok(), + create_wasi_state("test_prog") + .env("HOME", "/home/home=home") + .build() + .is_ok(), "equal sign in the value must be valid" ); // `\0` in the value is invalid. assert!( - create_wasi_state("test_prog").env("HOME", "/home/home\0").build().is_err(), + create_wasi_state("test_prog") + .env("HOME", "/home/home\0") + .build() + .is_err(), "nul in value must be invalid" ); } @@ -539,7 +564,9 @@ mod test { Err(WasiStateCreationError::ArgumentContainsNulByte(_)) => assert!(true), _ => assert!(false), } - let output = create_wasi_state("test_prog").args(&["--help", "--wat\0"]).build(); + let output = create_wasi_state("test_prog") + .args(&["--help", "--wat\0"]) + .build(); match output { Err(WasiStateCreationError::ArgumentContainsNulByte(_)) => assert!(true), _ => assert!(false), diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index b176fa775..eddc679e3 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -184,7 +184,11 @@ impl WasiFs { // TODO: think about this let default_rights = ALL_RIGHTS; let cur_dir_metadata = dir.metadata().map_err(|e| { - format!("Could not get metadata for file {:?}: {}", dir, e.to_string()) + format!( + "Could not get metadata for file {:?}: {}", + dir, + e.to_string() + ) })?; let kind = if cur_dir_metadata.is_dir() { Kind::Dir { @@ -199,12 +203,22 @@ impl WasiFs { )); }; // TODO: handle nested pats in `file` - let inode = - wasi_fs.create_inode(kind, true, dir.to_string_lossy().into_owned()).map_err( - |e| format!("Failed to create inode for preopened dir: WASI error code: {}", e), - )?; + let inode = wasi_fs + .create_inode(kind, true, dir.to_string_lossy().into_owned()) + .map_err(|e| { + format!( + "Failed to create inode for preopened dir: WASI error code: {}", + e + ) + })?; let fd = wasi_fs - .create_fd(default_rights, default_rights, 0, Fd::READ | Fd::WRITE, inode) + .create_fd( + default_rights, + default_rights, + 0, + Fd::READ | Fd::WRITE, + inode, + ) .map_err(|e| format!("Could not open fd for file {:?}: {}", dir, e))?; if let Kind::Root { entries } = &mut wasi_fs.inodes[root_inode].kind { let result = entries.insert(dir.to_string_lossy().into_owned(), inode); @@ -223,7 +237,11 @@ impl WasiFs { // TODO: think about this let default_rights = ALL_RIGHTS; let cur_dir_metadata = real_dir.metadata().map_err(|e| { - format!("Could not get metadata for file {:?}: {}", &real_dir, e.to_string()) + format!( + "Could not get metadata for file {:?}: {}", + &real_dir, + e.to_string() + ) })?; let kind = if cur_dir_metadata.is_dir() { Kind::Dir { @@ -238,11 +256,22 @@ impl WasiFs { )); }; // TODO: handle nested pats in `file` - let inode = wasi_fs.create_inode(kind, true, alias.clone()).map_err(|e| { - format!("Failed to create inode for preopened dir: WASI error code: {}", e) - })?; + let inode = wasi_fs + .create_inode(kind, true, alias.clone()) + .map_err(|e| { + format!( + "Failed to create inode for preopened dir: WASI error code: {}", + e + ) + })?; let fd = wasi_fs - .create_fd(default_rights, default_rights, 0, Fd::READ | Fd::WRITE, inode) + .create_fd( + default_rights, + default_rights, + 0, + Fd::READ | Fd::WRITE, + inode, + ) .map_err(|e| format!("Could not open fd for file {:?}: {}", &real_dir, e))?; if let Kind::Root { entries } = &mut wasi_fs.inodes[root_inode].kind { let result = entries.insert(alias.clone(), inode); @@ -264,10 +293,25 @@ impl WasiFs { pub(crate) fn new_with_preopen(preopens: &[PreopenedDir]) -> Result { let (mut wasi_fs, root_inode) = Self::new_init()?; - for PreopenedDir { path, alias, read, write, create } in preopens { - debug!("Attempting to preopen {} with alias {:?}", &path.to_string_lossy(), &alias); + for PreopenedDir { + path, + alias, + read, + write, + create, + } in preopens + { + debug!( + "Attempting to preopen {} with alias {:?}", + &path.to_string_lossy(), + &alias + ); let cur_dir_metadata = path.metadata().map_err(|e| { - format!("Could not get metadata for file {:?}: {}", path, e.to_string()) + format!( + "Could not get metadata for file {:?}: {}", + path, + e.to_string() + ) })?; let kind = if cur_dir_metadata.is_dir() { @@ -331,7 +375,10 @@ impl WasiFs { wasi_fs.create_inode(kind, true, path.to_string_lossy().into_owned()) } .map_err(|e| { - format!("Failed to create inode for preopened dir: WASI error code: {}", e) + format!( + "Failed to create inode for preopened dir: WASI error code: {}", + e + ) })?; let fd_flags = { let mut fd_flags = 0; @@ -529,7 +576,10 @@ impl WasiFs { self.create_inode_with_default_stat(kind, false, segment_name.clone()); // reborrow to insert match &mut self.inodes[cur_inode].kind { - Kind::Dir { ref mut entries, .. } | Kind::Root { ref mut entries } => { + Kind::Dir { + ref mut entries, .. + } + | Kind::Root { ref mut entries } => { entries.insert(segment_name, inode); } _ => unreachable!("Dir or Root became not Dir or Root"), @@ -542,8 +592,14 @@ impl WasiFs { } // TODO: review open flags (read, write); they were added without consideration - self.create_fd(rights, rights_inheriting, flags, Fd::READ | Fd::WRITE, cur_inode) - .map_err(WasiFsError::from_wasi_err) + self.create_fd( + rights, + rights_inheriting, + flags, + Fd::READ | Fd::WRITE, + cur_inode, + ) + .map_err(WasiFsError::from_wasi_err) } /// Opens a user-supplied file in the directory specified with the @@ -583,7 +639,10 @@ impl WasiFs { .map_err(|_| WasiFsError::IOError)?; // reborrow to insert match &mut self.inodes[base_inode].kind { - Kind::Dir { ref mut entries, .. } | Kind::Root { ref mut entries } => { + Kind::Dir { + ref mut entries, .. + } + | Kind::Root { ref mut entries } => { entries.insert(name, inode); } _ => unreachable!("Dir or Root became not Dir or Root"), @@ -691,7 +750,12 @@ impl WasiFs { 'symlink_resolution: while symlink_count < MAX_SYMLINKS { match &mut self.inodes[cur_inode].kind { Kind::Buffer { .. } => unimplemented!("state::get_inode_at_path for buffers"), - Kind::Dir { ref mut entries, ref path, ref parent, .. } => { + Kind::Dir { + ref mut entries, + ref path, + ref parent, + .. + } => { match component.as_os_str().to_string_lossy().borrow() { ".." => { if let Some(p) = parent { @@ -733,7 +797,11 @@ impl WasiFs { } else if file_type.is_file() { should_insert = true; // load file - Kind::File { handle: None, path: file.clone(), fd: None } + Kind::File { + handle: None, + path: file.clone(), + fd: None, + } } else if file_type.is_symlink() { let link_value = file.read_link().ok().ok_or(__WASI_EIO)?; debug!("attempting to decompose path {:?}", link_value); @@ -770,8 +838,11 @@ impl WasiFs { unimplemented!("state::get_inode_at_path unknown file type: not file, directory, symlink, char device, block device, fifo, or socket"); }; - let kind = - Kind::File { handle: None, path: file.clone(), fd: None }; + let kind = Kind::File { + handle: None, + path: file.clone(), + fd: None, + }; let new_inode = self.create_inode_with_stat( kind, false, @@ -781,8 +852,9 @@ impl WasiFs { ..__wasi_filestat_t::default() }, ); - if let Kind::Dir { ref mut entries, .. } = - &mut self.inodes[cur_inode].kind + if let Kind::Dir { + ref mut entries, .. + } = &mut self.inodes[cur_inode].kind { entries.insert( component.as_os_str().to_string_lossy().to_string(), @@ -803,8 +875,9 @@ impl WasiFs { let new_inode = self.create_inode(kind, false, file.to_string_lossy().to_string())?; if should_insert { - if let Kind::Dir { ref mut entries, .. } = - &mut self.inodes[cur_inode].kind + if let Kind::Dir { + ref mut entries, .. + } = &mut self.inodes[cur_inode].kind { entries.insert( component.as_os_str().to_string_lossy().to_string(), @@ -840,7 +913,11 @@ impl WasiFs { Kind::File { .. } => { return Err(__WASI_ENOTDIR); } - Kind::Symlink { base_po_dir, path_to_symlink, relative_path } => { + Kind::Symlink { + base_po_dir, + path_to_symlink, + relative_path, + } => { let new_base_dir = *base_po_dir; // allocate to reborrow mutabily to recur let new_path = { @@ -995,8 +1072,12 @@ impl WasiFs { ) -> Result<(Inode, String), __wasi_errno_t> { let mut parent_dir = std::path::PathBuf::new(); let mut components = path.components().rev(); - let new_entity_name = - components.next().ok_or(__WASI_EINVAL)?.as_os_str().to_string_lossy().to_string(); + let new_entity_name = components + .next() + .ok_or(__WASI_EINVAL)? + .as_os_str() + .to_string_lossy() + .to_string(); for comp in components.rev() { parent_dir.push(comp); } @@ -1172,7 +1253,12 @@ impl WasiFs { ) -> Inode { stat.st_ino = self.get_next_inode_index(); - self.inodes.insert(InodeVal { stat, is_preopened, name, kind }) + self.inodes.insert(InodeVal { + stat, + is_preopened, + name, + kind, + }) } pub fn create_fd( @@ -1185,8 +1271,17 @@ impl WasiFs { ) -> Result<__wasi_fd_t, __wasi_errno_t> { let idx = self.next_fd.get(); self.next_fd.set(idx + 1); - self.fd_map - .insert(idx, Fd { rights, rights_inheriting, flags, offset: 0, open_flags, inode }); + self.fd_map.insert( + idx, + Fd { + rights, + rights_inheriting, + flags, + offset: 0, + open_flags, + inode, + }, + ); Ok(idx) } @@ -1208,7 +1303,9 @@ impl WasiFs { st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; - let root_kind = Kind::Root { entries: HashMap::new() }; + let root_kind = Kind::Root { + entries: HashMap::new(), + }; self.inodes.insert(InodeVal { stat, @@ -1259,9 +1356,17 @@ impl WasiFs { st_ino: self.get_next_inode_index(), ..__wasi_filestat_t::default() }; - let kind = Kind::File { fd: Some(raw_fd), handle: Some(handle), path: "".into() }; - let inode = - self.inodes.insert(InodeVal { stat, is_preopened: true, name: name.to_string(), kind }); + let kind = Kind::File { + fd: Some(raw_fd), + handle: Some(handle), + path: "".into(), + }; + let inode = self.inodes.insert(InodeVal { + stat, + is_preopened: true, + name: name.to_string(), + kind, + }); self.fd_map.insert( raw_fd, Fd { @@ -1293,7 +1398,11 @@ impl WasiFs { None => path.metadata().ok()?, }, Kind::Dir { path, .. } => path.metadata().ok()?, - Kind::Symlink { base_po_dir, path_to_symlink, .. } => { + Kind::Symlink { + base_po_dir, + path_to_symlink, + .. + } => { let base_po_inode = &self.fd_map[base_po_dir].inode; let base_po_inode_v = &self.inodes[*base_po_inode]; match &base_po_inode_v.kind { @@ -1320,10 +1429,18 @@ impl WasiFs { Some(__wasi_filestat_t { st_filetype: host_file_type_to_wasi_file_type(md.file_type()), st_size: md.len(), - st_atim: md.accessed().ok()?.duration_since(SystemTime::UNIX_EPOCH).ok()?.as_nanos() - as u64, - st_mtim: md.modified().ok()?.duration_since(SystemTime::UNIX_EPOCH).ok()?.as_nanos() - as u64, + st_atim: md + .accessed() + .ok()? + .duration_since(SystemTime::UNIX_EPOCH) + .ok()? + .as_nanos() as u64, + st_mtim: md + .modified() + .ok()? + .duration_since(SystemTime::UNIX_EPOCH) + .ok()? + .as_nanos() as u64, st_ctim: md .created() .ok() @@ -1346,7 +1463,11 @@ impl WasiFs { } Kind::Dir { parent, path, .. } => { debug!("Closing dir {:?}", &path); - let key = path.file_name().ok_or(__WASI_EINVAL)?.to_string_lossy().to_string(); + let key = path + .file_name() + .ok_or(__WASI_EINVAL)? + .to_string_lossy() + .to_string(); if let Some(p) = *parent { match &mut self.inodes[p].kind { Kind::Dir { entries, .. } | Kind::Root { entries } => { diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index aa8fcde1c..8f6b23778 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -439,17 +439,23 @@ impl<'de> Deserialize<'de> for HostFile { where V: de::SeqAccess<'de>, { - let host_path = - seq.next_element()?.ok_or_else(|| de::Error::invalid_length(0, &self))?; - let flags = - seq.next_element()?.ok_or_else(|| de::Error::invalid_length(1, &self))?; + let host_path = seq + .next_element()? + .ok_or_else(|| de::Error::invalid_length(0, &self))?; + let flags = seq + .next_element()? + .ok_or_else(|| de::Error::invalid_length(1, &self))?; let inner = std::fs::OpenOptions::new() .read(flags & HostFile::READ != 0) .write(flags & HostFile::WRITE != 0) .append(flags & HostFile::APPEND != 0) .open(&host_path) .map_err(|_| de::Error::custom("Could not open file on this system"))?; - Ok(HostFile { inner, host_path, flags }) + Ok(HostFile { + inner, + host_path, + flags, + }) } fn visit_map(self, mut map: V) -> Result @@ -482,7 +488,11 @@ impl<'de> Deserialize<'de> for HostFile { .append(flags & HostFile::APPEND != 0) .open(&host_path) .map_err(|_| de::Error::custom("Could not open file on this system"))?; - Ok(HostFile { inner, host_path, flags }) + Ok(HostFile { + inner, + host_path, + flags, + }) } } @@ -508,7 +518,11 @@ impl HostFile { if append { flags |= Self::APPEND; } - Self { inner: file, host_path, flags } + Self { + inner: file, + host_path, + flags, + } } pub fn metadata(&self) -> fs::Metadata { @@ -683,16 +697,28 @@ fn host_file_bytes_available(_raw_fd: i32) -> Result { pub struct Stdout; impl Read for Stdout { fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stdout", + )) } fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stdout", + )) } fn read_to_string(&mut self, _buf: &mut String) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stdout", + )) } fn read_exact(&mut self, _buf: &mut [u8]) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stdout")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stdout", + )) } } impl Seek for Stdout { @@ -764,16 +790,28 @@ impl WasiFile for Stdout { pub struct Stderr; impl Read for Stderr { fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stderr")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stderr", + )) } fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stderr")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stderr", + )) } fn read_to_string(&mut self, _buf: &mut String) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stderr")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stderr", + )) } fn read_exact(&mut self, _buf: &mut [u8]) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not read from stderr")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from stderr", + )) } } impl Seek for Stderr { @@ -864,16 +902,28 @@ impl Seek for Stdin { } impl Write for Stdin { fn write(&mut self, _buf: &[u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not write to stdin")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not write to stdin", + )) } fn flush(&mut self) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not write to stdin")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not write to stdin", + )) } fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not write to stdin")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not write to stdin", + )) } fn write_fmt(&mut self, _fmt: ::std::fmt::Arguments) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not write to stdin")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not write to stdin", + )) } } @@ -955,7 +1005,10 @@ impl Write for Pipe { impl Seek for Pipe { fn seek(&mut self, _pos: io::SeekFrom) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not seek in a pipe")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not seek in a pipe", + )) } } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index 2a52a6166..119f75457 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -139,8 +139,9 @@ pub fn poll_oneoff( let in_new_type_ptr: WasmPtr = unsafe { std::mem::transmute(in_) }; - for (in_sub_new, orig) in - wasi_try!(in_new_type_ptr.deref(memory, 0, nsubscriptions)).iter().zip(in_origs.iter()) + for (in_sub_new, orig) in wasi_try!(in_new_type_ptr.deref(memory, 0, nsubscriptions)) + .iter() + .zip(in_origs.iter()) { in_sub_new.set(types::__wasi_subscription_t { userdata: orig.userdata, @@ -155,7 +156,9 @@ pub fn poll_oneoff( }, } } else { - types::__wasi_subscription_u { fd_readwrite: unsafe { orig.u.fd_readwrite } } + types::__wasi_subscription_u { + fd_readwrite: unsafe { orig.u.fd_readwrite }, + } }, }); } @@ -166,8 +169,9 @@ pub fn poll_oneoff( // replace the old values of in, in case the calling code reuses the memory let memory = env.memory(); - for (in_sub, orig) in - wasi_try!(in_.deref(memory, 0, nsubscriptions)).iter().zip(in_origs.into_iter()) + for (in_sub, orig) in wasi_try!(in_.deref(memory, 0, nsubscriptions)) + .iter() + .zip(in_origs.into_iter()) { in_sub.set(orig); } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index c3759d297..2080205d4 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,7 +1,12 @@ #![allow(unused, clippy::too_many_arguments, clippy::cognitive_complexity)] pub mod types; -#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "android", target_os = "macos"))] +#[cfg(any( + target_os = "freebsd", + target_os = "linux", + target_os = "android", + target_os = "macos" +))] pub mod unix; #[cfg(any(target_os = "windows"))] pub mod windows; @@ -114,7 +119,9 @@ fn write_buffer_array( fn get_current_time_in_nanos() -> Result<__wasi_timestamp_t, __wasi_errno_t> { let now = std::time::SystemTime::now(); - let duration = now.duration_since(std::time::SystemTime::UNIX_EPOCH).map_err(|_| __WASI_EIO)?; + let duration = now + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .map_err(|_| __WASI_EIO)?; Ok(duration.as_nanos() as __wasi_timestamp_t) } @@ -143,7 +150,11 @@ pub fn args_get( .args .iter() .enumerate() - .map(|(i, v)| format!("{:>20}: {}", i, ::std::str::from_utf8(v).unwrap().to_string())) + .map(|(i, v)| format!( + "{:>20}: {}", + i, + ::std::str::from_utf8(v).unwrap().to_string() + )) .collect::>() .join("\n") ); @@ -215,12 +226,19 @@ pub fn clock_time_get( precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t>, ) -> __wasi_errno_t { - debug!("wasi::clock_time_get clock_id: {}, precision: {}", clock_id, precision); + debug!( + "wasi::clock_time_get clock_id: {}, precision: {}", + clock_id, precision + ); let memory = env.memory(); let out_addr = wasi_try!(time.deref(memory)); let result = platform_clock_time_get(clock_id, precision, out_addr); - debug!("time: {} => {}", wasi_try!(time.deref(memory)).get(), result); + debug!( + "time: {} => {}", + wasi_try!(time.deref(memory)).get(), + result + ); result } @@ -266,7 +284,10 @@ pub fn environ_sizes_get( environ_count.set(env_var_count); environ_buf_size.set(env_buf_size); - debug!("env_var_count: {}, env_buf_size: {}", env_var_count, env_buf_size); + debug!( + "env_var_count: {}, env_buf_size: {}", + env_var_count, env_buf_size + ); __WASI_ESUCCESS } @@ -395,7 +416,11 @@ pub fn fd_fdstat_get( fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t>, ) -> __wasi_errno_t { - debug!("wasi::fd_fdstat_get: fd={}, buf_ptr={}", fd, buf_ptr.offset()); + debug!( + "wasi::fd_fdstat_get: fd={}, buf_ptr={}", + fd, + buf_ptr.offset() + ); let (memory, mut state) = env.get_memory_and_wasi_state(0); let fd_entry = wasi_try!(state.fs.get_fd(fd)); @@ -646,13 +671,19 @@ pub fn fd_pread( if !(has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) && has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK)) { - debug!("Invalid rights on {:X}: expected READ and SEEK", fd_entry.rights); + debug!( + "Invalid rights on {:X}: expected READ and SEEK", + fd_entry.rights + ); return __WASI_EACCES; } match &mut state.fs.inodes[inode].kind { Kind::File { handle, .. } => { if let Some(h) = handle { - wasi_try!(h.seek(std::io::SeekFrom::Start(offset as u64)).ok(), __WASI_EIO); + wasi_try!( + h.seek(std::io::SeekFrom::Start(offset as u64)).ok(), + __WASI_EIO + ); wasi_try!(read_bytes(h, memory, iov_cells)) } else { return __WASI_EINVAL; @@ -701,7 +732,10 @@ pub fn fd_prestat_dir_name( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { - debug!("wasi::fd_prestat_dir_name: fd={}, path_len={}", fd, path_len); + debug!( + "wasi::fd_prestat_dir_name: fd={}, path_len={}", + fd, path_len + ); let (memory, mut state) = env.get_memory_and_wasi_state(0); let path_chars = wasi_try!(path.deref(memory, 0, path_len)); @@ -813,7 +847,11 @@ pub fn fd_pwrite( } Kind::Symlink { .. } => unimplemented!("Symlinks in wasi::fd_pwrite"), Kind::Buffer { buffer } => { - wasi_try!(write_bytes(&mut buffer[(offset as usize)..], memory, iovs_arr_cell)) + wasi_try!(write_bytes( + &mut buffer[(offset as usize)..], + memory, + iovs_arr_cell + )) } } } @@ -956,12 +994,17 @@ pub fn fd_readdir( ))) .collect::, _>>()); entry_vec.extend( - entries.iter().filter(|(_, inode)| state.fs.inodes[**inode].is_preopened).map( - |(name, inode)| { + entries + .iter() + .filter(|(_, inode)| state.fs.inodes[**inode].is_preopened) + .map(|(name, inode)| { let entry = &state.fs.inodes[*inode]; - (entry.name.to_string(), entry.stat.st_filetype, entry.stat.st_ino) - }, - ), + ( + entry.name.to_string(), + entry.stat.st_filetype, + entry.stat.st_ino, + ) + }), ); entry_vec.sort_by(|a, b| a.0.cmp(&b.0)); entry_vec @@ -977,7 +1020,11 @@ pub fn fd_readdir( .into_iter() .map(|(name, inode)| { let entry = &state.fs.inodes[inode]; - (format!("/{}", entry.name), entry.stat.st_filetype, entry.stat.st_ino) + ( + format!("/{}", entry.name), + entry.stat.st_filetype, + entry.stat.st_ino, + ) }) .collect() } @@ -995,8 +1042,10 @@ pub fn fd_readdir( d_type: *wasi_file_type, }; let dirent_bytes = dirent_to_le_bytes(&dirent); - let upper_limit = - std::cmp::min(buf_len as usize - buf_idx, std::mem::size_of::<__wasi_dirent_t>()); + let upper_limit = std::cmp::min( + buf_len as usize - buf_idx, + std::mem::size_of::<__wasi_dirent_t>(), + ); for i in 0..upper_limit { buf_arr_cell[i + buf_idx].set(dirent_bytes[i]); } @@ -1308,7 +1357,10 @@ pub fn path_create_directory( let path_vec = wasi_try!(path .components() .map(|comp| { - comp.as_os_str().to_str().map(|inner_str| inner_str.to_string()).ok_or(__WASI_EINVAL) + comp.as_os_str() + .to_str() + .map(|inner_str| inner_str.to_string()) + .ok_or(__WASI_EINVAL) }) .collect::, __wasi_errno_t>>()); if path_vec.is_empty() { @@ -1321,7 +1373,11 @@ pub fn path_create_directory( for comp in &path_vec { debug!("Creating dir {}", comp); match &mut state.fs.inodes[cur_dir_inode].kind { - Kind::Dir { ref mut entries, path, parent } => { + Kind::Dir { + ref mut entries, + path, + parent, + } => { match comp.borrow() { ".." => { if let Some(p) = parent { @@ -1350,8 +1406,9 @@ pub fn path_create_directory( }; let new_inode = wasi_try!(state.fs.create_inode(kind, false, comp.to_string())); // reborrow to insert - if let Kind::Dir { ref mut entries, .. } = - &mut state.fs.inodes[cur_dir_inode].kind + if let Kind::Dir { + ref mut entries, .. + } = &mut state.fs.inodes[cur_dir_inode].kind { entries.insert(comp.to_string(), new_inode); } @@ -1408,7 +1465,10 @@ pub fn path_filestat_get( let stat = if state.fs.inodes[file_inode].is_preopened { state.fs.inodes[file_inode].stat } else { - wasi_try!(state.fs.get_stat_for_kind(&state.fs.inodes[file_inode].kind).ok_or(__WASI_EIO)) + wasi_try!(state + .fs + .get_stat_for_kind(&state.fs.inodes[file_inode].kind) + .ok_or(__WASI_EIO)) }; let buf_cell = wasi_try!(buf.deref(memory)); @@ -1466,8 +1526,10 @@ pub fn path_filestat_set_times( path_string, flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0, )); - let stat = - wasi_try!(state.fs.get_stat_for_kind(&state.fs.inodes[file_inode].kind).ok_or(__WASI_EIO)); + let stat = wasi_try!(state + .fs + .get_stat_for_kind(&state.fs.inodes[file_inode].kind) + .ok_or(__WASI_EIO)); let inode = &mut state.fs.inodes[fd_inode]; @@ -1557,7 +1619,9 @@ pub fn path_link( )); let target_path_arg = std::path::PathBuf::from(new_path_str); let (target_parent_inode, new_entry_name) = - wasi_try!(state.fs.get_parent_inode_at_path(new_fd, &target_path_arg, false)); + wasi_try!(state + .fs + .get_parent_inode_at_path(new_fd, &target_path_arg, false)); if state.fs.inodes[source_inode].stat.st_nlink == __wasi_linkcount_t::max_value() { return __WASI_EMLINK; @@ -1657,7 +1721,11 @@ pub fn path_open( let inode = if let Ok(inode) = maybe_inode { // Happy path, we found the file we're trying to open match &mut state.fs.inodes[inode].kind { - Kind::File { ref mut handle, path, fd } => { + Kind::File { + ref mut handle, + path, + fd, + } => { if let Some(special_fd) = fd { // short circuit if we're dealing with a special file assert!(handle.is_some()); @@ -1715,7 +1783,11 @@ pub fn path_open( return __WASI_EEXIST; } } - Kind::Symlink { base_po_dir, path_to_symlink, relative_path } => { + Kind::Symlink { + base_po_dir, + path_to_symlink, + relative_path, + } => { // I think this should return an error (because symlinks should be resolved away by the path traversal) // TODO: investigate this unimplemented!("SYMLINKS IN PATH_OPEN"); @@ -1772,11 +1844,18 @@ pub fn path_open( }; let new_inode = { - let kind = Kind::File { handle, path: new_file_host_path, fd: None }; + let kind = Kind::File { + handle, + path: new_file_host_path, + fd: None, + }; wasi_try!(state.fs.create_inode(kind, false, new_entity_name.clone())) }; - if let Kind::Dir { ref mut entries, .. } = &mut state.fs.inodes[parent_inode].kind { + if let Kind::Dir { + ref mut entries, .. + } = &mut state.fs.inodes[parent_inode].kind + { entries.insert(new_entity_name, new_inode); } @@ -1786,7 +1865,10 @@ pub fn path_open( } }; - debug!("inode {:?} value {:#?} found!", inode, state.fs.inodes[inode]); + debug!( + "inode {:?} value {:#?} found!", + inode, state.fs.inodes[inode] + ); // TODO: check and reduce these // TODO: ensure a mutable fd to root can never be opened @@ -1907,7 +1989,9 @@ pub fn path_remove_directory( let inode = wasi_try!(state.fs.get_inode_at_path(fd, path_str, false)); let (parent_inode, childs_name) = - wasi_try!(state.fs.get_parent_inode_at_path(fd, std::path::Path::new(path_str), false)); + wasi_try!(state + .fs + .get_parent_inode_at_path(fd, std::path::Path::new(path_str), false)); let host_path_to_remove = match &state.fs.inodes[inode].kind { Kind::Dir { entries, path, .. } => { @@ -1923,7 +2007,9 @@ pub fn path_remove_directory( }; match &mut state.fs.inodes[parent_inode].kind { - Kind::Dir { ref mut entries, .. } => { + Kind::Dir { + ref mut entries, .. + } => { let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(__WASI_EINVAL)); // TODO: make this a debug assert in the future assert!(inode == removed_inode); @@ -1936,7 +2022,10 @@ pub fn path_remove_directory( if std::fs::remove_dir(path_str).is_err() { // reinsert to prevent FS from being in bad state - if let Kind::Dir { ref mut entries, .. } = &mut state.fs.inodes[parent_inode].kind { + if let Kind::Dir { + ref mut entries, .. + } = &mut state.fs.inodes[parent_inode].kind + { entries.insert(childs_name, inode); } // TODO: more intelligently return error value by inspecting returned error value @@ -1970,7 +2059,10 @@ pub fn path_rename( new_path: WasmPtr, new_path_len: u32, ) -> __wasi_errno_t { - debug!("wasi::path_rename: old_fd = {}, new_fd = {}", old_fd, new_fd); + debug!( + "wasi::path_rename: old_fd = {}, new_fd = {}", + old_fd, new_fd + ); let (memory, mut state) = env.get_memory_and_wasi_state(0); let source_str = unsafe { get_input_str!(memory, old_path, old_path_len) }; let source_path = std::path::Path::new(source_str); @@ -2017,9 +2109,14 @@ pub fn path_rename( }; match &mut state.fs.inodes[source_entry].kind { - Kind::File { handle, ref mut path, .. } => { + Kind::File { + handle, + ref mut path, + .. + } => { let result = if let Some(h) = handle { - h.rename_file(&host_adjusted_target_path).map_err(|e| e.into_wasi_err()) + h.rename_file(&host_adjusted_target_path) + .map_err(|e| e.into_wasi_err()) } else { let out = std::fs::rename(&path, &host_adjusted_target_path).map_err(|_| __WASI_EIO); @@ -2109,16 +2206,25 @@ pub fn path_symlink( relative_path.push(".."); } relative_path.push(source_path); - debug!("Symlinking {} to {}", new_path_str, relative_path.to_string_lossy()); + debug!( + "Symlinking {} to {}", + new_path_str, + relative_path.to_string_lossy() + ); let kind = Kind::Symlink { base_po_dir: fd, path_to_symlink: std::path::PathBuf::from(new_path_str), relative_path, }; - let new_inode = state.fs.create_inode_with_default_stat(kind, false, entry_name.clone()); + let new_inode = state + .fs + .create_inode_with_default_stat(kind, false, entry_name.clone()); - if let Kind::Dir { ref mut entries, .. } = &mut state.fs.inodes[target_parent_inode].kind { + if let Kind::Dir { + ref mut entries, .. + } = &mut state.fs.inodes[target_parent_inode].kind + { entries.insert(entry_name, new_inode); } @@ -2152,10 +2258,14 @@ pub fn path_unlink_file( let inode = wasi_try!(state.fs.get_inode_at_path(fd, path_str, false)); let (parent_inode, childs_name) = - wasi_try!(state.fs.get_parent_inode_at_path(fd, std::path::Path::new(path_str), false)); + wasi_try!(state + .fs + .get_parent_inode_at_path(fd, std::path::Path::new(path_str), false)); let removed_inode = match &mut state.fs.inodes[parent_inode].kind { - Kind::Dir { ref mut entries, .. } => { + Kind::Dir { + ref mut entries, .. + } => { let removed_inode = wasi_try!(entries.remove(&childs_name).ok_or(__WASI_EINVAL)); // TODO: make this a debug assert in the future assert!(inode == removed_inode); @@ -2196,10 +2306,16 @@ pub fn path_unlink_file( false }; let removed_inode_val = unsafe { state.fs.remove_inode(removed_inode) }; - assert!(removed_inode_val.is_some(), "Inode could not be removed because it doesn't exist"); + assert!( + removed_inode_val.is_some(), + "Inode could not be removed because it doesn't exist" + ); if fd_is_orphaned { - state.fs.orphan_fds.insert(removed_inode, removed_inode_val.unwrap()); + state + .fs + .orphan_fds + .insert(removed_inode, removed_inode_val.unwrap()); } } @@ -2338,8 +2454,12 @@ pub fn poll_oneoff( } } let mut seen_events = vec![Default::default(); in_events.len()]; - wasi_try!(poll(fds.as_slice(), in_events.as_slice(), seen_events.as_mut_slice()) - .map_err(|e| e.into_wasi_err())); + wasi_try!(poll( + fds.as_slice(), + in_events.as_slice(), + seen_events.as_mut_slice() + ) + .map_err(|e| e.into_wasi_err())); for (i, seen_event) in seen_events.into_iter().enumerate() { let mut flags = 0; @@ -2386,7 +2506,12 @@ pub fn poll_oneoff( error: __WASI_ESUCCESS, type_: __WASI_EVENTTYPE_CLOCK, u: unsafe { - __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t { nbytes: 0, flags: 0 } } + __wasi_event_u { + fd_readwrite: __wasi_event_fd_readwrite_t { + nbytes: 0, + flags: 0, + }, + } }, }; event_array[events_seen].set(event); diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 518bc76c0..6fe1311e6 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -172,15 +172,18 @@ impl std::fmt::Debug for __wasi_event_u { #[derive(Debug, Copy, Clone)] pub enum EventEnum { - FdReadWrite { nbytes: __wasi_filesize_t, flags: __wasi_eventrwflags_t }, + FdReadWrite { + nbytes: __wasi_filesize_t, + flags: __wasi_eventrwflags_t, + }, } impl EventEnum { pub fn untagged(self) -> __wasi_event_u { match self { - EventEnum::FdReadWrite { nbytes, flags } => { - __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t { nbytes, flags } } - } + EventEnum::FdReadWrite { nbytes, flags } => __wasi_event_u { + fd_readwrite: __wasi_event_fd_readwrite_t { nbytes, flags }, + }, } } } @@ -279,9 +282,9 @@ pub enum PrestatEnum { impl PrestatEnum { pub fn untagged(self) -> __wasi_prestat_u { match self { - PrestatEnum::Dir { pr_name_len } => { - __wasi_prestat_u { dir: __wasi_prestat_u_dir_t { pr_name_len } } - } + PrestatEnum::Dir { pr_name_len } => __wasi_prestat_u { + dir: __wasi_prestat_u_dir_t { pr_name_len }, + }, } } } @@ -290,9 +293,9 @@ impl __wasi_prestat_t { #[allow(clippy::trivially_copy_pass_by_ref)] pub fn tagged(&self) -> Option { match self.pr_type { - __WASI_PREOPENTYPE_DIR => { - Some(PrestatEnum::Dir { pr_name_len: unsafe { self.u.dir.pr_name_len } }) - } + __WASI_PREOPENTYPE_DIR => Some(PrestatEnum::Dir { + pr_name_len: unsafe { self.u.dir.pr_name_len }, + }), _ => None, } } @@ -356,7 +359,11 @@ impl std::fmt::Debug for __wasi_filestat_t { .field("st_ino", &self.st_ino) .field( "st_filetype", - &format!("{} ({})", wasi_filetype_to_name(self.st_filetype), self.st_filetype,), + &format!( + "{} ({})", + wasi_filetype_to_name(self.st_filetype), + self.st_filetype, + ), ) .field("st_nlink", &self.st_nlink) .field("st_size", &self.st_size) @@ -627,16 +634,22 @@ impl std::convert::TryFrom for __wasi_subscription_t { fn try_from(ws: WasiSubscription) -> Result { let (type_, u) = match ws.event_type { EventType::Clock(c) => (__WASI_EVENTTYPE_CLOCK, __wasi_subscription_u { clock: c }), - EventType::Read(rw) => { - (__WASI_EVENTTYPE_FD_READ, __wasi_subscription_u { fd_readwrite: rw }) - } - EventType::Write(rw) => { - (__WASI_EVENTTYPE_FD_WRITE, __wasi_subscription_u { fd_readwrite: rw }) - } + EventType::Read(rw) => ( + __WASI_EVENTTYPE_FD_READ, + __wasi_subscription_u { fd_readwrite: rw }, + ), + EventType::Write(rw) => ( + __WASI_EVENTTYPE_FD_WRITE, + __wasi_subscription_u { fd_readwrite: rw }, + ), _ => return Err(__WASI_EINVAL), }; - Ok(Self { userdata: ws.user_data, type_, u }) + Ok(Self { + userdata: ws.user_data, + type_, + u, + }) } } @@ -671,7 +684,9 @@ impl __wasi_subscription_t { match self.type_ { __WASI_EVENTTYPE_CLOCK => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => { - Some(SubscriptionEnum::FdReadWrite(unsafe { self.u.fd_readwrite })) + Some(SubscriptionEnum::FdReadWrite(unsafe { + self.u.fd_readwrite + })) } _ => None, } diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 6a70c7580..9b1e224c7 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -19,7 +19,10 @@ pub fn platform_clock_res_get( }; let (output, timespec_out) = unsafe { - let mut timespec_out: timespec = timespec { tv_sec: 0, tv_nsec: 0 }; + let mut timespec_out: timespec = timespec { + tv_sec: 0, + tv_nsec: 0, + }; (clock_getres(unix_clock_id, &mut timespec_out), timespec_out) }; @@ -44,8 +47,14 @@ pub fn platform_clock_time_get( }; let (output, timespec_out) = unsafe { - let mut timespec_out: timespec = timespec { tv_sec: 0, tv_nsec: 0 }; - (clock_gettime(unix_clock_id, &mut timespec_out), timespec_out) + let mut timespec_out: timespec = timespec { + tv_sec: 0, + tv_nsec: 0, + }; + ( + clock_gettime(unix_clock_id, &mut timespec_out), + timespec_out, + ) }; let t_out = (timespec_out.tv_sec * 1_000_000_000).wrapping_add(timespec_out.tv_nsec); diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index 6448d757c..4614eb93e 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -100,7 +100,9 @@ fn dynamic_function_with_env() -> Result<()> { } } - let env: Env = Env { counter: Arc::new(AtomicUsize::new(0)) }; + let env: Env = Env { + counter: Arc::new(AtomicUsize::new(0)), + }; Instance::new( &module, &imports! { @@ -323,7 +325,9 @@ fn dynamic_function_with_env_wasmer_env_init_works() -> Result<()> { memory: LazyInit, } - let env: Env = Env { memory: LazyInit::default() }; + let env: Env = Env { + memory: LazyInit::default(), + }; let instance = Instance::new( &module, &imports! { @@ -359,7 +363,9 @@ fn multi_use_host_fn_manages_memory_correctly() -> Result<()> { } } - let env: Env = Env { memory: LazyInit::default() }; + let env: Env = Env { + memory: LazyInit::default(), + }; fn host_fn(env: &Env) { assert!(env.memory.get_ref().is_some()); println!("Hello, world!"); diff --git a/tests/compilers/middlewares.rs b/tests/compilers/middlewares.rs index 40a0c0e9a..02eabc373 100644 --- a/tests/compilers/middlewares.rs +++ b/tests/compilers/middlewares.rs @@ -18,7 +18,9 @@ struct Add2Mul { impl ModuleMiddleware for Add2MulGen { fn generate_function_middleware(&self, _: LocalFunctionIndex) -> Box { - Box::new(Add2Mul { value_off: self.value_off }) + Box::new(Add2Mul { + value_off: self.value_off, + }) } } @@ -32,7 +34,9 @@ impl FunctionMiddleware for Add2Mul { Operator::I32Add => { state.push_operator(Operator::I32Mul); if self.value_off != 0 { - state.push_operator(Operator::I32Const { value: self.value_off }); + state.push_operator(Operator::I32Const { + value: self.value_off, + }); state.push_operator(Operator::I32Add); } } diff --git a/tests/compilers/traps.rs b/tests/compilers/traps.rs index e86b5ae02..c619c2045 100644 --- a/tests/compilers/traps.rs +++ b/tests/compilers/traps.rs @@ -25,7 +25,10 @@ fn test_trap_return() -> Result<()> { } }, )?; - let run_func = instance.exports.get_function("run").expect("expected function export"); + let run_func = instance + .exports + .get_function("run") + .expect("expected function export"); let e = run_func.call(&[]).err().expect("error calling function"); @@ -55,7 +58,10 @@ fn test_trap_trace() -> Result<()> { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let run_func = instance.exports.get_function("run").expect("expected function export"); + let run_func = instance + .exports + .get_function("run") + .expect("expected function export"); let e = run_func.call(&[]).err().expect("error calling function"); @@ -67,7 +73,11 @@ fn test_trap_trace() -> Result<()> { assert_eq!(trace[1].module_name(), "hello_mod"); assert_eq!(trace[1].func_index(), 0); assert_eq!(trace[1].function_name(), None); - assert!(e.message().contains("unreachable"), "wrong message: {}", e.message()); + assert!( + e.message().contains("unreachable"), + "wrong message: {}", + e.message() + ); Ok(()) } @@ -95,7 +105,10 @@ fn test_trap_trace_cb() -> Result<()> { } }, )?; - let run_func = instance.exports.get_function("run").expect("expected function export"); + let run_func = instance + .exports + .get_function("run") + .expect("expected function export"); let e = run_func.call(&[]).err().expect("error calling function"); @@ -132,7 +145,10 @@ fn test_trap_stack_overflow() -> Result<()> { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let run_func = instance.exports.get_function("run").expect("expected function export"); + let run_func = instance + .exports + .get_function("run") + .expect("expected function export"); let e = run_func.call(&[]).err().expect("error calling function"); @@ -172,7 +188,10 @@ fn trap_display_pretty() -> Result<()> { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let run_func = instance.exports.get_function("bar").expect("expected function export"); + let run_func = instance + .exports + .get_function("bar") + .expect("expected function export"); let e = run_func.call(&[]).err().expect("error calling function"); assert_eq!( @@ -229,7 +248,10 @@ fn trap_display_multi_module() -> Result<()> { } }, )?; - let bar2 = instance.exports.get_function("bar2").expect("expected function export"); + let bar2 = instance + .exports + .get_function("bar2") + .expect("expected function export"); let e = bar2.call(&[]).err().expect("error calling function"); assert_eq!( @@ -364,7 +386,10 @@ fn rust_panic_start_function() -> Result<()> { )); })) .unwrap_err(); - assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is another panic")); + assert_eq!( + err.downcast_ref::<&'static str>(), + Some(&"this is another panic") + ); Ok(()) } @@ -389,7 +414,9 @@ fn mismatched_arguments() -> Result<()> { "Parameters of type [F32] did not match signature [I32] -> []", ); assert_eq!( - func.call(&[Val::I32(0), Val::I32(1)]).unwrap_err().message(), + func.call(&[Val::I32(0), Val::I32(1)]) + .unwrap_err() + .message(), "Parameters of type [I32, I32] did not match signature [I32] -> []" ); Ok(()) @@ -422,7 +449,9 @@ fn call_signature_mismatch() -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let err = Instance::new(&module, &imports! {}).err().expect("expected error"); + let err = Instance::new(&module, &imports! {}) + .err() + .expect("expected error"); assert_eq!( format!("{}", err), "\ @@ -457,7 +486,9 @@ fn start_trap_pretty() -> Result<()> { "#; let module = Module::new(&store, wat)?; - let err = Instance::new(&module, &imports! {}).err().expect("expected error"); + let err = Instance::new(&module, &imports! {}) + .err() + .expect("expected error"); assert_eq!( format!("{}", err), diff --git a/tests/compilers/wasi.rs b/tests/compilers/wasi.rs index e0c86c26a..fc3497b3b 100644 --- a/tests/compilers/wasi.rs +++ b/tests/compilers/wasi.rs @@ -18,7 +18,10 @@ use wasmer_wast::WasiTest; include!(concat!(env!("OUT_DIR"), "/generated_wasitests.rs")); pub fn run_wasi(wast_path: &str, base_dir: &str, compiler: &str) -> anyhow::Result<()> { - println!("Running wasi wast `{}` with the {} compiler", wast_path, compiler); + println!( + "Running wasi wast `{}` with the {} compiler", + wast_path, compiler + ); let store = get_store(true); let source = { diff --git a/tests/compilers/wast.rs b/tests/compilers/wast.rs index 60e262d77..093949bc7 100644 --- a/tests/compilers/wast.rs +++ b/tests/compilers/wast.rs @@ -41,7 +41,10 @@ fn get_store(features: Features, try_nan_canonicalization: bool) -> Store { } pub fn run_wast(wast_path: &str, compiler: &str) -> anyhow::Result<()> { - println!("Running wast `{}` with the {} compiler", wast_path, compiler); + println!( + "Running wast `{}` with the {} compiler", + wast_path, compiler + ); let try_nan_canonicalization = wast_path.contains("nan-canonicalization"); let mut features = Features::default(); let is_bulkmemory = wast_path.contains("bulk-memory"); diff --git a/tests/integration/cli/src/assets.rs b/tests/integration/cli/src/assets.rs index c68ea7942..f3ca082a6 100644 --- a/tests/integration/cli/src/assets.rs +++ b/tests/integration/cli/src/assets.rs @@ -1,20 +1,28 @@ use std::env; use std::path::PathBuf; -pub const ASSET_PATH: &str = - concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api/tests/assets"); +pub const ASSET_PATH: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../lib/c-api/tests/assets" +); pub const WASMER_INCLUDE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api"); -pub const WASMER_PATH: &str = - concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/release/wasmer"); +pub const WASMER_PATH: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../target/release/wasmer" +); #[cfg(not(windows))] -pub const LIBWASMER_PATH: &str = - concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/release/libwasmer_c_api.a"); +pub const LIBWASMER_PATH: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../target/release/libwasmer_c_api.a" +); #[cfg(windows)] -pub const LIBWASMER_PATH: &str = - concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/release/wasmer_c_api.lib"); +pub const LIBWASMER_PATH: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../target/release/wasmer_c_api.lib" +); /// Get the path to the `libwasmer.a` static library. pub fn get_libwasmer_path() -> PathBuf { diff --git a/tests/integration/cli/src/link_code.rs b/tests/integration/cli/src/link_code.rs index a6b139c8a..0346dbc7d 100644 --- a/tests/integration/cli/src/link_code.rs +++ b/tests/integration/cli/src/link_code.rs @@ -43,10 +43,18 @@ impl LinkCode { let command = command .current_dir(&self.current_dir) .arg(&self.optimization_flag) - .args(self.object_paths.iter().map(|path| path.canonicalize().unwrap())) + .args( + self.object_paths + .iter() + .map(|path| path.canonicalize().unwrap()), + ) .arg(&self.libwasmer_path.canonicalize()?); #[cfg(windows)] - let command = command.arg("-luserenv").arg("-lWs2_32").arg("-ladvapi32").arg("-lbcrypt"); + let command = command + .arg("-luserenv") + .arg("-lWs2_32") + .arg("-ladvapi32") + .arg("-lbcrypt"); #[cfg(not(windows))] let command = command.arg("-ldl").arg("-lm").arg("-pthread"); let output = command.arg("-o").arg(&self.output_path).output()?; diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index e7e7d0622..b8302bccd 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -134,7 +134,11 @@ fn create_exe_works_with_file() -> anyhow::Result<()> { let result = run_code( &operating_dir, &executable_path, - &["--dir=.".to_string(), "--script".to_string(), "test.js".to_string()], + &[ + "--dir=.".to_string(), + "--script".to_string(), + "test.js".to_string(), + ], ) .context("Failed to run generated executable")?; let result_lines = result.lines().collect::>(); @@ -144,7 +148,11 @@ fn create_exe_works_with_file() -> anyhow::Result<()> { let result = run_code( &operating_dir, &executable_path, - &["--mapdir=abc:.".to_string(), "--script".to_string(), "abc/test.js".to_string()], + &[ + "--mapdir=abc:.".to_string(), + "--script".to_string(), + "abc/test.js".to_string(), + ], ) .context("Failed to run generated executable")?; let result_lines = result.lines().collect::>(); diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs index 7047f99f5..a5a993c40 100644 --- a/tests/lib/engine-dummy/src/artifact.rs +++ b/tests/lib/engine-dummy/src/artifact.rs @@ -132,7 +132,9 @@ impl DummyArtifact { #[cfg(not(feature = "serialize"))] pub fn deserialize(engine: &DummyEngine, bytes: &[u8]) -> Result { - Err(DeserializeError::Generic("The serializer feature is not enabled in the DummyEngine")) + Err(DeserializeError::Generic( + "The serializer feature is not enabled in the DummyEngine", + )) } /// Construct a `DummyArtifact` from component parts. @@ -254,6 +256,8 @@ impl Artifact for DummyArtifact { #[cfg(not(feature = "serialize"))] fn serialize(&self) -> Result, SerializeError> { - Err(SerializeError::Generic("The serializer feature is not enabled in the DummyEngine")) + Err(SerializeError::Generic( + "The serializer feature is not enabled in the DummyEngine", + )) } } diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs index b0a70c17a..cdc80b81b 100644 --- a/tests/lib/engine-dummy/src/engine.rs +++ b/tests/lib/engine-dummy/src/engine.rs @@ -93,7 +93,9 @@ impl Engine for DummyEngine { deterministic_only: false, }; validator.wasm_features(wasm_features); - validator.validate_all(binary).map_err(|e| CompileError::Validate(format!("{}", e)))?; + validator + .validate_all(binary) + .map_err(|e| CompileError::Validate(format!("{}", e)))?; Ok(()) } diff --git a/tests/lib/test-generator/src/lib.rs b/tests/lib/test-generator/src/lib.rs index 9d150b121..f17ff21cd 100644 --- a/tests/lib/test-generator/src/lib.rs +++ b/tests/lib/test-generator/src/lib.rs @@ -70,7 +70,10 @@ pub fn build_ignores_from_textfile(path: PathBuf) -> anyhow::Result { // on that platform let (line, target) = if line.contains(" on ") { let l: Vec<&str> = line.split(" on ").collect(); - (l.get(0).unwrap().to_string(), Some(l.get(1).unwrap().to_string())) + ( + l.get(0).unwrap().to_string(), + Some(l.get(1).unwrap().to_string()), + ) } else { (line, None) }; @@ -128,7 +131,11 @@ pub fn test_directory( dir_entries.sort(); - for Test { name: testname, body } in dir_entries.iter() { + for Test { + name: testname, + body, + } in dir_entries.iter() + { out.path.push(testname.to_string()); write_test(out, &testname, &body).unwrap(); out.path.pop().unwrap(); diff --git a/tests/lib/test-generator/src/processors.rs b/tests/lib/test-generator/src/processors.rs index 439d96cec..b8fcdc688 100644 --- a/tests/lib/test-generator/src/processors.rs +++ b/tests/lib/test-generator/src/processors.rs @@ -22,7 +22,10 @@ pub fn wast_processor(out: &mut Testsuite, p: PathBuf) -> Option { // The implementation of `run_wast` lives in /tests/spectest.rs let body = format!("crate::run_wast(r#\"{}\"#, \"{}\")", p.display(), compiler); - Some(Test { name: testname, body }) + Some(Test { + name: testname, + body, + }) } /// Given a Testsuite and a path, process the path in case is a Emscripten @@ -55,7 +58,10 @@ pub fn emscripten_processor(out: &mut Testsuite, p: PathBuf) -> Option { compiler ); - Some(Test { name: testname, body }) + Some(Test { + name: testname, + body, + }) } /// Given a Testsuite and a path, process the path in case is a WASI @@ -83,5 +89,8 @@ pub fn wasi_processor(out: &mut Testsuite, p: PathBuf) -> Option { compiler ); - Some(Test { name: testname, body }) + Some(Test { + name: testname, + body, + }) } diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index 27f30c2c6..1a577f4a2 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -31,7 +31,9 @@ const BASE_TEST_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../wasi-was fn get_stdout_output(wasi_state: &WasiState) -> anyhow::Result { let stdout_boxed = wasi_state.fs.stdout()?.as_ref().unwrap(); - let stdout = (&**stdout_boxed).downcast_ref::().unwrap(); + let stdout = (&**stdout_boxed) + .downcast_ref::() + .unwrap(); let stdout_str = std::str::from_utf8(&stdout.output)?; #[cfg(target_os = "windows")] // normalize line endings @@ -43,7 +45,9 @@ fn get_stdout_output(wasi_state: &WasiState) -> anyhow::Result { fn get_stderr_output(wasi_state: &WasiState) -> anyhow::Result { let stderr_boxed = wasi_state.fs.stderr()?.as_ref().unwrap(); - let stderr = (&**stderr_boxed).downcast_ref::().unwrap(); + let stderr = (&**stderr_boxed) + .downcast_ref::() + .unwrap(); let stderr_str = std::str::from_utf8(&stderr.output)?; #[cfg(target_os = "windows")] @@ -391,7 +395,9 @@ struct Stdin<'a> { impl<'a> Parse<'a> for Stdin<'a> { fn parse(parser: Parser<'a>) -> parser::Result { parser.parse::()?; - Ok(Self { stream: parser.parse()? }) + Ok(Self { + stream: parser.parse()?, + }) } } @@ -403,7 +409,9 @@ struct AssertStdout<'a> { impl<'a> Parse<'a> for AssertStdout<'a> { fn parse(parser: Parser<'a>) -> parser::Result { parser.parse::()?; - Ok(Self { expected: parser.parse()? }) + Ok(Self { + expected: parser.parse()?, + }) } } @@ -415,7 +423,9 @@ struct AssertStderr<'a> { impl<'a> Parse<'a> for AssertStderr<'a> { fn parse(parser: Parser<'a>) -> parser::Result { parser.parse::()?; - Ok(Self { expected: parser.parse()? }) + Ok(Self { + expected: parser.parse()?, + }) } } @@ -440,11 +450,20 @@ mod test { let result = wast::parser::parse::(&pb).unwrap(); assert_eq!(result.args, vec!["hello", "world", "--help"]); - assert_eq!(result.envs, vec![("HELLO", "WORLD"), ("RUST_BACKTRACE", "1")]); + assert_eq!( + result.envs, + vec![("HELLO", "WORLD"), ("RUST_BACKTRACE", "1")] + ); assert_eq!(result.dirs, vec![".", "src/io"]); assert_eq!(result.assert_return.unwrap().return_value, 0); - assert_eq!(result.assert_stdout.unwrap().expected, "This is a \"string\" inside a string!"); - assert_eq!(result.stdin.unwrap().stream, "This is another \"string\" inside a string!"); + assert_eq!( + result.assert_stdout.unwrap().expected, + "This is a \"string\" inside a string!" + ); + assert_eq!( + result.stdin.unwrap().stream, + "This is another \"string\" inside a string!" + ); assert_eq!(result.assert_stderr.unwrap().expected, ""); } } @@ -462,21 +481,36 @@ impl OutputCapturerer { impl Read for OutputCapturerer { fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from logging wrapper")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from logging wrapper", + )) } fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from logging wrapper")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from logging wrapper", + )) } fn read_to_string(&mut self, _buf: &mut String) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not read from logging wrapper")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from logging wrapper", + )) } fn read_exact(&mut self, _buf: &mut [u8]) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "can not read from logging wrapper")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not read from logging wrapper", + )) } } impl Seek for OutputCapturerer { fn seek(&mut self, _pos: io::SeekFrom) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "can not seek logging wrapper")) + Err(io::Error::new( + io::ErrorKind::Other, + "can not seek logging wrapper", + )) } } impl Write for OutputCapturerer { diff --git a/tests/lib/wast/src/wast.rs b/tests/lib/wast/src/wast.rs index 8d9fd57f9..c9d3db8fc 100644 --- a/tests/lib/wast/src/wast.rs +++ b/tests/lib/wast/src/wast.rs @@ -55,13 +55,15 @@ impl Wast { /// A list of instantiation failures to allow. pub fn allow_instantiation_failures(&mut self, failures: &[&str]) { for &failure_str in failures.iter() { - self.allowed_instantiation_failures.insert(failure_str.to_string()); + self.allowed_instantiation_failures + .insert(failure_str.to_string()); } } /// A list of alternative messages to permit for a trap failure. pub fn allow_trap_message(&mut self, expected: &str, allowed: &str) { - self.match_trap_messages.insert(expected.into(), allowed.into()); + self.match_trap_messages + .insert(expected.into(), allowed.into()); } /// Do not run any code in assert_trap or assert_exhaustion. @@ -82,7 +84,10 @@ impl Wast { .get(name) .cloned() .ok_or_else(|| anyhow!("failed to find instance named `{}`", name)), - None => self.current.clone().ok_or_else(|| anyhow!("no previous instance found")), + None => self + .current + .clone() + .ok_or_else(|| anyhow!("no previous instance found")), } } @@ -100,7 +105,11 @@ impl Wast { } fn perform_invoke(&mut self, exec: wast::WastInvoke<'_>) -> Result> { - let values = exec.args.iter().map(|a| self.runtime_value(a)).collect::>>()?; + let values = exec + .args + .iter() + .map(|a| self.runtime_value(a)) + .collect::>>()?; self.invoke(exec.module.map(|i| i.name()), exec.name, &values) } @@ -148,29 +157,49 @@ impl Wast { let binary = module.encode()?; self.module(module.id.map(|s| s.name()), &binary)?; } - Register { span: _, name, module } => { + Register { + span: _, + name, + module, + } => { self.register(module.map(|s| s.name()), name)?; } Invoke(i) => { self.perform_invoke(i)?; } - AssertReturn { span: _, exec, results } => { + AssertReturn { + span: _, + exec, + results, + } => { let result = self.perform_execute(exec); self.assert_return(result, &results)?; } - AssertTrap { span: _, exec, message } => { + AssertTrap { + span: _, + exec, + message, + } => { if !self.disable_assert_trap_exhaustion { let result = self.perform_execute(exec); self.assert_trap(result, message)?; } } - AssertExhaustion { span: _, call, message } => { + AssertExhaustion { + span: _, + call, + message, + } => { if !self.disable_assert_trap_exhaustion { let result = self.perform_invoke(call); self.assert_trap(result, message)?; } } - AssertInvalid { span: _, mut module, message } => { + AssertInvalid { + span: _, + mut module, + message, + } => { let bytes = module.encode()?; let err = match self.module(None, &bytes) { Ok(()) => bail!("expected module to fail to build"), @@ -178,13 +207,21 @@ impl Wast { }; let error_message = format!("{:?}", err); if !Self::matches_message_assert_invalid(&message, &error_message) { - bail!("assert_invalid: expected \"{}\", got \"{}\"", message, error_message) + bail!( + "assert_invalid: expected \"{}\", got \"{}\"", + message, + error_message + ) } } QuoteModule { .. } => { // Do nothing } - AssertMalformed { module, span: _, message: _ } => { + AssertMalformed { + module, + span: _, + message: _, + } => { let mut module = match module { wast::QuoteModule::Module(m) => m, // This is a `*.wat` parser test which we're not @@ -196,7 +233,11 @@ impl Wast { bail!("expected malformed module to fail to instantiate"); } } - AssertUnlinkable { span: _, mut module, message } => { + AssertUnlinkable { + span: _, + mut module, + message, + } => { let bytes = module.encode()?; let err = match self.module(None, &bytes) { Ok(()) => bail!("expected module to fail to link"), @@ -204,7 +245,11 @@ impl Wast { }; let error_message = format!("{:?}", err); if !Self::matches_message_assert_unlinkable(&message, &error_message) { - bail!("assert_unlinkable: expected {}, got {}", message, error_message) + bail!( + "assert_unlinkable: expected {}, got {}", + message, + error_message + ) } } } @@ -239,14 +284,22 @@ impl Wast { continue; } let (line, col) = sp.linecol_in(wast); - errors.push(DirectiveError { line: line + 1, col, message }); + errors.push(DirectiveError { + line: line + 1, + col, + message, + }); if self.fail_fast { break; } } } if !errors.is_empty() { - return Err(DirectiveErrors { filename: filename.to_string(), errors }.into()); + return Err(DirectiveErrors { + filename: filename.to_string(), + errors, + } + .into()); } Ok(()) } @@ -352,8 +405,10 @@ impl Wast { RefNull(wast::HeapType::Func) => Val::FuncRef(None), RefNull(wast::HeapType::Extern) => Val::null(), RefExtern(number) => { - let extern_ref = - self.extern_refs.entry(*number).or_insert_with(|| ExternRef::new(*number)); + let extern_ref = self + .extern_refs + .entry(*number) + .or_insert_with(|| ExternRef::new(*number)); Val::ExternRef(extern_ref.clone()) } other => bail!("couldn't convert {:?} to a runtime value", other), @@ -426,7 +481,11 @@ impl Wast { false } } - _ => bail!("don't know how to compare {:?} and {:?} yet", actual, expected), + _ => bail!( + "don't know how to compare {:?} and {:?} yet", + actual, + expected + ), }) } } @@ -465,18 +524,22 @@ fn f64_matches(actual: f64, expected: &wast::NanPattern) -> bool fn v128_matches(actual: u128, expected: &wast::V128Pattern) -> bool { match expected { - wast::V128Pattern::I8x16(b) => { - b.iter().enumerate().all(|(i, b)| *b == extract_lane_as_i8(actual, i)) - } - wast::V128Pattern::I16x8(b) => { - b.iter().enumerate().all(|(i, b)| *b == extract_lane_as_i16(actual, i)) - } - wast::V128Pattern::I32x4(b) => { - b.iter().enumerate().all(|(i, b)| *b == extract_lane_as_i32(actual, i)) - } - wast::V128Pattern::I64x2(b) => { - b.iter().enumerate().all(|(i, b)| *b == extract_lane_as_i64(actual, i)) - } + wast::V128Pattern::I8x16(b) => b + .iter() + .enumerate() + .all(|(i, b)| *b == extract_lane_as_i8(actual, i)), + wast::V128Pattern::I16x8(b) => b + .iter() + .enumerate() + .all(|(i, b)| *b == extract_lane_as_i16(actual, i)), + wast::V128Pattern::I32x4(b) => b + .iter() + .enumerate() + .all(|(i, b)| *b == extract_lane_as_i32(actual, i)), + wast::V128Pattern::I64x2(b) => b + .iter() + .enumerate() + .all(|(i, b)| *b == extract_lane_as_i64(actual, i)), wast::V128Pattern::F32x4(b) => b.iter().enumerate().all(|(i, b)| { let a = extract_lane_as_i32(actual, i) as u32; f32_matches(f32::from_bits(a), b) @@ -529,14 +592,26 @@ fn v128_format(actual: u128, expected: &wast::V128Pattern) -> wast::V128Pattern extract_lane_as_i64(actual, 1), ]), wast::V128Pattern::F32x4(_) => wast::V128Pattern::F32x4([ - wast::NanPattern::Value(wast::Float32 { bits: extract_lane_as_i32(actual, 0) as _ }), - wast::NanPattern::Value(wast::Float32 { bits: extract_lane_as_i32(actual, 1) as _ }), - wast::NanPattern::Value(wast::Float32 { bits: extract_lane_as_i32(actual, 2) as _ }), - wast::NanPattern::Value(wast::Float32 { bits: extract_lane_as_i32(actual, 3) as _ }), + wast::NanPattern::Value(wast::Float32 { + bits: extract_lane_as_i32(actual, 0) as _, + }), + wast::NanPattern::Value(wast::Float32 { + bits: extract_lane_as_i32(actual, 1) as _, + }), + wast::NanPattern::Value(wast::Float32 { + bits: extract_lane_as_i32(actual, 2) as _, + }), + wast::NanPattern::Value(wast::Float32 { + bits: extract_lane_as_i32(actual, 3) as _, + }), ]), wast::V128Pattern::F64x2(_) => wast::V128Pattern::F64x2([ - wast::NanPattern::Value(wast::Float64 { bits: extract_lane_as_i64(actual, 0) as _ }), - wast::NanPattern::Value(wast::Float64 { bits: extract_lane_as_i64(actual, 1) as _ }), + wast::NanPattern::Value(wast::Float64 { + bits: extract_lane_as_i64(actual, 0) as _, + }), + wast::NanPattern::Value(wast::Float64 { + bits: extract_lane_as_i64(actual, 1) as _, + }), ]), } }