Skip to content

Commit 52e736c

Browse files
committed
---
yaml --- r: 6329 b: refs/heads/master c: cbcdeb8 h: refs/heads/master i: 6327: 2d9ba5d v: v3
1 parent c091f17 commit 52e736c

File tree

5 files changed

+336
-302
lines changed

5 files changed

+336
-302
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 23bb158acbb8af412371455c7493c8546c7afafd
2+
refs/heads/master: cbcdeb80d938177962d29f19ce8ef0c1060fa2ae

trunk/src/comp/middle/trans.rs

+9-141
Original file line numberDiff line numberDiff line change
@@ -5723,21 +5723,20 @@ fn raw_native_fn_type(ccx: @crate_ctxt, sp: span, args: [ty::arg],
57235723
ret T_fn(type_of_explicit_args(ccx, sp, args), type_of(ccx, sp, ret_ty));
57245724
}
57255725

5726-
fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5727-
id: ast::node_id) {
5726+
fn register_native_fn(ccx: @crate_ctxt, sp: span, _path: [str], name: str,
5727+
id: ast::node_id) {
57285728
let fn_type = node_id_type(ccx, id); // NB: has no type params
57295729
let abi = ty::ty_fn_abi(ccx.tcx, fn_type);
57305730

5731-
// FIXME: There's probably a lot of unused code here now that
5732-
// there's only one possible combination of these three options
5733-
let pass_task;
5734-
let uses_retptr;
5735-
let cast_to_i32;
57365731
alt abi {
57375732
ast::native_abi_rust_intrinsic. {
5738-
pass_task = true;
5739-
uses_retptr = true;
5740-
cast_to_i32 = false;
5733+
let num_ty_param = native_fn_ty_param_count(ccx, id);
5734+
let fn_type = native_fn_wrapper_type(ccx, sp, num_ty_param, fn_type);
5735+
let ri_name = "rust_intrinsic_2_" + name;
5736+
let llnativefn = get_extern_fn(ccx.externs, ccx.llmod, ri_name,
5737+
lib::llvm::LLVMCCallConv, fn_type);
5738+
ccx.item_ids.insert(id, llnativefn);
5739+
ccx.item_symbols.insert(id, ri_name);
57415740
}
57425741

57435742
ast::native_abi_cdecl. | ast::native_abi_stdcall. {
@@ -5747,140 +5746,9 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
57475746
ccx.llmod, shim_name, tys.shim_fn_ty);
57485747
ccx.item_ids.insert(id, llshimfn);
57495748
ccx.item_symbols.insert(id, shim_name);
5750-
ret;
57515749
}
57525750
}
57535751

5754-
let path = path;
5755-
let num_ty_param = native_fn_ty_param_count(ccx, id);
5756-
// Declare the wrapper.
5757-
5758-
let t = node_id_type(ccx, id);
5759-
let wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t);
5760-
let ps: str = mangle_exported_name(ccx, path, node_id_type(ccx, id));
5761-
let wrapper_fn = decl_cdecl_fn(ccx.llmod, ps, wrapper_type);
5762-
ccx.item_ids.insert(id, wrapper_fn);
5763-
ccx.item_symbols.insert(id, ps);
5764-
5765-
// Build the wrapper.
5766-
let fcx = new_fn_ctxt(new_local_ctxt(ccx), sp, wrapper_fn);
5767-
let bcx = new_top_block_ctxt(fcx);
5768-
let lltop = bcx.llbb;
5769-
5770-
// Declare the function itself.
5771-
// FIXME: If the returned type is not nil, then we assume it's 32 bits
5772-
// wide. This is obviously wildly unsafe. We should have a better FFI
5773-
// that allows types of different sizes to be returned.
5774-
5775-
let rty = ty::ty_fn_ret(ccx.tcx, fn_type);
5776-
let rty_is_nil = ty::type_is_nil(ccx.tcx, rty);
5777-
5778-
let call_args: [ValueRef] = [];
5779-
if pass_task { call_args += [C_null(T_ptr(ccx.task_type))]; }
5780-
if uses_retptr { call_args += [bcx.fcx.llretptr]; }
5781-
5782-
let arg_n = 2u;
5783-
uint::range(0u, num_ty_param) {|_i|
5784-
let llarg = llvm::LLVMGetParam(fcx.llfn, arg_n);
5785-
fcx.lltydescs += [llarg];
5786-
assert (llarg as int != 0);
5787-
if cast_to_i32 {
5788-
call_args += [vp2i(bcx, llarg)];
5789-
} else { call_args += [llarg]; }
5790-
arg_n += 1u;
5791-
};
5792-
fn convert_arg_to_i32(cx: @block_ctxt, v: ValueRef, t: ty::t,
5793-
mode: ty::mode) -> ValueRef {
5794-
if mode == ast::by_ref || mode == ast::by_val {
5795-
let ccx = bcx_ccx(cx);
5796-
if ty::type_is_integral(bcx_tcx(cx), t) {
5797-
// FIXME: would be nice to have a postcondition that says
5798-
// if a type is integral, then it has static size (#586)
5799-
let lldsttype = ccx.int_type;
5800-
let sp = cx.sp;
5801-
check (type_has_static_size(ccx, t));
5802-
let llsrctype = type_of(ccx, sp, t);
5803-
if llvm::LLVMGetIntTypeWidth(lldsttype) >
5804-
llvm::LLVMGetIntTypeWidth(llsrctype) {
5805-
ret ZExtOrBitCast(cx, v, ccx.int_type);
5806-
}
5807-
ret TruncOrBitCast(cx, v, ccx.int_type);
5808-
}
5809-
if ty::type_is_fp(bcx_tcx(cx), t) {
5810-
ret FPToSI(cx, v, ccx.int_type);
5811-
}
5812-
}
5813-
ret vp2i(cx, v);
5814-
}
5815-
5816-
fn trans_simple_native_abi(bcx: @block_ctxt, name: str,
5817-
&call_args: [ValueRef], fn_type: ty::t,
5818-
uses_retptr: bool, cc: uint) ->
5819-
{val: ValueRef, rptr: ValueRef} {
5820-
let call_arg_tys: [TypeRef] = [];
5821-
for arg: ValueRef in call_args { call_arg_tys += [val_ty(arg)]; }
5822-
let ccx = bcx_ccx(bcx);
5823-
5824-
let llnativefnty =
5825-
if uses_retptr {
5826-
T_fn(call_arg_tys, T_void())
5827-
} else {
5828-
let fn_ret_ty = ty::ty_fn_ret(bcx_tcx(bcx), fn_type);
5829-
// FIXME: Could follow from a constraint on fn_type...
5830-
check (type_has_static_size(ccx, fn_ret_ty));
5831-
let sp = bcx.sp;
5832-
T_fn(call_arg_tys, type_of(ccx, sp, fn_ret_ty))
5833-
};
5834-
5835-
let llnativefn =
5836-
get_extern_fn(ccx.externs, ccx.llmod, name, cc, llnativefnty);
5837-
let r =
5838-
if cc == lib::llvm::LLVMCCallConv {
5839-
Call(bcx, llnativefn, call_args)
5840-
} else { CallWithConv(bcx, llnativefn, call_args, cc) };
5841-
let rptr = bcx.fcx.llretptr;
5842-
ret {val: r, rptr: rptr};
5843-
}
5844-
5845-
let args = ty::ty_fn_args(ccx.tcx, fn_type);
5846-
// Build up the list of arguments.
5847-
5848-
let i = arg_n;
5849-
for arg: ty::arg in args {
5850-
let llarg = llvm::LLVMGetParam(fcx.llfn, i);
5851-
assert (llarg as int != 0);
5852-
if cast_to_i32 {
5853-
let llarg_i32 = convert_arg_to_i32(bcx, llarg, arg.ty, arg.mode);
5854-
call_args += [llarg_i32];
5855-
} else { call_args += [llarg]; }
5856-
i += 1u;
5857-
}
5858-
let r;
5859-
let rptr;
5860-
alt abi {
5861-
ast::native_abi_rust_intrinsic. {
5862-
let external_name = "rust_intrinsic_" + name;
5863-
let result =
5864-
trans_simple_native_abi(bcx, external_name, call_args, fn_type,
5865-
uses_retptr, lib::llvm::LLVMCCallConv);
5866-
r = result.val;
5867-
rptr = result.rptr;
5868-
}
5869-
_ {
5870-
r =
5871-
trans_native_call(new_raw_block_ctxt(bcx.fcx, bcx.llbb),
5872-
ccx.externs, ccx.llmod, name, call_args);
5873-
rptr = BitCast(bcx, fcx.llretptr, T_ptr(ccx.int_type));
5874-
}
5875-
}
5876-
// We don't store the return value if it's nil, to avoid stomping on a nil
5877-
// pointer. This is the only concession made to non-i32 return values. See
5878-
// the FIXME above.
5879-
5880-
if !rty_is_nil && !uses_retptr { Store(bcx, r, rptr); }
5881-
5882-
build_return(bcx);
5883-
finish_fn(fcx, lltop);
58845752
}
58855753

