Skip to content

Commit 214cdd0

Browse files
committed
rustc: Translate crust functions
1 parent 78034aa commit 214cdd0

File tree

6 files changed

+315
-86
lines changed

6 files changed

+315
-86
lines changed

src/comp/back/upcall.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type upcalls =
2828
dynastack_free: ValueRef,
2929
alloc_c_stack: ValueRef,
3030
call_shim_on_c_stack: ValueRef,
31+
call_shim_on_rust_stack: ValueRef,
3132
rust_personality: ValueRef,
3233
reset_stack_limit: ValueRef};
3334

@@ -106,6 +107,9 @@ fn declare_upcalls(targ_cfg: @session::config,
106107
// arguments: void *args, void *fn_ptr
107108
[T_ptr(T_i8()), T_ptr(T_i8())],
108109
int_t),
110+
call_shim_on_rust_stack:
111+
d("call_shim_on_rust_stack",
112+
[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
109113
rust_personality:
110114
d("rust_personality", [], T_i32()),
111115
reset_stack_limit:

src/comp/middle/trans/base.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,14 +4193,17 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
41934193
// Ties up the llstaticallocas -> llloadenv -> llderivedtydescs ->
41944194
// lldynamicallocas -> lltop edges, and builds the return block.
41954195
fn finish_fn(fcx: @fn_ctxt, lltop: BasicBlockRef) {
4196+
tie_up_header_blocks(fcx, lltop);
4197+
let ret_cx = new_raw_block_ctxt(fcx, fcx.llreturn);
4198+
trans_fn_cleanups(fcx, ret_cx);
4199+
RetVoid(ret_cx);
4200+
}
4201+
4202+
fn tie_up_header_blocks(fcx: @fn_ctxt, lltop: BasicBlockRef) {
41964203
Br(new_raw_block_ctxt(fcx, fcx.llstaticallocas), fcx.llloadenv);
41974204
Br(new_raw_block_ctxt(fcx, fcx.llloadenv), fcx.llderivedtydescs_first);
41984205
Br(new_raw_block_ctxt(fcx, fcx.llderivedtydescs), fcx.lldynamicallocas);
41994206
Br(new_raw_block_ctxt(fcx, fcx.lldynamicallocas), lltop);
4200-
4201-
let ret_cx = new_raw_block_ctxt(fcx, fcx.llreturn);
4202-
trans_fn_cleanups(fcx, ret_cx);
4203-
RetVoid(ret_cx);
42044207
}
42054208

42064209
enum self_arg { impl_self(ty::t), no_self, }
@@ -4552,13 +4555,20 @@ fn param_bounds(ccx: @crate_ctxt, tp: ast::ty_param) -> ty::param_bounds {
45524555
ccx.tcx.ty_param_bounds.get(tp.id)
45534556
}
45544557

4555-
fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path, _flav: str,
4558+
fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path, flav: str,
45564559
tps: [ast::ty_param], node_id: ast::node_id,
45574560
node_type: ty::t) {
45584561
let llfty = type_of_fn_from_ty(ccx, node_type,
45594562
vec::map(tps, {|p| param_bounds(ccx, p)}));
4563+
register_fn_fuller(ccx, sp, path, flav, node_id, node_type,
4564+
lib::llvm::CCallConv, llfty);
4565+
}
4566+
4567+
fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path, _flav: str,
4568+
node_id: ast::node_id, node_type: ty::t,
4569+
cc: lib::llvm::CallConv, llfty: TypeRef) {
45604570
let ps: str = mangle_exported_name(ccx, path, node_type);
4561-
let llfn: ValueRef = decl_cdecl_fn(ccx.llmod, ps, llfty);
4571+
let llfn: ValueRef = decl_fn(ccx.llmod, ps, cc, llfty);
45624572
ccx.item_ids.insert(node_id, llfn);
45634573
ccx.item_symbols.insert(node_id, ps);
45644574

@@ -4747,9 +4757,13 @@ fn collect_item(ccx: @crate_ctxt, abi: @mutable option<ast::native_abi>,
47474757
either::right(abi_) { *abi = option::some(abi_); }
47484758
}
47494759
}
4750-
ast::item_fn(_, tps, _) {
4751-
register_fn(ccx, i.span, my_path, "fn", tps,
4752-
i.id);
4760+
ast::item_fn(decl, tps, _) {
4761+
if decl.purity != ast::crust_fn {
4762+
register_fn(ccx, i.span, my_path, "fn", tps,
4763+
i.id);
4764+
} else {
4765+
native::register_crust_fn(ccx, i.span, my_path, i.id);
4766+
}
47534767
}
47544768
ast::item_impl(tps, _, _, methods) {
47554769
let path = my_path + [path_name(int::str(i.id))];

0 commit comments

Comments
 (0)