make stdcall use shim
This commit is contained in:
parent
d2199e8716
commit
e3699a2636
1 changed files with 26 additions and 43 deletions
|
@ -5396,14 +5396,15 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
|
|||
fn build_shim_fn(lcx: @local_ctxt,
|
||||
link_name: str,
|
||||
native_item: @ast::native_item,
|
||||
llshimfn: ValueRef) {
|
||||
llshimfn: ValueRef,
|
||||
cc: uint) {
|
||||
let ccx = lcx_ccx(lcx);
|
||||
let span = native_item.span;
|
||||
let id = native_item.id;
|
||||
let tys = c_stack_tys(ccx, span, id);
|
||||
|
||||
// Declare the "prototype" for the base function F:
|
||||
let llbasefn = decl_cdecl_fn(ccx.llmod, link_name, tys.base_fn_ty);
|
||||
let llbasefn = decl_fn(ccx.llmod, link_name, cc, tys.base_fn_ty);
|
||||
|
||||
// Declare the body of the shim function:
|
||||
let fcx = new_fn_ctxt(lcx, span, llshimfn);
|
||||
|
@ -5439,8 +5440,13 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
|
|||
}
|
||||
|
||||
let ccx = lcx_ccx(lcx);
|
||||
let cc: uint = lib::llvm::LLVMCCallConv;
|
||||
alt native_mod.abi {
|
||||
ast::native_abi_cdecl. {
|
||||
ast::native_abi_rust_intrinsic. { ret; }
|
||||
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
|
||||
ast::native_abi_stdcall. { cc = lib::llvm::LLVMX86StdcallCallConv; }
|
||||
}
|
||||
|
||||
for native_item in native_mod.items {
|
||||
alt native_item.node {
|
||||
ast::native_item_ty. {}
|
||||
|
@ -5449,7 +5455,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
|
|||
alt ccx.item_ids.find(id) {
|
||||
some(llshimfn) {
|
||||
let link_name = select_link_name(name, native_item.ident);
|
||||
build_shim_fn(lcx, link_name, native_item, llshimfn);
|
||||
build_shim_fn(lcx, link_name, native_item, llshimfn, cc);
|
||||
}
|
||||
|
||||
none. {
|
||||
|
@ -5461,9 +5467,6 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ { /* nothing to do for other ABIs */ }
|
||||
}
|
||||
}
|
||||
|
||||
fn trans_item(cx: @local_ctxt, item: ast::item) {
|
||||
|
@ -5736,7 +5739,8 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
|
|||
uses_retptr = true;
|
||||
cast_to_i32 = false;
|
||||
}
|
||||
ast::native_abi_cdecl. {
|
||||
|
||||
ast::native_abi_cdecl. | ast::native_abi_stdcall. {
|
||||
let tys = c_stack_tys(ccx, sp, id);
|
||||
let shim_name = name + "__c_stack_shim";
|
||||
let llshimfn = decl_internal_cdecl_fn(
|
||||
|
@ -5745,27 +5749,6 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
|
|||
ccx.item_symbols.insert(id, shim_name);
|
||||
ret;
|
||||
}
|
||||
ast::native_abi_stdcall. {
|
||||
// The name of stdcall functions depend on their argument count
|
||||
// so we have to declare them correctly
|
||||
let fn_args_tys = ty::ty_fn_args(ccx.tcx, fn_type);
|
||||
let fn_ret_ty = ty::ty_fn_ret(ccx.tcx, fn_type);
|
||||
let ll_args_tys = [];
|
||||
for arg in fn_args_tys {
|
||||
let arg_ty = arg.ty;
|
||||
check type_has_static_size(ccx, arg_ty);
|
||||
ll_args_tys += [type_of(ccx, sp, arg_ty)];
|
||||
}
|
||||
check type_has_static_size(ccx, fn_ret_ty);
|
||||
let ll_ret_ty = type_of(ccx, sp, fn_ret_ty);
|
||||
let native_fn_ty = T_fn(ll_args_tys, ll_ret_ty);
|
||||
|
||||
let llfn = decl_fn(ccx.llmod, name, lib::llvm::LLVMX86StdcallCallConv,
|
||||
native_fn_ty);
|
||||
ccx.item_ids.insert(id, llfn);
|
||||
ccx.item_symbols.insert(id, name);
|
||||
ret;
|
||||
}
|
||||
}
|
||||
|
||||
let path = path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue