wasm_interp: Don't panic while pushing a stack frame

This commit is contained in:
Brian Carroll 2022-12-06 20:31:50 +00:00
parent 4cf5d19ace
commit 2abae1b5e1
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
4 changed files with 127 additions and 89 deletions

View file

@ -67,6 +67,29 @@ pub(crate) enum Error {
}
impl Error {
pub fn to_string_at(&self, file_offset: usize) -> String {
match self {
Error::ValueStackType(expected, actual) => {
format!(
"ERROR: I found a type mismatch in the Value Stack at file offset {:#x}. Expected {:?}, but found {:?}.\n",
file_offset, expected, actual
)
}
Error::ValueStackEmpty => {
format!(
"ERROR: I tried to pop a value from the Value Stack at file offset {:#x}, but it was empty.\n",
file_offset
)
}
Error::UnreachableOp => {
format!(
"WebAssembly `unreachable` instruction at file offset {:#x}.\n",
file_offset
)
}
}
}
fn value_stack_type(expected: ValueType, is_float: bool, is_64: bool) -> Self {
let ty = type_from_flags_f_64(is_float, is_64);
Error::ValueStackType(expected, ty)