From 44c2c8dc1798dc8ae89649346c24da6fb6d0a5a4 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 13 Nov 2021 00:56:49 -0800 Subject: [PATCH] WIP. --- src/frontend.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/frontend.rs b/src/frontend.rs index 8670bee..86dec60 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -1,25 +1,23 @@ //! Frontend: convert Wasm to IR. use crate::ir::*; -use anyhow::{bail, Result}; -use log::debug; -use wasmparser::{Chunk, Parser, Payload, TypeDef}; +use anyhow::Result; +use log::trace; +use wasmparser::{Parser, Payload, TypeDef}; pub fn wasm_to_ir(bytes: &[u8]) -> Result { let mut module = Module::default(); - let mut parser = Parser::new(0); - for chunk in parser.parse(bytes, /* eof = */ true) { - match chunk { - Chunk::NeedMoreData(_) => bail!("Unexpected EOF in Wasm"), - Chunk::Parsed { payload, .. } => handle_payload(&mut module, payload)?, - } + let parser = Parser::new(0); + for payload in parser.parse_all(bytes) { + let payload = payload?; + handle_payload(&mut module, payload)?; } Ok(module) } fn handle_payload<'a>(module: &mut Module, payload: Payload<'a>) -> Result<()> { - debug!("Wasm parser item: {:?}", payload); + trace!("Wasm parser item: {:?}", payload); match payload { Payload::TypeSection(mut reader) => { for _ in 0..reader.get_count() {