Skip to content

Commit 1288a74

Browse files
committed
Add mechanism for displaying the WAT signatures of WASI modules
1 parent 6e5800b commit 1288a74

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tools/witx/examples/witx.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ enum Command {
4242
},
4343
/// Update documentation in WASI repository to reflect witx specs
4444
RepoDocs,
45+
/// Output the expected WAT signature of a witx module
46+
WatSignature {
47+
/// Path to root of witx document
48+
#[structopt(number_of_values = 1, value_name = "INPUT", parse(from_os_str))]
49+
input: Vec<PathBuf>,
50+
},
4551
/// Examine differences between interfaces
4652
Polyfill {
4753
/// Path to root of witx document
@@ -98,6 +104,27 @@ pub fn main() {
98104
write_docs(&doc, phases::docs_path(&phase));
99105
}
100106
}
107+
Command::WatSignature { input } => {
108+
let doc = load_witx(&input, "input", verbose);
109+
for module in doc.modules() {
110+
println!("(module");
111+
// For each function in the module, print something like:
112+
// (import "wasi" "load" (func (param i32 i32 i32) (result i32)))
113+
for func in module.funcs() {
114+
print!(" (import \"{}\" \"{}\" (func ", module.name.as_str(), func.name.as_str());
115+
let signature = func.core_type();
116+
if !signature.args.is_empty() {
117+
let args: Vec<String> = signature.args.iter().map(|arg| format!("{:?}", arg.repr())).collect();
118+
print!("(param {})", args.join(" "));
119+
}
120+
if let Some(ret) = signature.ret {
121+
print!(" (result {:?})", ret.repr())
122+
}
123+
println!("))");
124+
}
125+
println!(")");
126+
}
127+
}
101128
Command::Polyfill {
102129
input,
103130
older_interface,

0 commit comments

Comments
 (0)