@@ -180,33 +180,42 @@ pub fn register_static(ccx: &CrateContext,
180
180
}
181
181
}
182
182
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 {
185
185
/*!
186
186
* Registers a foreign function found in a library.
187
187
* Just adds a LLVM global.
188
188
*/
189
189
190
190
debug ! ( "register_foreign_item_fn(abi={}, \
191
- path ={}, \
192
- foreign_item.id ={})",
191
+ ty ={}, \
192
+ name ={})",
193
193
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 ) ;
196
196
197
197
let cc = match llvm_calling_convention ( ccx, abi) {
198
198
Some ( cc) => cc,
199
199
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
+ }
204
214
}
205
215
} ;
206
216
207
217
// 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) ;
210
219
211
220
// Make sure the calling convention is right for variadic functions
212
221
// (should've been caught if not in typeck)
@@ -219,7 +228,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi,
219
228
220
229
let llfn = base:: get_extern_fn ( & mut * ccx. externs . borrow_mut ( ) ,
221
230
ccx. llmod ,
222
- lname . get ( ) ,
231
+ name ,
223
232
cc,
224
233
llfn_ty,
225
234
tys. fn_sig . output ) ;
@@ -433,17 +442,23 @@ pub fn trans_native_call<'a>(
433
442
pub fn trans_foreign_mod ( ccx : & CrateContext , foreign_mod : & ast:: ForeignMod ) {
434
443
let _icx = push_ctxt ( "foreign::trans_foreign_mod" ) ;
435
444
for & foreign_item in foreign_mod. items . iter ( ) {
445
+ let lname = link_name ( foreign_item) ;
446
+
436
447
match foreign_item. node {
437
448
ast:: ForeignItemFn ( ..) => {
438
449
match foreign_mod. abi {
439
450
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
+ }
441
457
}
442
458
}
443
459
_ => { }
444
460
}
445
461
446
- let lname = link_name ( foreign_item) ;
447
462
ccx. item_symbols . borrow_mut ( ) . insert ( foreign_item. id ,
448
463
lname. get ( ) . to_strbuf ( ) ) ;
449
464
}
0 commit comments