File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,30 @@ pub struct Module<'a> {
308
308
}
309
309
310
310
impl < ' a > Module < ' a > {
311
+ /// Appends a function type to the module, returning the new function index.
312
+ pub fn append_function ( & mut self , inputs : & [ ValType ] , outputs : & [ ValType ] ) -> u32 {
313
+ // We either find an existing identical type, or we create a new one.
314
+ let type_idx = self
315
+ . types
316
+ . iter ( )
317
+ . position ( |t| t. ty . params ( ) == inputs && t. ty . results ( ) == outputs)
318
+ . unwrap_or_else ( || {
319
+ // Create a new type.
320
+ let type_idx = self . types . len ( ) ;
321
+ self . types . push ( Rc :: new ( FuncType {
322
+ unique_id : type_idx as u32 ,
323
+ ty : wasmparser:: FuncType :: new ( inputs. iter ( ) . cloned ( ) , outputs. iter ( ) . cloned ( ) ) ,
324
+ } ) ) ;
325
+
326
+ type_idx
327
+ } ) as u32 ;
328
+
329
+ let func_idx = self . func_types . len ( ) as u32 ;
330
+ self . func_types . push ( type_idx) ;
331
+
332
+ func_idx
333
+ }
334
+
311
335
fn get_type ( & self , type_idx : u32 ) -> & FuncType {
312
336
& self . types [ type_idx as usize ]
313
337
}
You can’t perform that action at this time.
0 commit comments