From 429cf89a220c450a5eddedd041d9a00cb42a2695 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 13 Nov 2021 01:17:53 -0800 Subject: [PATCH] WIP. --- src/frontend.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/frontend.rs b/src/frontend.rs index 552177b..1a7a591 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -5,7 +5,7 @@ use anyhow::anyhow; use anyhow::Result; use log::trace; use std::collections::VecDeque; -use wasmparser::{ImportSectionEntryType, Parser, Payload, TypeDef}; +use wasmparser::{ImportSectionEntryType, Operator, Parser, Payload, TypeDef}; pub fn wasm_to_ir(bytes: &[u8]) -> Result { let mut module = Module::default(); @@ -75,5 +75,31 @@ fn parse_body(body: wasmparser::FunctionBody) -> Result { } } + let mut builder = FunctionBodyBuilder::new(&mut ret); + let ops = body.get_operators_reader()?; + for op in ops.into_iter() { + let op = op?; + builder.handle_op(op)?; + } + Ok(ret) } + +#[derive(Debug)] +struct FunctionBodyBuilder<'a> { + body: &'a mut FunctionBody, +} + +impl<'a> FunctionBodyBuilder<'a> { + fn new(body: &'a mut FunctionBody) -> Self { + Self { body } + } + + fn handle_op(&mut self, op: Operator<'_>) -> Result<()> { + match op { + _ => {} + } + + Ok(()) + } +}