Serialize/deserialize exception codes.

This commit is contained in:
losfair
2020-01-10 02:53:08 +08:00
parent f44517b9fb
commit 4b5b8976e9
2 changed files with 11 additions and 2 deletions

View File

@ -184,14 +184,20 @@ pub struct CompilerConfig {
} }
/// An exception table for a `RunnableModule`. /// An exception table for a `RunnableModule`.
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ExceptionTable { pub struct ExceptionTable {
/// Mappings from offsets in generated machine code to the corresponding exception code. /// Mappings from offsets in generated machine code to the corresponding exception code.
pub offset_to_code: HashMap<usize, ExceptionCode>, pub offset_to_code: HashMap<usize, ExceptionCode>,
} }
impl ExceptionTable {
pub fn new() -> Self {
Self::default()
}
}
/// The code of an exception. /// The code of an exception.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub enum ExceptionCode { pub enum ExceptionCode {
/// An `unreachable` opcode was executed. /// An `unreachable` opcode was executed.
Unreachable, Unreachable,

View File

@ -1,6 +1,7 @@
//! The error module contains the data structures and helper functions used to implement errors that //! The error module contains the data structures and helper functions used to implement errors that
//! are produced and returned from the wasmer runtime core. //! are produced and returned from the wasmer runtime core.
use crate::types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type}; use crate::types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type};
use crate::backend::ExceptionCode;
use core::borrow::Borrow; use core::borrow::Borrow;
use std::any::Any; use std::any::Any;
@ -208,6 +209,8 @@ impl std::fmt::Display for RuntimeError {
write!(f, "\"{}\"", s) write!(f, "\"{}\"", s)
} else if let Some(s) = data.downcast_ref::<&str>() { } else if let Some(s) = data.downcast_ref::<&str>() {
write!(f, "\"{}\"", s) write!(f, "\"{}\"", s)
} else if let Some(exc_code) = data.downcast_ref::<ExceptionCode>() {
write!(f, "\"{:?}\"", exc_code)
} else { } else {
write!(f, "unknown error") write!(f, "unknown error")
} }