diff --git a/src/backend.rs b/src/backend.rs index b3502d3da0..3d89164435 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -2,7 +2,7 @@ use crate::error::Error; use crate::microwasm::{BrTarget, SignlessType, Type, Value, F32, F64, I32, I64}; -use crate::module::{ModuleContext, RuntimeFunc}; +use crate::module::ModuleContext; use cranelift_codegen::{binemit, ir}; use dynasmrt::x64::Assembler; use dynasmrt::{AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, ExecutableBuffer}; @@ -2296,7 +2296,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { self.block_state.regs.release(tmp); - for (i, target) in targets.enumerate() { + for target in targets { let label = target .map(|target| self.target_to_label(target)) .unwrap_or(end_label); @@ -3163,6 +3163,7 @@ impl<'this, M: ModuleContext> Context<'this, M> { self.push(out_val); } + pub fn i32_truncate_f32_u(&mut self) { let mut val = self.pop(); @@ -3177,7 +3178,6 @@ impl<'this, M: ModuleContext> Context<'this, M> { let sign_mask = self.aligned_label(4, LabelValue::I32(SIGN_MASK_F32 as i32)); let float_cmp_mask = self.aligned_label(16, LabelValue::I32(0x4f000000u32 as i32)); - let zero = self.aligned_label(16, LabelValue::I32(0)); let trap_label = self.trap_label(); dynasm!(self.asm @@ -3261,7 +3261,6 @@ impl<'this, M: ModuleContext> Context<'this, M> { let sign_mask = self.aligned_label(4, LabelValue::I32(SIGN_MASK_F32 as i32)); let float_cmp_mask = self.aligned_label(16, LabelValue::I64(0x41e0000000000000u64 as i64)); - let zero = self.aligned_label(16, LabelValue::I64(0)); let trap_label = self.trap_label(); dynasm!(self.asm @@ -4720,7 +4719,6 @@ impl<'this, M: ModuleContext> Context<'this, M> { let locs = arg_locs(arg_types); self.save_volatile(locs.len()..); - let depth = self.block_state.depth.clone(); let (_, label) = self.func_starts[defined_index as usize]; @@ -4846,10 +4844,8 @@ impl<'this, M: ModuleContext> Context<'this, M> { where F: IntoLabel, { - use std::collections::hash_map::Entry; - let key = fun.key(); - if let Some((label, current_align, func)) = self.labels.get(&(align, key)) { + if let Some((label, _, _)) = self.labels.get(&(align, key)) { return *label; } diff --git a/src/function_body.rs b/src/function_body.rs index abcecbf885..74d7160d64 100644 --- a/src/function_body.rs +++ b/src/function_body.rs @@ -1,11 +1,11 @@ use crate::backend::*; use crate::error::Error; use crate::microwasm::*; -use crate::module::{quickhash, ModuleContext, SigType, Signature}; +use crate::module::{ModuleContext, SigType, Signature}; use cranelift_codegen::binemit; use either::{Either, Left, Right}; use multi_mut::HashMapMultiMut; -use std::{collections::HashMap, convert::TryInto, hash::Hash}; +use std::{collections::HashMap, hash::Hash}; #[derive(Debug)] struct Block { @@ -49,7 +49,7 @@ where body, ); - crate::microwasm::dis( + let _ = crate::microwasm::dis( std::io::stdout(), func_idx, microwasm_conv.flat_map(|ops| ops.unwrap()), @@ -81,7 +81,6 @@ where M: ModuleContext, I: IntoIterator>, L: Hash + Clone + Eq, - Operator: std::fmt::Display, { fn drop_elements(stack: &mut Vec, depths: std::ops::RangeInclusive) { let _ = (|| { @@ -140,12 +139,7 @@ where if let Some(Operator::Label(label)) = body.peek() { let block = blocks .get_mut(&BrTarget::Label(label.clone())) - .unwrap_or_else(|| { - panic!( - "Block definition should be before label definition: {}", - Operator::Label(label.clone()) - ) - }); + .unwrap_or_else(|| panic!("Label defined before being declared")); block.is_next = true; } @@ -227,10 +221,7 @@ where entry.remove_entry(); } } else { - panic!( - "Label defined before being declared: {}", - Operator::Label(label) - ); + panic!("Label defined before being declared"); } } Operator::Block { @@ -320,7 +311,8 @@ where ) { ((Some(Left(ref cc)), to_drop), ref mut other @ (None, _)) | (ref mut other @ (None, _), (Some(Left(ref cc)), to_drop)) => { - let mut cc = ctx.serialize_block_args_preserve_flags(cc, to_drop.clone()); + let mut cc = + ctx.serialize_block_args_preserve_flags(cc, to_drop.clone()); if let Some(to_drop) = other.1 { drop_elements(&mut cc.arguments, to_drop.clone()); } @@ -710,8 +702,6 @@ where ctx.memory_grow(); } Operator::Call { function_index } => { - use cranelift_codegen::ir; - let callee_ty = module_context.func_type(function_index); if let Some(defined_index) = module_context.defined_func_index(function_index) { @@ -752,9 +742,6 @@ where callee_ty.returns().iter().map(|t| t.to_microwasm_type()), ); } - op => { - unimplemented!("{}", op); - } } } diff --git a/src/microwasm.rs b/src/microwasm.rs index 27037b0502..56f32521a3 100644 --- a/src/microwasm.rs +++ b/src/microwasm.rs @@ -20,10 +20,6 @@ where BrTarget: fmt::Display, L: Clone, { - use std::fmt::Write; - - const DISASSEMBLE_BLOCK_DEFS: bool = true; - writeln!(out, ".fn_{}:", function_name)?; let p = " "; @@ -508,8 +504,6 @@ pub enum Operator