@@ -5396,14 +5396,15 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
5396
5396
fn build_shim_fn ( lcx : @local_ctxt ,
5397
5397
link_name : str ,
5398
5398
native_item : @ast:: native_item ,
5399
- llshimfn : ValueRef ) {
5399
+ llshimfn : ValueRef ,
5400
+ cc : uint ) {
5400
5401
let ccx = lcx_ccx ( lcx) ;
5401
5402
let span = native_item. span ;
5402
5403
let id = native_item. id ;
5403
5404
let tys = c_stack_tys ( ccx, span, id) ;
5404
5405
5405
5406
// Declare the "prototype" for the base function F:
5406
- let llbasefn = decl_cdecl_fn ( ccx. llmod , link_name, tys. base_fn_ty ) ;
5407
+ let llbasefn = decl_fn ( ccx. llmod , link_name, cc , tys. base_fn_ty ) ;
5407
5408
5408
5409
// Declare the body of the shim function:
5409
5410
let fcx = new_fn_ctxt ( lcx, span, llshimfn) ;
@@ -5439,30 +5440,32 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
5439
5440
}
5440
5441
5441
5442
let ccx = lcx_ccx ( lcx) ;
5443
+ let cc: uint = lib:: llvm:: LLVMCCallConv ;
5442
5444
alt native_mod. abi {
5443
- ast:: native_abi_cdecl. {
5444
- for native_item in native_mod. items {
5445
- alt native_item. node {
5446
- ast:: native_item_ty. { }
5447
- ast:: native_item_fn ( name, fn_decl, _) {
5448
- let id = native_item. id ;
5449
- alt ccx. item_ids . find ( id) {
5450
- some ( llshimfn) {
5451
- let link_name = select_link_name ( name, native_item. ident ) ;
5452
- build_shim_fn ( lcx, link_name, native_item, llshimfn) ;
5453
- }
5445
+ ast:: native_abi_rust_intrinsic. { ret ; }
5446
+ ast:: native_abi_cdecl. { cc = lib:: llvm:: LLVMCCallConv ; }
5447
+ ast:: native_abi_stdcall. { cc = lib:: llvm:: LLVMX86StdcallCallConv ; }
5448
+ }
5449
+
5450
+ for native_item in native_mod. items {
5451
+ alt native_item. node {
5452
+ ast:: native_item_ty. { }
5453
+ ast:: native_item_fn ( name, fn_decl, _) {
5454
+ let id = native_item. id ;
5455
+ alt ccx. item_ids . find ( id) {
5456
+ some ( llshimfn) {
5457
+ let link_name = select_link_name ( name, native_item. ident ) ;
5458
+ build_shim_fn ( lcx, link_name, native_item, llshimfn, cc) ;
5459
+ }
5454
5460
5455
- none. {
5456
- ccx . sess . span_fatal (
5457
- native_item. span ,
5458
- "unbound function item in trans_native_mod" ) ;
5459
- }
5460
- }
5461
- }
5461
+ none. {
5462
+ ccx . sess . span_fatal (
5463
+ native_item. span ,
5464
+ "unbound function item in trans_native_mod" ) ;
5462
5465
}
5466
+ }
5463
5467
}
5464
5468
}
5465
- _ { /* nothing to do for other ABIs */ }
5466
5469
}
5467
5470
}
5468
5471
@@ -5736,7 +5739,8 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5736
5739
uses_retptr = true ;
5737
5740
cast_to_i32 = false ;
5738
5741
}
5739
- ast:: native_abi_cdecl. {
5742
+
5743
+ ast:: native_abi_cdecl. | ast:: native_abi_stdcall. {
5740
5744
let tys = c_stack_tys ( ccx, sp, id) ;
5741
5745
let shim_name = name + "__c_stack_shim" ;
5742
5746
let llshimfn = decl_internal_cdecl_fn (
@@ -5745,27 +5749,6 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5745
5749
ccx. item_symbols . insert ( id, shim_name) ;
5746
5750
ret;
5747
5751
}
5748
- ast:: native_abi_stdcall. {
5749
- // The name of stdcall functions depend on their argument count
5750
- // so we have to declare them correctly
5751
- let fn_args_tys = ty:: ty_fn_args ( ccx. tcx , fn_type) ;
5752
- let fn_ret_ty = ty:: ty_fn_ret ( ccx. tcx , fn_type) ;
5753
- let ll_args_tys = [ ] ;
5754
- for arg in fn_args_tys {
5755
- let arg_ty = arg. ty ;
5756
- check type_has_static_size ( ccx, arg_ty) ;
5757
- ll_args_tys += [ type_of ( ccx, sp, arg_ty) ] ;
5758
- }
5759
- check type_has_static_size ( ccx, fn_ret_ty) ;
5760
- let ll_ret_ty = type_of ( ccx, sp, fn_ret_ty) ;
5761
- let native_fn_ty = T_fn ( ll_args_tys, ll_ret_ty) ;
5762
-
5763
- let llfn = decl_fn ( ccx. llmod , name, lib:: llvm:: LLVMX86StdcallCallConv ,
5764
- native_fn_ty) ;
5765
- ccx. item_ids . insert ( id, llfn) ;
5766
- ccx. item_symbols . insert ( id, name) ;
5767
- ret;
5768
- }
5769
5752
}
5770
5753
5771
5754
let path = path;
0 commit comments