Return a WasmResult from ModuleEnvironment methods (#886)

* [wasm] return a WasmResult from `declare_table_elements`

This method in particular needs to accommodate failure because any table index other than zero is
currently invalid.

* [wasm] additional failure handling improvements

- Adds `WasmResult<()>` as the return type for most of the `ModuleEnvironment` methods that
previously returned nothing.

- Replaces some panics with `WasmError::Unsupported` now that the methods can return a result.

- Adds a `wasm_unsupported!()` macro for early returns with a formatted unsupported message.
This commit is contained in:
Adam C. Foltzer
2019-08-07 13:23:32 -07:00
committed by GitHub
parent 00b8d019c9
commit 73670aab43
7 changed files with 204 additions and 91 deletions

View File

@@ -5,9 +5,10 @@
//! WebAssembly module and the runtime environment.
use crate::code_translator::translate_operator;
use crate::environ::{FuncEnvironment, ReturnMode, WasmError, WasmResult};
use crate::environ::{FuncEnvironment, ReturnMode, WasmResult};
use crate::state::{TranslationState, VisibleTranslationState};
use crate::translation_utils::get_vmctx_value_label;
use crate::wasm_unsupported;
use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir::{self, Ebb, InstBuilder, ValueLabel};
use cranelift_codegen::timing;
@@ -176,7 +177,7 @@ fn declare_locals(
I64 => builder.ins().iconst(ir::types::I64, 0),
F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)),
F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)),
_ => return Err(WasmError::Unsupported("unsupported local type")),
ty => wasm_unsupported!("unsupported local type {:?}", ty),
};
let ty = builder.func.dfg.value_type(zeroval);