1
Fork 0

auto merge of #4795 : catamorphism/rust/less-copy, r=catamorphism

This commit is contained in:
bors 2013-02-06 17:06:15 -08:00
commit f13ea4121e
2 changed files with 16 additions and 14 deletions

View file

@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec,
ccx.stats.fn_times.push({ident: name, time: elapsed}); ccx.stats.fn_times.push({ident: name, time: elapsed});
} }
pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv, pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
llty: TypeRef) -> ValueRef { llty: TypeRef) -> ValueRef {
let llfn: ValueRef = str::as_c_str(name, |buf| { let llfn: ValueRef = str::as_c_str(name, |buf| {
unsafe { unsafe {
@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
return llfn; return llfn;
} }
pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef)
-> ValueRef { -> ValueRef {
return decl_fn(llmod, name, lib::llvm::CCallConv, llty); return decl_fn(llmod, name, lib::llvm::CCallConv, llty);
} }
@ -164,20 +164,19 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) ->
return llfn; return llfn;
} }
pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, pub fn get_extern_fn(externs: ExternMap,
llmod: ModuleRef, llmod: ModuleRef,
+name: ~str, name: @str,
cc: lib::llvm::CallConv, cc: lib::llvm::CallConv,
ty: TypeRef) -> ValueRef { ty: TypeRef) -> ValueRef {
if externs.contains_key_ref(&name) { return externs.get(&name); } if externs.contains_key_ref(&name) { return externs.get(&name); }
// XXX: Bad copy. let f = decl_fn(llmod, name, cc, ty);
let f = decl_fn(llmod, copy name, cc, ty);
externs.insert(name, f); externs.insert(name, f);
return f; return f;
} }
pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
+name: ~str, ty: TypeRef) -> ValueRef { name: @str, ty: TypeRef) -> ValueRef {
unsafe { unsafe {
if externs.contains_key_ref(&name) { return externs.get(&name); } if externs.contains_key_ref(&name) { return externs.get(&name); }
let c = str::as_c_str(name, |buf| { let c = str::as_c_str(name, |buf| {
@ -189,9 +188,9 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
} }
fn get_simple_extern_fn(cx: block, fn get_simple_extern_fn(cx: block,
externs: HashMap<~str, ValueRef>, externs: ExternMap,
llmod: ModuleRef, llmod: ModuleRef,
+name: ~str, name: @str,
n_args: int) -> ValueRef { n_args: int) -> ValueRef {
let _icx = cx.insn_ctxt("get_simple_extern_fn"); let _icx = cx.insn_ctxt("get_simple_extern_fn");
let ccx = cx.fcx.ccx; let ccx = cx.fcx.ccx;
@ -201,8 +200,8 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t); return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
} }
pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>, pub fn trans_foreign_call(cx: block, externs: ExternMap,
llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) -> llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
ValueRef { ValueRef {
let _icx = cx.insn_ctxt("trans_foreign_call"); let _icx = cx.insn_ctxt("trans_foreign_call");
let n = args.len() as int; let n = args.len() as int;
@ -474,6 +473,7 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
let class_ty = ty::subst_tps(tcx, substs, None, let class_ty = ty::subst_tps(tcx, substs, None,
ty::lookup_item_type(tcx, parent_id).ty); ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty); let llty = type_of_dtor(ccx, class_ty);
let name = name.to_managed(); // :-(
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv, get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
llty) llty)
} }
@ -775,7 +775,7 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {
pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t) pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
-> ValueRef { -> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did); let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
match ty::get(t).sty { match ty::get(t).sty {
ty::ty_fn(_) => { ty::ty_fn(_) => {
let llty = type_of_fn_from_ty(ccx, t); let llty = type_of_fn_from_ty(ccx, t);

View file

@ -152,13 +152,15 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
} }
} }
type ExternMap = HashMap<@str, ValueRef>;
// Crate context. Every crate we compile has one of these. // Crate context. Every crate we compile has one of these.
pub struct crate_ctxt { pub struct crate_ctxt {
sess: session::Session, sess: session::Session,
llmod: ModuleRef, llmod: ModuleRef,
td: target_data, td: target_data,
tn: type_names, tn: type_names,
externs: HashMap<~str, ValueRef>, externs: ExternMap,
intrinsics: HashMap<~str, ValueRef>, intrinsics: HashMap<~str, ValueRef>,
item_vals: HashMap<ast::node_id, ValueRef>, item_vals: HashMap<ast::node_id, ValueRef>,
exp_map2: resolve::ExportMap2, exp_map2: resolve::ExportMap2,