@@ -4972,11 +4972,6 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
4972
4972
let str s = cx. names. next( "_rust_wrapper" ) + sep( ) + name;
4973
4973
let ValueRef wrapper_fn = decl_fastcall_fn( cx. llmod, s, wrapper_type) ;
4974
4974
4975
- // Build the wrapper.
4976
- auto fcx = new_fn_ctxt( cx, wrapper_fn) ;
4977
- auto bcx = new_top_block_ctxt( fcx) ;
4978
- bcx. build. RetVoid ( ) ;
4979
-
4980
4975
// Declare the global constant pair that points to it.
4981
4976
auto wrapper_pair_type = T_fn_pair ( cx. tn, wrapper_type) ;
4982
4977
let str ps = cx. names. next( "_rust_wrapper_pair" ) + sep( ) + name;
@@ -4985,7 +4980,40 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
4985
4980
4986
4981
// Declare the function itself.
4987
4982
auto llfty = get_pair_fn_ty( node_type( cx, ann) ) ;
4988
- decl_cdecl_fn( cx. llmod, name, llfty) ;
4983
+ auto function = decl_cdecl_fn( cx. llmod, name, llfty) ;
4984
+
4985
+ // Build the wrapper.
4986
+ auto fcx = new_fn_ctxt( cx, wrapper_fn) ;
4987
+ auto bcx = new_top_block_ctxt( fcx) ;
4988
+ auto fn_type = node_ann_type( cx, ann) ;
4989
+
4990
+ let vec[ ValueRef ] call_args = vec( ) ;
4991
+ auto abi = ty. ty_fn_abi( fn_type) ;
4992
+ auto arg_n = 3 u;
4993
+ alt ( abi) {
4994
+ case ( ast. native_abi_rust) {
4995
+ call_args += vec( fcx. lltaskptr) ;
4996
+ auto num_ty_param = ty. count_ty_params( plain_ty( fn_type. struct ) ) ;
4997
+ for each ( uint i in _uint. range( 0 u, num_ty_param) ) {
4998
+ auto llarg = llvm. LLVMGetParam ( fcx. llfn, arg_n) ;
4999
+ check ( llarg as int != 0 ) ;
5000
+ call_args += vec( llarg) ;
5001
+ arg_n += 1 u;
5002
+ }
5003
+ }
5004
+ case ( ast. native_abi_cdecl) {
5005
+ }
5006
+ }
5007
+ auto args = ty. ty_fn_args( fn_type) ;
5008
+ for ( ty. arg arg in args) {
5009
+ auto llarg = llvm. LLVMGetParam ( fcx. llfn, arg_n) ;
5010
+ check ( llarg as int != 0 ) ;
5011
+ call_args += vec( llarg) ;
5012
+ arg_n += 1 u;
5013
+ }
5014
+ auto r = bcx. build. Call ( function, call_args) ;
5015
+ bcx. build. Store ( r, fcx. llretptr) ;
5016
+ bcx. build. RetVoid ( ) ;
4989
5017
}
4990
5018
4991
5019
fn collect_native_item( & @crate_ctxt cx, @ast. native_item i) -> @crate_ctxt {
0 commit comments