From eab9e6033895ed7e8bc512d34850a13104b270c8 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 13 Nov 2021 17:52:30 -0800 Subject: [PATCH] Cleanup --- fuzz/fuzz_targets/parse_ir.rs | 7 +++---- src/bin/waffle-util.rs | 4 ++-- src/ir.rs | 8 ++++++++ src/lib.rs | 9 ++++++--- src/localssa.rs | 2 ++ 5 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/localssa.rs diff --git a/fuzz/fuzz_targets/parse_ir.rs b/fuzz/fuzz_targets/parse_ir.rs index 780e018..6fbdc0a 100644 --- a/fuzz/fuzz_targets/parse_ir.rs +++ b/fuzz/fuzz_targets/parse_ir.rs @@ -1,10 +1,9 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use waffle::frontend::wasm_to_ir; -use wasm_smith::Module; +use waffle::Module; -fuzz_target!(|module: Module| { +fuzz_target!(|module: wasm_smith::Module| { let _ = env_logger::try_init(); - let _parsed_module = wasm_to_ir(&module.to_bytes()[..]).unwrap(); + let _parsed_module = Module::from_wasm_bytes(&module.to_bytes()[..]).unwrap(); }); diff --git a/src/bin/waffle-util.rs b/src/bin/waffle-util.rs index eec4fb4..b6037ae 100644 --- a/src/bin/waffle-util.rs +++ b/src/bin/waffle-util.rs @@ -4,7 +4,7 @@ use anyhow::Result; use log::debug; use std::path::PathBuf; use structopt::StructOpt; -use waffle::frontend; +use waffle::Module; #[derive(Debug, StructOpt)] #[structopt(name = "waffle-util", about = "WAFFLE utility.")] @@ -38,7 +38,7 @@ fn main() -> Result<()> { Command::PrintIR { wasm } => { let bytes = std::fs::read(wasm)?; debug!("Loaded {} bytes of Wasm data", bytes.len()); - let module = frontend::wasm_to_ir(&bytes[..])?; + let module = Module::from_wasm_bytes(&bytes[..])?; println!("{:?}", module); } } diff --git a/src/ir.rs b/src/ir.rs index b60425f..24bf3db 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -1,5 +1,7 @@ //! Intermediate representation for Wasm. +use crate::frontend; +use anyhow::Result; use wasmparser::{FuncType, Operator, Type}; pub type SignatureId = usize; @@ -119,3 +121,9 @@ impl<'a> std::default::Default for Terminator<'a> { Terminator::None } } + +impl<'a> Module<'a> { + pub fn from_wasm_bytes(bytes: &'a [u8]) -> Result { + frontend::wasm_to_ir(bytes) + } +} diff --git a/src/lib.rs b/src/lib.rs index ebcc7de..3541116 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,9 @@ pub use wasm_encoder; pub use wasmparser; -pub mod frontend; -pub mod ir; -pub mod op_traits; +mod frontend; +mod ir; +mod localssa; +mod op_traits; + +pub use ir::*; diff --git a/src/localssa.rs b/src/localssa.rs new file mode 100644 index 0000000..86a3d87 --- /dev/null +++ b/src/localssa.rs @@ -0,0 +1,2 @@ +//! Local-to-SSA conversion. +