Add a CtonError::InvalidInput variant.

This error code will be used to complain when a WebAssembly binary code
can't be parsed.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-01 13:06:05 -07:00
parent 8237893113
commit 52cbbcd069
2 changed files with 11 additions and 0 deletions

View File

@@ -195,6 +195,7 @@ fn handle_module(
CtonError::Verifier(err) => { CtonError::Verifier(err) => {
return Err(pretty_verifier_error(&context.func, None, err)); return Err(pretty_verifier_error(&context.func, None, err));
} }
CtonError::InvalidInput |
CtonError::ImplLimitExceeded | CtonError::ImplLimitExceeded |
CtonError::CodeTooLarge => return Err(String::from(error.description())), CtonError::CodeTooLarge => return Err(String::from(error.description())),
} }
@@ -207,6 +208,7 @@ fn handle_module(
CtonError::Verifier(err) => { CtonError::Verifier(err) => {
return Err(pretty_verifier_error(&context.func, None, err)); return Err(pretty_verifier_error(&context.func, None, err));
} }
CtonError::InvalidInput |
CtonError::ImplLimitExceeded | CtonError::ImplLimitExceeded |
CtonError::CodeTooLarge => return Err(String::from(error.description())), CtonError::CodeTooLarge => return Err(String::from(error.description())),
} }

View File

@@ -9,6 +9,12 @@ use std::fmt;
/// When Cretonne fails to compile a function, it will return one of these error codes. /// When Cretonne fails to compile a function, it will return one of these error codes.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum CtonError { 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.
InvalidInput,
/// An IL verifier error. /// An IL verifier error.
/// ///
/// This always represents a bug, either in the code that generated IL for Cretonne, or a bug /// This always represents a bug, either in the code that generated IL for Cretonne, or a bug
@@ -37,6 +43,7 @@ impl fmt::Display for CtonError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
CtonError::Verifier(ref e) => write!(f, "Verifier error: {}", e), CtonError::Verifier(ref e) => write!(f, "Verifier error: {}", e),
CtonError::InvalidInput |
CtonError::ImplLimitExceeded | CtonError::ImplLimitExceeded |
CtonError::CodeTooLarge => f.write_str(self.description()), CtonError::CodeTooLarge => f.write_str(self.description()),
} }
@@ -46,6 +53,7 @@ impl fmt::Display for CtonError {
impl StdError for CtonError { impl StdError for CtonError {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
CtonError::InvalidInput => "Invalid input code",
CtonError::Verifier(ref e) => &e.message, CtonError::Verifier(ref e) => &e.message,
CtonError::ImplLimitExceeded => "Implementation limit exceeded", CtonError::ImplLimitExceeded => "Implementation limit exceeded",
CtonError::CodeTooLarge => "Code for function is too large", CtonError::CodeTooLarge => "Code for function is too large",
@@ -54,6 +62,7 @@ impl StdError for CtonError {
fn cause(&self) -> Option<&StdError> { fn cause(&self) -> Option<&StdError> {
match *self { match *self {
CtonError::Verifier(ref e) => Some(e), CtonError::Verifier(ref e) => Some(e),
CtonError::InvalidInput |
CtonError::ImplLimitExceeded | CtonError::ImplLimitExceeded |
CtonError::CodeTooLarge => None, CtonError::CodeTooLarge => None,
} }