-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
spv-lower-dump
example with a more useful spv-lower-print
…
… one. (#30)
- Loading branch information
Showing
2 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |