@@ -24,7 +24,7 @@ import back::{link, abi, upcall};
24
24
import syntax:: { ast, ast_util} ;
25
25
import syntax:: visit;
26
26
import syntax:: codemap:: span;
27
- import syntax:: print:: pprust:: { expr_to_str, path_to_str , stmt_to_str} ;
27
+ import syntax:: print:: pprust:: { expr_to_str, stmt_to_str} ;
28
28
import visit:: vt;
29
29
import util:: common:: * ;
30
30
import lib:: llvm:: { llvm, mk_target_data, mk_type_names} ;
@@ -5393,16 +5393,17 @@ fn c_stack_tys(ccx: @crate_ctxt,
5393
5393
// }
5394
5394
//
5395
5395
fn trans_native_mod ( lcx : @local_ctxt , native_mod : ast:: native_mod ) {
5396
- fn build_shim_fn ( lcx : @local_ctxt , native_item : @ast:: native_item ,
5396
+ fn build_shim_fn ( lcx : @local_ctxt ,
5397
+ link_name : str ,
5398
+ native_item : @ast:: native_item ,
5397
5399
llshimfn : ValueRef ) {
5398
5400
let ccx = lcx_ccx ( lcx) ;
5399
5401
let span = native_item. span ;
5400
5402
let id = native_item. id ;
5401
5403
let tys = c_stack_tys ( ccx, span, id) ;
5402
5404
5403
5405
// Declare the "prototype" for the base function F:
5404
- let name = native_item. ident ;
5405
- let llbasefn = decl_cdecl_fn ( ccx. llmod , name, tys. base_fn_ty ) ;
5406
+ let llbasefn = decl_cdecl_fn ( ccx. llmod , link_name, tys. base_fn_ty ) ;
5406
5407
5407
5408
// Declare the body of the shim function:
5408
5409
let fcx = new_fn_ctxt ( lcx, span, llshimfn) ;
@@ -5430,17 +5431,25 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
5430
5431
finish_fn ( fcx, lltop) ;
5431
5432
}
5432
5433
5434
+ fn select_link_name ( user_name : option:: t < str > , rust_name : str ) -> str {
5435
+ ret alt user_name {
5436
+ some( n) { n }
5437
+ none. { rust_name }
5438
+ } ;
5439
+ }
5440
+
5433
5441
let ccx = lcx_ccx ( lcx) ;
5434
5442
alt native_mod. abi {
5435
5443
ast:: native_abi_cdecl. {
5436
5444
for native_item in native_mod. items {
5437
5445
alt native_item. node {
5438
5446
ast:: native_item_ty. { }
5439
- ast:: native_item_fn ( _ , fn_decl, _) {
5447
+ ast:: native_item_fn ( name , fn_decl, _) {
5440
5448
let id = native_item. id ;
5441
5449
alt ccx. item_ids . find ( id) {
5442
5450
some ( llshimfn) {
5443
- build_shim_fn ( lcx, native_item, llshimfn) ;
5451
+ let link_name = select_link_name ( name, native_item. ident ) ;
5452
+ build_shim_fn ( lcx, link_name, native_item, llshimfn) ;
5444
5453
}
5445
5454
5446
5455
none. {
0 commit comments