Update to the new wasmparser and port to the new readers API.

The new wasmparser API provides dedicated reader types for each section
type, which significantly simplifies the code.

This also changes WasmError::from_binary_reader_error into a From
trait so that we don't have to do .map_err(from_binary_reader_error)
throughout the code.
This commit is contained in:
Dan Gohman
2018-10-23 16:34:29 -07:00
parent 9e084dbadc
commit 5ea6c57b95
6 changed files with 319 additions and 430 deletions

View File

@@ -3,6 +3,7 @@
use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::ir::{self, InstBuilder};
use cranelift_codegen::isa::TargetFrontendConfig;
use std::convert::From;
use std::vec::Vec;
use translation_utils::{
FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
@@ -62,9 +63,9 @@ pub enum WasmError {
ImplLimitExceeded,
}
impl WasmError {
impl From<BinaryReaderError> for WasmError {
/// Convert from a `BinaryReaderError` to a `WasmError`.
pub fn from_binary_reader_error(e: BinaryReaderError) -> Self {
fn from(e: BinaryReaderError) -> Self {
let BinaryReaderError { message, offset } = e;
WasmError::InvalidWebAssembly { message, offset }
}