This commit is contained in:
Chris Fallin 2021-12-24 14:12:49 -08:00
parent 415e1d63e3
commit d5342a0a6a
2 changed files with 14 additions and 13 deletions

View file

@ -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();
}

View file

@ -23,6 +23,13 @@ enum Command {
#[structopt(help = "Wasm file to parse")] #[structopt(help = "Wasm file to parse")]
wasm: PathBuf, 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<()> { fn main() -> Result<()> {
@ -41,6 +48,13 @@ fn main() -> Result<()> {
let module = Module::from_wasm_bytes(&bytes[..])?; let module = Module::from_wasm_bytes(&bytes[..])?;
println!("{:?}", module); 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(()) Ok(())