Revert removal of intrinsics
Oops. We can't do this yet until the next snapshot.
This commit is contained in:
@@ -30,6 +30,69 @@ fn llvm_err(sess: session, msg: str) -> ! unsafe {
|
||||
} else { sess.fatal(msg + ": " + str::unsafe::from_c_str(cstr)); }
|
||||
}
|
||||
|
||||
fn load_intrinsics_bc(sess: session) -> option<ModuleRef> {
|
||||
let path = alt filesearch::search(
|
||||
sess.filesearch,
|
||||
bind filesearch::pick_file("intrinsics.bc", _)) {
|
||||
option::some(path) { path }
|
||||
option::none {
|
||||
sess.warn("couldn't find intrinsics.bc");
|
||||
ret option::none;
|
||||
}
|
||||
};
|
||||
let membuf = str::as_c_str(path, {|buf|
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
if membuf as uint == 0u {
|
||||
llvm_err(sess, "installation problem: couldn't open " + path);
|
||||
}
|
||||
let llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
|
||||
llvm::LLVMDisposeMemoryBuffer(membuf);
|
||||
if llintrinsicsmod as uint == 0u {
|
||||
sess.warn("couldn't parse intrinsics.bc");
|
||||
ret option::none;
|
||||
}
|
||||
|
||||
ret option::some(llintrinsicsmod);
|
||||
}
|
||||
|
||||
fn load_intrinsics_ll(sess: session) -> ModuleRef {
|
||||
let path = alt filesearch::search(
|
||||
sess.filesearch,
|
||||
bind filesearch::pick_file("intrinsics.ll", _)) {
|
||||
option::some(path) { path }
|
||||
option::none { sess.fatal("couldn't find intrinsics.ll") }
|
||||
};
|
||||
let llintrinsicsmod = str::as_c_str(path, { |buf|
|
||||
llvm::LLVMRustParseAssemblyFile(buf)
|
||||
});
|
||||
if llintrinsicsmod as uint == 0u {
|
||||
llvm_err(sess, "couldn't parse intrinsics.ll");
|
||||
}
|
||||
ret llintrinsicsmod;
|
||||
}
|
||||
|
||||
fn link_intrinsics(sess: session, llmod: ModuleRef) {
|
||||
let llintrinsicsmod = {
|
||||
alt load_intrinsics_bc(sess) {
|
||||
option::some(m) { m }
|
||||
option::none {
|
||||
// When the bitcode format changes we can't parse a .bc
|
||||
// file produced with a newer LLVM (as happens when stage0
|
||||
// is trying to build against a new LLVM revision), in
|
||||
// that case we'll try to parse the assembly.
|
||||
sess.warn("couldn't parse intrinsics.bc, trying intrinsics.ll");
|
||||
load_intrinsics_ll(sess)
|
||||
}
|
||||
}
|
||||
};
|
||||
let linkres = llvm::LLVMLinkModules(llmod, llintrinsicsmod);
|
||||
llvm::LLVMDisposeModule(llintrinsicsmod);
|
||||
if linkres == False {
|
||||
llvm_err(sess, "couldn't link the module with the intrinsics");
|
||||
}
|
||||
}
|
||||
|
||||
mod write {
|
||||
fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
|
||||
if ot == output_type_assembly || ot == output_type_object ||
|
||||
@@ -52,6 +115,7 @@ mod write {
|
||||
fn run_passes(sess: session, llmod: ModuleRef, output: str) {
|
||||
let opts = sess.opts;
|
||||
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
|
||||
link_intrinsics(sess, llmod);
|
||||
let mut pm = mk_pass_manager();
|
||||
let td = mk_target_data(
|
||||
sess.targ_cfg.target_strs.data_layout);
|
||||
|
||||
@@ -17,6 +17,7 @@ type upcalls =
|
||||
shared_realloc: ValueRef,
|
||||
mark: ValueRef,
|
||||
vec_grow: ValueRef,
|
||||
vec_push: ValueRef,
|
||||
str_concat: ValueRef,
|
||||
cmp_type: ValueRef,
|
||||
log_type: ValueRef,
|
||||
@@ -40,6 +41,7 @@ fn declare_upcalls(targ_cfg: @session::config,
|
||||
}
|
||||
let d = bind decl(llmod, "upcall_", _, _, _);
|
||||
let dv = bind decl(llmod, "upcall_", _, _, T_void());
|
||||
let dvi = bind decl(llmod, "upcall_intrinsic_", _, _, T_void());
|
||||
|
||||
let int_t = T_int(targ_cfg);
|
||||
let size_t = T_size_t(targ_cfg);
|
||||
@@ -64,6 +66,10 @@ fn declare_upcalls(targ_cfg: @session::config,
|
||||
d("mark", [T_ptr(T_i8())], int_t),
|
||||
vec_grow:
|
||||
dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)), int_t]),
|
||||
vec_push:
|
||||
dvi("vec_push",
|
||||
[T_ptr(T_ptr(opaque_vec_t)), T_ptr(tydesc_type),
|
||||
T_ptr(T_i8())]),
|
||||
str_concat:
|
||||
d("str_concat", [T_ptr(opaque_vec_t), T_ptr(opaque_vec_t)],
|
||||
T_ptr(opaque_vec_t)),
|
||||
|
||||
@@ -237,9 +237,12 @@ fn native_abi(attrs: [ast::attribute]) -> either<str, ast::native_abi> {
|
||||
option::none {
|
||||
either::right(ast::native_abi_cdecl)
|
||||
}
|
||||
option::some("rust-builtin") | option::some("rust-intrinsic") {
|
||||
option::some("rust-intrinsic") {
|
||||
either::right(ast::native_abi_rust_intrinsic)
|
||||
}
|
||||
option::some("rust-builtin") {
|
||||
either::right(ast::native_abi_rust_builtin)
|
||||
}
|
||||
option::some("cdecl") {
|
||||
either::right(ast::native_abi_cdecl)
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ const tag_mod_impl: uint = 0x30u;
|
||||
|
||||
const tag_item_method: uint = 0x31u;
|
||||
const tag_impl_iface: uint = 0x32u;
|
||||
const tag_item_is_intrinsic: uint = 0x33u;
|
||||
|
||||
// discriminator value for variants
|
||||
const tag_disr_val: uint = 0x34u;
|
||||
|
||||
@@ -26,6 +26,7 @@ export get_type;
|
||||
export get_impl_iface;
|
||||
export get_impl_method;
|
||||
export get_item_path;
|
||||
export item_is_intrinsic;
|
||||
export maybe_get_item_ast, found_ast, found, found_parent, not_found;
|
||||
|
||||
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
|
||||
@@ -189,6 +190,11 @@ fn get_class_method(cstore: cstore::cstore, def: ast::def_id, mname: str)
|
||||
decoder::get_class_method(cdata, def.node, mname)
|
||||
}
|
||||
|
||||
fn item_is_intrinsic(cstore: cstore::cstore, def: ast::def_id) -> bool {
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||
decoder::item_is_intrinsic(cdata, def.node)
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
||||
@@ -41,6 +41,7 @@ export get_item_path;
|
||||
export maybe_find_item; // sketchy
|
||||
export item_type; // sketchy
|
||||
export maybe_get_item_ast;
|
||||
export item_is_intrinsic;
|
||||
|
||||
// Used internally by astencode:
|
||||
export translate_def_id;
|
||||
@@ -308,6 +309,13 @@ fn get_class_method(cdata: cmd, id: ast::node_id, name: str) -> ast::def_id {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_is_intrinsic(cdata: cmd, id: ast::node_id) -> bool {
|
||||
let mut intrinsic = false;
|
||||
ebml::tagged_docs(lookup_item(id, cdata.data), tag_item_is_intrinsic,
|
||||
{|_i| intrinsic = true;});
|
||||
intrinsic
|
||||
}
|
||||
|
||||
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
|
||||
ret item_symbol(lookup_item(id, data));
|
||||
}
|
||||
|
||||
@@ -676,8 +676,12 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_family(ebml_w, purity_fn_family(fn_decl.purity));
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(ecx.ccx.tcx, nitem.id));
|
||||
if abi == native_abi_rust_intrinsic {
|
||||
ebml_w.start_tag(tag_item_is_intrinsic);
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
encode_type(ecx, ebml_w, node_id_to_type(ecx.ccx.tcx, nitem.id));
|
||||
if abi == native_abi_rust_builtin {
|
||||
astencode::encode_inlined_item(ecx, ebml_w, path,
|
||||
ii_native(nitem));
|
||||
} else {
|
||||
|
||||
@@ -92,7 +92,7 @@ fn map_decoded_item(sess: session, map: map, path: path, ii: inlined_item) {
|
||||
alt ii {
|
||||
ii_item(i) { /* fallthrough */ }
|
||||
ii_native(i) {
|
||||
cx.map.insert(i.id, node_native_item(i, native_abi_rust_intrinsic,
|
||||
cx.map.insert(i.id, node_native_item(i, native_abi_rust_builtin,
|
||||
@path));
|
||||
}
|
||||
ii_method(impl_did, m) {
|
||||
|
||||
@@ -124,7 +124,7 @@ fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) {
|
||||
fn check_item(tcx: ty::ctxt, it: @ast::item) {
|
||||
alt it.node {
|
||||
ast::item_native_mod(nmod) if attr::native_abi(it.attrs) !=
|
||||
either::right(ast::native_abi_rust_intrinsic) {
|
||||
either::right(ast::native_abi_rust_builtin) {
|
||||
for ni in nmod.items {
|
||||
alt ni.node {
|
||||
ast::native_item_fn(decl, tps) {
|
||||
|
||||
@@ -1801,7 +1801,9 @@ enum callee_env {
|
||||
type lval_maybe_callee = {bcx: block,
|
||||
val: ValueRef,
|
||||
kind: lval_kind,
|
||||
env: callee_env};
|
||||
env: callee_env,
|
||||
// Tydescs to pass. Only used to call intrinsics
|
||||
tds: option<[ValueRef]>};
|
||||
|
||||
fn null_env_ptr(bcx: block) -> ValueRef {
|
||||
C_null(T_opaque_box_ptr(bcx.ccx()))
|
||||
@@ -1820,7 +1822,7 @@ fn lval_temp(bcx: block, val: ValueRef) -> lval_result {
|
||||
|
||||
fn lval_no_env(bcx: block, val: ValueRef, kind: lval_kind)
|
||||
-> lval_maybe_callee {
|
||||
ret {bcx: bcx, val: val, kind: kind, env: is_closure};
|
||||
ret {bcx: bcx, val: val, kind: kind, env: is_closure, tds: none};
|
||||
}
|
||||
|
||||
fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
|
||||
@@ -1907,7 +1909,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: [ty::t],
|
||||
fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
|
||||
vtables: option<typeck::vtable_res>,
|
||||
ref_id: option<ast::node_id>)
|
||||
-> {val: ValueRef, must_cast: bool} {
|
||||
-> {val: ValueRef, must_cast: bool, intrinsic: bool} {
|
||||
let _icx = ccx.insn_ctxt("monomorphic_fn");
|
||||
let mut must_cast = false;
|
||||
let substs = vec::map(real_substs, {|t|
|
||||
@@ -1925,7 +1927,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
|
||||
}
|
||||
alt ccx.monomorphized.find(hash_id) {
|
||||
some(val) {
|
||||
ret {val: val, must_cast: must_cast};
|
||||
ret {val: val, must_cast: must_cast, intrinsic: false};
|
||||
}
|
||||
none {}
|
||||
}
|
||||
@@ -1947,12 +1949,13 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
|
||||
}
|
||||
ast_map::node_variant(v, _, pt) { (pt, v.node.name) }
|
||||
ast_map::node_method(m, _, pt) { (pt, m.ident) }
|
||||
ast_map::node_native_item(i, ast::native_abi_rust_intrinsic, pt)
|
||||
ast_map::node_native_item(i, ast::native_abi_rust_builtin, pt)
|
||||
{ (pt, i.ident) }
|
||||
ast_map::node_native_item(_, abi, _) {
|
||||
// Natives don't have to be monomorphized.
|
||||
ret {val: get_item_val(ccx, fn_id.node),
|
||||
must_cast: true};
|
||||
must_cast: true,
|
||||
intrinsic: abi == ast::native_abi_rust_intrinsic};
|
||||
}
|
||||
ast_map::node_ctor(i, _) {
|
||||
alt check ccx.tcx.items.get(i.id) {
|
||||
@@ -1981,8 +1984,8 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
|
||||
trans_fn(ccx, pt, d, body, lldecl, no_self, psubsts, d_id, none);
|
||||
}
|
||||
ast_map::node_native_item(i, _, _) {
|
||||
native::trans_intrinsic(ccx, lldecl, i, pt, option::get(psubsts),
|
||||
ref_id);
|
||||
native::trans_builtin(ccx, lldecl, i, pt, option::get(psubsts),
|
||||
ref_id);
|
||||
}
|
||||
ast_map::node_variant(v, enum_item, _) {
|
||||
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
|
||||
@@ -2011,7 +2014,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
|
||||
}
|
||||
}
|
||||
}
|
||||
{val: lldecl, must_cast: must_cast}
|
||||
{val: lldecl, must_cast: must_cast, intrinsic: false}
|
||||
}
|
||||
|
||||
fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
|
||||
@@ -2075,6 +2078,33 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
|
||||
}
|
||||
}
|
||||
|
||||
fn lval_intrinsic_fn(bcx: block, val: ValueRef, tys: [ty::t],
|
||||
id: ast::node_id) -> lval_maybe_callee {
|
||||
let _icx = bcx.insn_ctxt("lval_intrinsic_fn");
|
||||
fn add_tydesc_params(ccx: @crate_ctxt, llfty: TypeRef, n: uint)
|
||||
-> TypeRef {
|
||||
let out_ty = llvm::LLVMGetReturnType(llfty);
|
||||
let n_args = llvm::LLVMCountParamTypes(llfty);
|
||||
let args = vec::from_elem(n_args as uint, 0 as TypeRef);
|
||||
unsafe { llvm::LLVMGetParamTypes(llfty, vec::unsafe::to_ptr(args)); }
|
||||
T_fn(vec::slice(args, 0u, first_real_arg) +
|
||||
vec::from_elem(n, T_ptr(ccx.tydesc_type)) +
|
||||
vec::tailn(args, first_real_arg), out_ty)
|
||||
}
|
||||
|
||||
let mut bcx = bcx;
|
||||
let ccx = bcx.ccx();
|
||||
let tds = vec::map(tys, {|t|
|
||||
let mut ti = none, td = get_tydesc(bcx.ccx(), t, ti);
|
||||
lazily_emit_all_tydesc_glue(ccx, ti);
|
||||
td
|
||||
});
|
||||
let llfty = type_of_fn_from_ty(ccx, node_id_type(bcx, id));
|
||||
let val = PointerCast(bcx, val, T_ptr(add_tydesc_params(
|
||||
ccx, llfty, tys.len())));
|
||||
{bcx: bcx, val: val, kind: owned, env: null_env, tds: some(tds)}
|
||||
}
|
||||
|
||||
fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id)
|
||||
-> lval_maybe_callee {
|
||||
let _icx = bcx.insn_ctxt("lval_static_fn");
|
||||
@@ -2098,13 +2128,14 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id,
|
||||
} else { fn_id };
|
||||
|
||||
if fn_id.crate == ast::local_crate && tys.len() > 0u {
|
||||
let mut {val, must_cast} =
|
||||
let mut {val, must_cast, intrinsic} =
|
||||
monomorphic_fn(ccx, fn_id, tys, vtables, some(id));
|
||||
if intrinsic { ret lval_intrinsic_fn(bcx, val, tys, id); }
|
||||
if must_cast {
|
||||
val = PointerCast(bcx, val, T_ptr(type_of_fn_from_ty(
|
||||
ccx, node_id_type(bcx, id))));
|
||||
}
|
||||
ret {bcx: bcx, val: val, kind: owned, env: null_env};
|
||||
ret {bcx: bcx, val: val, kind: owned, env: null_env, tds: none};
|
||||
}
|
||||
|
||||
let mut val = if fn_id.crate == ast::local_crate {
|
||||
@@ -2115,6 +2146,11 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id,
|
||||
trans_external_path(ccx, fn_id, tpt.ty)
|
||||
};
|
||||
if tys.len() > 0u {
|
||||
// This is supposed to be an external native function.
|
||||
// Unfortunately, I found no easy/cheap way to assert that.
|
||||
if csearch::item_is_intrinsic(ccx.sess.cstore, fn_id) {
|
||||
ret lval_intrinsic_fn(bcx, val, tys, id);
|
||||
}
|
||||
val = PointerCast(bcx, val, T_ptr(type_of_fn_from_ty(
|
||||
ccx, node_id_type(bcx, id))));
|
||||
}
|
||||
@@ -2131,7 +2167,7 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id,
|
||||
}
|
||||
}
|
||||
|
||||
ret {bcx: bcx, val: val, kind: owned, env: null_env};
|
||||
ret {bcx: bcx, val: val, kind: owned, env: null_env, tds: none};
|
||||
}
|
||||
|
||||
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
|
||||
@@ -2589,7 +2625,7 @@ enum call_args {
|
||||
// - new_fn_ctxt
|
||||
// - trans_args
|
||||
fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t,
|
||||
dest: dest)
|
||||
dest: dest, always_valid_retptr: bool)
|
||||
-> {bcx: block, args: [ValueRef], retslot: ValueRef} {
|
||||
let _icx = cx.insn_ctxt("trans_args");
|
||||
let mut temp_cleanups = [];
|
||||
@@ -2603,7 +2639,7 @@ fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t,
|
||||
// Arg 0: Output pointer.
|
||||
let llretslot = alt dest {
|
||||
ignore {
|
||||
if ty::type_is_nil(retty) {
|
||||
if ty::type_is_nil(retty) && !always_valid_retptr {
|
||||
llvm::LLVMGetUndef(T_ptr(T_nil()))
|
||||
} else {
|
||||
let {bcx: cx, val} = alloc_ty(bcx, retty);
|
||||
@@ -2697,10 +2733,15 @@ fn trans_call_inner(in_cx: block, fn_expr_ty: ty::t, ret_ty: ty::t,
|
||||
};
|
||||
|
||||
let args_res = {
|
||||
trans_args(bcx, llenv, args, fn_expr_ty, dest)
|
||||
trans_args(bcx, llenv, args, fn_expr_ty, dest,
|
||||
option::is_some(f_res.tds))
|
||||
};
|
||||
bcx = args_res.bcx;
|
||||
let mut llargs = args_res.args;
|
||||
option::may(f_res.tds) {|vals|
|
||||
llargs = vec::slice(llargs, 0u, first_real_arg) + vals +
|
||||
vec::tailn(llargs, first_real_arg);
|
||||
}
|
||||
|
||||
let llretslot = args_res.retslot;
|
||||
|
||||
|
||||
@@ -416,6 +416,7 @@ fn trans_bind_1(cx: block, outgoing_fty: ty::t,
|
||||
args: [option<@ast::expr>], pair_ty: ty::t,
|
||||
dest: dest) -> block {
|
||||
let _icx = cx.insn_ctxt("closure::trans_bind1");
|
||||
assert option::is_none(f_res.tds);
|
||||
let ccx = cx.ccx();
|
||||
let mut bound: [@ast::expr] = [];
|
||||
for argopt: option<@ast::expr> in args {
|
||||
|
||||
@@ -79,7 +79,7 @@ fn trans_vtable_callee(bcx: block, env: callee_env, vtable: ValueRef,
|
||||
let vtable = PointerCast(bcx, vtable,
|
||||
T_ptr(T_array(T_ptr(llfty), n_method + 1u)));
|
||||
let mptr = Load(bcx, GEPi(bcx, vtable, [0, n_method as int]));
|
||||
{bcx: bcx, val: mptr, kind: owned, env: env}
|
||||
{bcx: bcx, val: mptr, kind: owned, env: env, tds: none}
|
||||
}
|
||||
|
||||
fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
|
||||
|
||||
@@ -16,7 +16,7 @@ import std::map::hashmap;
|
||||
import util::ppaux::ty_to_str;
|
||||
|
||||
export link_name, trans_native_mod, register_crust_fn, trans_crust_fn,
|
||||
decl_native_fn, trans_intrinsic;
|
||||
decl_native_fn, trans_builtin;
|
||||
|
||||
enum x86_64_reg_class {
|
||||
no_class,
|
||||
@@ -730,7 +730,11 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
||||
}
|
||||
|
||||
let mut cc = alt abi {
|
||||
ast::native_abi_rust_intrinsic { ret; }
|
||||
ast::native_abi_rust_intrinsic {
|
||||
for item in native_mod.items { get_item_val(ccx, item.id); }
|
||||
ret;
|
||||
}
|
||||
ast::native_abi_rust_builtin { ret; }
|
||||
ast::native_abi_cdecl { lib::llvm::CCallConv }
|
||||
ast::native_abi_stdcall { lib::llvm::X86StdcallCallConv }
|
||||
};
|
||||
@@ -752,9 +756,9 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
|
||||
path: ast_map::path, substs: param_substs,
|
||||
ref_id: option<ast::node_id>) {
|
||||
fn trans_builtin(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
|
||||
path: ast_map::path, substs: param_substs,
|
||||
ref_id: option<ast::node_id>) {
|
||||
let fcx = new_fn_ctxt_w_id(ccx, path, decl, item.id, none,
|
||||
some(substs), some(item.span));
|
||||
let bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
|
||||
@@ -1005,5 +1009,28 @@ fn abi_of_native_fn(ccx: @crate_ctxt, i: @ast::native_item)
|
||||
|
||||
fn decl_native_fn(ccx: @crate_ctxt, i: @ast::native_item,
|
||||
pth: ast_map::path) -> ValueRef {
|
||||
register_fn(ccx, i.span, pth, i.id)
|
||||
let _icx = ccx.insn_ctxt("native::decl_native_fn");
|
||||
alt i.node {
|
||||
ast::native_item_fn(_, _) {
|
||||
let node_type = ty::node_id_to_type(ccx.tcx, i.id);
|
||||
alt abi_of_native_fn(ccx, i) {
|
||||
ast::native_abi_rust_intrinsic {
|
||||
// For intrinsics: link the function directly to the intrinsic
|
||||
// function itself.
|
||||
let fn_type = type_of_fn_from_ty(ccx, node_type);
|
||||
let ri_name = "rust_intrinsic_" + native::link_name(i);
|
||||
ccx.item_symbols.insert(i.id, ri_name);
|
||||
get_extern_fn(ccx.externs, ccx.llmod, ri_name,
|
||||
lib::llvm::CCallConv, fn_type)
|
||||
}
|
||||
ast::native_abi_cdecl | ast::native_abi_stdcall |
|
||||
ast::native_abi_rust_builtin {
|
||||
// For true external functions: create a rust wrapper
|
||||
// and link to that. The rust wrapper will handle
|
||||
// switching to the C stack.
|
||||
register_fn(ccx, i.span, pth, i.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,11 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
|
||||
_ {}
|
||||
}
|
||||
|
||||
// FIXME handle external native functions in a more efficient way
|
||||
if fn_id_loc.crate != local_crate {
|
||||
if csearch::item_is_intrinsic(ccx.sess.cstore, fn_id) {
|
||||
uint::range(0u, n_tps) {|n| cx.uses[n] |= use_tydesc;}
|
||||
}
|
||||
let uses = vec::from_mut(cx.uses);
|
||||
ccx.type_use_cache.insert(fn_id, uses);
|
||||
ret uses;
|
||||
@@ -69,6 +73,8 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
|
||||
}
|
||||
ast_map::node_native_item(i@@{node: native_item_fn(_, _), _}, abi, _) {
|
||||
if abi == native_abi_rust_intrinsic {
|
||||
uint::range(0u, n_tps) {|n| cx.uses[n] |= use_tydesc;}
|
||||
} else if abi == native_abi_rust_builtin {
|
||||
let flags = alt check i.ident {
|
||||
"size_of" | "align_of" | "init" |
|
||||
"reinterpret_cast" { use_repr }
|
||||
|
||||
@@ -948,8 +948,8 @@ mod collect {
|
||||
ast::item_mod(_) {}
|
||||
ast::item_native_mod(m) {
|
||||
if front::attr::native_abi(it.attrs) ==
|
||||
either::right(ast::native_abi_rust_intrinsic) {
|
||||
for item in m.items { check_intrinsic_type(tcx, item); }
|
||||
either::right(ast::native_abi_rust_builtin) {
|
||||
for item in m.items { check_builtin_type(tcx, item); }
|
||||
}
|
||||
}
|
||||
ast::item_enum(variants, ty_params) {
|
||||
@@ -1414,7 +1414,7 @@ mod writeback {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_intrinsic_type(tcx: ty::ctxt, it: @ast::native_item) {
|
||||
fn check_builtin_type(tcx: ty::ctxt, it: @ast::native_item) {
|
||||
fn param(tcx: ty::ctxt, n: uint) -> ty::t {
|
||||
ty::mk_param(tcx, n, local_def(0))
|
||||
}
|
||||
@@ -1432,7 +1432,7 @@ fn check_intrinsic_type(tcx: ty::ctxt, it: @ast::native_item) {
|
||||
"addr_of" { (1u, [arg(ast::by_ref, param(tcx, 0u))],
|
||||
ty::mk_imm_ptr(tcx, param(tcx, 0u))) }
|
||||
other {
|
||||
tcx.sess.span_err(it.span, "unrecognized intrinsic function: `" +
|
||||
tcx.sess.span_err(it.span, "unrecognized builtin function: `" +
|
||||
other + "`");
|
||||
ret;
|
||||
}
|
||||
@@ -1444,11 +1444,11 @@ fn check_intrinsic_type(tcx: ty::ctxt, it: @ast::native_item) {
|
||||
let i_ty = ty_of_native_item(tcx, m_collect, it);
|
||||
let i_n_tps = (*i_ty.bounds).len();
|
||||
if i_n_tps != n_tps {
|
||||
tcx.sess.span_err(it.span, #fmt("intrinsic has wrong number \
|
||||
tcx.sess.span_err(it.span, #fmt("builtin function has wrong number \
|
||||
of type parameters. found %u, \
|
||||
expected %u", i_n_tps, n_tps));
|
||||
} else if !ty::same_type(tcx, i_ty.ty, fty) {
|
||||
tcx.sess.span_err(it.span, #fmt("intrinsic has wrong type. \
|
||||
tcx.sess.span_err(it.span, #fmt("builtin function has wrong type. \
|
||||
expected %s", ty_to_str(tcx, fty)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,6 +557,7 @@ type _mod = {view_items: [@view_item], items: [@item]};
|
||||
#[auto_serialize]
|
||||
enum native_abi {
|
||||
native_abi_rust_intrinsic,
|
||||
native_abi_rust_builtin,
|
||||
native_abi_cdecl,
|
||||
native_abi_stdcall,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user