Skip to content

Add mechanism for displaying the WAT signatures of WASI modules #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tools/witx/examples/witx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ enum Command {
},
/// Update documentation in WASI repository to reflect witx specs
RepoDocs,
/// Output the expected WAT signature of a witx module
WatSignature {
/// Path to root of witx document
#[structopt(number_of_values = 1, value_name = "INPUT", parse(from_os_str))]
input: Vec<PathBuf>,
},
/// Examine differences between interfaces
Polyfill {
/// Path to root of witx document
Expand Down Expand Up @@ -98,6 +104,35 @@ pub fn main() {
write_docs(&doc, phases::docs_path(&phase));
}
}
Command::WatSignature { input } => {
let doc = load_witx(&input, "input", verbose);
for module in doc.modules() {
println!("(module");
// For each function in the module, print something like:
// (import "wasi" "load" (func (param i32 i32 i32) (result i32)))
for func in module.funcs() {
print!(
" (import \"{}\" \"{}\" (func ",
module.name.as_str(),
func.name.as_str()
);
let signature = func.core_type();
if !signature.args.is_empty() {
let args: Vec<String> = signature
.args
.iter()
.map(|arg| format!("{:?}", arg.repr()))
.collect();
print!("(param {})", args.join(" "));
}
if let Some(ret) = signature.ret {
print!(" (result {:?})", ret.repr())
}
println!("))");
}
println!(")");
}
}
Command::Polyfill {
input,
older_interface,
Expand Down