@@ -42,6 +42,12 @@ enum Command {
42
42
} ,
43
43
/// Update documentation in WASI repository to reflect witx specs
44
44
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
+ } ,
45
51
/// Examine differences between interfaces
46
52
Polyfill {
47
53
/// Path to root of witx document
@@ -98,6 +104,27 @@ pub fn main() {
98
104
write_docs ( & doc, phases:: docs_path ( & phase) ) ;
99
105
}
100
106
}
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
+ }
101
128
Command :: Polyfill {
102
129
input,
103
130
older_interface,
0 commit comments