Converted all machine and emitter of singlepass to use Result instead of panic (but assert are still present)

This commit is contained in:
ptitSeb
2022-06-20 10:49:36 +02:00
parent 166799843c
commit e4b0b71164
7 changed files with 7781 additions and 4975 deletions

View File

@ -33,6 +33,12 @@ use wasmer_types::{
SectionIndex, TableIndex, TrapCode, VMOffsets,
};
impl From<CodegenError> 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 {
@ -94,7 +100,11 @@ impl Compiler for SinglepassCompiler {
Ok(CallingConvention::WindowsFastcall) => CallingConvention::WindowsFastcall,
Ok(CallingConvention::SystemV) => CallingConvention::SystemV,
Ok(CallingConvention::AppleAarch64) => CallingConvention::AppleAarch64,
_ => panic!("Unsupported Calling convention for Singlepass compiler"),
_ => {
return Err(CompileError::UnsupportedTarget(
"Unsupported Calling convention for Singlepass compiler".to_string(),
))
}
};
// Generate the frametable
@ -184,7 +194,7 @@ impl Compiler for SinglepassCompiler {
generator.feed_operator(op).map_err(to_compile_error)?;
}
Ok(generator.finalize(input))
generator.finalize(input).map_err(to_compile_error)
}
Architecture::Aarch64(_) => {
let machine = MachineARM64::new();
@ -206,7 +216,7 @@ impl Compiler for SinglepassCompiler {
generator.feed_operator(op).map_err(to_compile_error)?;
}
Ok(generator.finalize(input))
generator.finalize(input).map_err(to_compile_error)
}
_ => unimplemented!(),
}