58865754
fn item_path(item: @ast::item) -> [str] { ret [item.ident]; }

trunk/src/rt/intrinsics/intrinsics.cpp

+86-12
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@ extern "C" CDECL void
1616
rust_task_sleep(size_t time_in_us);
1717

1818
extern "C" void
19-
rust_intrinsic_vec_len(rust_task *task, size_t *retptr, type_desc *ty,
20-
rust_vec **vp)
19+
rust_intrinsic_2_vec_len(size_t *retptr,
20+
void *env,
21+
type_desc *ty,
22+
rust_vec **vp)
2123
{
2224
*retptr = (*vp)->fill / ty->size;
2325
}
2426

2527
extern "C" void
26-
rust_intrinsic_ptr_offset(rust_task *task, void **retptr, type_desc *ty,
27-
void *ptr, uintptr_t count)
28+
rust_intrinsic_2_ptr_offset(void **retptr,
29+
void *env,
30+
type_desc *ty,
31+
void *ptr,
32+
uintptr_t count)
2833
{
2934
*retptr = &((uint8_t *)ptr)[ty->size * count];
3035
}
3136

3237
extern "C" void
33-
rust_intrinsic_cast(rust_task *task, void *retptr, type_desc *t1,
34-
type_desc *t2, void *src)
38+
rust_intrinsic_2_cast(void *retptr,
39+
void *env,
40+
type_desc *t1,
41+
type_desc *t2,
42+
void *src)
3543
{
3644
if (t1->size != t2->size) {
3745
upcall_fail("attempt to cast values of differing sizes",
@@ -43,25 +51,91 @@ rust_intrinsic_cast(rust_task *task, void *retptr, type_desc *t1,
4351
}
4452

4553
extern "C" void
46-
rust_intrinsic_addr_of(rust_task *task, void **retptr, type_desc *ty,
54+
rust_intrinsic_2_addr_of(void **retptr,
55+
void *env,
56+
type_desc *ty,
4757
void *valptr) {
4858
*retptr = valptr;
4959
}
5060

5161
extern "C" void
52-
rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
62+
rust_intrinsic_2_recv(void **retptr,
63+
void *env,
64+
type_desc *ty,
5365
rust_port *port) {
5466
port_recv((uintptr_t*)retptr, port);
5567
}
5668

5769
extern "C" void
58-
rust_intrinsic_get_type_desc(rust_task *task, void **retptr,
70+
rust_intrinsic_2_get_type_desc(void **retptr,
71+
void *env,
5972
type_desc* ty) {
6073
*(type_desc**)retptr = ty;
6174
}
6275

6376
extern "C" void
64-
rust_intrinsic_task_sleep(rust_task *_task, void **retptr,
65-
size_t time_in_us) {
66-
rust_task_sleep(time_in_us);
77+
rust_intrinsic_2_task_sleep(void **retptr,
78+
void *env,
79+
size_t time_in_us) {
80+
rust_task_sleep(time_in_us);
81+
}
82+
83+
extern "C" void
84+
rust_intrinsic_vec_len(void *task,
85+
size_t *retptr,
86+
type_desc *ty,
87+
rust_vec **vp)
88+
{
89+
rust_intrinsic_2_vec_len(retptr, NULL, ty, vp);
90+
}
91+
92+
extern "C" void
93+
rust_intrinsic_ptr_offset(void *task,
94+
void **retptr,
95+
type_desc *ty,
96+
void *ptr,
97+
uintptr_t count)
98+
{
99+
rust_intrinsic_2_ptr_offset(retptr, NULL, ty, ptr, count);
100+
}
101+
102+
extern "C" void
103+
rust_intrinsic_cast(void *task,
104+
void *retptr,
105+
type_desc *t1,
106+
type_desc *t2,
107+
void *src)
108+
{
109+
rust_intrinsic_2_cast(retptr, NULL, t1, t2, src);
110+
}
111+
112+
extern "C" void
113+
rust_intrinsic_addr_of(void *task,
114+
void **retptr,
115+
type_desc *ty,
116+
void *valptr) {
117+
rust_intrinsic_2_addr_of(retptr, NULL, ty, valptr);
118+
}
119+
120+
extern "C" void
121+
rust_intrinsic_recv(void *task,
122+
void **retptr,
123+
type_desc *ty,
124+
rust_port *port) {
125+
rust_intrinsic_2_recv(retptr, NULL, ty, port);
67126
}
127+
128+
extern "C" void
129+
rust_intrinsic_get_type_desc(void *task,
130+
void **retptr,
131+
type_desc* ty) {
132+
rust_intrinsic_2_get_type_desc(retptr, NULL, ty);
133+
}
134+
135+
extern "C" void
136+
rust_intrinsic_task_sleep(void *task,
137+
void **retptr,
138+
size_t time_in_us) {
139+
rust_task_sleep(time_in_us);
140+
}
141+

0 commit comments

Comments
 (0)