Skip to content

Commit 9b96790

Browse files
committed
---
yaml --- r: 2337 b: refs/heads/master c: ac8eb20 h: refs/heads/master i: 2335: 4a6f69a v: v3
1 parent e94da88 commit 9b96790

File tree

5 files changed

+62
-29
lines changed

5 files changed

+62
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 2bc17adc299ef0fcfbf7c41fc1ad12950ffd7e56
2+
refs/heads/master: ac8eb202247b61412143c621a1ccdcb167d6f313

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ tag native_abi {
380380
native_abi_rust;
381381
native_abi_cdecl;
382382
native_abi_llvm;
383+
native_abi_rust_intrinsic;
383384
}
384385
385386
type native_mod = rec(str native_name,

trunk/src/comp/front/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,8 @@ fn parse_item_native_mod(parser p) -> @ast.item {
20152015
abi = ast.native_abi_rust;
20162016
} else if (_str.eq(t, "llvm")) {
20172017
abi = ast.native_abi_llvm;
2018+
} else if (_str.eq(t, "rust-intrinsic")) {
2019+
abi = ast.native_abi_rust_intrinsic;
20182020
} else {
20192021
p.err("unsupported abi: " + t);
20202022
fail;

trunk/src/comp/middle/trans.rs

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6737,6 +6737,10 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
67376737
arg_n += 1u;
67386738
}
67396739
}
6740+
case (ast.native_abi_rust_intrinsic) {
6741+
pass_task = true;
6742+
call_args += vec(lltaskptr);
6743+
}
67406744
case (ast.native_abi_cdecl) {
67416745
pass_task = false;
67426746
}
@@ -6772,46 +6776,69 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
67726776
args += vec(vp2i(cx, v));
67736777
}
67746778

6775-
auto r;
6776-
auto rptr;
6777-
auto args = ty.ty_fn_args(ccx.tcx, fn_type);
6778-
if (abi == ast.native_abi_llvm) {
6779-
let vec[ValueRef] call_args = vec();
6779+
fn trans_simple_native_abi(@block_ctxt bcx,
6780+
str name,
6781+
vec[ty.arg] args,
6782+
&mutable vec[ValueRef] call_args,
6783+
ty.t fn_type) -> tup(ValueRef, ValueRef) {
67806784
let vec[TypeRef] call_arg_tys = vec();
67816785
auto i = 0u;
67826786
while (i < _vec.len[ty.arg](args)) {
6783-
auto call_arg = llvm.LLVMGetParam(fcx.llfn, i + 3u);
6787+
auto call_arg = llvm.LLVMGetParam(bcx.fcx.llfn, i + 3u);
67846788
call_args += vec(call_arg);
67856789
call_arg_tys += vec(val_ty(call_arg));
67866790
i += 1u;
67876791
}
6788-
auto llnativefnty = T_fn(call_arg_tys,
6789-
type_of(ccx,
6790-
ty.ty_fn_ret(ccx.tcx, fn_type)));
6791-
auto llnativefn = get_extern_fn(ccx.externs, ccx.llmod, name,
6792-
lib.llvm.LLVMCCallConv, llnativefnty);
6793-
r = bcx.build.Call(llnativefn, call_args);
6794-
rptr = fcx.llretptr;
6795-
} else {
6792+
auto llnativefnty =
6793+
T_fn(call_arg_tys,
6794+
type_of(bcx.fcx.lcx.ccx,
6795+
ty.ty_fn_ret(bcx.fcx.lcx.ccx.tcx, fn_type)));
6796+
auto llnativefn = get_extern_fn(bcx.fcx.lcx.ccx.externs,
6797+
bcx.fcx.lcx.ccx.llmod,
6798+
name,
6799+
lib.llvm.LLVMCCallConv,
6800+
llnativefnty);
67966801

6797-
let vec[tup(ValueRef, ty.t)] drop_args = vec();
6802+
auto r = bcx.build.Call(llnativefn, call_args);
6803+
auto rptr = bcx.fcx.llretptr;
6804+
ret tup(r, rptr);
6805+
}
67986806

6799-
for (ty.arg arg in args) {
6800-
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
6801-
assert (llarg as int != 0);
6802-
push_arg(bcx, call_args, llarg, arg.ty, arg.mode);
6803-
if (arg.mode == ast.val) {
6804-
drop_args += vec(tup(llarg, arg.ty));
6805-
}
6806-
arg_n += 1u;
6807+
auto r;
6808+
auto rptr;
6809+
auto args = ty.ty_fn_args(ccx.tcx, fn_type);
6810+
alt (abi) {
6811+
case (ast.native_abi_llvm) {
6812+
auto result = trans_simple_native_abi(bcx, name, args, call_args,
6813+
fn_type);
6814+
r = result._0; rptr = result._1;
6815+
}
6816+
case (ast.native_abi_rust_intrinsic) {
6817+
auto result = trans_simple_native_abi(bcx, name, args, call_args,
6818+
fn_type);
6819+
r = result._0; rptr = result._1;
68076820
}
6821+
case (_) {
6822+
let vec[tup(ValueRef, ty.t)] drop_args = vec();
68086823

6809-
r = trans_native_call(bcx.build, ccx.glues, lltaskptr, ccx.externs,
6810-
ccx.tn, ccx.llmod, name, pass_task, call_args);
6811-
rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
6824+
for (ty.arg arg in args) {
6825+
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
6826+
assert (llarg as int != 0);
6827+
push_arg(bcx, call_args, llarg, arg.ty, arg.mode);
6828+
if (arg.mode == ast.val) {
6829+
drop_args += vec(tup(llarg, arg.ty));
6830+
}
6831+
arg_n += 1u;
6832+
}
68126833

6813-
for (tup(ValueRef, ty.t) d in drop_args) {
6814-
bcx = drop_ty(bcx, d._0, d._1).bcx;
6834+
r = trans_native_call(bcx.build, ccx.glues, lltaskptr,
6835+
ccx.externs, ccx.tn, ccx.llmod, name,
6836+
pass_task, call_args);
6837+
rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
6838+
6839+
for (tup(ValueRef, ty.t) d in drop_args) {
6840+
bcx = drop_ty(bcx, d._0, d._1).bcx;
6841+
}
68156842
}
68166843
}
68176844

trunk/src/comp/pretty/pprust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ fn print_item(ps s, @ast.item item) {
230230
alt (nmod.abi) {
231231
case (ast.native_abi_rust) {wrd1(s, "\"rust\"");}
232232
case (ast.native_abi_cdecl) {wrd1(s, "\"cdecl\"");}
233+
case (ast.native_abi_rust_intrinsic) {
234+
wrd1(s, "\"rust-intrinstic\"");
235+
}
233236
}
234237
wrd1(s, "mod");
235238
wrd1(s, id);

0 commit comments

Comments
 (0)