@@ -3,11 +3,11 @@ use serde::{Deserialize, Serialize};
3
3
4
4
use super :: {
5
5
bimap:: { BiMapIndex , IntoBiMapIndex } ,
6
- cilnode:: MethodKind ,
6
+ cilnode:: { IsPure , MethodKind } ,
7
7
Access , Assembly , BasicBlock , CILIterElem , CILNode , ClassDefIdx , ClassRef , ClassRefIdx , Int ,
8
8
SigIdx , StringIdx , Type , TypeIdx ,
9
9
} ;
10
- use crate :: v2:: iter:: TpeIter ;
10
+ use crate :: { cil_node :: CallOpArgs , v2:: iter:: TpeIter } ;
11
11
use crate :: v2:: CILRoot ;
12
12
pub type LocalId = u32 ;
13
13
#[ derive( Hash , PartialEq , Eq , Clone , Debug , Serialize , Deserialize ) ]
@@ -722,6 +722,19 @@ impl MethodImpl {
722
722
// Swap new and locals
723
723
std:: mem:: swap ( locals, new_locals. get_mut ( ) . unwrap ( ) ) ;
724
724
}
725
+
726
+ pub ( crate ) fn wrapper ( mref : MethodRefIdx , asm : & mut Assembly ) -> MethodImpl {
727
+ let sig = asm[ asm[ mref] . sig ( ) ] . clone ( ) ;
728
+ let args = sig. inputs ( ) . iter ( ) . enumerate ( ) . map ( |( idx, _) |asm. alloc_node ( CILNode :: LdArg ( idx. try_into ( ) . unwrap ( ) ) ) ) . collect ( ) ;
729
+ let roots = if asm. sizeof_type ( * sig. output ( ) ) == 0 {
730
+ let call = asm. alloc_root ( CILRoot :: Call ( Box :: new ( ( mref, args, IsPure :: NOT ) ) ) ) ;
731
+ vec ! [ call, asm. alloc_root( CILRoot :: VoidRet ) ]
732
+ } else {
733
+ let val = asm. alloc_node ( CILNode :: Call ( Box :: new ( ( mref, args, IsPure :: NOT ) ) ) ) ;
734
+ vec ! [ asm. alloc_root( CILRoot :: Ret ( val) ) ]
735
+ } ;
736
+ MethodImpl :: MethodBody { blocks : vec ! [ BasicBlock :: new( roots, 0 , None ) ] , locals : vec ! [ ] . into ( ) }
737
+ }
725
738
}
726
739
#[ derive( Hash , PartialEq , Eq , Clone , Copy , Debug , Serialize , Deserialize ) ]
727
740
pub struct MethodDefIdx ( pub MethodRefIdx ) ;
0 commit comments