@@ -180,33 +180,42 @@ pub fn register_static(ccx: &CrateContext,
180180 }
181181}
182182
183- pub fn register_foreign_item_fn ( ccx : & CrateContext , abi : Abi ,
184- foreign_item : & ast :: ForeignItem ) -> ValueRef {
183+ pub fn register_foreign_item_fn ( ccx : & CrateContext , abi : Abi , fty : ty :: t ,
184+ name : & str , span : Option < Span > ) -> ValueRef {
185185 /*!
186186 * Registers a foreign function found in a library.
187187 * Just adds a LLVM global.
188188 */
189189
190190 debug ! ( "register_foreign_item_fn(abi={}, \
191- path ={}, \
192- foreign_item.id ={})",
191+ ty ={}, \
192+ name ={})",
193193 abi. repr( ccx. tcx( ) ) ,
194- ccx. tcx. map . path_to_str ( foreign_item . id ) ,
195- foreign_item . id ) ;
194+ fty . repr ( ccx. tcx( ) ) ,
195+ name ) ;
196196
197197 let cc = match llvm_calling_convention ( ccx, abi) {
198198 Some ( cc) => cc,
199199 None => {
200- ccx. sess ( ) . span_fatal ( foreign_item. span ,
201- format ! ( "ABI `{}` has no suitable calling convention \
202- for target architecture",
203- abi. user_string( ccx. tcx( ) ) ) ) ;
200+ match span {
201+ Some ( s) => {
202+ ccx. sess ( ) . span_fatal ( s,
203+ format ! ( "ABI `{}` has no suitable calling convention \
204+ for target architecture",
205+ abi. user_string( ccx. tcx( ) ) ) )
206+ }
207+ None => {
208+ ccx. sess ( ) . fatal (
209+ format ! ( "ABI `{}` has no suitable calling convention \
210+ for target architecture",
211+ abi. user_string( ccx. tcx( ) ) ) )
212+ }
213+ }
204214 }
205215 } ;
206216
207217 // Register the function as a C extern fn
208- let lname = link_name ( foreign_item) ;
209- let tys = foreign_types_for_id ( ccx, foreign_item. id ) ;
218+ let tys = foreign_types_for_fn_ty ( ccx, fty) ;
210219
211220 // Make sure the calling convention is right for variadic functions
212221 // (should've been caught if not in typeck)
@@ -219,7 +228,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi,
219228
220229 let llfn = base:: get_extern_fn ( & mut * ccx. externs . borrow_mut ( ) ,
221230 ccx. llmod ,
222- lname . get ( ) ,
231+ name ,
223232 cc,
224233 llfn_ty,
225234 tys. fn_sig . output ) ;
@@ -433,17 +442,23 @@ pub fn trans_native_call<'a>(
433442pub fn trans_foreign_mod ( ccx : & CrateContext , foreign_mod : & ast:: ForeignMod ) {
434443 let _icx = push_ctxt ( "foreign::trans_foreign_mod" ) ;
435444 for & foreign_item in foreign_mod. items . iter ( ) {
445+ let lname = link_name ( foreign_item) ;
446+
436447 match foreign_item. node {
437448 ast:: ForeignItemFn ( ..) => {
438449 match foreign_mod. abi {
439450 Rust | RustIntrinsic => { }
440- abi => { register_foreign_item_fn ( ccx, abi, foreign_item) ; }
451+ abi => {
452+ let ty = ty:: node_id_to_type ( ccx. tcx ( ) , foreign_item. id ) ;
453+ register_foreign_item_fn ( ccx, abi, ty,
454+ lname. get ( ) . as_slice ( ) ,
455+ Some ( foreign_item. span ) ) ;
456+ }
441457 }
442458 }
443459 _ => { }
444460 }
445461
446- let lname = link_name ( foreign_item) ;
447462 ccx. item_symbols . borrow_mut ( ) . insert ( foreign_item. id ,
448463 lname. get ( ) . to_strbuf ( ) ) ;
449464 }
0 commit comments