@@ -5723,21 +5723,20 @@ fn raw_native_fn_type(ccx: @crate_ctxt, sp: span, args: [ty::arg],
5723
5723
ret T_fn ( type_of_explicit_args ( ccx, sp, args) , type_of ( ccx, sp, ret_ty) ) ;
5724
5724
}
5725
5725
5726
- fn register_native_fn ( ccx : @crate_ctxt , sp : span , path : [ str ] , name : str ,
5727
- id : ast:: node_id ) {
5726
+ fn register_native_fn ( ccx : @crate_ctxt , sp : span , _path : [ str ] , name : str ,
5727
+ id : ast:: node_id ) {
5728
5728
let fn_type = node_id_type ( ccx, id) ; // NB: has no type params
5729
5729
let abi = ty:: ty_fn_abi ( ccx. tcx , fn_type) ;
5730
5730
5731
- // FIXME: There's probably a lot of unused code here now that
5732
- // there's only one possible combination of these three options
5733
- let pass_task;
5734
- let uses_retptr;
5735
- let cast_to_i32;
5736
5731
alt abi {
5737
5732
ast : : native_abi_rust_intrinsic. {
5738
- pass_task = true ;
5739
- uses_retptr = true ;
5740
- cast_to_i32 = false ;
5733
+ let num_ty_param = native_fn_ty_param_count ( ccx, id) ;
5734
+ let fn_type = native_fn_wrapper_type ( ccx, sp, num_ty_param, fn_type) ;
5735
+ let ri_name = "rust_intrinsic_2_" + name;
5736
+ let llnativefn = get_extern_fn ( ccx. externs , ccx. llmod , ri_name,
5737
+ lib:: llvm:: LLVMCCallConv , fn_type) ;
5738
+ ccx. item_ids . insert ( id, llnativefn) ;
5739
+ ccx. item_symbols . insert ( id, ri_name) ;
5741
5740
}
5742
5741
5743
5742
ast:: native_abi_cdecl. | ast:: native_abi_stdcall. {
@@ -5747,140 +5746,9 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5747
5746
ccx. llmod , shim_name, tys. shim_fn_ty ) ;
5748
5747
ccx. item_ids . insert ( id, llshimfn) ;
5749
5748
ccx. item_symbols . insert ( id, shim_name) ;
5750
- ret;
5751
5749
}
5752
5750
}
5753
5751
5754
- let path = path;
5755
- let num_ty_param = native_fn_ty_param_count ( ccx, id) ;
5756
- // Declare the wrapper.
5757
-
5758
- let t = node_id_type ( ccx, id) ;
5759
- let wrapper_type = native_fn_wrapper_type ( ccx, sp, num_ty_param, t) ;
5760
- let ps: str = mangle_exported_name ( ccx, path, node_id_type ( ccx, id) ) ;
5761
- let wrapper_fn = decl_cdecl_fn ( ccx. llmod , ps, wrapper_type) ;
5762
- ccx. item_ids . insert ( id, wrapper_fn) ;
5763
- ccx. item_symbols . insert ( id, ps) ;
5764
-
5765
- // Build the wrapper.
5766
- let fcx = new_fn_ctxt ( new_local_ctxt ( ccx) , sp, wrapper_fn) ;
5767
- let bcx = new_top_block_ctxt ( fcx) ;
5768
- let lltop = bcx. llbb ;
5769
-
5770
- // Declare the function itself.
5771
- // FIXME: If the returned type is not nil, then we assume it's 32 bits
5772
- // wide. This is obviously wildly unsafe. We should have a better FFI
5773
- // that allows types of different sizes to be returned.
5774
-
5775
- let rty = ty:: ty_fn_ret ( ccx. tcx , fn_type) ;
5776
- let rty_is_nil = ty:: type_is_nil ( ccx. tcx , rty) ;
5777
-
5778
- let call_args: [ ValueRef ] = [ ] ;
5779
- if pass_task { call_args += [ C_null ( T_ptr ( ccx. task_type ) ) ] ; }
5780
- if uses_retptr { call_args += [ bcx. fcx . llretptr ] ; }
5781
-
5782
- let arg_n = 2 u;
5783
- uint:: range ( 0 u, num_ty_param) { |_i|
5784
- let llarg = llvm:: LLVMGetParam ( fcx. llfn , arg_n) ;
5785
- fcx. lltydescs += [ llarg] ;
5786
- assert ( llarg as int != 0 ) ;
5787
- if cast_to_i32 {
5788
- call_args += [ vp2i ( bcx, llarg) ] ;
5789
- } else { call_args += [ llarg] ; }
5790
- arg_n += 1 u;
5791
- } ;
5792
- fn convert_arg_to_i32 ( cx : @block_ctxt , v : ValueRef , t : ty:: t ,
5793
- mode : ty:: mode ) -> ValueRef {
5794
- if mode == ast:: by_ref || mode == ast:: by_val {
5795
- let ccx = bcx_ccx ( cx) ;
5796
- if ty:: type_is_integral ( bcx_tcx ( cx) , t) {
5797
- // FIXME: would be nice to have a postcondition that says
5798
- // if a type is integral, then it has static size (#586)
5799
- let lldsttype = ccx. int_type ;
5800
- let sp = cx. sp ;
5801
- check ( type_has_static_size ( ccx, t) ) ;
5802
- let llsrctype = type_of ( ccx, sp, t) ;
5803
- if llvm:: LLVMGetIntTypeWidth ( lldsttype) >
5804
- llvm:: LLVMGetIntTypeWidth ( llsrctype) {
5805
- ret ZExtOrBitCast ( cx, v, ccx. int_type ) ;
5806
- }
5807
- ret TruncOrBitCast ( cx, v, ccx. int_type ) ;
5808
- }
5809
- if ty:: type_is_fp ( bcx_tcx ( cx) , t) {
5810
- ret FPToSI ( cx, v, ccx. int_type ) ;
5811
- }
5812
- }
5813
- ret vp2i( cx, v) ;
5814
- }
5815
-
5816
- fn trans_simple_native_abi ( bcx : @block_ctxt , name : str ,
5817
- & call_args: [ ValueRef ] , fn_type : ty:: t ,
5818
- uses_retptr : bool , cc : uint ) ->
5819
- { val : ValueRef , rptr : ValueRef } {
5820
- let call_arg_tys: [ TypeRef ] = [ ] ;
5821
- for arg: ValueRef in call_args { call_arg_tys += [ val_ty ( arg) ] ; }
5822
- let ccx = bcx_ccx ( bcx) ;
5823
-
5824
- let llnativefnty =
5825
- if uses_retptr {
5826
- T_fn ( call_arg_tys, T_void ( ) )
5827
- } else {
5828
- let fn_ret_ty = ty:: ty_fn_ret ( bcx_tcx ( bcx) , fn_type) ;
5829
- // FIXME: Could follow from a constraint on fn_type...
5830
- check ( type_has_static_size ( ccx, fn_ret_ty) ) ;
5831
- let sp = bcx. sp ;
5832
- T_fn ( call_arg_tys, type_of ( ccx, sp, fn_ret_ty) )
5833
- } ;
5834
-
5835
- let llnativefn =
5836
- get_extern_fn ( ccx. externs , ccx. llmod , name, cc, llnativefnty) ;
5837
- let r =
5838
- if cc == lib:: llvm:: LLVMCCallConv {
5839
- Call ( bcx, llnativefn, call_args)
5840
- } else { CallWithConv ( bcx, llnativefn, call_args, cc) } ;
5841
- let rptr = bcx. fcx . llretptr ;
5842
- ret { val : r, rptr : rptr} ;
5843
- }
5844
-
5845
- let args = ty:: ty_fn_args ( ccx. tcx , fn_type) ;
5846
- // Build up the list of arguments.
5847
-
5848
- let i = arg_n;
5849
- for arg: ty:: arg in args {
5850
- let llarg = llvm:: LLVMGetParam ( fcx. llfn , i) ;
5851
- assert ( llarg as int != 0 ) ;
5852
- if cast_to_i32 {
5853
- let llarg_i32 = convert_arg_to_i32 ( bcx, llarg, arg. ty , arg. mode ) ;
5854
- call_args += [ llarg_i32] ;
5855
- } else { call_args += [ llarg] ; }
5856
- i += 1 u;
5857
- }
5858
- let r;
5859
- let rptr;
5860
- alt abi {
5861
- ast : : native_abi_rust_intrinsic. {
5862
- let external_name = "rust_intrinsic_" + name;
5863
- let result =
5864
- trans_simple_native_abi ( bcx, external_name, call_args, fn_type,
5865
- uses_retptr, lib:: llvm:: LLVMCCallConv ) ;
5866
- r = result. val ;
5867
- rptr = result. rptr ;
5868
- }
5869
- _ {
5870
- r =
5871
- trans_native_call ( new_raw_block_ctxt ( bcx. fcx , bcx. llbb ) ,
5872
- ccx. externs , ccx. llmod , name, call_args) ;
5873
- rptr = BitCast ( bcx, fcx. llretptr , T_ptr ( ccx. int_type ) ) ;
5874
- }
5875
- }
5876
- // We don't store the return value if it's nil, to avoid stomping on a nil
5877
- // pointer. This is the only concession made to non-i32 return values. See
5878
- // the FIXME above.
5879
-
5880
- if !rty_is_nil && !uses_retptr { Store ( bcx, r, rptr) ; }
5881
-
5882
- build_return ( bcx) ;
5883
- finish_fn ( fcx, lltop) ;
5884
5752
}
5885
5753
5886
5754
fn item_path ( item : @ast:: item ) -> [ str ] { ret [ item. ident ] ; }
0 commit comments