Skip to content

Commit 4bced5e

Browse files
committed
Use invoke to call (most) rust functions
No landing pads yet. Issue #236
1 parent 9f4b4d8 commit 4bced5e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3761,7 +3761,7 @@ fn trans_call(in_cx: &@block_ctxt, f: &@ast::expr,
37613761
for the call itself is unreachable. */
37623762
let retval = C_nil();
37633763
if !is_terminated(bcx) {
3764-
FastCall(bcx, faddr, llargs);
3764+
bcx = invoke_fastcall(bcx, faddr, llargs).bcx;
37653765
alt lliterbody {
37663766
none. {
37673767
if !ty::type_is_nil(bcx_tcx(cx), ret_ty) {
@@ -3794,6 +3794,22 @@ fn trans_call(in_cx: &@block_ctxt, f: &@ast::expr,
37943794
ret rslt(bcx, retval);
37953795
}
37963796

3797+
fn invoke_fastcall(bcx: &@block_ctxt, llfn: ValueRef,
3798+
llargs: &[ValueRef]) -> result {
3799+
3800+
let normal_bcx = new_sub_block_ctxt(bcx, "normal return");
3801+
let unwind_bcx = new_sub_block_ctxt(bcx, "unwind");
3802+
let retval = trans_build::FastInvoke(bcx, llfn, llargs,
3803+
normal_bcx.llbb,
3804+
unwind_bcx.llbb);
3805+
trans_landing_pad(unwind_bcx);
3806+
ret rslt(normal_bcx, retval);
3807+
}
3808+
3809+
fn trans_landing_pad(bcx: &@block_ctxt) {
3810+
Unreachable(bcx);
3811+
}
3812+
37973813
fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id) ->
37983814
result {
37993815
let bcx = cx;

src/comp/middle/trans_build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
6868
});
6969
}
7070

71+
fn FastInvoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
72+
Then: BasicBlockRef, Catch: BasicBlockRef) -> ValueRef {
73+
assert (!cx.terminated);
74+
cx.terminated = true;
75+
let v = str::as_buf("",
76+
{|buf|
77+
llvm::LLVMBuildInvoke(B(cx), Fn,
78+
vec::to_ptr(Args),
79+
vec::len(Args), Then,
80+
Catch, buf)
81+
});
82+
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
83+
ret v;
84+
}
85+
7186
fn Unreachable(cx: &@block_ctxt) -> ValueRef {
7287
assert (!cx.terminated);
7388
cx.terminated = true;

0 commit comments

Comments
 (0)