@@ -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,35 @@ 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 ! (
115
+ " (import \" {}\" \" {}\" (func " ,
116
+ module. name. as_str( ) ,
117
+ func. name. as_str( )
118
+ ) ;
119
+ let signature = func. core_type ( ) ;
120
+ if !signature. args . is_empty ( ) {
121
+ let args: Vec < String > = signature
122
+ . args
123
+ . iter ( )
124
+ . map ( |arg| format ! ( "{:?}" , arg. repr( ) ) )
125
+ . collect ( ) ;
126
+ print ! ( "(param {})" , args. join( " " ) ) ;
127
+ }
128
+ if let Some ( ret) = signature. ret {
129
+ print ! ( " (result {:?})" , ret. repr( ) )
130
+ }
131
+ println ! ( "))" ) ;
132
+ }
133
+ println ! ( ")" ) ;
134
+ }
135
+ }
101
136
Command :: Polyfill {
102
137
input,
103
138
older_interface,
0 commit comments