@@ -4395,6 +4395,12 @@ fn decl_fn_and_pair(@crate_ctxt cx,
4395
4395
4396
4396
// Declare the global constant pair that points to it.
4397
4397
let str ps = cx. names. next( "_rust_" + kind + "_pair" ) + sep( ) + name;
4398
+
4399
+ register_fn_pair( cx, ps, llpairty, llfn, id) ;
4400
+ }
4401
+
4402
+ fn register_fn_pair( @crate_ctxt cx, str ps, TypeRef llpairty, ValueRef llfn,
4403
+ ast. def_id id) {
4398
4404
let ValueRef gvar = llvm. LLVMAddGlobal ( cx. llmod, llpairty,
4399
4405
_str. buf( ps) ) ;
4400
4406
auto pair = C_struct ( vec( llfn,
@@ -4410,16 +4416,34 @@ fn decl_fn_and_pair(@crate_ctxt cx,
4410
4416
cx. fn_pairs. insert( id, gvar) ;
4411
4417
}
4412
4418
4419
+ fn native_fn_wrapper_type( @crate_ctxt cx, & ast. ann ann) -> TypeRef {
4420
+ auto x = node_ann_type( cx, ann) ;
4421
+ alt ( x. struct ) {
4422
+ case ( ty. ty_native_fn( ?abi, ?args, ?out) ) {
4423
+ ret type_of_fn( cx, ast. proto_fn, args, out) ;
4424
+ }
4425
+ }
4426
+ fail;
4427
+ }
4428
+
4413
4429
fn decl_native_fn_and_pair( @crate_ctxt cx,
4414
4430
str name,
4415
4431
& ast. ann ann,
4416
4432
ast. def_id id) {
4433
+ // Declare the wrapper.
4434
+ auto wrapper_type = native_fn_wrapper_type( cx, ann) ;
4435
+ let str s = cx. names. next( "_rust_wrapper" ) + sep( ) + name;
4436
+ let ValueRef wrapper_fn = decl_fastcall_fn( cx. llmod, s, wrapper_type) ;
4417
4437
4418
- auto llpairty = node_type( cx, ann) ;
4419
- auto llfty = get_pair_fn_ty( llpairty) ;
4438
+ // Declare the global constant pair that points to it.
4439
+ auto wrapper_pair_type = T_fn_pair ( cx. tn, wrapper_type) ;
4440
+ let str ps = cx. names. next( "_rust_wrapper_pair" ) + sep( ) + name;
4420
4441
4421
- let ValueRef llfn = decl_cdecl_fn( cx. llmod, name, llfty) ;
4422
- cx. item_ids. insert( id, llfn) ;
4442
+ register_fn_pair( cx, ps, wrapper_pair_type, wrapper_fn, id) ;
4443
+
4444
+ // Declare the function itself.
4445
+ auto llfty = get_pair_fn_ty( node_type( cx, ann) ) ;
4446
+ decl_cdecl_fn( cx. llmod, name, llfty) ;
4423
4447
}
4424
4448
4425
4449
fn collect_native_item( & @crate_ctxt cx, @ast. native_item i) -> @crate_ctxt {
0 commit comments