diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 575f6961140..f045982e898 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -3,7 +3,7 @@ use crate::codegen_error; #[cfg(feature = "unwind")] use crate::dwarf::WriterRelocate; use crate::location::{Location, Reg}; -use crate::machine::{CodegenError, Label, Machine, MachineStackOffset, NATIVE_PAGE_SIZE}; +use crate::machine::{Label, Machine, MachineStackOffset, NATIVE_PAGE_SIZE}; use crate::unwind::UnwindFrame; use crate::{common_decl::*, config::Singlepass}; #[cfg(feature = "unwind")] @@ -17,7 +17,7 @@ use wasmer_compiler::FunctionBodyData; use wasmer_types::CompiledFunctionUnwindInfo; use wasmer_types::{ entity::{EntityRef, PrimaryMap}, - CallingConvention, FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, + CallingConvention, CompileError, FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, LocalMemoryIndex, MemoryIndex, MemoryStyle, ModuleInfo, Relocation, RelocationTarget, SectionIndex, SignatureIndex, TableIndex, TableStyle, TrapCode, Type, VMBuiltinFunctionIndex, VMOffsets, @@ -128,7 +128,7 @@ impl FloatValue { } } - fn promote(self, depth: usize) -> Result { + fn promote(self, depth: usize) -> Result { let ret = FloatValue { canonicalization: match self.canonicalization { Some(CanonicalizeType::F32) => Some(CanonicalizeType::F64), @@ -140,7 +140,7 @@ impl FloatValue { Ok(ret) } - fn demote(self, depth: usize) -> Result { + fn demote(self, depth: usize) -> Result { let ret = FloatValue { canonicalization: match self.canonicalization { Some(CanonicalizeType::F64) => Some(CanonicalizeType::F32), @@ -171,27 +171,25 @@ impl CanonicalizeType { } trait PopMany { - fn peek1(&self) -> Result<&T, CodegenError>; - fn pop1(&mut self) -> Result; - fn pop2(&mut self) -> Result<(T, T), CodegenError>; + fn peek1(&self) -> Result<&T, CompileError>; + fn pop1(&mut self) -> Result; + fn pop2(&mut self) -> Result<(T, T), CompileError>; } impl PopMany for Vec { - fn peek1(&self) -> Result<&T, CodegenError> { - self.last().ok_or_else(|| CodegenError { - message: "peek1() expects at least 1 element".into(), - }) + fn peek1(&self) -> Result<&T, CompileError> { + self.last() + .ok_or_else(|| CompileError::Codegen("peek1() expects at least 1 element".to_owned())) } - fn pop1(&mut self) -> Result { - self.pop().ok_or_else(|| CodegenError { - message: "pop1() expects at least 1 element".into(), - }) + fn pop1(&mut self) -> Result { + self.pop() + .ok_or_else(|| CompileError::Codegen("pop1() expects at least 1 element".to_owned())) } - fn pop2(&mut self) -> Result<(T, T), CodegenError> { + fn pop2(&mut self) -> Result<(T, T), CompileError> { if self.len() < 2 { - return Err(CodegenError { - message: "pop2() expects at least 2 elements".into(), - }); + return Err(CompileError::Codegen( + "pop2() expects at least 2 elements".to_owned(), + )); } let right = self.pop().unwrap(); @@ -263,7 +261,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { &mut self, tys: &[(WpType, MachineValue)], zeroed: bool, - ) -> Result; 1]>, CodegenError> { + ) -> Result; 1]>, CompileError> { let mut ret = smallvec![]; let mut delta_stack_offset: usize = 0; @@ -311,7 +309,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn release_locations( &mut self, locs: &[Location], - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut delta_stack_offset: usize = 0; for loc in locs.iter().rev() { @@ -341,16 +339,18 @@ impl<'a, M: Machine> FuncGen<'a, M> { } self.stack_offset.0 -= 8; delta_stack_offset += 8; - self.state.stack_values.pop().ok_or(CodegenError { - message: "Empty stack_value".to_string(), - })?; + self.state + .stack_values + .pop() + .ok_or_else(|| CompileError::Codegen("Empty stack_value".to_owned()))?; } } _ => {} } - self.state.wasm_stack.pop().ok_or(CodegenError { - message: "Pop with wasm stack empty".to_string(), - })?; + self.state + .wasm_stack + .pop() + .ok_or_else(|| CompileError::Codegen("Pop with wasm stack empty".to_owned()))?; } let delta_stack_offset = self.machine.round_stack_adjust(delta_stack_offset); if delta_stack_offset != 0 { @@ -359,7 +359,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { Ok(()) } /// Releases locations used for stack value. - fn release_locations_value(&mut self, stack_depth: usize) -> Result<(), CodegenError> { + fn release_locations_value(&mut self, stack_depth: usize) -> Result<(), CompileError> { let mut delta_stack_offset: usize = 0; let locs: &[Location] = &self.value_stack[stack_depth..]; @@ -390,16 +390,17 @@ impl<'a, M: Machine> FuncGen<'a, M> { } self.stack_offset.0 -= 8; delta_stack_offset += 8; - self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop with values stack empty".to_string(), + self.state.stack_values.pop().ok_or_else(|| { + CompileError::Codegen("Pop with values stack empty".to_owned()) })?; } } _ => {} } - self.state.wasm_stack.pop().ok_or(CodegenError { - message: "Pop with wasm stack empty".to_string(), - })?; + self.state + .wasm_stack + .pop() + .ok_or_else(|| CompileError::Codegen("Pop with wasm stack empty".to_owned()))?; } let delta_stack_offset = self.machine.round_stack_adjust(delta_stack_offset); @@ -412,7 +413,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn release_locations_only_regs( &mut self, locs: &[Location], - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { for loc in locs.iter().rev() { match *loc { Location::GPR(ref x) => { @@ -435,7 +436,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn release_locations_only_stack( &mut self, locs: &[Location], - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut delta_stack_offset: usize = 0; for loc in locs.iter().rev() { @@ -450,8 +451,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { } self.stack_offset.0 -= 8; delta_stack_offset += 8; - self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop on empty value stack".to_string(), + self.state.stack_values.pop().ok_or_else(|| { + CompileError::Codegen("Pop on empty value stack".to_owned()) })?; } } @@ -465,7 +466,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { Ok(()) } - fn release_locations_only_osr_state(&mut self, n: usize) -> Result<(), CodegenError> { + fn release_locations_only_osr_state(&mut self, n: usize) -> Result<(), CompileError> { let new_length = self .state .wasm_stack @@ -476,7 +477,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { Ok(()) } - fn release_locations_keep_state(&mut self, stack_depth: usize) -> Result<(), CodegenError> { + fn release_locations_keep_state(&mut self, stack_depth: usize) -> Result<(), CompileError> { let mut delta_stack_offset: usize = 0; let mut stack_offset = self.stack_offset.0; let locs = &self.value_stack[stack_depth..]; @@ -510,7 +511,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { n: usize, sig: FunctionType, calling_convention: CallingConvention, - ) -> Result>, CodegenError> { + ) -> Result>, CompileError> { // How many machine stack slots will all the locals use? let num_mem_slots = (0..n) .filter(|&x| self.machine.is_local_on_stack(x)) @@ -665,7 +666,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn finalize_locals( &mut self, calling_convention: CallingConvention, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // Unwind stack to the "save area". self.machine .restore_saved_area(self.save_area_offset.as_ref().unwrap().0 as i32)?; @@ -696,20 +697,20 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn get_location_released( &mut self, loc: Location, - ) -> Result, CodegenError> { + ) -> Result, CompileError> { self.release_locations(&[loc])?; Ok(loc) } - fn pop_value_released(&mut self) -> Result, CodegenError> { - let loc = self.value_stack.pop().ok_or(CodegenError { - message: "pop_value_released: value stack is empty".to_string(), + fn pop_value_released(&mut self) -> Result, CompileError> { + let loc = self.value_stack.pop().ok_or_else(|| { + CompileError::Codegen("pop_value_released: value stack is empty".to_owned()) })?; self.get_location_released(loc) } /// Prepare data for binary operator with 2 inputs and 1 output. - fn i2o1_prepare(&mut self, ty: WpType) -> Result, CodegenError> { + fn i2o1_prepare(&mut self, ty: WpType) -> Result, CompileError> { let loc_b = self.pop_value_released()?; let loc_a = self.pop_value_released()?; let ret = self.acquire_locations( @@ -759,13 +760,13 @@ impl<'a, M: Machine> FuncGen<'a, M> { fn emit_call_native< I: Iterator>, J: Iterator, - F: FnOnce(&mut Self) -> Result<(), CodegenError>, + F: FnOnce(&mut Self) -> Result<(), CompileError>, >( &mut self, cb: F, params: I, params_type: J, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // Values pushed in this function are above the shadow region. self.state.stack_values.push(MachineValue::ExplicitShadow); @@ -784,9 +785,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { for r in used_gprs.iter() { let content = self.state.register_values[self.machine.index_from_gpr(*r).0].clone(); if content == MachineValue::Undefined { - return Err(CodegenError { - message: "emit_call_native: Undefined used_gprs content".to_string(), - }); + return Err(CompileError::Codegen( + "emit_call_native: Undefined used_gprs content".to_owned(), + )); } self.state.stack_values.push(content); } @@ -800,9 +801,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { let content = self.state.register_values[self.machine.index_from_simd(*r).0].clone(); if content == MachineValue::Undefined { - return Err(CodegenError { - message: "emit_call_native: Undefined used_simds content".to_string(), - }); + return Err(CompileError::Codegen( + "emit_call_native: Undefined used_simds content".to_owned(), + )); } self.state.stack_values.push(content); } @@ -871,10 +872,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { } Location::Memory(reg, offset) => { if reg != self.machine.local_pointer() { - return Err(CodegenError { - message: "emit_call_native loc param: unreachable code" - .to_string(), - }); + return Err(CompileError::Codegen( + "emit_call_native loc param: unreachable code".to_owned(), + )); } self.state .stack_values @@ -889,9 +889,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { .move_location_for_native(params_size[i], *param, loc)?; } _ => { - return Err(CodegenError { - message: "emit_call_native loc: unreachable code".to_string(), - }) + return Err(CompileError::Codegen( + "emit_call_native loc: unreachable code".to_owned(), + )) } } } @@ -947,14 +947,15 @@ impl<'a, M: Machine> FuncGen<'a, M> { .round_stack_adjust(stack_offset + stack_padding) as u32, )?; if (stack_offset % 8) != 0 { - return Err(CodegenError { - message: "emit_call_native: Bad restoring stack alignement".to_string(), - }); + return Err(CompileError::Codegen( + "emit_call_native: Bad restoring stack alignement".to_owned(), + )); } for _ in 0..pushed_args { - self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop an empty value stack".to_string(), - })?; + self.state + .stack_values + .pop() + .ok_or_else(|| CompileError::Codegen("Pop an empty value stack".to_owned()))?; } } @@ -962,27 +963,32 @@ impl<'a, M: Machine> FuncGen<'a, M> { if !used_simds.is_empty() { self.machine.pop_used_simd(&used_simds)?; for _ in 0..used_simds.len() { - self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop an empty value stack".to_string(), - })?; + self.state + .stack_values + .pop() + .ok_or_else(|| CompileError::Codegen("Pop an empty value stack".to_owned()))?; } } // Restore GPRs. self.machine.pop_used_gpr(&used_gprs)?; for _ in used_gprs.iter().rev() { - self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop an empty value stack".to_string(), - })?; + self.state + .stack_values + .pop() + .ok_or_else(|| CompileError::Codegen("Pop an empty value stack".to_owned()))?; } - if self.state.stack_values.pop().ok_or(CodegenError { - message: "Pop an empty value stack".to_string(), - })? != MachineValue::ExplicitShadow + if self + .state + .stack_values + .pop() + .ok_or_else(|| CompileError::Codegen("Pop an empty value stack".to_owned()))? + != MachineValue::ExplicitShadow { - return Err(CodegenError { - message: "emit_call_native: Popped value is not ExplicitShadow".to_string(), - }); + return Err(CompileError::Codegen( + "emit_call_native: Popped value is not ExplicitShadow".to_owned(), + )); } Ok(()) } @@ -996,7 +1002,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { label: Label, params: I, params_type: J, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_call_native( |this| this.machine.emit_call_label(label), params, @@ -1006,10 +1012,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { } /// Emits a memory operation. - fn op_memory Result<(), CodegenError>>( + fn op_memory Result<(), CompileError>>( &mut self, cb: F, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let need_check = match self.memory_styles[MemoryIndex::new(0)] { MemoryStyle::Static { .. } => false, MemoryStyle::Dynamic { .. } => true, @@ -1045,7 +1051,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { id } - fn emit_head(&mut self) -> Result<(), CodegenError> { + fn emit_head(&mut self) -> Result<(), CompileError> { self.machine.emit_function_prolog()?; // Initialize locals. @@ -1090,9 +1096,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { self.machine.insert_stackoverflow(); if self.state.wasm_inst_offset != std::usize::MAX { - return Err(CodegenError { - message: "emit_head: wasm_inst_offset not std::usize::MAX".to_string(), - }); + return Err(CompileError::Codegen( + "emit_head: wasm_inst_offset not std::usize::MAX".to_owned(), + )); } Ok(()) } @@ -1108,7 +1114,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { local_types_excluding_arguments: &[WpType], machine: M, calling_convention: CallingConvention, - ) -> Result, CodegenError> { + ) -> Result, CompileError> { let func_index = module.func_index(local_func_index); let sig_index = module.functions[func_index]; let signature = module.signatures[sig_index].clone(); @@ -1170,7 +1176,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { !self.control_stack.is_empty() } - pub fn feed_operator(&mut self, op: Operator) -> Result<(), CodegenError> { + pub fn feed_operator(&mut self, op: Operator) -> Result<(), CompileError> { assert!(self.fp_stack.len() <= self.value_stack.len()); self.state.wasm_inst_offset = self.state.wasm_inst_offset.wrapping_add(1); @@ -2939,9 +2945,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { - return Err(CodegenError { - message: "If: multi-value returns not yet implemented".to_string(), - }) + return Err(CompileError::Codegen( + "If: multi-value returns not yet implemented".to_owned(), + )) } }, value_stack_depth: self.value_stack.len(), @@ -2987,9 +2993,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { frame.if_else = IfElseState::Else; } _ => { - return Err(CodegenError { - message: "Else: frame.if_else unreachable code".to_string(), - }) + return Err(CompileError::Codegen( + "Else: frame.if_else unreachable code".to_owned(), + )) } } } @@ -3062,10 +3068,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { - return Err(CodegenError { - message: "Block: multi-value returns not yet implemented" - .to_string(), - }) + return Err(CompileError::Codegen( + "Block: multi-value returns not yet implemented".to_owned(), + )) } }, value_stack_depth: self.value_stack.len(), @@ -3089,10 +3094,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { - return Err(CodegenError { - message: "Loop: multi-value returns not yet implemented" - .to_string(), - }) + return Err(CompileError::Codegen( + "Loop: multi-value returns not yet implemented".to_owned(), + )) } }, value_stack_depth: self.value_stack.len(), @@ -3826,9 +3830,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { let frame = &self.control_stack[0]; if !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: "Return: incorrect frame.returns".to_string(), - }); + return Err(CompileError::Codegen( + "Return: incorrect frame.returns".to_owned(), + )); } let first_return = frame.returns[0]; let loc = *self.value_stack.last().unwrap(); @@ -3855,9 +3859,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { &self.control_stack[self.control_stack.len() - 1 - (relative_depth as usize)]; if !frame.loop_like && !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: "Br: incorrect frame.returns".to_string(), - }); + return Err(CompileError::Codegen( + "Br: incorrect frame.returns".to_owned(), + )); } let first_return = frame.returns[0]; let loc = *self.value_stack.last().unwrap(); @@ -3892,9 +3896,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { &self.control_stack[self.control_stack.len() - 1 - (relative_depth as usize)]; if !frame.loop_like && !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: "BrIf: incorrect frame.returns".to_string(), - }); + return Err(CompileError::Codegen( + "BrIf: incorrect frame.returns".to_owned(), + )); } let first_return = frame.returns[0]; @@ -3923,9 +3927,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { let targets = table .targets() .collect::, _>>() - .map_err(|e| CodegenError { - message: format!("BrTable read_table: {:?}", e), - })?; + .map_err(|e| CompileError::Codegen(format!("BrTable read_table: {:?}", e)))?; let default_target = table.default(); let cond = self.pop_value_released()?; let table_label = self.machine.get_label(); @@ -3948,12 +3950,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { &self.control_stack[self.control_stack.len() - 1 - (*target as usize)]; if !frame.loop_like && !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: format!( - "BrTable: incorrect frame.returns for {:?}", - target - ), - }); + return Err(CompileError::Codegen(format!( + "BrTable: incorrect frame.returns for {:?}", + target + ))); } let first_return = frame.returns[0]; @@ -3983,9 +3983,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { [self.control_stack.len() - 1 - (default_target as usize)]; if !frame.loop_like && !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: "BrTable: incorrect frame.returns".to_string(), - }); + return Err(CompileError::Codegen( + "BrTable: incorrect frame.returns".to_owned(), + )); } let first_return = frame.returns[0]; @@ -4069,9 +4069,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { if !frame.returns.is_empty() { if frame.returns.len() != 1 { - return Err(CodegenError { - message: "End: incorrect frame.returns".to_string(), - }); + return Err(CompileError::Codegen( + "End: incorrect frame.returns".to_owned(), + )); } let loc = self.acquire_locations( &[( @@ -5897,9 +5897,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { )?; } _ => { - return Err(CodegenError { - message: format!("not yet implemented: {:?}", op), - }); + return Err(CompileError::Codegen(format!( + "not yet implemented: {:?}", + op + ))); } } @@ -5909,7 +5910,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { pub fn finalize( mut self, data: &FunctionBodyData, - ) -> Result<(CompiledFunction, Option), CodegenError> { + ) -> Result<(CompiledFunction, Option), CompileError> { // Generate actual code for special labels. self.machine .emit_label(self.special_labels.integer_division_by_zero)?; @@ -5968,7 +5969,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { let address_map = get_function_address_map(self.machine.instructions_address_map(), data, body_len); let traps = self.machine.collect_trap_information(); - let body = self.machine.assembler_finalize(); + let mut body = self.machine.assembler_finalize(); + body.shrink_to_fit(); Ok(( CompiledFunction { diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index 510dc47bb7a..6c2d9be7103 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -8,7 +8,7 @@ use crate::config::Singlepass; use crate::dwarf::WriterRelocate; use crate::machine::Machine; use crate::machine::{ - gen_import_call_trampoline, gen_std_dynamic_import_trampoline, gen_std_trampoline, CodegenError, + gen_import_call_trampoline, gen_std_dynamic_import_trampoline, gen_std_trampoline, }; use crate::machine_arm64::MachineARM64; use crate::machine_x64::MachineX86_64; @@ -31,12 +31,6 @@ use wasmer_types::{ TrapCode, TrapInformation, VMOffsets, }; -impl From for CompileError { - fn from(err: CodegenError) -> Self { - Self::Codegen(err.message) - } -} - /// A compiler that compiles a WebAssembly module with Singlepass. /// It does the compilation in one pass pub struct SinglepassCompiler { @@ -80,20 +74,6 @@ impl Compiler for SinglepassCompiler { } } - let simd_arch = match target.triple().architecture { - Architecture::X86_64 => { - if target.cpu_features().contains(CpuFeature::AVX) { - Some(CpuFeature::AVX) - } else if target.cpu_features().contains(CpuFeature::SSE42) { - Some(CpuFeature::SSE42) - } else { - return Err(CompileError::UnsupportedTarget( - "x86_64 without AVX or SSE 4.2".to_string(), - )); - } - } - _ => None, - }; let calling_convention = match target.triple().default_calling_convention() { Ok(CallingConvention::WindowsFastcall) => CallingConvention::WindowsFastcall, Ok(CallingConvention::SystemV) => CallingConvention::SystemV, @@ -144,6 +124,7 @@ impl Compiler for SinglepassCompiler { target, calling_convention, ) + .unwrap() }) .collect::>() .into_iter() @@ -173,7 +154,7 @@ impl Compiler for SinglepassCompiler { match target.triple().architecture { Architecture::X86_64 => { - let machine = MachineX86_64::new(simd_arch); + let machine = MachineX86_64::new(Some(target.clone()))?; let mut generator = FuncGen::new( module, &self.config, @@ -184,15 +165,14 @@ impl Compiler for SinglepassCompiler { &locals, machine, calling_convention, - ) - .map_err(to_compile_error)?; + )?; while generator.has_control_frames() { generator.set_srcloc(reader.original_position() as u32); let op = reader.read_operator()?; - generator.feed_operator(op).map_err(to_compile_error)?; + generator.feed_operator(op)?; } - generator.finalize(input).map_err(to_compile_error) + generator.finalize(input) } Architecture::Aarch64(_) => { let machine = MachineARM64::new(); @@ -206,15 +186,14 @@ impl Compiler for SinglepassCompiler { &locals, machine, calling_convention, - ) - .map_err(to_compile_error)?; + )?; while generator.has_control_frames() { generator.set_srcloc(reader.original_position() as u32); let op = reader.read_operator()?; - generator.feed_operator(op).map_err(to_compile_error)?; + generator.feed_operator(op)?; } - generator.finalize(input).map_err(to_compile_error) + generator.finalize(input) } _ => unimplemented!(), } @@ -228,7 +207,7 @@ impl Compiler for SinglepassCompiler { .values() .collect::>() .into_par_iter_if_rayon() - .map(|func_type| gen_std_trampoline(func_type, target, calling_convention)) + .map(|func_type| gen_std_trampoline(func_type, target, calling_convention).unwrap()) .collect::>() .into_iter() .collect::>(); @@ -244,6 +223,7 @@ impl Compiler for SinglepassCompiler { target, calling_convention, ) + .unwrap() }) .collect::>() .into_iter() @@ -278,20 +258,6 @@ impl Compiler for SinglepassCompiler { } } -trait ToCompileError { - fn to_compile_error(self) -> CompileError; -} - -impl ToCompileError for CodegenError { - fn to_compile_error(self) -> CompileError { - CompileError::Codegen(self.message) - } -} - -fn to_compile_error(x: T) -> CompileError { - x.to_compile_error() -} - trait IntoParIterIfRayon { type Output; fn into_par_iter_if_rayon(self) -> Self::Output; diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index 23ca12c45d5..bdf010a38b2 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -3,7 +3,6 @@ use crate::codegen_error; use crate::common_decl::Size; use crate::location::Location as AbstractLocation; pub use crate::location::{Multiplier, Reg}; -use crate::machine::CodegenError; pub use crate::machine::{Label, Offset}; use dynasm::dynasm; pub use dynasmrt::aarch64::{encode_logical_immediate_32bit, encode_logical_immediate_64bit}; @@ -12,8 +11,8 @@ use dynasmrt::{ VecAssembler, }; use wasmer_types::{ - CallingConvention, CustomSection, CustomSectionProtection, FunctionBody, FunctionIndex, - FunctionType, SectionBody, Type, VMOffsets, + CallingConvention, CompileError, CustomSection, CustomSectionProtection, FunctionBody, + FunctionIndex, FunctionType, SectionBody, Type, VMOffsets, }; type Assembler = VecAssembler; @@ -92,43 +91,43 @@ pub trait EmitterARM64 { fn finalize_function(&mut self); - fn emit_str(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CodegenError>; - fn emit_ldr(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CodegenError>; + fn emit_str(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CompileError>; + fn emit_ldr(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CompileError>; fn emit_stur( &mut self, sz: Size, reg: Location, addr: GPR, offset: i32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_ldur( &mut self, sz: Size, reg: Location, addr: GPR, offset: i32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_strdb( &mut self, sz: Size, reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_stria( &mut self, sz: Size, reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_ldria( &mut self, sz: Size, reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_stpdb( &mut self, sz: Size, @@ -136,7 +135,7 @@ pub trait EmitterARM64 { reg2: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_ldpia( &mut self, sz: Size, @@ -144,23 +143,23 @@ pub trait EmitterARM64 { reg2: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_ldrb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_ldrh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_ldrsb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_ldrsh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_ldrsw(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_strb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_strh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_ldrb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_ldrh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_ldrsb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_ldrsh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_ldrsw(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_strb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; + fn emit_strh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError>; - fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; - fn emit_movn(&mut self, sz: Size, reg: Location, val: u32) -> Result<(), CodegenError>; - fn emit_movz(&mut self, reg: Location, val: u32) -> Result<(), CodegenError>; - fn emit_movk(&mut self, reg: Location, val: u32, shift: u32) -> Result<(), CodegenError>; + fn emit_movn(&mut self, sz: Size, reg: Location, val: u32) -> Result<(), CompileError>; + fn emit_movz(&mut self, reg: Location, val: u32) -> Result<(), CompileError>; + fn emit_movk(&mut self, reg: Location, val: u32, shift: u32) -> Result<(), CompileError>; - fn emit_mov_imm(&mut self, dst: Location, val: u64) -> Result<(), CodegenError>; + fn emit_mov_imm(&mut self, dst: Location, val: u64) -> Result<(), CompileError>; fn emit_add( &mut self, @@ -168,35 +167,35 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_sub( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_mul( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_adds( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_subs( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_add_lsl( &mut self, @@ -205,10 +204,10 @@ pub trait EmitterARM64 { src2: Location, lsl: u32, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_tst(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_tst(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_lsl( &mut self, @@ -216,28 +215,28 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_lsr( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_asr( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_ror( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_or( &mut self, @@ -245,21 +244,21 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_and( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_eor( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_bfc( &mut self, @@ -267,7 +266,7 @@ pub trait EmitterARM64 { lsb: u32, width: u32, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_bfi( &mut self, se: Size, @@ -275,7 +274,7 @@ pub trait EmitterARM64 { lsb: u32, width: u32, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_udiv( &mut self, @@ -283,14 +282,14 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_sdiv( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// msub : c - a*b -> dst fn emit_msub( &mut self, @@ -299,69 +298,69 @@ pub trait EmitterARM64 { b: Location, c: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_sxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_sxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_sxtw(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_uxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_uxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_sxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_sxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_sxtw(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_uxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_uxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; - fn emit_cset(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CodegenError>; - fn emit_csetm(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CodegenError>; + fn emit_cset(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CompileError>; + fn emit_csetm(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CompileError>; fn emit_cinc( &mut self, sz: Size, src: Location, dst: Location, cond: Condition, - ) -> Result<(), CodegenError>; - fn emit_clz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_clz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError>; - fn emit_load_label(&mut self, reg: GPR, label: Label) -> Result<(), CodegenError>; - fn emit_b_label(&mut self, label: Label) -> Result<(), CodegenError>; + fn emit_label(&mut self, label: Label) -> Result<(), CompileError>; + fn emit_load_label(&mut self, reg: GPR, label: Label) -> Result<(), CompileError>; + fn emit_b_label(&mut self, label: Label) -> Result<(), CompileError>; fn emit_cbz_label(&mut self, sz: Size, reg: Location, label: Label) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_cbnz_label( &mut self, sz: Size, reg: Location, label: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_tbz_label( &mut self, sz: Size, reg: Location, n: u32, label: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_tbnz_label( &mut self, sz: Size, reg: Location, n: u32, label: Label, - ) -> Result<(), CodegenError>; - fn emit_bcond_label(&mut self, condition: Condition, label: Label) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_bcond_label(&mut self, condition: Condition, label: Label) -> Result<(), CompileError>; fn emit_bcond_label_far( &mut self, condition: Condition, label: Label, - ) -> Result<(), CodegenError>; - fn emit_b_register(&mut self, reg: GPR) -> Result<(), CodegenError>; - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError>; - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError>; - fn emit_ret(&mut self) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_b_register(&mut self, reg: GPR) -> Result<(), CompileError>; + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError>; + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError>; + fn emit_ret(&mut self) -> Result<(), CompileError>; - fn emit_udf(&mut self, payload: u16) -> Result<(), CodegenError>; - fn emit_dmb(&mut self) -> Result<(), CodegenError>; - fn emit_brk(&mut self) -> Result<(), CodegenError>; + fn emit_udf(&mut self, payload: u16) -> Result<(), CompileError>; + fn emit_dmb(&mut self) -> Result<(), CompileError>; + fn emit_brk(&mut self) -> Result<(), CompileError>; - fn emit_fcmp(&mut self, sz: Size, src1: Location, src2: Location) -> Result<(), CodegenError>; - fn emit_fneg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_fsqrt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_fcmp(&mut self, sz: Size, src1: Location, src2: Location) -> Result<(), CompileError>; + fn emit_fneg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_fsqrt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_fadd( &mut self, @@ -369,28 +368,28 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fsub( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fmul( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fdiv( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fmin( &mut self, @@ -398,19 +397,19 @@ pub trait EmitterARM64 { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fmax( &mut self, sz: Size, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_frintz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_frintn(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_frintm(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_frintp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_frintz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_frintn(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_frintm(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_frintp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_scvtf( &mut self, @@ -418,34 +417,34 @@ pub trait EmitterARM64 { src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_ucvtf( &mut self, sz_in: Size, src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError>; - fn emit_fcvt(&mut self, sz_in: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_fcvt(&mut self, sz_in: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_fcvtzs( &mut self, sz_in: Size, src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_fcvtzu( &mut self, sz_in: Size, src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_read_fpcr(&mut self, reg: GPR) -> Result<(), CodegenError>; - fn emit_write_fpcr(&mut self, reg: GPR) -> Result<(), CodegenError>; - fn emit_read_fpsr(&mut self, reg: GPR) -> Result<(), CodegenError>; - fn emit_write_fpsr(&mut self, reg: GPR) -> Result<(), CodegenError>; + fn emit_read_fpcr(&mut self, reg: GPR) -> Result<(), CompileError>; + fn emit_write_fpcr(&mut self, reg: GPR) -> Result<(), CompileError>; + fn emit_read_fpsr(&mut self, reg: GPR) -> Result<(), CompileError>; + fn emit_write_fpsr(&mut self, reg: GPR) -> Result<(), CompileError>; fn arch_supports_canonicalize_nan(&self) -> bool { true @@ -458,7 +457,7 @@ pub trait EmitterARM64 { fn arch_emit_indirect_call_with_trampoline( &mut self, _loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_indirect_call_with_trampoline unimplemented") } } @@ -488,7 +487,7 @@ impl EmitterARM64 for Assembler { ); } - fn emit_str(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CodegenError> { + fn emit_str(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CompileError> { match (sz, reg, addr) { (Size::S64, Location::GPR(reg), Location::Memory(addr, disp)) => { let reg = reg.into_index() as u32; @@ -560,7 +559,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_ldr(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CodegenError> { + fn emit_ldr(&mut self, sz: Size, reg: Location, addr: Location) -> Result<(), CompileError> { match (sz, reg, addr) { (Size::S64, Location::GPR(reg), Location::Memory(addr, disp)) => { let reg = reg.into_index() as u32; @@ -662,7 +661,7 @@ impl EmitterARM64 for Assembler { reg: Location, addr: GPR, offset: i32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!((-255..=255).contains(&offset)); match (sz, reg) { (Size::S64, Location::GPR(reg)) => { @@ -701,7 +700,7 @@ impl EmitterARM64 for Assembler { reg: Location, addr: GPR, offset: i32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!((-255..=255).contains(&offset)); match (sz, reg) { (Size::S64, Location::GPR(reg)) => { @@ -741,7 +740,7 @@ impl EmitterARM64 for Assembler { reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!(offset <= 255); match (sz, reg) { (Size::S64, Location::GPR(reg)) => { @@ -764,7 +763,7 @@ impl EmitterARM64 for Assembler { reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!(offset <= 255); match (sz, reg) { (Size::S64, Location::GPR(reg)) => { @@ -787,7 +786,7 @@ impl EmitterARM64 for Assembler { reg: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!(offset <= 255); match (sz, reg) { (Size::S64, Location::GPR(reg)) => { @@ -812,7 +811,7 @@ impl EmitterARM64 for Assembler { reg2: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!(offset <= 255); match (sz, reg1, reg2) { (Size::S64, Location::GPR(reg1), Location::GPR(reg2)) => { @@ -832,7 +831,7 @@ impl EmitterARM64 for Assembler { reg2: Location, addr: GPR, offset: u32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { assert!(offset <= 255); match (sz, reg1, reg2) { (Size::S64, Location::GPR(reg1), Location::GPR(reg2)) => { @@ -846,7 +845,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_ldrb(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ldrb(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (reg, dst) { (Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -871,7 +870,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_ldrh(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ldrh(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (reg, dst) { (Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -896,7 +895,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_ldrsb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ldrsb(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (sz, reg, dst) { (Size::S64, Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -940,7 +939,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_ldrsh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ldrsh(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (sz, reg, dst) { (Size::S64, Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -984,7 +983,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_ldrsw(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ldrsw(&mut self, sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (sz, reg, dst) { (Size::S64, Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -1009,7 +1008,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_strb(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_strb(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (reg, dst) { (Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -1034,7 +1033,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_strh(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_strh(&mut self, _sz: Size, reg: Location, dst: Location) -> Result<(), CompileError> { match (reg, dst) { (Location::GPR(reg), Location::Memory(addr, offset)) => { let reg = reg.into_index() as u32; @@ -1060,7 +1059,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -1137,7 +1136,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_movn(&mut self, sz: Size, reg: Location, val: u32) -> Result<(), CodegenError> { + fn emit_movn(&mut self, sz: Size, reg: Location, val: u32) -> Result<(), CompileError> { match (sz, reg) { (Size::S32, Location::GPR(reg)) => { let reg = reg.into_index() as u32; @@ -1151,7 +1150,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_movz(&mut self, reg: Location, val: u32) -> Result<(), CodegenError> { + fn emit_movz(&mut self, reg: Location, val: u32) -> Result<(), CompileError> { match reg { Location::GPR(reg) => { let reg = reg.into_index() as u32; @@ -1161,7 +1160,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_movk(&mut self, reg: Location, val: u32, shift: u32) -> Result<(), CodegenError> { + fn emit_movk(&mut self, reg: Location, val: u32, shift: u32) -> Result<(), CompileError> { match reg { Location::GPR(reg) => { let reg = reg.into_index() as u32; @@ -1172,7 +1171,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_mov_imm(&mut self, dst: Location, val: u64) -> Result<(), CodegenError> { + fn emit_mov_imm(&mut self, dst: Location, val: u64) -> Result<(), CompileError> { match dst { Location::GPR(dst) => { let dst = dst.into_index() as u32; @@ -1207,7 +1206,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1277,7 +1276,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1341,7 +1340,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1371,7 +1370,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1431,7 +1430,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1472,7 +1471,7 @@ impl EmitterARM64 for Assembler { src2: Location, lsl: u32, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1492,7 +1491,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -1538,7 +1537,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_tst(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_tst(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -1582,7 +1581,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1657,7 +1656,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1732,7 +1731,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1807,7 +1806,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1875,7 +1874,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1923,7 +1922,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -1971,7 +1970,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S64, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -2020,7 +2019,7 @@ impl EmitterARM64 for Assembler { lsb: u32, width: u32, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, dst) { (Size::S32, Location::GPR(dst)) => { dynasm!(self ; bfc W(dst as u32), lsb, width); @@ -2039,7 +2038,7 @@ impl EmitterARM64 for Assembler { lsb: u32, width: u32, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::GPR(src), Location::GPR(dst)) => { dynasm!(self ; bfi W(dst as u32), W(src as u32), lsb, width); @@ -2058,7 +2057,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -2088,7 +2087,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::GPR(src1), Location::GPR(src2), Location::GPR(dst)) => { let src1 = src1.into_index() as u32; @@ -2121,7 +2120,7 @@ impl EmitterARM64 for Assembler { b: Location, c: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, a, b, c, dst) { ( Size::S32, @@ -2161,7 +2160,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_sxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_sxtb(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2177,7 +2176,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_sxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_sxth(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2193,7 +2192,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_sxtw(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_sxtw(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (src, dst) { (Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2204,7 +2203,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_uxtb(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_uxtb(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (src, dst) { (Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2215,7 +2214,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_uxth(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_uxth(&mut self, _sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (src, dst) { (Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2227,7 +2226,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_cset(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CodegenError> { + fn emit_cset(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CompileError> { match (sz, dst) { (Size::S32, Location::GPR(reg)) => { let reg = reg as u32; @@ -2273,7 +2272,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_csetm(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CodegenError> { + fn emit_csetm(&mut self, sz: Size, dst: Location, cond: Condition) -> Result<(), CompileError> { match (sz, dst) { (Size::S32, Location::GPR(reg)) => { let reg = reg as u32; @@ -2325,7 +2324,7 @@ impl EmitterARM64 for Assembler { src: Location, dst: Location, cond: Condition, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2374,7 +2373,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_clz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_clz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2390,7 +2389,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -2407,17 +2406,17 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_label(&mut self, label: Label) -> Result<(), CompileError> { dynasm!(self ; => label); Ok(()) } - fn emit_load_label(&mut self, reg: GPR, label: Label) -> Result<(), CodegenError> { + fn emit_load_label(&mut self, reg: GPR, label: Label) -> Result<(), CompileError> { let reg = reg.into_index() as u32; dynasm!(self ; adr X(reg), =>label); Ok(()) } - fn emit_b_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_b_label(&mut self, label: Label) -> Result<(), CompileError> { dynasm!(self ; b =>label); Ok(()) } @@ -2426,7 +2425,7 @@ impl EmitterARM64 for Assembler { sz: Size, reg: Location, label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, reg) { (Size::S32, Location::GPR(reg)) => { let reg = reg.into_index() as u32; @@ -2445,7 +2444,7 @@ impl EmitterARM64 for Assembler { sz: Size, reg: Location, label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, reg) { (Size::S32, Location::GPR(reg)) => { let reg = reg.into_index() as u32; @@ -2465,7 +2464,7 @@ impl EmitterARM64 for Assembler { reg: Location, n: u32, label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, reg) { (Size::S32, Location::GPR(reg)) => { let reg = reg.into_index() as u32; @@ -2491,7 +2490,7 @@ impl EmitterARM64 for Assembler { reg: Location, n: u32, label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, reg) { (Size::S32, Location::GPR(reg)) => { let reg = reg.into_index() as u32; @@ -2511,7 +2510,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_bcond_label(&mut self, condition: Condition, label: Label) -> Result<(), CodegenError> { + fn emit_bcond_label(&mut self, condition: Condition, label: Label) -> Result<(), CompileError> { match condition { Condition::Eq => dynasm!(self ; b.eq => label), Condition::Ne => dynasm!(self ; b.ne => label), @@ -2535,7 +2534,7 @@ impl EmitterARM64 for Assembler { &mut self, condition: Condition, label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let cont: Label = self.get_label(); match condition { // if not condition than continue @@ -2559,37 +2558,37 @@ impl EmitterARM64 for Assembler { self.emit_label(cont)?; Ok(()) } - fn emit_b_register(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_b_register(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; br X(reg.into_index() as u32)); Ok(()) } - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError> { dynasm!(self ; bl =>label); Ok(()) } - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; blr X(reg.into_index() as u32)); Ok(()) } - fn emit_ret(&mut self) -> Result<(), CodegenError> { + fn emit_ret(&mut self) -> Result<(), CompileError> { dynasm!(self ; ret); Ok(()) } - fn emit_udf(&mut self, payload: u16) -> Result<(), CodegenError> { + fn emit_udf(&mut self, payload: u16) -> Result<(), CompileError> { dynasm!(self ; udf (payload as u32)); Ok(()) } - fn emit_dmb(&mut self) -> Result<(), CodegenError> { + fn emit_dmb(&mut self) -> Result<(), CompileError> { dynasm!(self ; dmb ish); Ok(()) } - fn emit_brk(&mut self) -> Result<(), CodegenError> { + fn emit_brk(&mut self) -> Result<(), CompileError> { dynasm!(self ; brk 0); Ok(()) } - fn emit_fcmp(&mut self, sz: Size, src1: Location, src2: Location) -> Result<(), CodegenError> { + fn emit_fcmp(&mut self, sz: Size, src1: Location, src2: Location) -> Result<(), CompileError> { match (sz, src1, src2) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2)) => { let src1 = src1.into_index() as u32; @@ -2606,7 +2605,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_fneg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_fneg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2622,7 +2621,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_fsqrt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_fsqrt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2645,7 +2644,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2675,7 +2674,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2705,7 +2704,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2735,7 +2734,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2766,7 +2765,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2796,7 +2795,7 @@ impl EmitterARM64 for Assembler { src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src1, src2, dst) { (Size::S32, Location::SIMD(src1), Location::SIMD(src2), Location::SIMD(dst)) => { let src1 = src1.into_index() as u32; @@ -2821,7 +2820,7 @@ impl EmitterARM64 for Assembler { Ok(()) } - fn emit_frintz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_frintz(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2837,7 +2836,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_frintn(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_frintn(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2853,7 +2852,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_frintm(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_frintm(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2869,7 +2868,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_frintp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_frintp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2892,7 +2891,7 @@ impl EmitterARM64 for Assembler { src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_in, src, sz_out, dst) { (Size::S32, Location::GPR(src), Size::S32, Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2930,7 +2929,7 @@ impl EmitterARM64 for Assembler { src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_in, src, sz_out, dst) { (Size::S32, Location::GPR(src), Size::S32, Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2962,7 +2961,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } - fn emit_fcvt(&mut self, sz_in: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_fcvt(&mut self, sz_in: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz_in, src, dst) { (Size::S32, Location::SIMD(src), Location::SIMD(dst)) => { let src = src.into_index() as u32; @@ -2989,7 +2988,7 @@ impl EmitterARM64 for Assembler { src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_in, src, sz_out, dst) { (Size::S32, Location::SIMD(src), Size::S32, Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -3027,7 +3026,7 @@ impl EmitterARM64 for Assembler { src: Location, sz_out: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_in, src, sz_out, dst) { (Size::S32, Location::SIMD(src), Size::S32, Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -3061,20 +3060,20 @@ impl EmitterARM64 for Assembler { } // 1 011 0100 0100 000 => fpcr - fn emit_read_fpcr(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_read_fpcr(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; mrs X(reg as u32), 0b1_011_0100_0100_000); Ok(()) } - fn emit_write_fpcr(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_write_fpcr(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; msr 0b1_011_0100_0100_000, X(reg as u32)); Ok(()) } // 1 011 0100 0100 001 => fpsr - fn emit_read_fpsr(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_read_fpsr(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; mrs X(reg as u32), 0b1_011_0100_0100_001); Ok(()) } - fn emit_write_fpsr(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_write_fpsr(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; msr 0b1_011_0100_0100_001, X(reg as u32)); Ok(()) } @@ -3083,7 +3082,7 @@ impl EmitterARM64 for Assembler { pub fn gen_std_trampoline_arm64( sig: &FunctionType, calling_convention: CallingConvention, -) -> Result { +) -> Result { let mut a = Assembler::new(0); let fptr = GPR::X27; @@ -3210,7 +3209,7 @@ pub fn gen_std_dynamic_import_trampoline_arm64( vmoffsets: &VMOffsets, sig: &FunctionType, calling_convention: CallingConvention, -) -> Result { +) -> Result { let mut a = Assembler::new(0); // Allocate argument array. let stack_offset: usize = 16 * std::cmp::max(sig.params().len(), sig.results().len()); @@ -3368,7 +3367,7 @@ pub fn gen_import_call_trampoline_arm64( index: FunctionIndex, sig: &FunctionType, calling_convention: CallingConvention, -) -> Result { +) -> Result { let mut a = Assembler::new(0); // Singlepass internally treats all arguments as integers diff --git a/lib/compiler-singlepass/src/emitter_x64.rs b/lib/compiler-singlepass/src/emitter_x64.rs index 635635e9d72..0b45f562b8b 100644 --- a/lib/compiler-singlepass/src/emitter_x64.rs +++ b/lib/compiler-singlepass/src/emitter_x64.rs @@ -2,13 +2,12 @@ use crate::codegen_error; use crate::common_decl::Size; use crate::location::Location as AbstractLocation; pub use crate::location::Multiplier; -use crate::machine::CodegenError; pub use crate::machine::{Label, Offset}; use crate::machine_x64::AssemblerX64; pub use crate::x64_decl::{GPR, XMM}; use dynasm::dynasm; use dynasmrt::{AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi}; -use wasmer_types::CpuFeature; +use wasmer_types::{CompileError, CpuFeature}; /// Force `dynasm!` to use the correct arch (x64) when cross-compiling. /// `dynasm!` proc-macro tries to auto-detect it by default by looking at the @@ -68,265 +67,265 @@ pub trait EmitterX64 { fn get_offset(&self) -> Offset; fn get_jmp_instr_size(&self) -> u8; - fn finalize_function(&mut self) -> Result<(), CodegenError> { + fn finalize_function(&mut self) -> Result<(), CompileError> { Ok(()) } - fn emit_u64(&mut self, x: u64) -> Result<(), CodegenError>; - fn emit_bytes(&mut self, bytes: &[u8]) -> Result<(), CodegenError>; + fn emit_u64(&mut self, x: u64) -> Result<(), CompileError>; + fn emit_bytes(&mut self, bytes: &[u8]) -> Result<(), CompileError>; - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError>; + fn emit_label(&mut self, label: Label) -> Result<(), CompileError>; - fn emit_nop(&mut self) -> Result<(), CodegenError>; + fn emit_nop(&mut self) -> Result<(), CompileError>; /// A high-level assembler method. Emits an instruction sequence of length `n` that is functionally /// equivalent to a `nop` instruction, without guarantee about the underlying implementation. - fn emit_nop_n(&mut self, n: usize) -> Result<(), CodegenError>; - - fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_lea(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_lea_label(&mut self, label: Label, dst: Location) -> Result<(), CodegenError>; - fn emit_cdq(&mut self) -> Result<(), CodegenError>; - fn emit_cqo(&mut self) -> Result<(), CodegenError>; - fn emit_xor(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_jmp(&mut self, condition: Condition, label: Label) -> Result<(), CodegenError>; - fn emit_jmp_location(&mut self, loc: Location) -> Result<(), CodegenError>; - fn emit_set(&mut self, condition: Condition, dst: GPR) -> Result<(), CodegenError>; - fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CodegenError>; - fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CodegenError>; - fn emit_cmp(&mut self, sz: Size, left: Location, right: Location) -> Result<(), CodegenError>; - fn emit_add(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_sub(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_neg(&mut self, sz: Size, value: Location) -> Result<(), CodegenError>; - fn emit_imul(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_imul_imm32_gpr64(&mut self, src: u32, dst: GPR) -> Result<(), CodegenError>; - fn emit_div(&mut self, sz: Size, divisor: Location) -> Result<(), CodegenError>; - fn emit_idiv(&mut self, sz: Size, divisor: Location) -> Result<(), CodegenError>; - fn emit_shl(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_shr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_sar(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_rol(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_ror(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_and(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_test(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_or(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_bsr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_bsf(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; - fn emit_popcnt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + fn emit_nop_n(&mut self, n: usize) -> Result<(), CompileError>; + + fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_lea(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_lea_label(&mut self, label: Label, dst: Location) -> Result<(), CompileError>; + fn emit_cdq(&mut self) -> Result<(), CompileError>; + fn emit_cqo(&mut self) -> Result<(), CompileError>; + fn emit_xor(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_jmp(&mut self, condition: Condition, label: Label) -> Result<(), CompileError>; + fn emit_jmp_location(&mut self, loc: Location) -> Result<(), CompileError>; + fn emit_set(&mut self, condition: Condition, dst: GPR) -> Result<(), CompileError>; + fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CompileError>; + fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CompileError>; + fn emit_cmp(&mut self, sz: Size, left: Location, right: Location) -> Result<(), CompileError>; + fn emit_add(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_sub(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_neg(&mut self, sz: Size, value: Location) -> Result<(), CompileError>; + fn emit_imul(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_imul_imm32_gpr64(&mut self, src: u32, dst: GPR) -> Result<(), CompileError>; + fn emit_div(&mut self, sz: Size, divisor: Location) -> Result<(), CompileError>; + fn emit_idiv(&mut self, sz: Size, divisor: Location) -> Result<(), CompileError>; + fn emit_shl(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_shr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_sar(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_rol(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_ror(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_and(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_test(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_or(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_bsr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_bsf(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; + fn emit_popcnt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_movzx( &mut self, sz_src: Size, src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_movsx( &mut self, sz_src: Size, src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError>; - fn emit_xchg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_xchg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError>; fn emit_lock_xadd( &mut self, sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_lock_cmpxchg( &mut self, sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError>; - fn emit_rep_stosq(&mut self) -> Result<(), CodegenError>; - - fn emit_btc_gpr_imm8_32(&mut self, src: u8, dst: GPR) -> Result<(), CodegenError>; - fn emit_btc_gpr_imm8_64(&mut self, src: u8, dst: GPR) -> Result<(), CodegenError>; - - fn emit_cmovae_gpr_32(&mut self, src: GPR, dst: GPR) -> Result<(), CodegenError>; - fn emit_cmovae_gpr_64(&mut self, src: GPR, dst: GPR) -> Result<(), CodegenError>; - - fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CodegenError>; - fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CodegenError>; - fn emit_vxorps(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vxorpd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - - fn emit_vaddss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vaddsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vsubss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vsubsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vmulss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vmulsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vdivss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vdivsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vmaxss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vmaxsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vminss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vminsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; + fn emit_rep_stosq(&mut self) -> Result<(), CompileError>; + + fn emit_btc_gpr_imm8_32(&mut self, src: u8, dst: GPR) -> Result<(), CompileError>; + fn emit_btc_gpr_imm8_64(&mut self, src: u8, dst: GPR) -> Result<(), CompileError>; + + fn emit_cmovae_gpr_32(&mut self, src: GPR, dst: GPR) -> Result<(), CompileError>; + fn emit_cmovae_gpr_64(&mut self, src: GPR, dst: GPR) -> Result<(), CompileError>; + + fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CompileError>; + fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CompileError>; + fn emit_vxorps(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vxorpd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + + fn emit_vaddss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vaddsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vsubss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vsubsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vmulss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vmulsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vdivss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vdivsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vmaxss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vmaxsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vminss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vminsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; fn emit_vcmpeqss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpeqsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpneqss( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcmpneqsd( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcmpltss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpltsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpless(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmplesd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpgtss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpgtsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpgess(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpgesd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) - -> Result<(), CodegenError>; + -> Result<(), CompileError>; fn emit_vcmpunordss( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcmpunordsd( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcmpordss( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcmpordsd( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_vsqrtss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_vsqrtsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; + fn emit_vsqrtss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_vsqrtsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; fn emit_vroundss_nearest( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundss_floor( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundss_ceil( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundss_trunc( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundsd_nearest( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundsd_floor( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundsd_ceil( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vroundsd_trunc( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcvtss2sd( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcvtsd2ss( &mut self, src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; - fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CodegenError>; + fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; + fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CompileError>; - fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError>; - fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError>; - fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError>; - fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError>; + fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError>; + fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError>; + fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError>; + fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError>; fn emit_vcvtsi2ss_32( &mut self, src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcvtsi2ss_64( &mut self, src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcvtsi2sd_32( &mut self, src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vcvtsi2sd_64( &mut self, src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vblendvps( &mut self, @@ -334,92 +333,92 @@ pub trait EmitterX64 { src2: XMMOrMemory, mask: XMM, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; fn emit_vblendvpd( &mut self, src1: XMM, src2: XMMOrMemory, mask: XMM, dst: XMM, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; - fn emit_test_gpr_64(&mut self, reg: GPR) -> Result<(), CodegenError>; + fn emit_test_gpr_64(&mut self, reg: GPR) -> Result<(), CompileError>; - fn emit_ud2(&mut self) -> Result<(), CodegenError>; - fn emit_ud1_payload(&mut self, payload: u8) -> Result<(), CodegenError>; - fn emit_ret(&mut self) -> Result<(), CodegenError>; - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError>; - fn emit_call_location(&mut self, loc: Location) -> Result<(), CodegenError>; + fn emit_ud2(&mut self) -> Result<(), CompileError>; + fn emit_ud1_payload(&mut self, payload: u8) -> Result<(), CompileError>; + fn emit_ret(&mut self) -> Result<(), CompileError>; + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError>; + fn emit_call_location(&mut self, loc: Location) -> Result<(), CompileError>; - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError>; + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError>; - fn emit_bkpt(&mut self) -> Result<(), CodegenError>; + fn emit_bkpt(&mut self) -> Result<(), CompileError>; - fn emit_host_redirection(&mut self, target: GPR) -> Result<(), CodegenError>; + fn emit_host_redirection(&mut self, target: GPR) -> Result<(), CompileError>; fn arch_has_itruncf(&self) -> bool { false } - fn arch_emit_i32_trunc_sf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i32_trunc_sf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i32_trunc_sf32 unimplemented") } - fn arch_emit_i32_trunc_sf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i32_trunc_sf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i32_trunc_sf64 unimplemented") } - fn arch_emit_i32_trunc_uf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i32_trunc_uf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i32_trunc_uf32 unimplemented") } - fn arch_emit_i32_trunc_uf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i32_trunc_uf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i32_trunc_uf64 unimplemented") } - fn arch_emit_i64_trunc_sf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i64_trunc_sf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i64_trunc_sf32 unimplemented") } - fn arch_emit_i64_trunc_sf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i64_trunc_sf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i64_trunc_sf64 unimplemented") } - fn arch_emit_i64_trunc_uf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i64_trunc_uf32(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i64_trunc_uf32 unimplemented") } - fn arch_emit_i64_trunc_uf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CodegenError> { + fn arch_emit_i64_trunc_uf64(&mut self, _src: XMM, _dst: GPR) -> Result<(), CompileError> { codegen_error!("singplepass arch_emit_i64_trunc_uf64 unimplemented") } fn arch_has_fconverti(&self) -> bool { false } - fn arch_emit_f32_convert_si32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f32_convert_si32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f32_convert_si32 unimplemented") } - fn arch_emit_f32_convert_si64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f32_convert_si64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f32_convert_si64 unimplemented") } - fn arch_emit_f32_convert_ui32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f32_convert_ui32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f32_convert_ui32 unimplemented") } - fn arch_emit_f32_convert_ui64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f32_convert_ui64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f32_convert_ui64 unimplemented") } - fn arch_emit_f64_convert_si32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f64_convert_si32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f64_convert_si32 unimplemented") } - fn arch_emit_f64_convert_si64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f64_convert_si64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f64_convert_si64 unimplemented") } - fn arch_emit_f64_convert_ui32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f64_convert_ui32(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f64_convert_ui32 unimplemented") } - fn arch_emit_f64_convert_ui64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f64_convert_ui64(&mut self, _src: GPR, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f64_convert_ui64 unimplemented") } fn arch_has_fneg(&self) -> bool { false } - fn arch_emit_f32_neg(&mut self, _src: XMM, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f32_neg(&mut self, _src: XMM, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f32_neg unimplemented") } - fn arch_emit_f64_neg(&mut self, _src: XMM, _dst: XMM) -> Result<(), CodegenError> { + fn arch_emit_f64_neg(&mut self, _src: XMM, _dst: XMM) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_f64_neg unimplemented") } @@ -431,7 +430,7 @@ pub trait EmitterX64 { _sz: Size, _src: Location, _dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_lzcnt unimplemented") } fn arch_emit_tzcnt( @@ -439,7 +438,7 @@ pub trait EmitterX64 { _sz: Size, _src: Location, _dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_tzcnt unimplemented") } @@ -454,18 +453,18 @@ pub trait EmitterX64 { fn arch_emit_indirect_call_with_trampoline( &mut self, _loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass arch_emit_indirect_call_with_trampoline unimplemented") } // Emits entry trampoline just before the real function. - fn arch_emit_entry_trampoline(&mut self) -> Result<(), CodegenError> { + fn arch_emit_entry_trampoline(&mut self) -> Result<(), CompileError> { Ok(()) } // Byte offset from the beginning of a `mov Imm64, GPR` instruction to the imm64 value. // Required to support emulation on Aarch64. - fn arch_mov64_imm_offset(&self) -> Result { + fn arch_mov64_imm_offset(&self) -> Result { codegen_error!("singlepass arch_mov64_imm_offset unimplemented") } } @@ -934,7 +933,7 @@ impl EmitterX64 for AssemblerX64 { 5 } - fn finalize_function(&mut self) -> Result<(), CodegenError> { + fn finalize_function(&mut self) -> Result<(), CompileError> { dynasm!( self ; const_neg_one_32: @@ -947,29 +946,29 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_u64(&mut self, x: u64) -> Result<(), CodegenError> { + fn emit_u64(&mut self, x: u64) -> Result<(), CompileError> { self.push_u64(x); Ok(()) } - fn emit_bytes(&mut self, bytes: &[u8]) -> Result<(), CodegenError> { + fn emit_bytes(&mut self, bytes: &[u8]) -> Result<(), CompileError> { for &b in bytes { self.push(b); } Ok(()) } - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_label(&mut self, label: Label) -> Result<(), CompileError> { dynasm!(self ; => label); Ok(()) } - fn emit_nop(&mut self) -> Result<(), CodegenError> { + fn emit_nop(&mut self) -> Result<(), CompileError> { dynasm!(self ; nop); Ok(()) } - fn emit_nop_n(&mut self, mut n: usize) -> Result<(), CodegenError> { + fn emit_nop_n(&mut self, mut n: usize) -> Result<(), CompileError> { /* 1 90H NOP 2 66 90H 66 NOP @@ -1001,7 +1000,7 @@ impl EmitterX64 for AssemblerX64 { self.emit_bytes(seq) } - fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_mov(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { // fast path if let (Location::Imm32(0), Location::GPR(x)) = (src, dst) { dynasm!(self ; xor Rd(x as u8), Rd(x as u8)); @@ -1088,7 +1087,7 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_lea(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_lea(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S32, Location::Memory(src, disp), Location::GPR(dst)) => { dynasm!(self ; lea Rd(dst as u8), [Rq(src as u8) + disp]); @@ -1134,7 +1133,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_lea_label(&mut self, label: Label, dst: Location) -> Result<(), CodegenError> { + fn emit_lea_label(&mut self, label: Label, dst: Location) -> Result<(), CompileError> { match dst { Location::GPR(x) => { dynasm!(self ; lea Rq(x as u8), [=>label]); @@ -1143,21 +1142,21 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_cdq(&mut self) -> Result<(), CodegenError> { + fn emit_cdq(&mut self) -> Result<(), CompileError> { dynasm!(self ; cdq); Ok(()) } - fn emit_cqo(&mut self) -> Result<(), CodegenError> { + fn emit_cqo(&mut self) -> Result<(), CompileError> { dynasm!(self ; cqo); Ok(()) } - fn emit_xor(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_xor(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_all_nofp!(xor, self, sz, src, dst, { codegen_error!("singlepass can't emit XOR {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_jmp(&mut self, condition: Condition, label: Label) -> Result<(), CodegenError> { + fn emit_jmp(&mut self, condition: Condition, label: Label) -> Result<(), CompileError> { match condition { Condition::None => jmp_op!(jmp, self, label), Condition::Above => jmp_op!(ja, self, label), @@ -1175,7 +1174,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_jmp_location(&mut self, loc: Location) -> Result<(), CodegenError> { + fn emit_jmp_location(&mut self, loc: Location) -> Result<(), CompileError> { match loc { Location::GPR(x) => dynasm!(self ; jmp Rq(x as u8)), Location::Memory(base, disp) => dynasm!(self ; jmp QWORD [Rq(base as u8) + disp]), @@ -1183,7 +1182,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_set(&mut self, condition: Condition, dst: GPR) -> Result<(), CodegenError> { + fn emit_set(&mut self, condition: Condition, dst: GPR) -> Result<(), CompileError> { match condition { Condition::Above => dynasm!(self ; seta Rb(dst as u8)), Condition::AboveEqual => dynasm!(self ; setae Rb(dst as u8)), @@ -1201,7 +1200,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CodegenError> { + fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CompileError> { match (sz, src) { (Size::S64, Location::Imm32(src)) => dynasm!(self ; push src as i32), (Size::S64, Location::GPR(src)) => dynasm!(self ; push Rq(src as u8)), @@ -1212,7 +1211,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CodegenError> { + fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CompileError> { match (sz, dst) { (Size::S64, Location::GPR(dst)) => dynasm!(self ; pop Rq(dst as u8)), (Size::S64, Location::Memory(dst, disp)) => { @@ -1222,7 +1221,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_cmp(&mut self, sz: Size, left: Location, right: Location) -> Result<(), CodegenError> { + fn emit_cmp(&mut self, sz: Size, left: Location, right: Location) -> Result<(), CompileError> { // Constant elimination for comparison between consts. // // Only needed for `emit_cmp`, since other binary operators actually write to `right` and `right` must @@ -1247,7 +1246,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_add(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_add(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { // Fast path if let Location::Imm32(0) = src { return Ok(()); @@ -1257,7 +1256,7 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_sub(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_sub(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { // Fast path if let Location::Imm32(0) = src { return Ok(()); @@ -1267,7 +1266,7 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_neg(&mut self, sz: Size, value: Location) -> Result<(), CodegenError> { + fn emit_neg(&mut self, sz: Size, value: Location) -> Result<(), CompileError> { match (sz, value) { (Size::S8, Location::GPR(value)) => dynasm!(self ; neg Rb(value as u8)), (Size::S8, Location::Memory(value, disp)) => { @@ -1289,7 +1288,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_imul(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_imul(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_gpr_gpr!(imul, self, sz, src, dst, { binop_mem_gpr!(imul, self, sz, src, dst, { codegen_error!("singlepass can't emit IMUL {:?} {:?} {:?}", sz, src, dst) @@ -1297,71 +1296,71 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_imul_imm32_gpr64(&mut self, src: u32, dst: GPR) -> Result<(), CodegenError> { + fn emit_imul_imm32_gpr64(&mut self, src: u32, dst: GPR) -> Result<(), CompileError> { dynasm!(self ; imul Rq(dst as u8), Rq(dst as u8), src as i32); Ok(()) } - fn emit_div(&mut self, sz: Size, divisor: Location) -> Result<(), CodegenError> { + fn emit_div(&mut self, sz: Size, divisor: Location) -> Result<(), CompileError> { unop_gpr_or_mem!(div, self, sz, divisor, { codegen_error!("singlepass can't emit DIV {:?} {:?}", sz, divisor) }); Ok(()) } - fn emit_idiv(&mut self, sz: Size, divisor: Location) -> Result<(), CodegenError> { + fn emit_idiv(&mut self, sz: Size, divisor: Location) -> Result<(), CompileError> { unop_gpr_or_mem!(idiv, self, sz, divisor, { codegen_error!("singlepass can't emit IDIV {:?} {:?}", sz, divisor) }); Ok(()) } - fn emit_shl(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_shl(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_shift!(shl, self, sz, src, dst, { codegen_error!("singlepass can't emit SHL {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_shr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_shr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_shift!(shr, self, sz, src, dst, { codegen_error!("singlepass can't emit SHR {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_sar(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_sar(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_shift!(sar, self, sz, src, dst, { codegen_error!("singlepass can't emit SAR {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_rol(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_rol(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_shift!(rol, self, sz, src, dst, { codegen_error!("singlepass can't emit ROL {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_ror(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_ror(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_shift!(ror, self, sz, src, dst, { codegen_error!("singlepass can't emit ROR {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_and(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_and(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_all_nofp!(and, self, sz, src, dst, { codegen_error!("singlepass can't emit AND {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_test(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_test(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_all_nofp!(test, self, sz, src, dst, { codegen_error!("singlepass can't emit TEST {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_or(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_or(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_all_nofp!(or, self, sz, src, dst, { codegen_error!("singlepass can't emit OR {:?} {:?} {:?}", sz, src, dst) }); Ok(()) } - fn emit_bsr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_bsr(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_gpr_gpr!(bsr, self, sz, src, dst, { binop_mem_gpr!(bsr, self, sz, src, dst, { codegen_error!("singlepass can't emit BSR {:?} {:?} {:?}", sz, src, dst) @@ -1369,7 +1368,7 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_bsf(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_bsf(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_gpr_gpr!(bsf, self, sz, src, dst, { binop_mem_gpr!(bsf, self, sz, src, dst, { codegen_error!("singlepass can't emit BSF {:?} {:?} {:?}", sz, src, dst) @@ -1377,7 +1376,7 @@ impl EmitterX64 for AssemblerX64 { }); Ok(()) } - fn emit_popcnt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_popcnt(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { binop_gpr_gpr!(popcnt, self, sz, src, dst, { binop_mem_gpr!(popcnt, self, sz, src, dst, { codegen_error!("singlepass can't emit POPCNT {:?} {:?} {:?}", sz, src, dst) @@ -1391,7 +1390,7 @@ impl EmitterX64 for AssemblerX64 { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_src, src, sz_dst, dst) { (Size::S8, Location::GPR(src), Size::S32, Location::GPR(dst)) => { dynasm!(self ; movzx Rd(dst as u8), Rb(src as u8)); @@ -1435,7 +1434,7 @@ impl EmitterX64 for AssemblerX64 { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz_src, src, sz_dst, dst) { (Size::S8, Location::GPR(src), Size::S32, Location::GPR(dst)) => { dynasm!(self ; movsx Rd(dst as u8), Rb(src as u8)); @@ -1480,7 +1479,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_xchg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CodegenError> { + fn emit_xchg(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S8, Location::GPR(src), Location::GPR(dst)) => { dynasm!(self ; xchg Rb(dst as u8), Rb(src as u8)); @@ -1528,7 +1527,7 @@ impl EmitterX64 for AssemblerX64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S8, Location::GPR(src), Location::Memory(dst, disp)) => { dynasm!(self ; lock xadd [Rq(dst as u8) + disp], Rb(src as u8)); @@ -1557,7 +1556,7 @@ impl EmitterX64 for AssemblerX64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S8, Location::GPR(src), Location::Memory(dst, disp)) => { dynasm!(self ; lock cmpxchg [Rq(dst as u8) + disp], Rb(src as u8)); @@ -1581,31 +1580,31 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_rep_stosq(&mut self) -> Result<(), CodegenError> { + fn emit_rep_stosq(&mut self) -> Result<(), CompileError> { dynasm!(self ; rep stosq); Ok(()) } - fn emit_btc_gpr_imm8_32(&mut self, src: u8, dst: GPR) -> Result<(), CodegenError> { + fn emit_btc_gpr_imm8_32(&mut self, src: u8, dst: GPR) -> Result<(), CompileError> { dynasm!(self ; btc Rd(dst as u8), BYTE src as i8); Ok(()) } - fn emit_btc_gpr_imm8_64(&mut self, src: u8, dst: GPR) -> Result<(), CodegenError> { + fn emit_btc_gpr_imm8_64(&mut self, src: u8, dst: GPR) -> Result<(), CompileError> { dynasm!(self ; btc Rq(dst as u8), BYTE src as i8); Ok(()) } - fn emit_cmovae_gpr_32(&mut self, src: GPR, dst: GPR) -> Result<(), CodegenError> { + fn emit_cmovae_gpr_32(&mut self, src: GPR, dst: GPR) -> Result<(), CompileError> { dynasm!(self ; cmovae Rd(dst as u8), Rd(src as u8)); Ok(()) } - fn emit_cmovae_gpr_64(&mut self, src: GPR, dst: GPR) -> Result<(), CodegenError> { + fn emit_cmovae_gpr_64(&mut self, src: GPR, dst: GPR) -> Result<(), CompileError> { dynasm!(self ; cmovae Rq(dst as u8), Rq(src as u8)); Ok(()) } - fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CodegenError> { + fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CompileError> { match (src, dst) { (XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => { dynasm!(self ; movaps Rx(dst as u8), Rx(src as u8)) @@ -1621,7 +1620,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CodegenError> { + fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) -> Result<(), CompileError> { match (src, dst) { (XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => { dynasm!(self ; movapd Rx(dst as u8), Rx(src as u8)) @@ -1636,7 +1635,7 @@ impl EmitterX64 for AssemblerX64 { }; Ok(()) } - fn emit_vxorps(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vxorps(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vxorps)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(xorps)(self, Precision::Single, src1, src2, dst), @@ -1644,7 +1643,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vxorpd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vxorpd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vxorpd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(xorpd)(self, Precision::Double, src1, src2, dst), @@ -1652,7 +1651,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vaddss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vaddss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vaddss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(addss)(self, Precision::Single, src1, src2, dst), @@ -1660,7 +1659,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vaddsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vaddsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vaddsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(addsd)(self, Precision::Double, src1, src2, dst), @@ -1668,7 +1667,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vsubss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vsubss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vsubss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(subss)(self, Precision::Single, src1, src2, dst), @@ -1676,7 +1675,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vsubsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vsubsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vsubsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(subsd)(self, Precision::Double, src1, src2, dst), @@ -1684,7 +1683,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vmulss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vmulss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vmulss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(mulss)(self, Precision::Single, src1, src2, dst), @@ -1692,7 +1691,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vmulsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vmulsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vmulsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(mulsd)(self, Precision::Double, src1, src2, dst), @@ -1700,7 +1699,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vdivss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vdivss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vdivss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(divss)(self, Precision::Single, src1, src2, dst), @@ -1708,7 +1707,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vdivsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vdivsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vdivsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(divsd)(self, Precision::Double, src1, src2, dst), @@ -1716,7 +1715,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vmaxss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vmaxss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vmaxss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(maxss)(self, Precision::Single, src1, src2, dst), @@ -1724,7 +1723,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vmaxsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vmaxsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vmaxsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(maxsd)(self, Precision::Double, src1, src2, dst), @@ -1732,7 +1731,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vminss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vminss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vminss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(minss)(self, Precision::Single, src1, src2, dst), @@ -1740,7 +1739,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vminsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vminsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vminsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(minsd)(self, Precision::Double, src1, src2, dst), @@ -1753,7 +1752,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpeqss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 0)(self, Precision::Single, src1, src2, dst), @@ -1766,7 +1765,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpeqsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 0)(self, Precision::Double, src1, src2, dst), @@ -1779,7 +1778,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpneqss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 4)(self, Precision::Single, src1, src2, dst), @@ -1792,7 +1791,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpneqsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 4)(self, Precision::Double, src1, src2, dst), @@ -1805,7 +1804,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpltss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 1)(self, Precision::Single, src1, src2, dst), @@ -1818,7 +1817,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpltsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 1)(self, Precision::Double, src1, src2, dst), @@ -1831,7 +1830,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpless)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 2)(self, Precision::Single, src1, src2, dst), @@ -1844,7 +1843,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmplesd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 2)(self, Precision::Double, src1, src2, dst), @@ -1857,7 +1856,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpgtss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 6)(self, Precision::Single, src1, src2, dst), @@ -1870,7 +1869,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpgtsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 6)(self, Precision::Double, src1, src2, dst), @@ -1883,7 +1882,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpgess)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 5)(self, Precision::Single, src1, src2, dst), @@ -1896,7 +1895,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpgesd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 5)(self, Precision::Double, src1, src2, dst), @@ -1909,7 +1908,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpunordss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 3)(self, Precision::Single, src1, src2, dst), @@ -1922,7 +1921,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpunordsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 3)(self, Precision::Double, src1, src2, dst), @@ -1935,7 +1934,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpordss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpss, 7)(self, Precision::Single, src1, src2, dst), @@ -1948,7 +1947,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcmpordsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cmpsd, 7)(self, Precision::Double, src1, src2, dst), @@ -1956,7 +1955,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vsqrtss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vsqrtss(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vsqrtss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(sqrtss)(self, Precision::Single, src1, src2, dst), @@ -1964,7 +1963,7 @@ impl EmitterX64 for AssemblerX64 { } Ok(()) } - fn emit_vsqrtsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_vsqrtsd(&mut self, src1: XMM, src2: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vsqrtsd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(sqrtsd)(self, Precision::Double, src1, src2, dst), @@ -1977,7 +1976,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcvtss2sd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cvtss2sd)(self, Precision::Single, src1, src2, dst), @@ -1990,7 +1989,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_fn!(vcvtsd2ss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => sse_fn!(cvtsd2ss)(self, Precision::Double, src1, src2, dst), @@ -2003,7 +2002,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundss, 0)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2018,7 +2017,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundsd, 0)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2033,7 +2032,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundss, 1)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2048,7 +2047,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundsd, 1)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2063,7 +2062,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundss, 2)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2078,7 +2077,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundsd, 2)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2093,7 +2092,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundss, 3)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2108,7 +2107,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: XMMOrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_round_fn!(vroundsd, 3)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2123,7 +2122,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_i2f_32_fn!(vcvtsi2ss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2138,7 +2137,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_i2f_32_fn!(vcvtsi2sd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2153,7 +2152,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_i2f_64_fn!(vcvtsi2ss)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2168,7 +2167,7 @@ impl EmitterX64 for AssemblerX64 { src1: XMM, src2: GPROrMemory, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match self.get_simd_arch() { Some(CpuFeature::AVX) => avx_i2f_64_fn!(vcvtsi2sd)(self, src1, src2, dst), Some(CpuFeature::SSE42) => { @@ -2185,7 +2184,7 @@ impl EmitterX64 for AssemblerX64 { src2: XMMOrMemory, mask: XMM, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // this implementation works only for sse 4.1 and greater match self.get_simd_arch() { Some(CpuFeature::AVX) => match src2 { @@ -2218,7 +2217,7 @@ impl EmitterX64 for AssemblerX64 { src2: XMMOrMemory, mask: XMM, dst: XMM, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // this implementation works only for sse 4.1 and greater match self.get_simd_arch() { Some(CpuFeature::AVX) => match src2 { @@ -2245,7 +2244,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; ucomiss Rx(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2255,7 +2254,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CodegenError> { + fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; ucomisd Rx(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2265,7 +2264,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError> { + fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rd(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2275,7 +2274,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError> { + fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rq(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2285,7 +2284,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError> { + fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rd(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2295,7 +2294,7 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CodegenError> { + fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) -> Result<(), CompileError> { match src { XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rq(dst as u8), Rx(x as u8)), XMMOrMemory::Memory(base, disp) => { @@ -2305,30 +2304,30 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_test_gpr_64(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_test_gpr_64(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; test Rq(reg as u8), Rq(reg as u8)); Ok(()) } - fn emit_ud2(&mut self) -> Result<(), CodegenError> { + fn emit_ud2(&mut self) -> Result<(), CompileError> { dynasm!(self ; ud2); Ok(()) } - fn emit_ud1_payload(&mut self, payload: u8) -> Result<(), CodegenError> { + fn emit_ud1_payload(&mut self, payload: u8) -> Result<(), CompileError> { assert!(payload & 0xf0 == 0); dynasm!(self ; ud1 Rd((payload>>3)&1), Rd(payload&7)); Ok(()) } - fn emit_ret(&mut self) -> Result<(), CodegenError> { + fn emit_ret(&mut self) -> Result<(), CompileError> { dynasm!(self ; ret); Ok(()) } - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError> { dynasm!(self ; call =>label); Ok(()) } - fn emit_call_location(&mut self, loc: Location) -> Result<(), CodegenError> { + fn emit_call_location(&mut self, loc: Location) -> Result<(), CompileError> { match loc { Location::GPR(x) => dynasm!(self ; call Rq(x as u8)), Location::Memory(base, disp) => dynasm!(self ; call QWORD [Rq(base as u8) + disp]), @@ -2337,21 +2336,21 @@ impl EmitterX64 for AssemblerX64 { Ok(()) } - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError> { dynasm!(self ; call Rq(reg as u8)); Ok(()) } - fn emit_bkpt(&mut self) -> Result<(), CodegenError> { + fn emit_bkpt(&mut self) -> Result<(), CompileError> { dynasm!(self ; int3); Ok(()) } - fn emit_host_redirection(&mut self, target: GPR) -> Result<(), CodegenError> { + fn emit_host_redirection(&mut self, target: GPR) -> Result<(), CompileError> { self.emit_jmp_location(Location::GPR(target)) } - fn arch_mov64_imm_offset(&self) -> Result { + fn arch_mov64_imm_offset(&self) -> Result { Ok(2) } } diff --git a/lib/compiler-singlepass/src/machine.rs b/lib/compiler-singlepass/src/machine.rs index 31f007e2e45..cf89e5232ef 100644 --- a/lib/compiler-singlepass/src/machine.rs +++ b/lib/compiler-singlepass/src/machine.rs @@ -9,7 +9,7 @@ use std::fmt::Debug; pub use wasmer_compiler::wasmparser::MemoryImmediate; use wasmer_compiler::wasmparser::Type as WpType; use wasmer_types::{ - Architecture, CallingConvention, CpuFeature, CustomSection, FunctionBody, FunctionIndex, + Architecture, CallingConvention, CompileError, CustomSection, FunctionBody, FunctionIndex, FunctionType, InstructionAddressMap, Relocation, RelocationTarget, Target, TrapCode, TrapInformation, VMOffsets, }; @@ -27,14 +27,9 @@ pub enum Value { F64(f64), } -#[derive(Debug)] -pub struct CodegenError { - pub message: String, -} - #[macro_export] macro_rules! codegen_error { - ($($arg:tt)*) => {return Err(CodegenError{message : format!($($arg)*)})} + ($($arg:tt)*) => {return Err(CompileError::Codegen(format!($($arg)*)))} } pub trait MaybeImmediate { @@ -88,9 +83,9 @@ pub trait Machine { /// reserve a GPR fn reserve_gpr(&mut self, gpr: Self::GPR); /// Push used gpr to the stack. Return the bytes taken on the stack - fn push_used_gpr(&mut self, grps: &[Self::GPR]) -> Result; + fn push_used_gpr(&mut self, grps: &[Self::GPR]) -> Result; /// Pop used gpr to the stack - fn pop_used_gpr(&mut self, grps: &[Self::GPR]) -> Result<(), CodegenError>; + fn pop_used_gpr(&mut self, grps: &[Self::GPR]) -> Result<(), CompileError>; /// Picks an unused SIMD register. /// /// This method does not mark the register as used @@ -106,9 +101,9 @@ pub trait Machine { /// Releases a temporary XMM register. fn release_simd(&mut self, simd: Self::SIMD); /// Push used simd regs to the stack. Return bytes taken on the stack - fn push_used_simd(&mut self, simds: &[Self::SIMD]) -> Result; + fn push_used_simd(&mut self, simds: &[Self::SIMD]) -> Result; /// Pop used simd regs to the stack - fn pop_used_simd(&mut self, simds: &[Self::SIMD]) -> Result<(), CodegenError>; + fn pop_used_simd(&mut self, simds: &[Self::SIMD]) -> Result<(), CompileError>; /// Return a rounded stack adjustement value (must be multiple of 16bytes on ARM64 for example) fn round_stack_adjust(&self, value: usize) -> usize; /// Set the source location of the Wasm to the given offset. @@ -133,19 +128,19 @@ pub trait Machine { fn local_on_stack(&mut self, stack_offset: i32) -> Location; /// Adjust stack for locals /// Like assembler.emit_sub(Size::S64, Location::Imm32(delta_stack_offset as u32), Location::GPR(GPR::RSP)) - fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError>; + fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError>; /// restore stack /// Like assembler.emit_add(Size::S64, Location::Imm32(delta_stack_offset as u32), Location::GPR(GPR::RSP)) - fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError>; + fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError>; /// Pop stack of locals /// Like assembler.emit_add(Size::S64, Location::Imm32(delta_stack_offset as u32), Location::GPR(GPR::RSP)) - fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError>; + fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CompileError>; /// Zero a location taht is 32bits fn zero_location( &mut self, size: Size, location: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// GPR Reg used for local pointer on the stack fn local_pointer(&self) -> Self::GPR; /// push a value on the stack for a native call @@ -154,7 +149,7 @@ pub trait Machine { size: Size, loc: Location, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Determine whether a local should be allocated on the stack. fn is_local_on_stack(&self, idx: usize) -> bool; /// Determine a local's location. @@ -169,7 +164,7 @@ pub trait Machine { &mut self, stack_offset: i32, location: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// List of register to save, depending on the CallingConvention fn list_to_save( &self, @@ -203,7 +198,7 @@ pub trait Machine { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// move a location to another, with zero or sign extension fn move_location_extend( &mut self, @@ -212,7 +207,7 @@ pub trait Machine { source: Location, size_op: Size, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Load a memory value to a register, zero extending to 64bits. /// Panic if gpr is not a Location::GPR or if mem is not a Memory(2) fn load_address( @@ -220,20 +215,20 @@ pub trait Machine { size: Size, gpr: Location, mem: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Init the stack loc counter fn init_stack_loc( &mut self, init_stack_loc_cnt: u64, last_stack_loc: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Restore save_area - fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CodegenError>; + fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CompileError>; /// Pop a location fn pop_location( &mut self, location: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Create a new `MachineState` with default values. fn new_machine_state(&self) -> MachineState; @@ -244,21 +239,21 @@ pub trait Machine { fn get_offset(&self) -> Offset; /// finalize a function - fn finalize_function(&mut self) -> Result<(), CodegenError>; + fn finalize_function(&mut self) -> Result<(), CompileError>; /// emit native function prolog (depending on the calling Convention, like "PUSH RBP / MOV RSP, RBP") - fn emit_function_prolog(&mut self) -> Result<(), CodegenError>; + fn emit_function_prolog(&mut self) -> Result<(), CompileError>; /// emit native function epilog (depending on the calling Convention, like "MOV RBP, RSP / POP RBP") - fn emit_function_epilog(&mut self) -> Result<(), CodegenError>; + fn emit_function_epilog(&mut self) -> Result<(), CompileError>; /// handle return value, with optionnal cannonicalization if wanted fn emit_function_return_value( &mut self, ty: WpType, cannonicalize: bool, loc: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Handle copy to SIMD register from ret value (if needed by the arch/calling convention) - fn emit_function_return_float(&mut self) -> Result<(), CodegenError>; + fn emit_function_return_float(&mut self) -> Result<(), CompileError>; /// Is NaN canonicalization supported fn arch_supports_canonicalize_nan(&self) -> bool; /// Cannonicalize a NaN (or panic if not supported) @@ -267,40 +262,40 @@ pub trait Machine { sz: Size, input: Location, output: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// emit an Illegal Opcode, associated with a trapcode - fn emit_illegal_op(&mut self, trp: TrapCode) -> Result<(), CodegenError>; + fn emit_illegal_op(&mut self, trp: TrapCode) -> Result<(), CompileError>; /// create a new label fn get_label(&mut self) -> Label; /// emit a label - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError>; + fn emit_label(&mut self, label: Label) -> Result<(), CompileError>; /// get the gpr use for call. like RAX on x86_64 fn get_grp_for_call(&self) -> Self::GPR; /// Emit a call using the value in register - fn emit_call_register(&mut self, register: Self::GPR) -> Result<(), CodegenError>; + fn emit_call_register(&mut self, register: Self::GPR) -> Result<(), CompileError>; /// Emit a call to a label - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError>; + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError>; /// Does an trampoline is neededfor indirect call fn arch_requires_indirect_call_trampoline(&self) -> bool; /// indirect call with trampoline fn arch_emit_indirect_call_with_trampoline( &mut self, location: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// emit a call to a location fn emit_call_location( &mut self, location: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// get the gpr for the return of generic values fn get_gpr_for_ret(&self) -> Self::GPR; /// get the simd for the return of float/double values fn get_simd_for_ret(&self) -> Self::SIMD; /// Emit a debug breakpoint - fn emit_debug_breakpoint(&mut self) -> Result<(), CodegenError>; + fn emit_debug_breakpoint(&mut self) -> Result<(), CompileError>; /// load the address of a memory location (will panic if src is not a memory) /// like LEA opcode on x86_64 @@ -309,7 +304,7 @@ pub trait Machine { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// And src & dst -> dst (with or without flags) fn location_and( @@ -318,7 +313,7 @@ pub trait Machine { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Xor src & dst -> dst (with or without flags) fn location_xor( &mut self, @@ -326,7 +321,7 @@ pub trait Machine { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Or src & dst -> dst (with or without flags) fn location_or( &mut self, @@ -334,7 +329,7 @@ pub trait Machine { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Add src+dst -> dst (with or without flags) fn location_add( @@ -343,7 +338,7 @@ pub trait Machine { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Sub dst-src -> dst (with or without flags) fn location_sub( &mut self, @@ -351,7 +346,7 @@ pub trait Machine { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// -src -> dst fn location_neg( &mut self, @@ -360,7 +355,7 @@ pub trait Machine { source: Location, size_op: Size, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Cmp src - dst and set flags fn location_cmp( @@ -368,77 +363,77 @@ pub trait Machine { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Test src & dst and set flags fn location_test( &mut self, size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// jmp without condidtion - fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on equal (src==dst) /// like Equal set on x86_64 - fn jmp_on_equal(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_equal(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on different (src!=dst) /// like NotEqual set on x86_64 - fn jmp_on_different(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_different(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on above (src>dst) /// like Above set on x86_64 - fn jmp_on_above(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_above(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on above (src>=dst) /// like Above or Equal set on x86_64 - fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on above (src<=dst) /// like Below or Equal set on x86_64 - fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CompileError>; /// jmp on overflow /// like Carry set on x86_64 - fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CodegenError>; + fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CompileError>; /// jmp using a jump table at lable with cond as the indice fn emit_jmp_to_jumptable( &mut self, label: Label, cond: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Align for Loop (may do nothing, depending on the arch) - fn align_for_loop(&mut self) -> Result<(), CodegenError>; + fn align_for_loop(&mut self) -> Result<(), CompileError>; /// ret (from a Call) - fn emit_ret(&mut self) -> Result<(), CodegenError>; + fn emit_ret(&mut self) -> Result<(), CompileError>; /// Stack push of a location fn emit_push( &mut self, size: Size, loc: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Stack pop of a location fn emit_pop( &mut self, size: Size, loc: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// relaxed mov: move from anywhere to anywhere fn emit_relaxed_mov( &mut self, sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// relaxed cmp: compare from anywhere and anywhere fn emit_relaxed_cmp( &mut self, sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Emit a memory fence. Can be nothing for x86_64 or a DMB on ARM64 for example - fn emit_memory_fence(&mut self) -> Result<(), CodegenError>; + fn emit_memory_fence(&mut self) -> Result<(), CompileError>; /// relaxed move with zero extension fn emit_relaxed_zero_extension( &mut self, @@ -446,7 +441,7 @@ pub trait Machine { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// relaxed move with sign extension fn emit_relaxed_sign_extension( &mut self, @@ -454,35 +449,35 @@ pub trait Machine { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Multiply location with immediate fn emit_imul_imm32( &mut self, size: Size, imm32: u32, gpr: Self::GPR, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Add with location directly from the stack fn emit_binop_add32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Sub with location directly from the stack fn emit_binop_sub32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Multiply with location directly from the stack fn emit_binop_mul32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Division with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_udiv32( &mut self, @@ -491,7 +486,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Signed Division with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_sdiv32( &mut self, @@ -500,7 +495,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Unsigned Reminder (of a division) with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_urem32( &mut self, @@ -509,7 +504,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Signed Reminder (of a Division) with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_srem32( &mut self, @@ -518,151 +513,151 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// And with location directly from the stack fn emit_binop_and32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Or with location directly from the stack fn emit_binop_or32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Xor with location directly from the stack fn emit_binop_xor32( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Greater of Equal Compare 2 i32, result in a GPR fn i32_cmp_ge_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Greater Than Compare 2 i32, result in a GPR fn i32_cmp_gt_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Less of Equal Compare 2 i32, result in a GPR fn i32_cmp_le_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Less Than Compare 2 i32, result in a GPR fn i32_cmp_lt_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Greater of Equal Compare 2 i32, result in a GPR fn i32_cmp_ge_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Greater Than Compare 2 i32, result in a GPR fn i32_cmp_gt_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Less of Equal Compare 2 i32, result in a GPR fn i32_cmp_le_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Less Than Compare 2 i32, result in a GPR fn i32_cmp_lt_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Not Equal Compare 2 i32, result in a GPR fn i32_cmp_ne( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Equal Compare 2 i32, result in a GPR fn i32_cmp_eq( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count Leading 0 bit of an i32 fn i32_clz( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count Trailling 0 bit of an i32 fn i32_ctz( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count the number of 1 bit of an i32 fn i32_popcnt( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 Logical Shift Left fn i32_shl( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 Logical Shift Right fn i32_shr( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 Arithmetic Shift Right fn i32_sar( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 Roll Left fn i32_rol( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 Roll Right fn i32_ror( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 load #[allow(clippy::too_many_arguments)] fn i32_load( @@ -674,7 +669,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 load of an unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_load_8u( @@ -686,7 +681,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 load of an signed 8bits #[allow(clippy::too_many_arguments)] fn i32_load_8s( @@ -698,7 +693,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 load of an unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_load_16u( @@ -710,7 +705,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 load of an signed 16bits #[allow(clippy::too_many_arguments)] fn i32_load_16s( @@ -722,7 +717,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic load #[allow(clippy::too_many_arguments)] fn i32_atomic_load( @@ -734,7 +729,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic load of an unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_load_8u( @@ -746,7 +741,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic load of an unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_load_16u( @@ -758,7 +753,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 save #[allow(clippy::too_many_arguments)] fn i32_save( @@ -770,7 +765,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 save of the lower 8bits #[allow(clippy::too_many_arguments)] fn i32_save_8( @@ -782,7 +777,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 save of the lower 16bits #[allow(clippy::too_many_arguments)] fn i32_save_16( @@ -794,7 +789,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic save #[allow(clippy::too_many_arguments)] fn i32_atomic_save( @@ -806,7 +801,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic save of a the lower 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_save_8( @@ -818,7 +813,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic save of a the lower 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_save_16( @@ -830,7 +825,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Add with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_add( @@ -843,7 +838,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Add with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_add_8u( @@ -856,7 +851,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Add with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_add_16u( @@ -869,7 +864,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Sub with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_sub( @@ -882,7 +877,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Sub with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_sub_8u( @@ -895,7 +890,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Sub with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_sub_16u( @@ -908,7 +903,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic And with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_and( @@ -921,7 +916,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic And with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_and_8u( @@ -934,7 +929,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic And with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_and_16u( @@ -947,7 +942,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Or with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_or( @@ -960,7 +955,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Or with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_or_8u( @@ -973,7 +968,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Or with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_or_16u( @@ -986,7 +981,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Xor with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_xor( @@ -999,7 +994,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Xor with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i32_atomic_xor_8u( @@ -1012,7 +1007,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Xor with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i32_atomic_xor_16u( @@ -1025,7 +1020,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Exchange with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_xchg( @@ -1038,7 +1033,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Exchange with u8 #[allow(clippy::too_many_arguments)] fn i32_atomic_xchg_8u( @@ -1051,7 +1046,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Exchange with u16 #[allow(clippy::too_many_arguments)] fn i32_atomic_xchg_16u( @@ -1064,7 +1059,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Compare and Exchange with i32 #[allow(clippy::too_many_arguments)] fn i32_atomic_cmpxchg( @@ -1078,7 +1073,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Compare and Exchange with u8 #[allow(clippy::too_many_arguments)] fn i32_atomic_cmpxchg_8u( @@ -1092,7 +1087,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i32 atomic Compare and Exchange with u16 #[allow(clippy::too_many_arguments)] fn i32_atomic_cmpxchg_16u( @@ -1106,35 +1101,35 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// emit a move function address to GPR ready for call, using appropriate relocation fn emit_call_with_reloc( &mut self, calling_convention: CallingConvention, reloc_target: RelocationTarget, - ) -> Result, CodegenError>; + ) -> Result, CompileError>; /// Add with location directly from the stack fn emit_binop_add64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Sub with location directly from the stack fn emit_binop_sub64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Multiply with location directly from the stack fn emit_binop_mul64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Division with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_udiv64( &mut self, @@ -1143,7 +1138,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Signed Division with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_sdiv64( &mut self, @@ -1152,7 +1147,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Unsigned Reminder (of a division) with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_urem64( &mut self, @@ -1161,7 +1156,7 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// Signed Reminder (of a Division) with location directly from the stack. return the offset of the DIV opcode, to mark as trappable. fn emit_binop_srem64( &mut self, @@ -1170,151 +1165,151 @@ pub trait Machine { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result; + ) -> Result; /// And with location directly from the stack fn emit_binop_and64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Or with location directly from the stack fn emit_binop_or64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Xor with location directly from the stack fn emit_binop_xor64( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Greater of Equal Compare 2 i64, result in a GPR fn i64_cmp_ge_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Greater Than Compare 2 i64, result in a GPR fn i64_cmp_gt_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Less of Equal Compare 2 i64, result in a GPR fn i64_cmp_le_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Signed Less Than Compare 2 i64, result in a GPR fn i64_cmp_lt_s( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Greater of Equal Compare 2 i64, result in a GPR fn i64_cmp_ge_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Greater Than Compare 2 i64, result in a GPR fn i64_cmp_gt_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Less of Equal Compare 2 i64, result in a GPR fn i64_cmp_le_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Unsigned Less Than Compare 2 i64, result in a GPR fn i64_cmp_lt_u( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Not Equal Compare 2 i64, result in a GPR fn i64_cmp_ne( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Equal Compare 2 i64, result in a GPR fn i64_cmp_eq( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count Leading 0 bit of an i64 fn i64_clz( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count Trailling 0 bit of an i64 fn i64_ctz( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Count the number of 1 bit of an i64 fn i64_popcnt( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 Logical Shift Left fn i64_shl( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 Logical Shift Right fn i64_shr( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 Arithmetic Shift Right fn i64_sar( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 Roll Left fn i64_rol( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 Roll Right fn i64_ror( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load #[allow(clippy::too_many_arguments)] fn i64_load( @@ -1326,7 +1321,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_load_8u( @@ -1338,7 +1333,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an signed 8bits #[allow(clippy::too_many_arguments)] fn i64_load_8s( @@ -1350,7 +1345,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_load_32u( @@ -1362,7 +1357,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an signed 32bits #[allow(clippy::too_many_arguments)] fn i64_load_32s( @@ -1374,7 +1369,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an signed 16bits #[allow(clippy::too_many_arguments)] fn i64_load_16u( @@ -1386,7 +1381,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 load of an signed 16bits #[allow(clippy::too_many_arguments)] fn i64_load_16s( @@ -1398,7 +1393,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic load #[allow(clippy::too_many_arguments)] fn i64_atomic_load( @@ -1410,7 +1405,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic load from unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_load_8u( @@ -1422,7 +1417,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic load from unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_load_16u( @@ -1434,7 +1429,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic load from unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_load_32u( @@ -1446,7 +1441,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 save #[allow(clippy::too_many_arguments)] fn i64_save( @@ -1458,7 +1453,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 save of the lower 8bits #[allow(clippy::too_many_arguments)] fn i64_save_8( @@ -1470,7 +1465,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 save of the lower 16bits #[allow(clippy::too_many_arguments)] fn i64_save_16( @@ -1482,7 +1477,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 save of the lower 32bits #[allow(clippy::too_many_arguments)] fn i64_save_32( @@ -1494,7 +1489,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic save #[allow(clippy::too_many_arguments)] fn i64_atomic_save( @@ -1506,7 +1501,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic save of a the lower 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_save_8( @@ -1518,7 +1513,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic save of a the lower 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_save_16( @@ -1530,7 +1525,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic save of a the lower 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_save_32( @@ -1542,7 +1537,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Add with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_add( @@ -1555,7 +1550,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Add with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_add_8u( @@ -1568,7 +1563,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Add with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_add_16u( @@ -1581,7 +1576,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Add with unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_add_32u( @@ -1594,7 +1589,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Sub with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_sub( @@ -1607,7 +1602,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Sub with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_sub_8u( @@ -1620,7 +1615,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Sub with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_sub_16u( @@ -1633,7 +1628,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Sub with unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_sub_32u( @@ -1646,7 +1641,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic And with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_and( @@ -1659,7 +1654,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic And with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_and_8u( @@ -1672,7 +1667,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic And with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_and_16u( @@ -1685,7 +1680,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic And with unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_and_32u( @@ -1698,7 +1693,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Or with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_or( @@ -1711,7 +1706,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Or with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_or_8u( @@ -1724,7 +1719,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Or with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_or_16u( @@ -1737,7 +1732,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Or with unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_or_32u( @@ -1750,7 +1745,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Xor with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_xor( @@ -1763,7 +1758,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Xor with unsigned 8bits #[allow(clippy::too_many_arguments)] fn i64_atomic_xor_8u( @@ -1776,7 +1771,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Xor with unsigned 16bits #[allow(clippy::too_many_arguments)] fn i64_atomic_xor_16u( @@ -1789,7 +1784,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Xor with unsigned 32bits #[allow(clippy::too_many_arguments)] fn i64_atomic_xor_32u( @@ -1802,7 +1797,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Exchange with i64 #[allow(clippy::too_many_arguments)] fn i64_atomic_xchg( @@ -1815,7 +1810,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Exchange with u8 #[allow(clippy::too_many_arguments)] fn i64_atomic_xchg_8u( @@ -1828,7 +1823,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Exchange with u16 #[allow(clippy::too_many_arguments)] fn i64_atomic_xchg_16u( @@ -1841,7 +1836,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Exchange with u32 #[allow(clippy::too_many_arguments)] fn i64_atomic_xchg_32u( @@ -1854,7 +1849,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Compare and Exchange with i32 #[allow(clippy::too_many_arguments)] fn i64_atomic_cmpxchg( @@ -1868,7 +1863,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Compare and Exchange with u8 #[allow(clippy::too_many_arguments)] fn i64_atomic_cmpxchg_8u( @@ -1882,7 +1877,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Compare and Exchange with u16 #[allow(clippy::too_many_arguments)] fn i64_atomic_cmpxchg_16u( @@ -1896,7 +1891,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// i64 atomic Compare and Exchange with u32 #[allow(clippy::too_many_arguments)] fn i64_atomic_cmpxchg_32u( @@ -1910,7 +1905,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// load an F32 #[allow(clippy::too_many_arguments)] @@ -1923,7 +1918,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// f32 save #[allow(clippy::too_many_arguments)] fn f32_save( @@ -1936,7 +1931,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// load an F64 #[allow(clippy::too_many_arguments)] fn f64_load( @@ -1948,7 +1943,7 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// f64 save #[allow(clippy::too_many_arguments)] fn f64_save( @@ -1961,35 +1956,35 @@ pub trait Machine { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F64 from I64, signed or unsigned fn convert_f64_i64( &mut self, loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F64 from I32, signed or unsigned fn convert_f64_i32( &mut self, loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F32 from I64, signed or unsigned fn convert_f32_i64( &mut self, loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F32 from I32, signed or unsigned fn convert_f32_i32( &mut self, loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F64 to I64, signed or unsigned, without or without saturation fn convert_i64_f64( &mut self, @@ -1997,7 +1992,7 @@ pub trait Machine { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F64 to I32, signed or unsigned, without or without saturation fn convert_i32_f64( &mut self, @@ -2005,7 +2000,7 @@ pub trait Machine { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F32 to I64, signed or unsigned, without or without saturation fn convert_i64_f32( &mut self, @@ -2013,7 +2008,7 @@ pub trait Machine { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F32 to I32, signed or unsigned, without or without saturation fn convert_i32_f32( &mut self, @@ -2021,289 +2016,289 @@ pub trait Machine { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F32 to F64 fn convert_f64_f32( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Convert a F64 to F32 fn convert_f32_f64( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Negate an F64 fn f64_neg( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Get the Absolute Value of an F64 fn f64_abs( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Copy sign from tmp1 Self::GPR to tmp2 Self::GPR - fn emit_i64_copysign(&mut self, tmp1: Self::GPR, tmp2: Self::GPR) -> Result<(), CodegenError>; + fn emit_i64_copysign(&mut self, tmp1: Self::GPR, tmp2: Self::GPR) -> Result<(), CompileError>; /// Get the Square Root of an F64 fn f64_sqrt( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Trunc of an F64 fn f64_trunc( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Ceil of an F64 fn f64_ceil( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Floor of an F64 fn f64_floor( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Round at nearest int of an F64 fn f64_nearest( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Greater of Equal Compare 2 F64, result in a GPR fn f64_cmp_ge( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Greater Than Compare 2 F64, result in a GPR fn f64_cmp_gt( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Less of Equal Compare 2 F64, result in a GPR fn f64_cmp_le( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Less Than Compare 2 F64, result in a GPR fn f64_cmp_lt( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Not Equal Compare 2 F64, result in a GPR fn f64_cmp_ne( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Equal Compare 2 F64, result in a GPR fn f64_cmp_eq( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// get Min for 2 F64 values fn f64_min( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// get Max for 2 F64 values fn f64_max( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Add 2 F64 values fn f64_add( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Sub 2 F64 values fn f64_sub( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Multiply 2 F64 values fn f64_mul( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Divide 2 F64 values fn f64_div( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Negate an F32 fn f32_neg( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Get the Absolute Value of an F32 fn f32_abs( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Copy sign from tmp1 Self::GPR to tmp2 Self::GPR - fn emit_i32_copysign(&mut self, tmp1: Self::GPR, tmp2: Self::GPR) -> Result<(), CodegenError>; + fn emit_i32_copysign(&mut self, tmp1: Self::GPR, tmp2: Self::GPR) -> Result<(), CompileError>; /// Get the Square Root of an F32 fn f32_sqrt( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Trunc of an F32 fn f32_trunc( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Ceil of an F32 fn f32_ceil( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Floor of an F32 fn f32_floor( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Round at nearest int of an F32 fn f32_nearest( &mut self, loc: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Greater of Equal Compare 2 F32, result in a GPR fn f32_cmp_ge( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Greater Than Compare 2 F32, result in a GPR fn f32_cmp_gt( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Less of Equal Compare 2 F32, result in a GPR fn f32_cmp_le( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Less Than Compare 2 F32, result in a GPR fn f32_cmp_lt( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Not Equal Compare 2 F32, result in a GPR fn f32_cmp_ne( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Equal Compare 2 F32, result in a GPR fn f32_cmp_eq( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// get Min for 2 F32 values fn f32_min( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// get Max for 2 F32 values fn f32_max( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Add 2 F32 values fn f32_add( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Sub 2 F32 values fn f32_sub( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Multiply 2 F32 values fn f32_mul( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Divide 2 F32 values fn f32_div( &mut self, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError>; + ) -> Result<(), CompileError>; /// Standard function Trampoline generation fn gen_std_trampoline( &self, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result; + ) -> Result; /// Generates dynamic import function call trampoline for a function type. fn gen_std_dynamic_import_trampoline( &self, vmoffsets: &VMOffsets, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result; + ) -> Result; /// Singlepass calls import functions through a trampoline. fn gen_import_call_trampoline( &self, @@ -2311,7 +2306,7 @@ pub trait Machine { index: FunctionIndex, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result; + ) -> Result; /// generate eh_frame instruction (or None if not possible / supported) fn gen_dwarf_unwind_info(&mut self, code_len: usize) -> Option; /// generate Windows unwind instructions (or None if not possible / supported) @@ -2323,23 +2318,19 @@ pub fn gen_std_trampoline( sig: &FunctionType, target: &Target, calling_convention: CallingConvention, -) -> FunctionBody { +) -> Result { match target.triple().architecture { Architecture::X86_64 => { - let machine = if target.cpu_features().contains(CpuFeature::AVX) { - MachineX86_64::new(Some(CpuFeature::AVX)) - } else if target.cpu_features().contains(CpuFeature::SSE42) { - MachineX86_64::new(Some(CpuFeature::SSE42)) - } else { - panic!("singlepass unimplement X86_64 variant for gen_std_trampoline") - }; - machine.gen_std_trampoline(sig, calling_convention).unwrap() + let machine = MachineX86_64::new(Some(target.clone()))?; + machine.gen_std_trampoline(sig, calling_convention) } Architecture::Aarch64(_) => { let machine = MachineARM64::new(); - machine.gen_std_trampoline(sig, calling_convention).unwrap() + machine.gen_std_trampoline(sig, calling_convention) } - _ => panic!("singlepass unimplemented arch for gen_std_trampoline"), + _ => Err(CompileError::UnsupportedTarget( + "singlepass unimplemented arch for gen_std_trampoline".to_owned(), + )), } } @@ -2349,29 +2340,19 @@ pub fn gen_std_dynamic_import_trampoline( sig: &FunctionType, target: &Target, calling_convention: CallingConvention, -) -> FunctionBody { +) -> Result { match target.triple().architecture { Architecture::X86_64 => { - let machine = if target.cpu_features().contains(CpuFeature::AVX) { - MachineX86_64::new(Some(CpuFeature::AVX)) - } else if target.cpu_features().contains(CpuFeature::SSE42) { - MachineX86_64::new(Some(CpuFeature::SSE42)) - } else { - panic!( - "singlepass unimplement X86_64 variant for gen_std_dynamic_import_trampoline" - ) - }; - machine - .gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention) - .unwrap() + let machine = MachineX86_64::new(Some(target.clone()))?; + machine.gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention) } Architecture::Aarch64(_) => { let machine = MachineARM64::new(); - machine - .gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention) - .unwrap() + machine.gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention) } - _ => panic!("singlepass unimplemented arch for gen_std_dynamic_import_trampoline"), + _ => Err(CompileError::UnsupportedTarget( + "singlepass unimplemented arch for gen_std_dynamic_import_trampoline".to_owned(), + )), } } /// Singlepass calls import functions through a trampoline. @@ -2381,27 +2362,19 @@ pub fn gen_import_call_trampoline( sig: &FunctionType, target: &Target, calling_convention: CallingConvention, -) -> CustomSection { +) -> Result { match target.triple().architecture { Architecture::X86_64 => { - let machine = if target.cpu_features().contains(CpuFeature::AVX) { - MachineX86_64::new(Some(CpuFeature::AVX)) - } else if target.cpu_features().contains(CpuFeature::SSE42) { - MachineX86_64::new(Some(CpuFeature::SSE42)) - } else { - panic!("singlepass unimplement X86_64 variant for gen_import_call_trampoline") - }; - machine - .gen_import_call_trampoline(vmoffsets, index, sig, calling_convention) - .unwrap() + let machine = MachineX86_64::new(Some(target.clone()))?; + machine.gen_import_call_trampoline(vmoffsets, index, sig, calling_convention) } Architecture::Aarch64(_) => { let machine = MachineARM64::new(); - machine - .gen_import_call_trampoline(vmoffsets, index, sig, calling_convention) - .unwrap() + machine.gen_import_call_trampoline(vmoffsets, index, sig, calling_convention) } - _ => panic!("singlepass unimplemented arch for gen_import_call_trampoline"), + _ => Err(CompileError::UnsupportedTarget( + "singlepass unimplemented arch for gen_import_call_trampoline".to_owned(), + )), } } diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index e7aadbbfdfd..bab8ffa8fe8 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -12,7 +12,7 @@ use dynasmrt::{aarch64::Aarch64Relocation, VecAssembler}; use gimli::{write::CallFrameInstruction, AArch64}; use wasmer_compiler::wasmparser::Type as WpType; use wasmer_types::{ - CallingConvention, CustomSection, FunctionBody, FunctionIndex, FunctionType, + CallingConvention, CompileError, CustomSection, FunctionBody, FunctionIndex, FunctionType, InstructionAddressMap, Relocation, RelocationKind, RelocationTarget, SourceLoc, TrapCode, TrapInformation, VMOffsets, }; @@ -176,7 +176,7 @@ impl MachineARM64 { allow_imm: ImmType, read_val: bool, wanted: Option, - ) -> Result { + ) -> Result { match src { Location::GPR(_) | Location::SIMD(_) => Ok(src), Location::Imm8(val) => { @@ -188,8 +188,8 @@ impl MachineARM64 { let tmp = if let Some(wanted) = wanted { wanted } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); tmp @@ -208,8 +208,8 @@ impl MachineARM64 { let tmp = if let Some(wanted) = wanted { wanted } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); tmp @@ -228,8 +228,8 @@ impl MachineARM64 { let tmp = if let Some(wanted) = wanted { wanted } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); tmp @@ -243,8 +243,8 @@ impl MachineARM64 { let tmp = if let Some(wanted) = wanted { wanted } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); tmp @@ -327,12 +327,12 @@ impl MachineARM64 { temps: &mut Vec, allow_imm: ImmType, read_val: bool, - ) -> Result { + ) -> Result { match src { Location::SIMD(_) => Ok(src), Location::GPR(_) => { - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; temps.push(tmp); if read_val { @@ -344,11 +344,11 @@ impl MachineARM64 { if self.compatible_imm(val as i64, allow_imm) { Ok(src) } else { - let gpr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let gpr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; temps.push(tmp); self.assembler @@ -363,11 +363,11 @@ impl MachineARM64 { if self.compatible_imm(val as i64, allow_imm) { Ok(src) } else { - let gpr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let gpr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; temps.push(tmp); self.assembler @@ -382,11 +382,11 @@ impl MachineARM64 { if self.compatible_imm(val as i64, allow_imm) { Ok(src) } else { - let gpr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let gpr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; temps.push(tmp); self.assembler @@ -398,8 +398,8 @@ impl MachineARM64 { } } Location::Memory(reg, val) => { - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; temps.push(tmp); if read_val { @@ -418,8 +418,8 @@ impl MachineARM64 { self.assembler .emit_ldur(sz, Location::SIMD(tmp), reg, val)?; } else { - let gpr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let gpr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(gpr), (val as i64) as u64)?; @@ -439,12 +439,12 @@ impl MachineARM64 { fn emit_relaxed_binop( &mut self, - op: fn(&mut Assembler, Size, Location, Location) -> Result<(), CodegenError>, + op: fn(&mut Assembler, Size, Location, Location) -> Result<(), CompileError>, sz: Size, src: Location, dst: Location, putback: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src_imm = if putback { ImmType::None @@ -464,12 +464,12 @@ impl MachineARM64 { } fn emit_relaxed_binop_neon( &mut self, - op: fn(&mut Assembler, Size, Location, Location) -> Result<(), CodegenError>, + op: fn(&mut Assembler, Size, Location, Location) -> Result<(), CompileError>, sz: Size, src: Location, dst: Location, putback: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_neon(sz, src, &mut temps, ImmType::None, true)?; let dest = self.location_to_neon(sz, dst, &mut temps, ImmType::None, !putback)?; @@ -484,13 +484,13 @@ impl MachineARM64 { } fn emit_relaxed_binop3( &mut self, - op: fn(&mut Assembler, Size, Location, Location, Location) -> Result<(), CodegenError>, + op: fn(&mut Assembler, Size, Location, Location, Location) -> Result<(), CompileError>, sz: Size, src1: Location, src2: Location, dst: Location, allow_imm: ImmType, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src1 = self.location_to_reg(sz, src1, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(sz, src2, &mut temps, allow_imm, true, None)?; @@ -506,13 +506,13 @@ impl MachineARM64 { } fn emit_relaxed_binop3_neon( &mut self, - op: fn(&mut Assembler, Size, Location, Location, Location) -> Result<(), CodegenError>, + op: fn(&mut Assembler, Size, Location, Location, Location) -> Result<(), CompileError>, sz: Size, src1: Location, src2: Location, dst: Location, allow_imm: ImmType, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src1 = self.location_to_neon(sz, src1, &mut temps, ImmType::None, true)?; let src2 = self.location_to_neon(sz, src2, &mut temps, allow_imm, true)?; @@ -531,7 +531,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -541,8 +541,8 @@ impl MachineARM64 { } else if self.compatible_imm(offset as i64, ImmType::UnscaledOffset) { self.assembler.emit_ldur(Size::S64, dest, addr, offset)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -569,7 +569,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -579,8 +579,8 @@ impl MachineARM64 { } else if self.compatible_imm(offset as i64, ImmType::UnscaledOffset) { self.assembler.emit_ldur(Size::S32, dest, addr, offset)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -607,7 +607,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -615,8 +615,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetWord) { self.assembler.emit_ldrsw(Size::S64, dest, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -643,7 +643,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -651,8 +651,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetHWord) { self.assembler.emit_ldrh(Size::S32, dest, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -679,7 +679,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -687,8 +687,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetHWord) { self.assembler.emit_ldrsh(sz, dest, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -715,7 +715,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -723,8 +723,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetByte) { self.assembler.emit_ldrb(Size::S32, dest, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -751,7 +751,7 @@ impl MachineARM64 { sz: Size, dst: Location, src: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(sz, dst, &mut temps, ImmType::None, false, None)?; match src { @@ -759,8 +759,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetByte) { self.assembler.emit_ldrsb(sz, dest, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -782,7 +782,7 @@ impl MachineARM64 { } Ok(()) } - fn emit_relaxed_str64(&mut self, dst: Location, src: Location) -> Result<(), CodegenError> { + fn emit_relaxed_str64(&mut self, dst: Location, src: Location) -> Result<(), CompileError> { let mut temps = vec![]; let dst = self.location_to_reg(Size::S64, dst, &mut temps, ImmType::NoneXzr, true, None)?; match src { @@ -792,8 +792,8 @@ impl MachineARM64 { } else if self.compatible_imm(offset as i64, ImmType::UnscaledOffset) { self.assembler.emit_stur(Size::S64, dst, addr, offset)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -812,7 +812,7 @@ impl MachineARM64 { } Ok(()) } - fn emit_relaxed_str32(&mut self, dst: Location, src: Location) -> Result<(), CodegenError> { + fn emit_relaxed_str32(&mut self, dst: Location, src: Location) -> Result<(), CompileError> { let mut temps = vec![]; let dst = self.location_to_reg(Size::S64, dst, &mut temps, ImmType::NoneXzr, true, None)?; match src { @@ -822,8 +822,8 @@ impl MachineARM64 { } else if self.compatible_imm(offset as i64, ImmType::UnscaledOffset) { self.assembler.emit_stur(Size::S32, dst, addr, offset)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -842,7 +842,7 @@ impl MachineARM64 { } Ok(()) } - fn emit_relaxed_str16(&mut self, dst: Location, src: Location) -> Result<(), CodegenError> { + fn emit_relaxed_str16(&mut self, dst: Location, src: Location) -> Result<(), CompileError> { let mut temps = vec![]; let dst = self.location_to_reg(Size::S64, dst, &mut temps, ImmType::NoneXzr, true, None)?; match src { @@ -850,8 +850,8 @@ impl MachineARM64 { if self.compatible_imm(offset as i64, ImmType::OffsetHWord) { self.assembler.emit_strh(Size::S32, dst, src)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -870,7 +870,7 @@ impl MachineARM64 { } Ok(()) } - fn emit_relaxed_str8(&mut self, dst: Location, src: Location) -> Result<(), CodegenError> { + fn emit_relaxed_str8(&mut self, dst: Location, src: Location) -> Result<(), CompileError> { let mut temps = vec![]; let dst = self.location_to_reg(Size::S64, dst, &mut temps, ImmType::NoneXzr, true, None)?; match src { @@ -879,8 +879,8 @@ impl MachineARM64 { self.assembler .emit_strb(Size::S32, dst, Location::Memory(addr, offset))?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -906,15 +906,15 @@ impl MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match ret { Location::GPR(_) => { self.emit_relaxed_cmp(Size::S64, loc_b, loc_a)?; self.assembler.emit_cset(Size::S32, ret, c)?; } Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_cmp(Size::S64, loc_b, loc_a)?; self.assembler.emit_cset(Size::S32, Location::GPR(tmp), c)?; @@ -934,15 +934,15 @@ impl MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match ret { Location::GPR(_) => { self.emit_relaxed_cmp(Size::S32, loc_b, loc_a)?; self.assembler.emit_cset(Size::S32, ret, c)?; } Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_cmp(Size::S32, loc_b, loc_a)?; self.assembler.emit_cset(Size::S32, Location::GPR(tmp), c)?; @@ -957,7 +957,7 @@ impl MachineARM64 { } #[allow(clippy::too_many_arguments)] - fn memory_op Result<(), CodegenError>>( + fn memory_op Result<(), CompileError>>( &mut self, addr: Location, memarg: &MemoryImmediate, @@ -968,9 +968,9 @@ impl MachineARM64 { offset: i32, heap_access_oob: Label, cb: F, - ) -> Result<(), CodegenError> { - let tmp_addr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let tmp_addr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; // Reusing `tmp_addr` for temporary indirection here, since it's not used before the last reference to `{base,bound}_loc`. @@ -991,11 +991,11 @@ impl MachineARM64 { ) }; - let tmp_base = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_base = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_bound = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_bound = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; // Load base into temporary register. @@ -1022,8 +1022,8 @@ impl MachineARM64 { Location::GPR(tmp_bound), )?; } else { - let tmp2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp2), value_size as u64)?; @@ -1052,8 +1052,8 @@ impl MachineARM64 { Location::GPR(tmp_addr), )?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), memarg.offset as _)?; @@ -1151,7 +1151,7 @@ impl MachineARM64 { true } - fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CodegenError> { + fn emit_push(&mut self, sz: Size, src: Location) -> Result<(), CompileError> { match (sz, src) { (Size::S64, Location::GPR(_)) | (Size::S64, Location::SIMD(_)) => { let offset = if self.pushed { @@ -1199,7 +1199,7 @@ impl MachineARM64 { sz: Size, src1: Location, src2: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.pushed { match (sz, src1, src2) { (Size::S64, Location::GPR(_), Location::GPR(_)) => { @@ -1217,7 +1217,7 @@ impl MachineARM64 { } Ok(()) } - fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CodegenError> { + fn emit_pop(&mut self, sz: Size, dst: Location) -> Result<(), CompileError> { match (sz, dst) { (Size::S64, Location::GPR(_)) | (Size::S64, Location::SIMD(_)) => { let offset = if self.pushed { 8 } else { 0 }; @@ -1242,7 +1242,7 @@ impl MachineARM64 { sz: Size, dst1: Location, dst2: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.pushed { match (sz, dst1, dst2) { (Size::S64, Location::GPR(_), Location::GPR(_)) => { @@ -1261,19 +1261,19 @@ impl MachineARM64 { Ok(()) } - fn set_default_nan(&mut self, temps: &mut Vec) -> Result { + fn set_default_nan(&mut self, temps: &mut Vec) -> Result { // temporarly set FPCR to DefaultNan - let old_fpcr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let old_fpcr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(old_fpcr); self.assembler.emit_read_fpcr(old_fpcr)?; - let new_fpcr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let new_fpcr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(new_fpcr); - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -1291,15 +1291,15 @@ impl MachineARM64 { self.assembler.emit_write_fpcr(new_fpcr)?; Ok(old_fpcr) } - fn set_trap_enabled(&mut self, temps: &mut Vec) -> Result { + fn set_trap_enabled(&mut self, temps: &mut Vec) -> Result { // temporarly set FPCR to DefaultNan - let old_fpcr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let old_fpcr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(old_fpcr); self.assembler.emit_read_fpcr(old_fpcr)?; - let new_fpcr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let new_fpcr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(new_fpcr); self.assembler @@ -1310,14 +1310,14 @@ impl MachineARM64 { self.assembler.emit_write_fpcr(new_fpcr)?; Ok(old_fpcr) } - fn restore_fpcr(&mut self, old_fpcr: GPR) -> Result<(), CodegenError> { + fn restore_fpcr(&mut self, old_fpcr: GPR) -> Result<(), CompileError> { self.assembler.emit_write_fpcr(old_fpcr) } - fn reset_exception_fpsr(&mut self) -> Result<(), CodegenError> { + fn reset_exception_fpsr(&mut self) -> Result<(), CompileError> { // reset exception count in FPSR - let fpsr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let fpsr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_read_fpsr(fpsr)?; // IOC is 0 @@ -1327,9 +1327,9 @@ impl MachineARM64 { self.release_gpr(fpsr); Ok(()) } - fn read_fpsr(&mut self) -> Result { - let fpsr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn read_fpsr(&mut self) -> Result { + let fpsr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_read_fpsr(fpsr)?; Ok(fpsr) @@ -1341,7 +1341,7 @@ impl MachineARM64 { sz: Size, f: Location, temps: &mut Vec, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let trap_badconv = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -1392,7 +1392,7 @@ impl MachineARM64 { fn emit_unwind_op(&mut self, op: UnwindOps) { self.unwind_ops.push((self.get_offset().0, op)); } - fn emit_illegal_op_internal(&mut self, trap: TrapCode) -> Result<(), CodegenError> { + fn emit_illegal_op_internal(&mut self, trap: TrapCode) -> Result<(), CompileError> { self.assembler.emit_udf(0xc0 | (trap as u8) as u16) } } @@ -1473,7 +1473,7 @@ impl Machine for MachineARM64 { self.used_gprs_insert(gpr); } - fn push_used_gpr(&mut self, used_gprs: &[GPR]) -> Result { + fn push_used_gpr(&mut self, used_gprs: &[GPR]) -> Result { if used_gprs.len() % 2 == 1 { self.emit_push(Size::S64, Location::GPR(GPR::XzrSp))?; } @@ -1482,7 +1482,7 @@ impl Machine for MachineARM64 { } Ok(((used_gprs.len() + 1) / 2) * 16) } - fn pop_used_gpr(&mut self, used_gprs: &[GPR]) -> Result<(), CodegenError> { + fn pop_used_gpr(&mut self, used_gprs: &[GPR]) -> Result<(), CompileError> { for r in used_gprs.iter().rev() { self.emit_pop(Size::S64, Location::GPR(*r))?; } @@ -1534,7 +1534,7 @@ impl Machine for MachineARM64 { assert!(self.used_simd_remove(&simd)); } - fn push_used_simd(&mut self, used_neons: &[NEON]) -> Result { + fn push_used_simd(&mut self, used_neons: &[NEON]) -> Result { let stack_adjust = if used_neons.len() & 1 == 1 { (used_neons.len() * 8) as u32 + 8 } else { @@ -1551,7 +1551,7 @@ impl Machine for MachineARM64 { } Ok(stack_adjust as usize) } - fn pop_used_simd(&mut self, used_neons: &[NEON]) -> Result<(), CodegenError> { + fn pop_used_simd(&mut self, used_neons: &[NEON]) -> Result<(), CompileError> { for (i, r) in used_neons.iter().enumerate() { self.assembler.emit_ldr( Size::S64, @@ -1647,7 +1647,7 @@ impl Machine for MachineARM64 { } // Adjust stack for locals - fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { let delta = if self.compatible_imm(delta_stack_offset as _, ImmType::Bits12) { Location::Imm32(delta_stack_offset as _) } else { @@ -1664,7 +1664,7 @@ impl Machine for MachineARM64 { ) } // restore stack - fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { let delta = if self.compatible_imm(delta_stack_offset as _, ImmType::Bits12) { Location::Imm32(delta_stack_offset as _) } else { @@ -1680,7 +1680,7 @@ impl Machine for MachineARM64 { Location::GPR(GPR::XzrSp), ) } - fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { let real_delta = if delta_stack_offset & 15 != 0 { delta_stack_offset + 8 } else { @@ -1707,7 +1707,7 @@ impl Machine for MachineARM64 { size: Size, loc: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match loc { Location::Imm64(_) | Location::Imm32(_) @@ -1722,7 +1722,7 @@ impl Machine for MachineARM64 { } // Zero a location that is 32bits - fn zero_location(&mut self, size: Size, location: Location) -> Result<(), CodegenError> { + fn zero_location(&mut self, size: Size, location: Location) -> Result<(), CompileError> { self.move_location(size, Location::GPR(GPR::XzrSp), location) } @@ -1752,7 +1752,7 @@ impl Machine for MachineARM64 { } } // Move a local to the stack - fn move_local(&mut self, stack_offset: i32, location: Location) -> Result<(), CodegenError> { + fn move_local(&mut self, stack_offset: i32, location: Location) -> Result<(), CompileError> { if stack_offset < 256 { self.assembler .emit_stur(Size::S64, location, GPR::X29, -stack_offset)?; @@ -1917,7 +1917,7 @@ impl Machine for MachineARM64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match source { Location::GPR(_) | Location::SIMD(_) => match dest { Location::GPR(_) | Location::SIMD(_) => self.assembler.emit_mov(size, source, dest), @@ -2061,7 +2061,7 @@ impl Machine for MachineARM64 { source: Location, size_op: Size, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if size_op != Size::S64 { codegen_error!("singlepass move_location_extend unreachable"); } @@ -2110,7 +2110,7 @@ impl Machine for MachineARM64 { _size: Size, _reg: Location, _mem: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass load_address unimplemented"); } // Init the stack loc counter @@ -2118,11 +2118,11 @@ impl Machine for MachineARM64 { &mut self, init_stack_loc_cnt: u64, last_stack_loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let label = self.assembler.get_label(); let mut temps = vec![]; - let dest = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let dest = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(dest); let cnt = self.location_to_reg( @@ -2147,8 +2147,8 @@ impl Machine for MachineARM64 { Location::GPR(dest), )?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -2171,8 +2171,8 @@ impl Machine for MachineARM64 { Location::GPR(dest), )?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), (offset as i64) as u64)?; @@ -2201,7 +2201,7 @@ impl Machine for MachineARM64 { Ok(()) } // Restore save_area - fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CodegenError> { + fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CompileError> { let real_delta = if saved_area_offset & 15 != 0 { self.pushed = true; saved_area_offset + 8 @@ -2217,8 +2217,8 @@ impl Machine for MachineARM64 { Location::GPR(GPR::XzrSp), )?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), real_delta as u64)?; @@ -2233,7 +2233,7 @@ impl Machine for MachineARM64 { Ok(()) } // Pop a location - fn pop_location(&mut self, location: Location) -> Result<(), CodegenError> { + fn pop_location(&mut self, location: Location) -> Result<(), CompileError> { self.emit_pop(Size::S64, location) } // Create a new `MachineState` with default values. @@ -2250,12 +2250,12 @@ impl Machine for MachineARM64 { self.assembler.get_offset() } - fn finalize_function(&mut self) -> Result<(), CodegenError> { + fn finalize_function(&mut self) -> Result<(), CompileError> { self.assembler.finalize_function(); Ok(()) } - fn emit_function_prolog(&mut self) -> Result<(), CodegenError> { + fn emit_function_prolog(&mut self) -> Result<(), CompileError> { self.emit_double_push(Size::S64, Location::GPR(GPR::X29), Location::GPR(GPR::X30))?; // save LR too self.emit_unwind_op(UnwindOps::Push2Regs { reg1: GPR::X29.to_dwarf(), @@ -2279,7 +2279,7 @@ impl Machine for MachineARM64 { Ok(()) } - fn emit_function_epilog(&mut self) -> Result<(), CodegenError> { + fn emit_function_epilog(&mut self) -> Result<(), CompileError> { // cannot use mov, because XSP is XZR there. Need to use ADD with #0 self.assembler.emit_add( Size::S64, @@ -2298,7 +2298,7 @@ impl Machine for MachineARM64 { ty: WpType, canonicalize: bool, loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if canonicalize { self.canonicalize_nan( match ty { @@ -2315,7 +2315,7 @@ impl Machine for MachineARM64 { Ok(()) } - fn emit_function_return_float(&mut self) -> Result<(), CodegenError> { + fn emit_function_return_float(&mut self) -> Result<(), CompileError> { self.assembler .emit_mov(Size::S64, Location::GPR(GPR::X0), Location::SIMD(NEON::V0)) } @@ -2328,7 +2328,7 @@ impl Machine for MachineARM64 { sz: Size, input: Location, output: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut tempn = vec![]; let mut temps = vec![]; let old_fpcr = self.set_default_nan(&mut temps)?; @@ -2371,7 +2371,7 @@ impl Machine for MachineARM64 { Ok(()) } - fn emit_illegal_op(&mut self, trap: TrapCode) -> Result<(), CodegenError> { + fn emit_illegal_op(&mut self, trap: TrapCode) -> Result<(), CompileError> { let offset = self.assembler.get_offset().0; self.assembler.emit_udf(0xc0 | (trap as u8) as u16)?; self.mark_instruction_address_end(offset); @@ -2380,16 +2380,16 @@ impl Machine for MachineARM64 { fn get_label(&mut self) -> Label { self.assembler.new_dynamic_label() } - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_label(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_label(label) } fn get_grp_for_call(&self) -> GPR { GPR::X27 } - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError> { self.assembler.emit_call_register(reg) } - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_call_label(label) } fn get_gpr_for_ret(&self) -> GPR { @@ -2406,16 +2406,16 @@ impl Machine for MachineARM64 { fn arch_emit_indirect_call_with_trampoline( &mut self, location: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler .arch_emit_indirect_call_with_trampoline(location) } - fn emit_debug_breakpoint(&mut self) -> Result<(), CodegenError> { + fn emit_debug_breakpoint(&mut self) -> Result<(), CompileError> { self.assembler.emit_brk() } - fn emit_call_location(&mut self, location: Location) -> Result<(), CodegenError> { + fn emit_call_location(&mut self, location: Location) -> Result<(), CompileError> { let mut temps = vec![]; let loc = self.location_to_reg( Size::S64, @@ -2440,7 +2440,7 @@ impl Machine for MachineARM64 { _size: Size, _source: Location, _dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_address not implemented") } // logic @@ -2450,7 +2450,7 @@ impl Machine for MachineARM64 { _source: Location, _dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_and not implemented") } fn location_xor( @@ -2459,7 +2459,7 @@ impl Machine for MachineARM64 { _source: Location, _dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_xor not implemented") } fn location_or( @@ -2468,7 +2468,7 @@ impl Machine for MachineARM64 { _source: Location, _dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_or not implemented") } fn location_test( @@ -2476,7 +2476,7 @@ impl Machine for MachineARM64 { _size: Size, _source: Location, _dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_test not implemented") } // math @@ -2486,7 +2486,7 @@ impl Machine for MachineARM64 { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_reg(size, source, &mut temps, ImmType::Bits12, true, None)?; let dst = self.location_to_reg(size, dest, &mut temps, ImmType::None, true, None)?; @@ -2509,7 +2509,7 @@ impl Machine for MachineARM64 { source: Location, dest: Location, flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_reg(size, source, &mut temps, ImmType::Bits12, true, None)?; let dst = self.location_to_reg(size, dest, &mut temps, ImmType::None, true, None)?; @@ -2531,38 +2531,38 @@ impl Machine for MachineARM64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(Assembler::emit_cmp, size, source, dest, false) } - fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_b_label(label) } - fn jmp_on_equal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_equal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Eq, label) } - fn jmp_on_different(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_different(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Ne, label) } - fn jmp_on_above(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_above(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Hi, label) } - fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Cs, label) } - fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Ls, label) } - fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_bcond_label_far(Condition::Cs, label) } // jmp table - fn emit_jmp_to_jumptable(&mut self, label: Label, cond: Location) -> Result<(), CodegenError> { - let tmp1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn emit_jmp_to_jumptable(&mut self, label: Label, cond: Location) -> Result<(), CompileError> { + let tmp1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_load_label(tmp1, label)?; @@ -2581,23 +2581,23 @@ impl Machine for MachineARM64 { Ok(()) } - fn align_for_loop(&mut self) -> Result<(), CodegenError> { + fn align_for_loop(&mut self) -> Result<(), CompileError> { // noting to do on ARM64 Ok(()) } - fn emit_ret(&mut self) -> Result<(), CodegenError> { + fn emit_ret(&mut self) -> Result<(), CompileError> { self.assembler.emit_ret() } - fn emit_push(&mut self, size: Size, loc: Location) -> Result<(), CodegenError> { + fn emit_push(&mut self, size: Size, loc: Location) -> Result<(), CompileError> { self.emit_push(size, loc) } - fn emit_pop(&mut self, size: Size, loc: Location) -> Result<(), CodegenError> { + fn emit_pop(&mut self, size: Size, loc: Location) -> Result<(), CompileError> { self.emit_pop(size, loc) } - fn emit_memory_fence(&mut self) -> Result<(), CodegenError> { + fn emit_memory_fence(&mut self) -> Result<(), CompileError> { self.assembler.emit_dmb() } @@ -2608,13 +2608,13 @@ impl Machine for MachineARM64 { _source: Location, _size_op: Size, _dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass location_neg unimplemented"); } - fn emit_imul_imm32(&mut self, size: Size, imm32: u32, gpr: GPR) -> Result<(), CodegenError> { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn emit_imul_imm32(&mut self, size: Size, imm32: u32, gpr: GPR) -> Result<(), CompileError> { + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov_imm(Location::GPR(tmp), imm32 as u64)?; @@ -2634,7 +2634,7 @@ impl Machine for MachineARM64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(Assembler::emit_mov, sz, src, dst, true) } fn emit_relaxed_cmp( @@ -2642,7 +2642,7 @@ impl Machine for MachineARM64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(Assembler::emit_cmp, sz, src, dst, false) } fn emit_relaxed_zero_extension( @@ -2651,7 +2651,7 @@ impl Machine for MachineARM64 { _src: Location, _sz_dst: Size, _dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass emit_relaxed_zero_extension unimplemented"); } fn emit_relaxed_sign_extension( @@ -2660,7 +2660,7 @@ impl Machine for MachineARM64 { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (src, dst) { (Location::Memory(_, _), Location::GPR(_)) => match sz_src { Size::S8 => self.emit_relaxed_ldr8s(sz_dst, dst, src), @@ -2696,7 +2696,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_add, Size::S32, @@ -2711,7 +2711,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_sub, Size::S32, @@ -2726,7 +2726,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_mul, Size::S32, @@ -2743,7 +2743,7 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S32, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S32, loc_b, &mut temps, ImmType::None, true, None)?; @@ -2768,7 +2768,7 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S32, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S32, loc_b, &mut temps, ImmType::None, true, None)?; @@ -2810,14 +2810,14 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S32, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S32, loc_b, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; let dest = if dest == src1 || dest == src2 { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -2848,14 +2848,14 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S32, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S32, loc_b, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; let dest = if dest == src1 || dest == src2 { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -2884,7 +2884,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_and, Size::S32, @@ -2899,7 +2899,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_or, Size::S32, @@ -2914,7 +2914,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_eor, Size::S32, @@ -2929,7 +2929,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Ge, loc_a, loc_b, ret) } fn i32_cmp_gt_s( @@ -2937,7 +2937,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Gt, loc_a, loc_b, ret) } fn i32_cmp_le_s( @@ -2945,7 +2945,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Le, loc_a, loc_b, ret) } fn i32_cmp_lt_s( @@ -2953,7 +2953,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Lt, loc_a, loc_b, ret) } fn i32_cmp_ge_u( @@ -2961,7 +2961,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Cs, loc_a, loc_b, ret) } fn i32_cmp_gt_u( @@ -2969,7 +2969,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Hi, loc_a, loc_b, ret) } fn i32_cmp_le_u( @@ -2977,7 +2977,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Ls, loc_a, loc_b, ret) } fn i32_cmp_lt_u( @@ -2985,7 +2985,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Cc, loc_a, loc_b, ret) } fn i32_cmp_ne( @@ -2993,7 +2993,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Ne, loc_a, loc_b, ret) } fn i32_cmp_eq( @@ -3001,13 +3001,13 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Eq, loc_a, loc_b, ret) } - fn i32_clz(&mut self, src: Location, dst: Location) -> Result<(), CodegenError> { + fn i32_clz(&mut self, src: Location, dst: Location) -> Result<(), CompileError> { self.emit_relaxed_binop(Assembler::emit_clz, Size::S32, src, dst, true) } - fn i32_ctz(&mut self, src: Location, dst: Location) -> Result<(), CodegenError> { + fn i32_ctz(&mut self, src: Location, dst: Location) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_reg(Size::S32, src, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S32, dst, &mut temps, ImmType::None, false, None)?; @@ -3021,15 +3021,15 @@ impl Machine for MachineARM64 { } Ok(()) } - fn i32_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i32_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { // no opcode for that. // 2 solutions: using NEON CNT, that count bits per Byte, or using clz with some shift and loop let mut temps = vec![]; let src = self.location_to_reg(Size::S32, loc, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; let src = if src == loc { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -3039,8 +3039,8 @@ impl Machine for MachineARM64 { src }; let tmp = { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); Location::GPR(tmp) @@ -3072,7 +3072,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_lsl, Size::S32, @@ -3087,7 +3087,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_lsr, Size::S32, @@ -3102,7 +3102,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_asr, Size::S32, @@ -3117,7 +3117,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let src2 = match loc_b { Location::Imm8(imm) => Location::Imm8(32 - (imm & 31)), @@ -3156,7 +3156,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_ror, Size::S32, @@ -3175,7 +3175,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3197,7 +3197,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3219,7 +3219,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3241,7 +3241,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3263,7 +3263,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3285,7 +3285,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_load unimplemented"); } fn i32_atomic_load_8u( @@ -3297,7 +3297,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_load_8u unimplemented"); } fn i32_atomic_load_16u( @@ -3309,7 +3309,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_load_16u unimplemented"); } fn i32_save( @@ -3321,7 +3321,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3343,7 +3343,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3365,7 +3365,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3387,7 +3387,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_save unimplemented"); } fn i32_atomic_save_8( @@ -3399,7 +3399,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_save_8 unimplemented"); } fn i32_atomic_save_16( @@ -3411,7 +3411,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_save_16 unimplemented"); } // i32 atomic Add with i32 @@ -3425,7 +3425,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_add unimplemented"); } // i32 atomic Add with u8 @@ -3439,7 +3439,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_add_8u unimplemented"); } // i32 atomic Add with u16 @@ -3453,7 +3453,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_add_16u unimplemented"); } // i32 atomic Sub with i32 @@ -3467,7 +3467,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_sub unimplemented"); } // i32 atomic Sub with u8 @@ -3481,7 +3481,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_sub_8u unimplemented"); } // i32 atomic Sub with u16 @@ -3495,7 +3495,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_sub_16u unimplemented"); } // i32 atomic And with i32 @@ -3509,7 +3509,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_and unimplemented"); } // i32 atomic And with u8 @@ -3523,7 +3523,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_and_8u unimplemented"); } // i32 atomic And with u16 @@ -3537,7 +3537,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_and_16u unimplemented"); } // i32 atomic Or with i32 @@ -3551,7 +3551,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_or unimplemented"); } // i32 atomic Or with u8 @@ -3565,7 +3565,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_or_8u unimplemented"); } // i32 atomic Or with u16 @@ -3579,7 +3579,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_or_16u unimplemented"); } // i32 atomic Xor with i32 @@ -3593,7 +3593,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xor unimplemented"); } // i32 atomic Xor with u8 @@ -3607,7 +3607,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xor_8u unimplemented"); } // i32 atomic Xor with u16 @@ -3621,7 +3621,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xor_16u unimplemented"); } // i32 atomic Exchange with i32 @@ -3635,7 +3635,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xchg unimplemented"); } // i32 atomic Exchange with u8 @@ -3649,7 +3649,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xchg_8u unimplemented"); } // i32 atomic Exchange with u16 @@ -3663,7 +3663,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_xchg_16u unimplemented"); } // i32 atomic Exchange with i32 @@ -3678,7 +3678,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_cmpxchg unimplemented"); } // i32 atomic Exchange with u8 @@ -3693,7 +3693,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_cmpxchg_8u unimplemented"); } // i32 atomic Exchange with u16 @@ -3708,7 +3708,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i32_atomic_cmpxchg_16u unimplemented"); } @@ -3716,7 +3716,7 @@ impl Machine for MachineARM64 { &mut self, _calling_convention: CallingConvention, reloc_target: RelocationTarget, - ) -> Result, CodegenError> { + ) -> Result, CompileError> { let mut relocations = vec![]; let next = self.get_label(); let reloc_at = self.assembler.get_offset().0; @@ -3736,7 +3736,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_add, Size::S64, @@ -3751,7 +3751,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_sub, Size::S64, @@ -3766,7 +3766,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_mul, Size::S64, @@ -3783,7 +3783,7 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S64, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S64, loc_b, &mut temps, ImmType::None, true, None)?; @@ -3808,7 +3808,7 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S64, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S64, loc_b, &mut temps, ImmType::None, true, None)?; @@ -3850,14 +3850,14 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S64, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S64, loc_b, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; let dest = if dest == src1 || dest == src2 { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -3888,14 +3888,14 @@ impl Machine for MachineARM64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { let mut temps = vec![]; let src1 = self.location_to_reg(Size::S64, loc_a, &mut temps, ImmType::None, true, None)?; let src2 = self.location_to_reg(Size::S64, loc_b, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; let dest = if dest == src1 || dest == src2 { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -3924,7 +3924,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_and, Size::S64, @@ -3939,7 +3939,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_or, Size::S64, @@ -3954,7 +3954,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_eor, Size::S64, @@ -3969,7 +3969,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Ge, loc_a, loc_b, ret) } fn i64_cmp_gt_s( @@ -3977,7 +3977,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Gt, loc_a, loc_b, ret) } fn i64_cmp_le_s( @@ -3985,7 +3985,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Le, loc_a, loc_b, ret) } fn i64_cmp_lt_s( @@ -3993,7 +3993,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Lt, loc_a, loc_b, ret) } fn i64_cmp_ge_u( @@ -4001,7 +4001,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Cs, loc_a, loc_b, ret) } fn i64_cmp_gt_u( @@ -4009,7 +4009,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Hi, loc_a, loc_b, ret) } fn i64_cmp_le_u( @@ -4017,7 +4017,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Ls, loc_a, loc_b, ret) } fn i64_cmp_lt_u( @@ -4025,7 +4025,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Cc, loc_a, loc_b, ret) } fn i64_cmp_ne( @@ -4033,7 +4033,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Ne, loc_a, loc_b, ret) } fn i64_cmp_eq( @@ -4041,13 +4041,13 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Eq, loc_a, loc_b, ret) } - fn i64_clz(&mut self, src: Location, dst: Location) -> Result<(), CodegenError> { + fn i64_clz(&mut self, src: Location, dst: Location) -> Result<(), CompileError> { self.emit_relaxed_binop(Assembler::emit_clz, Size::S64, src, dst, true) } - fn i64_ctz(&mut self, src: Location, dst: Location) -> Result<(), CodegenError> { + fn i64_ctz(&mut self, src: Location, dst: Location) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_reg(Size::S64, src, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S64, dst, &mut temps, ImmType::None, false, None)?; @@ -4061,13 +4061,13 @@ impl Machine for MachineARM64 { } Ok(()) } - fn i64_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i64_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { let mut temps = vec![]; let src = self.location_to_reg(Size::S64, loc, &mut temps, ImmType::None, true, None)?; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; let src = if src == loc { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); self.assembler @@ -4077,8 +4077,8 @@ impl Machine for MachineARM64 { src }; let tmp = { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; temps.push(tmp); Location::GPR(tmp) @@ -4110,7 +4110,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_lsl, Size::S64, @@ -4125,7 +4125,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_lsr, Size::S64, @@ -4140,7 +4140,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_asr, Size::S64, @@ -4155,7 +4155,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // there is no ROL on ARM64. We use ROR with 64-value instead let mut temps = vec![]; let src2 = match loc_b { @@ -4195,7 +4195,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3( Assembler::emit_ror, Size::S64, @@ -4214,7 +4214,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4236,7 +4236,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4258,7 +4258,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4280,7 +4280,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4302,7 +4302,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4324,7 +4324,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4346,7 +4346,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4368,7 +4368,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_load unimplemented"); } fn i64_atomic_load_8u( @@ -4380,7 +4380,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_load_8u unimplemented"); } fn i64_atomic_load_16u( @@ -4392,7 +4392,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_load_16u unimplemented"); } fn i64_atomic_load_32u( @@ -4404,7 +4404,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_load_32u unimplemented"); } fn i64_save( @@ -4416,7 +4416,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -4438,7 +4438,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -4460,7 +4460,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -4482,7 +4482,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -4504,7 +4504,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_save unimplemented"); } fn i64_atomic_save_8( @@ -4516,7 +4516,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_save_8 unimplemented"); } fn i64_atomic_save_16( @@ -4528,7 +4528,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_save_16 unimplemented"); } fn i64_atomic_save_32( @@ -4540,7 +4540,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_save_32 unimplemented"); } // i64 atomic Add with i64 @@ -4554,7 +4554,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_add unimplemented"); } // i64 atomic Add with u8 @@ -4568,7 +4568,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_add_8u unimplemented"); } // i64 atomic Add with u16 @@ -4582,7 +4582,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_add_16u unimplemented"); } // i64 atomic Add with u32 @@ -4596,7 +4596,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_add_32u unimplemented"); } // i64 atomic Sub with i64 @@ -4610,7 +4610,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_sub unimplemented"); } // i64 atomic Sub with u8 @@ -4624,7 +4624,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_sub_8u unimplemented"); } // i64 atomic Sub with u16 @@ -4638,7 +4638,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_sub_16u unimplemented"); } // i64 atomic Sub with u32 @@ -4652,7 +4652,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_sub_32u unimplemented"); } // i64 atomic And with i64 @@ -4666,7 +4666,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_and unimplemented"); } // i64 atomic And with u8 @@ -4680,7 +4680,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_and_8u unimplemented"); } // i64 atomic And with u16 @@ -4694,7 +4694,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_and_16u unimplemented"); } // i64 atomic And with u32 @@ -4708,7 +4708,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_and_32u unimplemented"); } // i64 atomic Or with i64 @@ -4722,7 +4722,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_or unimplemented"); } // i64 atomic Or with u8 @@ -4736,7 +4736,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_or_8u unimplemented"); } // i64 atomic Or with u16 @@ -4750,7 +4750,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_or_16u unimplemented"); } // i64 atomic Or with u32 @@ -4764,7 +4764,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_or_32u unimplemented"); } // i64 atomic xor with i64 @@ -4778,7 +4778,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xor unimplemented"); } // i64 atomic xor with u8 @@ -4792,7 +4792,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xor_8u unimplemented"); } // i64 atomic xor with u16 @@ -4806,7 +4806,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xor_16u unimplemented"); } // i64 atomic xor with u32 @@ -4820,7 +4820,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xor_32u unimplemented"); } // i64 atomic Exchange with i64 @@ -4834,7 +4834,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xchg unimplemented"); } // i64 atomic Exchange with u8 @@ -4848,7 +4848,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xchg_8u unimplemented"); } // i64 atomic Exchange with u16 @@ -4862,7 +4862,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xchg_16u unimplemented"); } // i64 atomic Exchange with u32 @@ -4876,7 +4876,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_xchg_32u unimplemented"); } // i64 atomic Exchange with i64 @@ -4891,7 +4891,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_cmpxchg unimplemented"); } // i64 atomic Exchange with u8 @@ -4906,7 +4906,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_cmpxchg_8u unimplemented"); } // i64 atomic Exchange with u16 @@ -4921,7 +4921,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_cmpxchg_16u unimplemented"); } // i64 atomic Exchange with u32 @@ -4936,7 +4936,7 @@ impl Machine for MachineARM64 { _imported_memories: bool, _offset: i32, _heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { codegen_error!("singlepass i64_atomic_cmpxchg_32u unimplemented"); } @@ -4949,7 +4949,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4972,7 +4972,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let canonicalize = canonicalize && self.arch_supports_canonicalize_nan(); self.memory_op( target_addr, @@ -5001,7 +5001,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5024,7 +5024,7 @@ impl Machine for MachineARM64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let canonicalize = canonicalize && self.arch_supports_canonicalize_nan(); self.memory_op( target_addr, @@ -5050,7 +5050,7 @@ impl Machine for MachineARM64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_reg(Size::S64, loc, &mut gprs, ImmType::NoneXzr, true, None)?; @@ -5076,7 +5076,7 @@ impl Machine for MachineARM64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_reg(Size::S32, loc, &mut gprs, ImmType::NoneXzr, true, None)?; @@ -5102,7 +5102,7 @@ impl Machine for MachineARM64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_reg(Size::S64, loc, &mut gprs, ImmType::NoneXzr, true, None)?; @@ -5128,7 +5128,7 @@ impl Machine for MachineARM64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_reg(Size::S32, loc, &mut gprs, ImmType::NoneXzr, true, None)?; @@ -5155,7 +5155,7 @@ impl Machine for MachineARM64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_neon(Size::S64, loc, &mut neons, ImmType::None, true)?; @@ -5193,7 +5193,7 @@ impl Machine for MachineARM64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_neon(Size::S64, loc, &mut neons, ImmType::None, true)?; @@ -5231,7 +5231,7 @@ impl Machine for MachineARM64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_neon(Size::S32, loc, &mut neons, ImmType::None, true)?; @@ -5269,7 +5269,7 @@ impl Machine for MachineARM64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut gprs = vec![]; let mut neons = vec![]; let src = self.location_to_neon(Size::S32, loc, &mut neons, ImmType::None, true)?; @@ -5301,18 +5301,18 @@ impl Machine for MachineARM64 { } Ok(()) } - fn convert_f64_f32(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_f64_f32(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fcvt, Size::S32, loc, ret, true) } - fn convert_f32_f64(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_f32_f64(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fcvt, Size::S64, loc, ret, true) } - fn f64_neg(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_neg(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fneg, Size::S64, loc, ret, true) } - fn f64_abs(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn f64_abs(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; @@ -5327,7 +5327,7 @@ impl Machine for MachineARM64 { self.release_gpr(tmp); Ok(()) } - fn emit_i64_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CodegenError> { + fn emit_i64_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CompileError> { self.assembler.emit_and( Size::S64, Location::GPR(tmp1), @@ -5349,19 +5349,19 @@ impl Machine for MachineARM64 { Location::GPR(tmp1), ) } - fn f64_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fsqrt, Size::S64, loc, ret, true) } - fn f64_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintz, Size::S64, loc, ret, true) } - fn f64_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintp, Size::S64, loc, ret, true) } - fn f64_floor(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_floor(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintm, Size::S64, loc, ret, true) } - fn f64_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintn, Size::S64, loc, ret, true) } fn f64_cmp_ge( @@ -5369,7 +5369,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_b, loc_a, false)?; @@ -5387,7 +5387,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_b, loc_a, false)?; @@ -5405,7 +5405,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_a, loc_b, false)?; @@ -5423,7 +5423,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_a, loc_b, false)?; @@ -5441,7 +5441,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_a, loc_b, false)?; @@ -5459,7 +5459,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S64, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S64, loc_a, loc_b, false)?; @@ -5477,7 +5477,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let old_fpcr = self.set_default_nan(&mut temps)?; self.emit_relaxed_binop3_neon( @@ -5499,7 +5499,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let old_fpcr = self.set_default_nan(&mut temps)?; self.emit_relaxed_binop3_neon( @@ -5521,7 +5521,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fadd, Size::S64, @@ -5536,7 +5536,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fsub, Size::S64, @@ -5551,7 +5551,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fmul, Size::S64, @@ -5566,7 +5566,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fdiv, Size::S64, @@ -5576,12 +5576,12 @@ impl Machine for MachineARM64 { ImmType::None, ) } - fn f32_neg(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_neg(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fneg, Size::S32, loc, ret, true) } - fn f32_abs(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn f32_abs(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; self.assembler.emit_and( @@ -5594,7 +5594,7 @@ impl Machine for MachineARM64 { self.release_gpr(tmp); Ok(()) } - fn emit_i32_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CodegenError> { + fn emit_i32_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CompileError> { self.assembler.emit_and( Size::S32, Location::GPR(tmp1), @@ -5614,19 +5614,19 @@ impl Machine for MachineARM64 { Location::GPR(tmp1), ) } - fn f32_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_fsqrt, Size::S32, loc, ret, true) } - fn f32_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintz, Size::S32, loc, ret, true) } - fn f32_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintp, Size::S32, loc, ret, true) } - fn f32_floor(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_floor(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintm, Size::S32, loc, ret, true) } - fn f32_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_binop_neon(Assembler::emit_frintn, Size::S32, loc, ret, true) } fn f32_cmp_ge( @@ -5634,7 +5634,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_b, loc_a, false)?; @@ -5652,7 +5652,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_b, loc_a, false)?; @@ -5670,7 +5670,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_a, loc_b, false)?; @@ -5688,7 +5688,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_a, loc_b, false)?; @@ -5706,7 +5706,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_a, loc_b, false)?; @@ -5724,7 +5724,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let dest = self.location_to_reg(Size::S32, ret, &mut temps, ImmType::None, false, None)?; self.emit_relaxed_binop_neon(Assembler::emit_fcmp, Size::S32, loc_a, loc_b, false)?; @@ -5742,7 +5742,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let old_fpcr = self.set_default_nan(&mut temps)?; self.emit_relaxed_binop3_neon( @@ -5764,7 +5764,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let mut temps = vec![]; let old_fpcr = self.set_default_nan(&mut temps)?; self.emit_relaxed_binop3_neon( @@ -5786,7 +5786,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fadd, Size::S32, @@ -5801,7 +5801,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fsub, Size::S32, @@ -5816,7 +5816,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fmul, Size::S32, @@ -5831,7 +5831,7 @@ impl Machine for MachineARM64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop3_neon( Assembler::emit_fdiv, Size::S32, @@ -5846,7 +5846,7 @@ impl Machine for MachineARM64 { &self, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { gen_std_trampoline_arm64(sig, calling_convention) } // Generates dynamic import function call trampoline for a function type. @@ -5855,7 +5855,7 @@ impl Machine for MachineARM64 { vmoffsets: &VMOffsets, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { gen_std_dynamic_import_trampoline_arm64(vmoffsets, sig, calling_convention) } // Singlepass calls import functions through a trampoline. @@ -5865,7 +5865,7 @@ impl Machine for MachineARM64 { index: FunctionIndex, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { gen_import_call_trampoline_arm64(vmoffsets, index, sig, calling_convention) } #[cfg(feature = "unwind")] diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index 2bfeaa9d6d6..63df504707d 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -15,8 +15,8 @@ use gimli::{write::CallFrameInstruction, X86_64}; use std::ops::{Deref, DerefMut}; use wasmer_compiler::wasmparser::Type as WpType; use wasmer_types::{ - CallingConvention, CpuFeature, CustomSection, CustomSectionProtection, Relocation, - RelocationKind, RelocationTarget, SectionBody, + CallingConvention, CompileError, CpuFeature, CustomSection, CustomSectionProtection, + Relocation, RelocationKind, RelocationTarget, SectionBody, Target, }; use wasmer_types::{FunctionBody, InstructionAddressMap, SourceLoc, TrapInformation}; use wasmer_types::{FunctionIndex, FunctionType, TrapCode, Type, VMOffsets}; @@ -29,14 +29,32 @@ pub struct AssemblerX64 { /// the simd instructions set on the target. /// Currently only supports SSE 4.2 and AVX pub simd_arch: Option, + /// Full Target cpu + pub target: Option, } impl AssemblerX64 { - fn new(baseaddr: usize, simd_arch: Option) -> Self { - Self { + fn new(baseaddr: usize, target: Option) -> Result { + let simd_arch = if target.is_none() { + Some(CpuFeature::SSE42) + } else { + let target = target.as_ref().unwrap(); + if target.cpu_features().contains(CpuFeature::AVX) { + Some(CpuFeature::AVX) + } else if target.cpu_features().contains(CpuFeature::SSE42) { + Some(CpuFeature::SSE42) + } else { + return Err(CompileError::UnsupportedTarget( + "x86_64 without AVX or SSE 4.2".to_string(), + )); + } + }; + + Ok(Self { inner: Assembler::new(baseaddr), simd_arch, - } + target, + }) } fn finalize(self) -> Result, DynasmError> { @@ -121,24 +139,25 @@ pub struct MachineX86_64 { } impl MachineX86_64 { - pub fn new(simd_arch: Option) -> Self { - MachineX86_64 { - assembler: AssemblerX64::new(0, simd_arch), + pub fn new(target: Option) -> Result { + let assembler = AssemblerX64::new(0, target)?; + Ok(MachineX86_64 { + assembler, used_gprs: 0, used_simd: 0, trap_table: TrapTable::default(), instructions_address_map: vec![], src_loc: 0, unwind_ops: vec![], - } + }) } pub fn emit_relaxed_binop( &mut self, - op: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CodegenError>, + op: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CompileError>, sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { enum RelaxMode { Direct, SrcToGPR, @@ -172,27 +191,27 @@ impl MachineX86_64 { match mode { RelaxMode::SrcToGPR => { - let temp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let temp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(sz, src, Location::GPR(temp))?; op(&mut self.assembler, sz, Location::GPR(temp), dst)?; self.release_gpr(temp); } RelaxMode::DstToGPR => { - let temp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let temp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(sz, dst, Location::GPR(temp))?; op(&mut self.assembler, sz, src, Location::GPR(temp))?; self.release_gpr(temp); } RelaxMode::BothToGPR => { - let temp_src = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let temp_src = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let temp_dst = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let temp_dst = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(sz, src, Location::GPR(temp_src))?; self.move_location(sz, dst, Location::GPR(temp_dst))?; @@ -219,16 +238,16 @@ impl MachineX86_64 { } pub fn emit_relaxed_zx_sx( &mut self, - op: fn(&mut AssemblerX64, Size, Location, Size, Location) -> Result<(), CodegenError>, + op: fn(&mut AssemblerX64, Size, Location, Size, Location) -> Result<(), CompileError>, sz_src: Size, src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match src { Location::Imm32(_) | Location::Imm64(_) => { - let tmp_src = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_src = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_mov(Size::S64, src, Location::GPR(tmp_src))?; @@ -237,8 +256,8 @@ impl MachineX86_64 { match dst { Location::Imm32(_) | Location::Imm64(_) => unreachable!(), Location::Memory(_, _) => { - let tmp_dst = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_dst = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; op( &mut self.assembler, @@ -265,8 +284,8 @@ impl MachineX86_64 { match dst { Location::Imm32(_) | Location::Imm64(_) => unreachable!(), Location::Memory(_, _) => { - let tmp_dst = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_dst = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; op( &mut self.assembler, @@ -296,14 +315,14 @@ impl MachineX86_64 { /// I32 binary operation with both operands popped from the virtual stack. fn emit_binop_i32( &mut self, - f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CodegenError>, + f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CompileError>, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if loc_a != ret { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc_a, Location::GPR(tmp))?; self.emit_relaxed_binop(f, Size::S32, loc_b, Location::GPR(tmp))?; @@ -317,14 +336,14 @@ impl MachineX86_64 { /// I64 binary operation with both operands popped from the virtual stack. fn emit_binop_i64( &mut self, - f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CodegenError>, + f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CompileError>, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if loc_a != ret { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc_a, Location::GPR(tmp))?; self.emit_relaxed_binop(f, Size::S64, loc_b, Location::GPR(tmp))?; @@ -342,7 +361,7 @@ impl MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match ret { Location::GPR(x) => { self.emit_relaxed_cmp(Size::S64, loc_b, loc_a)?; @@ -351,8 +370,8 @@ impl MachineX86_64 { .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x))?; } Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_cmp(Size::S64, loc_b, loc_a)?; self.assembler.emit_set(c, tmp)?; @@ -370,11 +389,11 @@ impl MachineX86_64 { /// I64 shift with both operands popped from the virtual stack. fn emit_shift_i64( &mut self, - f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CodegenError>, + f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CompileError>, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler .emit_mov(Size::S64, loc_b, Location::GPR(GPR::RCX))?; @@ -387,11 +406,11 @@ impl MachineX86_64 { /// Moves `loc` to a valid location for `div`/`idiv`. fn emit_relaxed_xdiv( &mut self, - op: fn(&mut AssemblerX64, Size, Location) -> Result<(), CodegenError>, + op: fn(&mut AssemblerX64, Size, Location) -> Result<(), CompileError>, sz: Size, loc: Location, integer_division_by_zero: Label, - ) -> Result { + ) -> Result { self.assembler.emit_cmp(sz, Location::Imm32(0), loc)?; self.assembler .emit_jmp(Condition::Equal, integer_division_by_zero)?; @@ -419,7 +438,7 @@ impl MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match ret { Location::GPR(x) => { self.emit_relaxed_cmp(Size::S32, loc_b, loc_a)?; @@ -428,8 +447,8 @@ impl MachineX86_64 { .emit_and(Size::S32, Location::Imm32(0xff), Location::GPR(x))?; } Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.emit_relaxed_cmp(Size::S32, loc_b, loc_a)?; self.assembler.emit_set(c, tmp)?; @@ -447,11 +466,11 @@ impl MachineX86_64 { /// I32 shift with both operands popped from the virtual stack. fn emit_shift_i32( &mut self, - f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CodegenError>, + f: fn(&mut AssemblerX64, Size, Location, Location) -> Result<(), CompileError>, loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler .emit_mov(Size::S32, loc_b, Location::GPR(GPR::RCX))?; @@ -463,7 +482,7 @@ impl MachineX86_64 { } #[allow(clippy::too_many_arguments)] - fn memory_op Result<(), CodegenError>>( + fn memory_op Result<(), CompileError>>( &mut self, addr: Location, memarg: &MemoryImmediate, @@ -474,17 +493,17 @@ impl MachineX86_64 { offset: i32, heap_access_oob: Label, cb: F, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // This function as been re-writen to use only 2 temporary register instead of 3 // without compromisong on the perfomances. // The number of memory move should be equivalent to previous 3-temp regs version // Register pressure is high on x86_64, and this is needed to be able to use // instruction that neead RAX, like cmpxchg for example - let tmp_addr = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_addr = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; // Reusing `tmp_addr` for temporary indirection here, since it's not used before the last reference to `{base,bound}_loc`. @@ -573,8 +592,8 @@ impl MachineX86_64 { let align = memarg.align; if check_alignment && align != 1 { - let tmp_aligncheck = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_aligncheck = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_mov( Size::S32, @@ -600,7 +619,7 @@ impl MachineX86_64 { } #[allow(clippy::too_many_arguments)] - fn emit_compare_and_swap Result<(), CodegenError>>( + fn emit_compare_and_swap Result<(), CompileError>>( &mut self, loc: Location, target: Location, @@ -614,7 +633,7 @@ impl MachineX86_64 { offset: i32, heap_access_oob: Label, cb: F, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if memory_sz > stack_sz { codegen_error!("singlepass emit_compare_and_swap unreachable"); } @@ -671,15 +690,15 @@ impl MachineX86_64 { overflow_label: Label, nan_label: Label, succeed_label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let lower_bound = f32::to_bits(lower_bound); let upper_bound = f32::to_bits(upper_bound); - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_x = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // Underflow. @@ -725,7 +744,7 @@ impl MachineX86_64 { reg: XMM, lower_bound: f32, upper_bound: f32, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let trap_overflow = self.assembler.get_label(); let trap_badconv = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -753,10 +772,10 @@ impl MachineX86_64 { } #[allow(clippy::too_many_arguments)] fn emit_f32_int_conv_check_sat< - F1: FnOnce(&mut Self) -> Result<(), CodegenError>, - F2: FnOnce(&mut Self) -> Result<(), CodegenError>, - F3: FnOnce(&mut Self) -> Result<(), CodegenError>, - F4: FnOnce(&mut Self) -> Result<(), CodegenError>, + F1: FnOnce(&mut Self) -> Result<(), CompileError>, + F2: FnOnce(&mut Self) -> Result<(), CompileError>, + F3: FnOnce(&mut Self) -> Result<(), CompileError>, + F4: FnOnce(&mut Self) -> Result<(), CompileError>, >( &mut self, reg: XMM, @@ -766,7 +785,7 @@ impl MachineX86_64 { overflow_cb: F2, nan_cb: Option, convert_cb: F4, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // As an optimization nan_cb is optional, and when set to None we turn // use 'underflow' as the 'nan' label. This is useful for callers who // set the return value to zero for both underflow and nan. @@ -820,15 +839,15 @@ impl MachineX86_64 { overflow_label: Label, nan_label: Label, succeed_label: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let lower_bound = f64::to_bits(lower_bound); let upper_bound = f64::to_bits(upper_bound); - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_x = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // Underflow. @@ -873,7 +892,7 @@ impl MachineX86_64 { reg: XMM, lower_bound: f64, upper_bound: f64, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let trap_overflow = self.assembler.get_label(); let trap_badconv = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -898,10 +917,10 @@ impl MachineX86_64 { } #[allow(clippy::too_many_arguments)] fn emit_f64_int_conv_check_sat< - F1: FnOnce(&mut Self) -> Result<(), CodegenError>, - F2: FnOnce(&mut Self) -> Result<(), CodegenError>, - F3: FnOnce(&mut Self) -> Result<(), CodegenError>, - F4: FnOnce(&mut Self) -> Result<(), CodegenError>, + F1: FnOnce(&mut Self) -> Result<(), CompileError>, + F2: FnOnce(&mut Self) -> Result<(), CompileError>, + F3: FnOnce(&mut Self) -> Result<(), CompileError>, + F4: FnOnce(&mut Self) -> Result<(), CompileError>, >( &mut self, reg: XMM, @@ -911,7 +930,7 @@ impl MachineX86_64 { overflow_cb: F2, nan_cb: Option, convert_cb: F4, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // As an optimization nan_cb is optional, and when set to None we turn // use 'underflow' as the 'nan' label. This is useful for callers who // set the return value to zero for both underflow and nan. @@ -957,11 +976,11 @@ impl MachineX86_64 { /// Moves `src1` and `src2` to valid locations and possibly adds a layer of indirection for `dst` for AVX instructions. fn emit_relaxed_avx( &mut self, - op: fn(&mut AssemblerX64, XMM, XMMOrMemory, XMM) -> Result<(), CodegenError>, + op: fn(&mut AssemblerX64, XMM, XMMOrMemory, XMM) -> Result<(), CompileError>, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx_base( |this, src1, src2, dst| op(&mut this.assembler, src1, src2, dst), src1, @@ -972,25 +991,25 @@ impl MachineX86_64 { /// Moves `src1` and `src2` to valid locations and possibly adds a layer of indirection for `dst` for AVX instructions. fn emit_relaxed_avx_base< - F: FnOnce(&mut Self, XMM, XMMOrMemory, XMM) -> Result<(), CodegenError>, + F: FnOnce(&mut Self, XMM, XMMOrMemory, XMM) -> Result<(), CompileError>, >( &mut self, op: F, src1: Location, src2: Location, dst: Location, - ) -> Result<(), CodegenError> { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp3 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp3 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmpg = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let src1 = match src1 { @@ -1063,12 +1082,12 @@ impl MachineX86_64 { Ok(()) } - fn convert_i64_f64_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i64_f64_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; @@ -1087,19 +1106,19 @@ impl MachineX86_64 { Location::GPR(tmp_out), ) }, - None:: Result<(), CodegenError>>, + None:: Result<(), CompileError>>, |this| { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i64_trunc_uf64(tmp_in, tmp_out) } else { - let tmp = this.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = this.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_x1 = this.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x1 = this.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_x2 = this.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x2 = this.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; this.assembler.emit_mov( @@ -1151,13 +1170,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i64_f64_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i64_f64_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i64_trunc_uf64(tmp_in, tmp_out)?; @@ -1165,24 +1184,24 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm2 self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; self.emit_f64_int_conv_check_trap(tmp_in, GEF64_LT_U64_MIN, LEF64_GT_U64_MAX)?; - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; // r15 - let tmp_x1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm1 - let tmp_x2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm3 self.move_location( @@ -1218,12 +1237,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i64_f64_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i64_f64_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; @@ -1265,13 +1284,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i64_f64_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i64_f64_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i64_trunc_sf64(tmp_in, tmp_out)?; @@ -1279,11 +1298,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; @@ -1298,12 +1317,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i32_f64_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i32_f64_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; let real_in = match loc { @@ -1357,13 +1376,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i32_f64_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i32_f64_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i32_trunc_sf64(tmp_in, tmp_out)?; @@ -1371,11 +1390,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; let real_in = match loc { @@ -1402,12 +1421,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i32_f64_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i32_f64_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; @@ -1426,7 +1445,7 @@ impl MachineX86_64 { Location::GPR(tmp_out), ) }, - None:: Result<(), CodegenError>>, + None:: Result<(), CompileError>>, |this| { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_uf64(tmp_in, tmp_out) @@ -1443,13 +1462,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i32_f64_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i32_f64_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i32_trunc_uf64(tmp_in, tmp_out)?; @@ -1457,11 +1476,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp_in))?; @@ -1476,12 +1495,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i64_f32_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i64_f32_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; @@ -1500,19 +1519,19 @@ impl MachineX86_64 { Location::GPR(tmp_out), ) }, - None:: Result<(), CodegenError>>, + None:: Result<(), CompileError>>, |this| { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i64_trunc_uf32(tmp_in, tmp_out) } else { - let tmp = this.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = this.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_x1 = this.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x1 = this.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_x2 = this.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x2 = this.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; this.assembler.emit_mov( @@ -1564,13 +1583,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i64_f32_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i64_f32_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i64_trunc_uf32(tmp_in, tmp_out)?; @@ -1578,24 +1597,24 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm2 self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.emit_f32_int_conv_check_trap(tmp_in, GEF32_LT_U64_MIN, LEF32_GT_U64_MAX)?; - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; // r15 - let tmp_x1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm1 - let tmp_x2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_x2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; // xmm3 self.move_location( @@ -1631,12 +1650,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i64_f32_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i64_f32_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; @@ -1678,13 +1697,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i64_f32_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i64_f32_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i64_trunc_sf32(tmp_in, tmp_out)?; @@ -1692,11 +1711,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; @@ -1710,12 +1729,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i32_f32_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i32_f32_s_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; @@ -1757,13 +1776,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i32_f32_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i32_f32_s_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i32_trunc_sf32(tmp_in, tmp_out)?; @@ -1771,11 +1790,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; @@ -1790,12 +1809,12 @@ impl MachineX86_64 { } Ok(()) } - fn convert_i32_f32_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn convert_i32_f32_u_s(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.emit_f32_int_conv_check_sat( @@ -1813,7 +1832,7 @@ impl MachineX86_64 { Location::GPR(tmp_out), ) }, - None:: Result<(), CodegenError>>, + None:: Result<(), CompileError>>, |this| { if this.assembler.arch_has_itruncf() { this.assembler.arch_emit_i32_trunc_uf32(tmp_in, tmp_out) @@ -1830,13 +1849,13 @@ impl MachineX86_64 { self.release_gpr(tmp_out); Ok(()) } - fn convert_i32_f32_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_i32_f32_u_u(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_itruncf() { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.assembler.arch_emit_i32_trunc_uf32(tmp_in, tmp_out)?; @@ -1844,11 +1863,11 @@ impl MachineX86_64 { self.release_simd(tmp_in); self.release_gpr(tmp_out); } else { - let tmp_out = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_out = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmp_in = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp_in = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp_in))?; self.emit_f32_int_conv_check_trap(tmp_in, GEF32_LT_U32_MIN, LEF32_GT_U32_MAX)?; @@ -1868,7 +1887,7 @@ impl MachineX86_64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(AssemblerX64::emit_xchg, sz, src, dst) } @@ -1894,11 +1913,11 @@ impl MachineX86_64 { self.used_simd &= !(1 << r.into_index()); ret } - fn emit_unwind_op(&mut self, op: UnwindOps) -> Result<(), CodegenError> { + fn emit_unwind_op(&mut self, op: UnwindOps) -> Result<(), CompileError> { self.unwind_ops.push((self.get_offset().0, op)); Ok(()) } - fn emit_illegal_op_internal(&mut self, trap: TrapCode) -> Result<(), CodegenError> { + fn emit_illegal_op_internal(&mut self, trap: TrapCode) -> Result<(), CompileError> { let v = trap as u8; self.assembler.emit_ud1_payload(v) } @@ -1980,13 +1999,13 @@ impl Machine for MachineX86_64 { self.used_gprs_insert(gpr); } - fn push_used_gpr(&mut self, used_gprs: &[GPR]) -> Result { + fn push_used_gpr(&mut self, used_gprs: &[GPR]) -> Result { for r in used_gprs.iter() { self.assembler.emit_push(Size::S64, Location::GPR(*r))?; } Ok(used_gprs.len() * 8) } - fn pop_used_gpr(&mut self, used_gprs: &[GPR]) -> Result<(), CodegenError> { + fn pop_used_gpr(&mut self, used_gprs: &[GPR]) -> Result<(), CompileError> { for r in used_gprs.iter().rev() { self.assembler.emit_pop(Size::S64, Location::GPR(*r))?; } @@ -2035,7 +2054,7 @@ impl Machine for MachineX86_64 { assert!(self.used_simd_remove(&simd)); } - fn push_used_simd(&mut self, used_xmms: &[XMM]) -> Result { + fn push_used_simd(&mut self, used_xmms: &[XMM]) -> Result { self.adjust_stack((used_xmms.len() * 8) as u32)?; for (i, r) in used_xmms.iter().enumerate() { @@ -2048,7 +2067,7 @@ impl Machine for MachineX86_64 { Ok(used_xmms.len() * 8) } - fn pop_used_simd(&mut self, used_xmms: &[XMM]) -> Result<(), CodegenError> { + fn pop_used_simd(&mut self, used_xmms: &[XMM]) -> Result<(), CompileError> { for (i, r) in used_xmms.iter().enumerate() { self.move_location( Size::S64, @@ -2134,7 +2153,7 @@ impl Machine for MachineX86_64 { } // Adjust stack for locals - fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn adjust_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { self.assembler.emit_sub( Size::S64, Location::Imm32(delta_stack_offset), @@ -2142,14 +2161,14 @@ impl Machine for MachineX86_64 { ) } // restore stack - fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn restore_stack(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { self.assembler.emit_add( Size::S64, Location::Imm32(delta_stack_offset), Location::GPR(GPR::RSP), ) } - fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CodegenError> { + fn pop_stack_locals(&mut self, delta_stack_offset: u32) -> Result<(), CompileError> { self.assembler.emit_add( Size::S64, Location::Imm32(delta_stack_offset), @@ -2162,7 +2181,7 @@ impl Machine for MachineX86_64 { _size: Size, loc: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match loc { Location::Imm64(_) | Location::Memory(_, _) | Location::Memory2(_, _, _, _) => { let tmp = self.pick_temp_gpr(); @@ -2183,7 +2202,7 @@ impl Machine for MachineX86_64 { } // Zero a location that is 32bits - fn zero_location(&mut self, size: Size, location: Location) -> Result<(), CodegenError> { + fn zero_location(&mut self, size: Size, location: Location) -> Result<(), CompileError> { self.assembler.emit_mov(size, Location::Imm32(0), location) } @@ -2209,7 +2228,7 @@ impl Machine for MachineX86_64 { } } // Move a local to the stack - fn move_local(&mut self, stack_offset: i32, location: Location) -> Result<(), CodegenError> { + fn move_local(&mut self, stack_offset: i32, location: Location) -> Result<(), CompileError> { self.assembler.emit_mov( Size::S64, location, @@ -2331,14 +2350,14 @@ impl Machine for MachineX86_64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match source { Location::GPR(_) => self.assembler.emit_mov(size, source, dest), Location::Memory(_, _) => match dest { Location::GPR(_) | Location::SIMD(_) => self.assembler.emit_mov(size, source, dest), Location::Memory(_, _) | Location::Memory2(_, _, _, _) => { - let tmp = self.pick_temp_gpr().ok_or(CodegenError { - message: "singlepass can't pick a temp gpr".to_string(), + let tmp = self.pick_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass can't pick a temp gpr".to_owned()) })?; self.assembler.emit_mov(size, source, Location::GPR(tmp))?; self.assembler.emit_mov(size, Location::GPR(tmp), dest) @@ -2348,8 +2367,8 @@ impl Machine for MachineX86_64 { Location::Memory2(_, _, _, _) => match dest { Location::GPR(_) | Location::SIMD(_) => self.assembler.emit_mov(size, source, dest), Location::Memory(_, _) | Location::Memory2(_, _, _, _) => { - let tmp = self.pick_temp_gpr().ok_or(CodegenError { - message: "singlepass can't pick a temp gpr".to_string(), + let tmp = self.pick_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass can't pick a temp gpr".to_owned()) })?; self.assembler.emit_mov(size, source, Location::GPR(tmp))?; self.assembler.emit_mov(size, Location::GPR(tmp), dest) @@ -2359,8 +2378,8 @@ impl Machine for MachineX86_64 { Location::Imm8(_) | Location::Imm32(_) | Location::Imm64(_) => match dest { Location::GPR(_) | Location::SIMD(_) => self.assembler.emit_mov(size, source, dest), Location::Memory(_, _) | Location::Memory2(_, _, _, _) => { - let tmp = self.pick_temp_gpr().ok_or(CodegenError { - message: "singlepass can't pick a temp gpr".to_string(), + let tmp = self.pick_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass can't pick a temp gpr".to_owned()) })?; self.assembler.emit_mov(size, source, Location::GPR(tmp))?; self.assembler.emit_mov(size, Location::GPR(tmp), dest) @@ -2379,11 +2398,11 @@ impl Machine for MachineX86_64 { source: Location, size_op: Size, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let dst = match dest { Location::Memory(_, _) | Location::Memory2(_, _, _, _) => { - Location::GPR(self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + Location::GPR(self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?) } Location::GPR(_) | Location::SIMD(_) => dest, @@ -2422,7 +2441,7 @@ impl Machine for MachineX86_64 { size: Size, reg: Location, mem: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match reg { Location::GPR(_) => { match mem { @@ -2445,7 +2464,7 @@ impl Machine for MachineX86_64 { &mut self, init_stack_loc_cnt: u64, last_stack_loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { // Since these assemblies take up to 24 bytes, if more than 2 slots are initialized, then they are smaller. self.assembler.emit_mov( Size::S64, @@ -2459,7 +2478,7 @@ impl Machine for MachineX86_64 { self.assembler.emit_rep_stosq() } // Restore save_area - fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CodegenError> { + fn restore_saved_area(&mut self, saved_area_offset: i32) -> Result<(), CompileError> { self.assembler.emit_lea( Size::S64, Location::Memory(GPR::RBP, -saved_area_offset), @@ -2467,7 +2486,7 @@ impl Machine for MachineX86_64 { ) } // Pop a location - fn pop_location(&mut self, location: Location) -> Result<(), CodegenError> { + fn pop_location(&mut self, location: Location) -> Result<(), CompileError> { self.assembler.emit_pop(Size::S64, location) } // Create a new `MachineState` with default values. @@ -2484,19 +2503,19 @@ impl Machine for MachineX86_64 { self.assembler.get_offset() } - fn finalize_function(&mut self) -> Result<(), CodegenError> { + fn finalize_function(&mut self) -> Result<(), CompileError> { self.assembler.finalize_function()?; Ok(()) } - fn emit_function_prolog(&mut self) -> Result<(), CodegenError> { + fn emit_function_prolog(&mut self) -> Result<(), CompileError> { self.emit_push(Size::S64, Location::GPR(GPR::RBP))?; self.emit_unwind_op(UnwindOps::PushFP { up_to_sp: 16 })?; self.move_location(Size::S64, Location::GPR(GPR::RSP), Location::GPR(GPR::RBP))?; self.emit_unwind_op(UnwindOps::DefineNewFrame) } - fn emit_function_epilog(&mut self) -> Result<(), CodegenError> { + fn emit_function_epilog(&mut self) -> Result<(), CompileError> { self.move_location(Size::S64, Location::GPR(GPR::RBP), Location::GPR(GPR::RSP))?; self.emit_pop(Size::S64, Location::GPR(GPR::RBP)) } @@ -2506,7 +2525,7 @@ impl Machine for MachineX86_64 { ty: WpType, canonicalize: bool, loc: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if canonicalize { self.canonicalize_nan( match ty { @@ -2522,7 +2541,7 @@ impl Machine for MachineX86_64 { } } - fn emit_function_return_float(&mut self) -> Result<(), CodegenError> { + fn emit_function_return_float(&mut self) -> Result<(), CompileError> { self.move_location( Size::S64, Location::GPR(GPR::RAX), @@ -2538,20 +2557,20 @@ impl Machine for MachineX86_64 { sz: Size, input: Location, output: Location, - ) -> Result<(), CodegenError> { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp3 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp3 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(sz, input, Location::SIMD(tmp1))?; - let tmpg1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; match sz { @@ -2591,7 +2610,7 @@ impl Machine for MachineX86_64 { Ok(()) } - fn emit_illegal_op(&mut self, trap: TrapCode) -> Result<(), CodegenError> { + fn emit_illegal_op(&mut self, trap: TrapCode) -> Result<(), CompileError> { // code below is kept as a reference on how to emit illegal op with trap info // without an Undefined opcode with payload /* @@ -2612,16 +2631,16 @@ impl Machine for MachineX86_64 { fn get_label(&mut self) -> Label { self.assembler.new_dynamic_label() } - fn emit_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_label(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_label(label) } fn get_grp_for_call(&self) -> GPR { GPR::RAX } - fn emit_call_register(&mut self, reg: GPR) -> Result<(), CodegenError> { + fn emit_call_register(&mut self, reg: GPR) -> Result<(), CompileError> { self.assembler.emit_call_register(reg) } - fn emit_call_label(&mut self, label: Label) -> Result<(), CodegenError> { + fn emit_call_label(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_call_label(label) } fn get_gpr_for_ret(&self) -> GPR { @@ -2638,16 +2657,16 @@ impl Machine for MachineX86_64 { fn arch_emit_indirect_call_with_trampoline( &mut self, location: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler .arch_emit_indirect_call_with_trampoline(location) } - fn emit_debug_breakpoint(&mut self) -> Result<(), CodegenError> { + fn emit_debug_breakpoint(&mut self) -> Result<(), CompileError> { self.assembler.emit_bkpt() } - fn emit_call_location(&mut self, location: Location) -> Result<(), CodegenError> { + fn emit_call_location(&mut self, location: Location) -> Result<(), CompileError> { self.assembler.emit_call_location(location) } @@ -2656,7 +2675,7 @@ impl Machine for MachineX86_64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_lea(size, source, dest) } // logic @@ -2666,7 +2685,7 @@ impl Machine for MachineX86_64 { source: Location, dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_and(size, source, dest) } fn location_xor( @@ -2675,7 +2694,7 @@ impl Machine for MachineX86_64 { source: Location, dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_xor(size, source, dest) } fn location_or( @@ -2684,7 +2703,7 @@ impl Machine for MachineX86_64 { source: Location, dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_or(size, source, dest) } fn location_test( @@ -2692,7 +2711,7 @@ impl Machine for MachineX86_64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_test(size, source, dest) } // math @@ -2702,7 +2721,7 @@ impl Machine for MachineX86_64 { source: Location, dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_add(size, source, dest) } fn location_sub( @@ -2711,7 +2730,7 @@ impl Machine for MachineX86_64 { source: Location, dest: Location, _flags: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_sub(size, source, dest) } fn location_cmp( @@ -2719,42 +2738,42 @@ impl Machine for MachineX86_64 { size: Size, source: Location, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.assembler.emit_cmp(size, source, dest) } // (un)conditionnal jmp // (un)conditionnal jmp - fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_unconditionnal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::None, label) } - fn jmp_on_equal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_equal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::Equal, label) } - fn jmp_on_different(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_different(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::NotEqual, label) } - fn jmp_on_above(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_above(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::Above, label) } - fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_aboveequal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::AboveEqual, label) } - fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_belowequal(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::BelowEqual, label) } - fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CodegenError> { + fn jmp_on_overflow(&mut self, label: Label) -> Result<(), CompileError> { self.assembler.emit_jmp(Condition::Carry, label) } // jmp table - fn emit_jmp_to_jumptable(&mut self, label: Label, cond: Location) -> Result<(), CodegenError> { - let tmp1 = self.pick_temp_gpr().ok_or(CodegenError { - message: "singlepass can't pick a temp gpr".to_string(), - })?; + fn emit_jmp_to_jumptable(&mut self, label: Label, cond: Location) -> Result<(), CompileError> { + let tmp1 = self + .pick_temp_gpr() + .ok_or_else(|| CompileError::Codegen("singlepass can't pick a temp gpr".to_owned()))?; self.reserve_gpr(tmp1); - let tmp2 = self.pick_temp_gpr().ok_or(CodegenError { - message: "singlepass can't pick a temp gpr".to_string(), - })?; + let tmp2 = self + .pick_temp_gpr() + .ok_or_else(|| CompileError::Codegen("singlepass can't pick a temp gpr".to_owned()))?; self.reserve_gpr(tmp2); self.assembler.emit_lea_label(label, Location::GPR(tmp1))?; @@ -2771,7 +2790,7 @@ impl Machine for MachineX86_64 { Ok(()) } - fn align_for_loop(&mut self) -> Result<(), CodegenError> { + fn align_for_loop(&mut self) -> Result<(), CompileError> { // Pad with NOPs to the next 16-byte boundary. // Here we don't use the dynasm `.align 16` attribute because it pads the alignment with single-byte nops // which may lead to efficiency problems. @@ -2785,18 +2804,18 @@ impl Machine for MachineX86_64 { Ok(()) } - fn emit_ret(&mut self) -> Result<(), CodegenError> { + fn emit_ret(&mut self) -> Result<(), CompileError> { self.assembler.emit_ret() } - fn emit_push(&mut self, size: Size, loc: Location) -> Result<(), CodegenError> { + fn emit_push(&mut self, size: Size, loc: Location) -> Result<(), CompileError> { self.assembler.emit_push(size, loc) } - fn emit_pop(&mut self, size: Size, loc: Location) -> Result<(), CodegenError> { + fn emit_pop(&mut self, size: Size, loc: Location) -> Result<(), CompileError> { self.assembler.emit_pop(size, loc) } - fn emit_memory_fence(&mut self) -> Result<(), CodegenError> { + fn emit_memory_fence(&mut self) -> Result<(), CompileError> { // nothing on x86_64 Ok(()) } @@ -2808,12 +2827,12 @@ impl Machine for MachineX86_64 { source: Location, size_op: Size, dest: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.move_location_extend(size_val, signed, source, size_op, dest)?; self.assembler.emit_neg(size_val, dest) } - fn emit_imul_imm32(&mut self, size: Size, imm32: u32, gpr: GPR) -> Result<(), CodegenError> { + fn emit_imul_imm32(&mut self, size: Size, imm32: u32, gpr: GPR) -> Result<(), CompileError> { match size { Size::S64 => self.assembler.emit_imul_imm32_gpr64(imm32, gpr), _ => { @@ -2828,7 +2847,7 @@ impl Machine for MachineX86_64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(AssemblerX64::emit_mov, sz, src, dst) } fn emit_relaxed_cmp( @@ -2836,7 +2855,7 @@ impl Machine for MachineX86_64 { sz: Size, src: Location, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_binop(AssemblerX64::emit_cmp, sz, src, dst) } fn emit_relaxed_zero_extension( @@ -2845,7 +2864,7 @@ impl Machine for MachineX86_64 { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if (sz_src == Size::S32 || sz_src == Size::S64) && sz_dst == Size::S64 { self.emit_relaxed_binop(AssemblerX64::emit_mov, sz_src, src, dst) } else { @@ -2858,7 +2877,7 @@ impl Machine for MachineX86_64 { src: Location, sz_dst: Size, dst: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_zx_sx(AssemblerX64::emit_movsx, sz_src, src, sz_dst, dst) } @@ -2867,7 +2886,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_add, loc_a, loc_b, ret) } fn emit_binop_sub32( @@ -2875,7 +2894,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_sub, loc_a, loc_b, ret) } fn emit_binop_mul32( @@ -2883,7 +2902,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_imul, loc_a, loc_b, ret) } fn emit_binop_udiv32( @@ -2893,7 +2912,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX))?; @@ -2916,7 +2935,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX))?; @@ -2938,7 +2957,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S32, loc_a, Location::GPR(GPR::RAX))?; @@ -2961,7 +2980,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. let normal_path = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -2994,7 +3013,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_and, loc_a, loc_b, ret) } fn emit_binop_or32( @@ -3002,7 +3021,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_or, loc_a, loc_b, ret) } fn emit_binop_xor32( @@ -3010,7 +3029,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i32(AssemblerX64::emit_xor, loc_a, loc_b, ret) } fn i32_cmp_ge_s( @@ -3018,7 +3037,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::GreaterEqual, loc_a, loc_b, ret) } fn i32_cmp_gt_s( @@ -3026,7 +3045,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Greater, loc_a, loc_b, ret) } fn i32_cmp_le_s( @@ -3034,7 +3053,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::LessEqual, loc_a, loc_b, ret) } fn i32_cmp_lt_s( @@ -3042,7 +3061,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Less, loc_a, loc_b, ret) } fn i32_cmp_ge_u( @@ -3050,7 +3069,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::AboveEqual, loc_a, loc_b, ret) } fn i32_cmp_gt_u( @@ -3058,7 +3077,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Above, loc_a, loc_b, ret) } fn i32_cmp_le_u( @@ -3066,7 +3085,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::BelowEqual, loc_a, loc_b, ret) } fn i32_cmp_lt_u( @@ -3074,7 +3093,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Below, loc_a, loc_b, ret) } fn i32_cmp_ne( @@ -3082,7 +3101,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::NotEqual, loc_a, loc_b, ret) } fn i32_cmp_eq( @@ -3090,14 +3109,14 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i32_dynamic_b(Condition::Equal, loc_a, loc_b, ret) } - fn i32_clz(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i32_clz(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { let src = match loc { Location::Imm32(_) | Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; tmp @@ -3108,8 +3127,8 @@ impl Machine for MachineX86_64 { } }; let dst = match ret { - Location::Memory(_, _) => self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + Location::Memory(_, _) => self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?, Location::GPR(reg) => reg, _ => { @@ -3147,11 +3166,11 @@ impl Machine for MachineX86_64 { }; Ok(()) } - fn i32_ctz(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i32_ctz(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { let src = match loc { Location::Imm32(_) | Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; tmp @@ -3162,8 +3181,8 @@ impl Machine for MachineX86_64 { } }; let dst = match ret { - Location::Memory(_, _) => self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + Location::Memory(_, _) => self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?, Location::GPR(reg) => reg, _ => { @@ -3200,16 +3219,16 @@ impl Machine for MachineX86_64 { }; Ok(()) } - fn i32_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i32_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { match loc { Location::Imm32(_) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; if let Location::Memory(_, _) = ret { - let out_tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let out_tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_popcnt( Size::S32, @@ -3226,8 +3245,8 @@ impl Machine for MachineX86_64 { } Location::Memory(_, _) | Location::GPR(_) => { if let Location::Memory(_, _) = ret { - let out_tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let out_tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_popcnt(Size::S32, loc, Location::GPR(out_tmp))?; @@ -3248,7 +3267,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i32(AssemblerX64::emit_shl, loc_a, loc_b, ret) } fn i32_shr( @@ -3256,7 +3275,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i32(AssemblerX64::emit_shr, loc_a, loc_b, ret) } fn i32_sar( @@ -3264,7 +3283,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i32(AssemblerX64::emit_sar, loc_a, loc_b, ret) } fn i32_rol( @@ -3272,7 +3291,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i32(AssemblerX64::emit_rol, loc_a, loc_b, ret) } fn i32_ror( @@ -3280,7 +3299,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i32(AssemblerX64::emit_ror, loc_a, loc_b, ret) } fn i32_load( @@ -3292,7 +3311,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3321,7 +3340,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3351,7 +3370,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3381,7 +3400,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3411,7 +3430,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3441,7 +3460,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3463,7 +3482,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3492,7 +3511,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -3521,7 +3540,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3550,7 +3569,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3579,7 +3598,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3611,7 +3630,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3640,7 +3659,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3669,7 +3688,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -3700,9 +3719,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(value))?; self.memory_op( @@ -3737,9 +3756,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location_extend(Size::S8, false, loc, Size::S32, Location::GPR(value))?; self.memory_op( @@ -3774,9 +3793,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location_extend(Size::S16, false, loc, Size::S32, Location::GPR(value))?; self.memory_op( @@ -3811,9 +3830,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S32, false, loc, Size::S32, Location::GPR(value))?; self.memory_op( @@ -3848,9 +3867,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S8, false, loc, Size::S32, Location::GPR(value))?; self.memory_op( @@ -3885,9 +3904,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S16, false, loc, Size::S32, Location::GPR(value))?; self.memory_op( @@ -3922,7 +3941,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -3952,7 +3971,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -3982,7 +4001,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4012,7 +4031,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4042,7 +4061,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4072,7 +4091,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4102,7 +4121,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4132,7 +4151,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4162,7 +4181,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -4192,9 +4211,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(value))?; self.memory_op( @@ -4226,9 +4245,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_movzx(Size::S8, loc, Size::S32, Location::GPR(value))?; @@ -4261,9 +4280,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_movzx(Size::S16, loc, Size::S32, Location::GPR(value))?; @@ -4297,7 +4316,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -4349,7 +4368,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -4401,7 +4420,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -4446,7 +4465,7 @@ impl Machine for MachineX86_64 { &mut self, _calling_convention: CallingConvention, reloc_target: RelocationTarget, - ) -> Result, CodegenError> { + ) -> Result, CompileError> { let mut relocations = vec![]; let next = self.get_label(); let reloc_at = self.assembler.get_offset().0 + 1; // skip E8 @@ -4466,7 +4485,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_add, loc_a, loc_b, ret) } fn emit_binop_sub64( @@ -4474,7 +4493,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_sub, loc_a, loc_b, ret) } fn emit_binop_mul64( @@ -4482,7 +4501,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_imul, loc_a, loc_b, ret) } fn emit_binop_udiv64( @@ -4492,7 +4511,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX))?; @@ -4515,7 +4534,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX))?; @@ -4537,7 +4556,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. self.assembler .emit_mov(Size::S64, loc_a, Location::GPR(GPR::RAX))?; @@ -4560,7 +4579,7 @@ impl Machine for MachineX86_64 { ret: Location, integer_division_by_zero: Label, _integer_overflow: Label, - ) -> Result { + ) -> Result { // We assume that RAX and RDX are temporary registers here. let normal_path = self.assembler.get_label(); let end = self.assembler.get_label(); @@ -4593,7 +4612,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_and, loc_a, loc_b, ret) } fn emit_binop_or64( @@ -4601,7 +4620,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_or, loc_a, loc_b, ret) } fn emit_binop_xor64( @@ -4609,7 +4628,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_binop_i64(AssemblerX64::emit_xor, loc_a, loc_b, ret) } fn i64_cmp_ge_s( @@ -4617,7 +4636,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::GreaterEqual, loc_a, loc_b, ret) } fn i64_cmp_gt_s( @@ -4625,7 +4644,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Greater, loc_a, loc_b, ret) } fn i64_cmp_le_s( @@ -4633,7 +4652,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::LessEqual, loc_a, loc_b, ret) } fn i64_cmp_lt_s( @@ -4641,7 +4660,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Less, loc_a, loc_b, ret) } fn i64_cmp_ge_u( @@ -4649,7 +4668,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::AboveEqual, loc_a, loc_b, ret) } fn i64_cmp_gt_u( @@ -4657,7 +4676,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Above, loc_a, loc_b, ret) } fn i64_cmp_le_u( @@ -4665,7 +4684,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::BelowEqual, loc_a, loc_b, ret) } fn i64_cmp_lt_u( @@ -4673,7 +4692,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Below, loc_a, loc_b, ret) } fn i64_cmp_ne( @@ -4681,7 +4700,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::NotEqual, loc_a, loc_b, ret) } fn i64_cmp_eq( @@ -4689,14 +4708,14 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_cmpop_i64_dynamic_b(Condition::Equal, loc_a, loc_b, ret) } - fn i64_clz(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i64_clz(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { let src = match loc { Location::Imm64(_) | Location::Imm32(_) | Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; tmp @@ -4707,8 +4726,8 @@ impl Machine for MachineX86_64 { } }; let dst = match ret { - Location::Memory(_, _) => self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + Location::Memory(_, _) => self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?, Location::GPR(reg) => reg, _ => { @@ -4746,11 +4765,11 @@ impl Machine for MachineX86_64 { }; Ok(()) } - fn i64_ctz(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i64_ctz(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { let src = match loc { Location::Imm64(_) | Location::Imm32(_) | Location::Memory(_, _) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; tmp @@ -4761,8 +4780,8 @@ impl Machine for MachineX86_64 { } }; let dst = match ret { - Location::Memory(_, _) => self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + Location::Memory(_, _) => self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?, Location::GPR(reg) => reg, _ => { @@ -4799,16 +4818,16 @@ impl Machine for MachineX86_64 { }; Ok(()) } - fn i64_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn i64_popcnt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { match loc { Location::Imm64(_) | Location::Imm32(_) => { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; if let Location::Memory(_, _) = ret { - let out_tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let out_tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler.emit_popcnt( Size::S64, @@ -4825,8 +4844,8 @@ impl Machine for MachineX86_64 { } Location::Memory(_, _) | Location::GPR(_) => { if let Location::Memory(_, _) = ret { - let out_tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let out_tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_popcnt(Size::S64, loc, Location::GPR(out_tmp))?; @@ -4847,7 +4866,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i64(AssemblerX64::emit_shl, loc_a, loc_b, ret) } fn i64_shr( @@ -4855,7 +4874,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i64(AssemblerX64::emit_shr, loc_a, loc_b, ret) } fn i64_sar( @@ -4863,7 +4882,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i64(AssemblerX64::emit_sar, loc_a, loc_b, ret) } fn i64_rol( @@ -4871,7 +4890,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i64(AssemblerX64::emit_rol, loc_a, loc_b, ret) } fn i64_ror( @@ -4879,7 +4898,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_shift_i64(AssemblerX64::emit_ror, loc_a, loc_b, ret) } fn i64_load( @@ -4891,7 +4910,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4920,7 +4939,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4950,7 +4969,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -4980,7 +4999,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5010,7 +5029,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5040,7 +5059,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5082,7 +5101,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5112,7 +5131,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5134,7 +5153,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5163,7 +5182,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5192,7 +5211,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -5234,7 +5253,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5263,7 +5282,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5292,7 +5311,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5321,7 +5340,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5350,7 +5369,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5372,7 +5391,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5394,7 +5413,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5416,7 +5435,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( target_addr, memarg, @@ -5440,9 +5459,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(value))?; self.memory_op( @@ -5477,9 +5496,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location_extend(Size::S8, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5514,9 +5533,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location_extend(Size::S16, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5551,9 +5570,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location_extend(Size::S32, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5588,9 +5607,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S64, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5625,9 +5644,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S8, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5662,9 +5681,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S16, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5699,9 +5718,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.location_neg(Size::S32, false, loc, Size::S64, Location::GPR(value))?; self.memory_op( @@ -5736,7 +5755,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5766,7 +5785,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5796,7 +5815,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5826,7 +5845,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5856,7 +5875,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5885,7 +5904,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5914,7 +5933,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5943,7 +5962,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -5972,7 +5991,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -6001,7 +6020,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -6030,7 +6049,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -6059,7 +6078,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_compare_and_swap( loc, target, @@ -6088,9 +6107,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(value))?; self.memory_op( @@ -6122,9 +6141,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_movzx(Size::S8, loc, Size::S64, Location::GPR(value))?; @@ -6157,9 +6176,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_movzx(Size::S16, loc, Size::S64, Location::GPR(value))?; @@ -6192,9 +6211,9 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { - let value = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + ) -> Result<(), CompileError> { + let value = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.assembler .emit_movzx(Size::S32, loc, Size::S64, Location::GPR(value))?; @@ -6228,7 +6247,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -6280,7 +6299,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -6332,7 +6351,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -6384,7 +6403,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let compare = self.reserve_unused_temp_gpr(GPR::RAX); let value = if cmp == Location::GPR(GPR::R14) { if new == Location::GPR(GPR::R13) { @@ -6434,7 +6453,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -6464,7 +6483,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let canonicalize = canonicalize && self.arch_supports_canonicalize_nan(); self.memory_op( target_addr, @@ -6498,7 +6517,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.memory_op( addr, memarg, @@ -6528,7 +6547,7 @@ impl Machine for MachineX86_64 { imported_memories: bool, offset: i32, heap_access_oob: Label, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { let canonicalize = canonicalize && self.arch_supports_canonicalize_nan(); self.memory_op( target_addr, @@ -6559,12 +6578,12 @@ impl Machine for MachineX86_64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_in = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_in = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; if self.assembler.arch_has_fconverti() { self.emit_relaxed_mov(Size::S64, loc, Location::GPR(tmp_in))?; @@ -6581,8 +6600,8 @@ impl Machine for MachineX86_64 { .emit_vcvtsi2sd_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out)?; self.move_location(Size::S64, Location::SIMD(tmp_out), ret)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let do_convert = self.assembler.get_label(); @@ -6621,12 +6640,12 @@ impl Machine for MachineX86_64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_in = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_in = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; if self.assembler.arch_has_fconverti() { self.emit_relaxed_mov(Size::S32, loc, Location::GPR(tmp_in))?; @@ -6657,12 +6676,12 @@ impl Machine for MachineX86_64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_in = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_in = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; if self.assembler.arch_has_fconverti() { self.emit_relaxed_mov(Size::S64, loc, Location::GPR(tmp_in))?; @@ -6679,8 +6698,8 @@ impl Machine for MachineX86_64 { .emit_vcvtsi2ss_64(tmp_out, GPROrMemory::GPR(tmp_in), tmp_out)?; self.move_location(Size::S32, Location::SIMD(tmp_out), ret)?; } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let do_convert = self.assembler.get_label(); @@ -6719,12 +6738,12 @@ impl Machine for MachineX86_64 { loc: Location, signed: bool, ret: Location, - ) -> Result<(), CodegenError> { - let tmp_out = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + ) -> Result<(), CompileError> { + let tmp_out = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp_in = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp_in = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; if self.assembler.arch_has_fconverti() { self.emit_relaxed_mov(Size::S32, loc, Location::GPR(tmp_in))?; @@ -6756,7 +6775,7 @@ impl Machine for MachineX86_64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (signed, sat) { (false, true) => self.convert_i64_f64_u_s(loc, ret), (false, false) => self.convert_i64_f64_u_u(loc, ret), @@ -6770,7 +6789,7 @@ impl Machine for MachineX86_64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (signed, sat) { (false, true) => self.convert_i32_f64_u_s(loc, ret), (false, false) => self.convert_i32_f64_u_u(loc, ret), @@ -6784,7 +6803,7 @@ impl Machine for MachineX86_64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (signed, sat) { (false, true) => self.convert_i64_f32_u_s(loc, ret), (false, false) => self.convert_i64_f32_u_u(loc, ret), @@ -6798,7 +6817,7 @@ impl Machine for MachineX86_64 { ret: Location, signed: bool, sat: bool, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { match (signed, sat) { (false, true) => self.convert_i32_f32_u_s(loc, ret), (false, false) => self.convert_i32_f32_u_u(loc, ret), @@ -6806,24 +6825,24 @@ impl Machine for MachineX86_64 { (true, false) => self.convert_i32_f32_s_u(loc, ret), } } - fn convert_f64_f32(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_f64_f32(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcvtss2sd, loc, loc, ret) } - fn convert_f32_f64(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn convert_f32_f64(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcvtsd2ss, loc, loc, ret) } - fn f64_neg(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_neg(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_fneg() { - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S64, loc, Location::SIMD(tmp))?; self.assembler.arch_emit_f64_neg(tmp, tmp)?; self.emit_relaxed_mov(Size::S64, Location::SIMD(tmp), ret)?; self.release_simd(tmp); } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; self.assembler.emit_btc_gpr_imm8_64(63, tmp)?; @@ -6832,12 +6851,12 @@ impl Machine for MachineX86_64 { } Ok(()) } - fn f64_abs(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn f64_abs(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let c = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let c = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S64, loc, Location::GPR(tmp))?; @@ -6854,9 +6873,9 @@ impl Machine for MachineX86_64 { self.release_gpr(tmp); Ok(()) } - fn emit_i64_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CodegenError> { - let c = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn emit_i64_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CompileError> { + let c = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location( @@ -6881,19 +6900,19 @@ impl Machine for MachineX86_64 { self.release_gpr(c); Ok(()) } - fn f64_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vsqrtsd, loc, loc, ret) } - fn f64_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundsd_trunc, loc, loc, ret) } - fn f64_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundsd_ceil, loc, loc, ret) } - fn f64_floor(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_floor(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundsd_floor, loc, loc, ret) } - fn f64_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f64_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundsd_nearest, loc, loc, ret) } fn f64_cmp_ge( @@ -6901,7 +6920,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpgesd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6910,7 +6929,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpgtsd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6919,7 +6938,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmplesd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6928,7 +6947,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpltsd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6937,7 +6956,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpneqsd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6946,7 +6965,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpeqsd, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -6955,21 +6974,21 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.arch_supports_canonicalize_nan() { self.emit_relaxed_avx(AssemblerX64::emit_vminsd, loc_a, loc_b, ret) } else { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmpg1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmpg2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let src1 = match loc_a { @@ -7082,21 +7101,21 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.arch_supports_canonicalize_nan() { self.emit_relaxed_avx(AssemblerX64::emit_vmaxsd, loc_a, loc_b, ret) } else { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmpg1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmpg2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let src1 = match loc_a { @@ -7204,7 +7223,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vaddsd, loc_a, loc_b, ret) } fn f64_sub( @@ -7212,7 +7231,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vsubsd, loc_a, loc_b, ret) } fn f64_mul( @@ -7220,7 +7239,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vmulsd, loc_a, loc_b, ret) } fn f64_div( @@ -7228,21 +7247,21 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vdivsd, loc_a, loc_b, ret) } - fn f32_neg(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_neg(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { if self.assembler.arch_has_fneg() { - let tmp = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; self.emit_relaxed_mov(Size::S32, loc, Location::SIMD(tmp))?; self.assembler.arch_emit_f32_neg(tmp, tmp)?; self.emit_relaxed_mov(Size::S32, Location::SIMD(tmp), ret)?; self.release_simd(tmp); } else { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; self.assembler.emit_btc_gpr_imm8_32(31, tmp)?; @@ -7251,9 +7270,9 @@ impl Machine for MachineX86_64 { } Ok(()) } - fn f32_abs(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { - let tmp = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + fn f32_abs(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { + let tmp = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; self.move_location(Size::S32, loc, Location::GPR(tmp))?; self.assembler.emit_and( @@ -7265,7 +7284,7 @@ impl Machine for MachineX86_64 { self.release_gpr(tmp); Ok(()) } - fn emit_i32_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CodegenError> { + fn emit_i32_copysign(&mut self, tmp1: GPR, tmp2: GPR) -> Result<(), CompileError> { self.assembler.emit_and( Size::S32, Location::Imm32(0x7fffffffu32), @@ -7279,19 +7298,19 @@ impl Machine for MachineX86_64 { self.assembler .emit_or(Size::S32, Location::GPR(tmp2), Location::GPR(tmp1)) } - fn f32_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_sqrt(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vsqrtss, loc, loc, ret) } - fn f32_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_trunc(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundss_trunc, loc, loc, ret) } - fn f32_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_ceil(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundss_ceil, loc, loc, ret) } - fn f32_floor(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_floor(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundss_floor, loc, loc, ret) } - fn f32_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CodegenError> { + fn f32_nearest(&mut self, loc: Location, ret: Location) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vroundss_nearest, loc, loc, ret) } fn f32_cmp_ge( @@ -7299,7 +7318,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpgess, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7308,7 +7327,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpgtss, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7317,7 +7336,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpless, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7326,7 +7345,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpltss, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7335,7 +7354,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpneqss, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7344,7 +7363,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vcmpeqss, loc_a, loc_b, ret)?; self.assembler.emit_and(Size::S32, Location::Imm32(1), ret) } @@ -7353,21 +7372,21 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.arch_supports_canonicalize_nan() { self.emit_relaxed_avx(AssemblerX64::emit_vminss, loc_a, loc_b, ret) } else { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmpg1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmpg2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let src1 = match loc_a { @@ -7480,21 +7499,21 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { if !self.arch_supports_canonicalize_nan() { self.emit_relaxed_avx(AssemblerX64::emit_vmaxss, loc_a, loc_b, ret) } else { - let tmp1 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp1 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmp2 = self.acquire_temp_simd().ok_or(CodegenError { - message: "singlepass cannot acquire temp simd".to_string(), + let tmp2 = self.acquire_temp_simd().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp simd".to_owned()) })?; - let tmpg1 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg1 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; - let tmpg2 = self.acquire_temp_gpr().ok_or(CodegenError { - message: "singlepass cannot acquire temp gpr".to_string(), + let tmpg2 = self.acquire_temp_gpr().ok_or_else(|| { + CompileError::Codegen("singlepass cannot acquire temp gpr".to_owned()) })?; let src1 = match loc_a { @@ -7602,7 +7621,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vaddss, loc_a, loc_b, ret) } fn f32_sub( @@ -7610,7 +7629,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vsubss, loc_a, loc_b, ret) } fn f32_mul( @@ -7618,7 +7637,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vmulss, loc_a, loc_b, ret) } fn f32_div( @@ -7626,7 +7645,7 @@ impl Machine for MachineX86_64 { loc_a: Location, loc_b: Location, ret: Location, - ) -> Result<(), CodegenError> { + ) -> Result<(), CompileError> { self.emit_relaxed_avx(AssemblerX64::emit_vdivss, loc_a, loc_b, ret) } @@ -7634,9 +7653,9 @@ impl Machine for MachineX86_64 { &self, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { // the cpu feature here is irrelevant - let mut a = AssemblerX64::new(0, None); + let mut a = AssemblerX64::new(0, None)?; // Calculate stack offset. let mut stack_offset: u32 = 0; @@ -7749,9 +7768,9 @@ impl Machine for MachineX86_64 { vmoffsets: &VMOffsets, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { // the cpu feature here is irrelevant - let mut a = AssemblerX64::new(0, None); + let mut a = AssemblerX64::new(0, None)?; // 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 @@ -7874,9 +7893,9 @@ impl Machine for MachineX86_64 { index: FunctionIndex, sig: &FunctionType, calling_convention: CallingConvention, - ) -> Result { + ) -> Result { // the cpu feature here is irrelevant - let mut a = AssemblerX64::new(0, None); + let mut a = AssemblerX64::new(0, None)?; // TODO: ARM entry trampoline is not emitted.