Allow wasm embedders to reject wasm modules with unsupported features. (#345)

Define `WasmError` (and an accompanying `WasmResult`) to represent
errors translating WebAssembly functions. Make `translate_call` and
related functions return `WasmResult`s so that embedders have the
flexibility to reject features they don't support.

Move `InvalidInput` out of `CtonError` and into `WasmError`, where it's
now named `InvalidWebAssembly`, as it's a WebAssembly-specific error
condition. Also extend it to preserve the original error message and
bytecode offset.
This commit is contained in:
Dan Gohman
2018-05-21 20:49:19 -07:00
committed by GitHub
parent 923ea8ada9
commit 89e7d56120
11 changed files with 185 additions and 177 deletions

View File

@@ -7,13 +7,6 @@ use verifier;
/// When Cretonne fails to compile a function, it will return one of these error codes.
#[derive(Fail, Debug, PartialEq, Eq)]
pub enum CtonError {
/// The input is invalid.
///
/// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly
/// code. This should never happen for validated WebAssembly code.
#[fail(display = "Invalid input code")]
InvalidInput,
/// An IR verifier error.
///
/// This always represents a bug, either in the code that generated IR for Cretonne, or a bug