Skip to content

Commit

Permalink
Replace spv-lower-dump example with a more useful spv-lower-print
Browse files Browse the repository at this point in the history
… one. (#30)
  • Loading branch information
eddyb authored Jun 1, 2023
2 parents 08b696b + 42cf805 commit 7733196
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
16 changes: 0 additions & 16 deletions examples/spv-lower-dump.rs

This file was deleted.

47 changes: 47 additions & 0 deletions examples/spv-lower-print.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::fs;
use std::path::Path;
use std::rc::Rc;

fn main() -> std::io::Result<()> {
match &std::env::args().collect::<Vec<_>>()[..] {
[_, in_files @ ..] => {
for in_file in in_files {
let in_file_path = Path::new(in_file);

let save_print_plan = |suffix: &str, plan: spirt::print::Plan| {
let pretty = plan.pretty_print();
let ext = if suffix.is_empty() {
"spirt".into()
} else {
format!("{suffix}.spirt")
};

// FIXME(eddyb) don't allocate whole `String`s here.
fs::write(in_file_path.with_extension(&ext), pretty.to_string())?;
fs::write(
in_file_path.with_extension(ext + ".html"),
pretty
.render_to_html()
.with_dark_mode_support()
.to_html_doc(),
)
};

let mut module = spirt::Module::lower_from_spv_file(
Rc::new(spirt::Context::new()),
in_file_path,
)?;
save_print_plan("", spirt::print::Plan::for_module(&module))?;

spirt::passes::legalize::structurize_func_cfgs(&mut module);
save_print_plan("structured", spirt::print::Plan::for_module(&module))?;
}

Ok(())
}
args => {
eprintln!("Usage: {} FILES", args[0]);
std::process::exit(1);
}
}
}

0 comments on commit 7733196

Please sign in to comment.