diff --git a/src/bin/roundtrip.rs b/src/bin/roundtrip.rs deleted file mode 100644 index e75d032..0000000 --- a/src/bin/roundtrip.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Roundtrip utility. - -use std::io::{Read, Write}; -use waffle::Module; - -fn main() { - let _ = env_logger::try_init(); - let mut bytes = vec![]; - std::io::stdin().read_to_end(&mut bytes).unwrap(); - let module = Module::from_wasm_bytes(&bytes).unwrap(); - let new_bytes = module.to_wasm_bytes(); - std::io::stdout().write(&new_bytes[..]).unwrap(); -} diff --git a/src/bin/waffle-util.rs b/src/bin/waffle-util.rs index b6037ae..976da0a 100644 --- a/src/bin/waffle-util.rs +++ b/src/bin/waffle-util.rs @@ -23,6 +23,13 @@ enum Command { #[structopt(help = "Wasm file to parse")] wasm: PathBuf, }, + #[structopt(name = "roundtrip", about = "Round-trip Wasm through IR")] + RoundTrip { + #[structopt(help = "Wasm file to parse", short = "i")] + input: PathBuf, + #[structopt(help = "Wasm file to produce", short = "o")] + output: PathBuf, + }, } fn main() -> Result<()> { @@ -41,6 +48,13 @@ fn main() -> Result<()> { let module = Module::from_wasm_bytes(&bytes[..])?; println!("{:?}", module); } + Command::RoundTrip { input, output } => { + let bytes = std::fs::read(input)?; + debug!("Loaded {} bytes of Wasm data", bytes.len()); + let module = Module::from_wasm_bytes(&bytes[..])?; + let produced = module.to_wasm_bytes(); + std::fs::write(output, &produced[..])?; + } } Ok(())