Move rust_vec_append_glue to rt.
This commit is contained in:
parent
b6971d94df
commit
cc96eeafca
4 changed files with 140 additions and 143 deletions
|
|
@ -7997,147 +7997,6 @@ fn vec_p1_adjusted(&@block_ctxt bcx, ValueRef v,
|
|||
ret bcx.build.GEP(vec_p0(bcx, v), [len]);
|
||||
}
|
||||
|
||||
fn trans_vec_append_glue(@local_ctxt cx, &ast::span sp) {
|
||||
|
||||
auto llfn = cx.ccx.glues.vec_append_glue;
|
||||
|
||||
let ValueRef lltaskptr = llvm::LLVMGetParam(llfn, 0u);
|
||||
let ValueRef llvec_tydesc = llvm::LLVMGetParam(llfn, 1u);
|
||||
let ValueRef llelt_tydesc = llvm::LLVMGetParam(llfn, 2u);
|
||||
let ValueRef lldst_vec_ptr = llvm::LLVMGetParam(llfn, 3u);
|
||||
let ValueRef llsrc_vec = llvm::LLVMGetParam(llfn, 4u);
|
||||
let ValueRef llskipnull = llvm::LLVMGetParam(llfn, 5u);
|
||||
auto derived_tydescs =
|
||||
map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty);
|
||||
|
||||
auto llbbs = mk_standard_basic_blocks(llfn);
|
||||
|
||||
auto fcx = @rec(llfn=llfn,
|
||||
lltaskptr=lltaskptr,
|
||||
llenv=C_null(T_ptr(T_nil())),
|
||||
llretptr=C_null(T_ptr(T_nil())),
|
||||
mutable llallocas = llbbs._0,
|
||||
mutable llcopyargs = llbbs._1,
|
||||
mutable llderivedtydescs = llbbs._2,
|
||||
mutable llself=none[self_vt],
|
||||
mutable lliterbody=none[ValueRef],
|
||||
llargs=new_def_hash[ValueRef](),
|
||||
llobjfields=new_def_hash[ValueRef](),
|
||||
lllocals=new_def_hash[ValueRef](),
|
||||
llupvars=new_def_hash[ValueRef](),
|
||||
mutable lltydescs=vec::empty[ValueRef](),
|
||||
derived_tydescs=derived_tydescs,
|
||||
sp=sp,
|
||||
lcx=cx);
|
||||
|
||||
auto bcx = new_top_block_ctxt(fcx);
|
||||
auto lltop = bcx.llbb;
|
||||
|
||||
auto lldst_vec = bcx.build.Load(lldst_vec_ptr);
|
||||
|
||||
// First the dst vec needs to grow to accommodate the src vec.
|
||||
// To do this we have to figure out how many bytes to add.
|
||||
|
||||
auto llcopy_dst_ptr = alloca(bcx, T_int());
|
||||
auto llnew_vec = bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.vec_grow,
|
||||
[bcx.fcx.lltaskptr, lldst_vec,
|
||||
vec_fill_adjusted(bcx, llsrc_vec, llskipnull),
|
||||
llcopy_dst_ptr, llvec_tydesc]);
|
||||
maybe_name_value(bcx.fcx.lcx.ccx, llnew_vec, "llnew_vec");
|
||||
|
||||
auto copy_dst_cx = new_sub_block_ctxt(bcx, "copy new <- dst");
|
||||
auto copy_src_cx = new_sub_block_ctxt(bcx, "copy new <- src");
|
||||
|
||||
auto pp0 = alloca(bcx, T_ptr(T_i8()));
|
||||
bcx.build.Store(vec_p1_adjusted(bcx, llnew_vec, llskipnull), pp0);
|
||||
maybe_name_value(bcx.fcx.lcx.ccx, pp0, "pp0");
|
||||
|
||||
bcx.build.CondBr(bcx.build.TruncOrBitCast
|
||||
(bcx.build.Load(llcopy_dst_ptr),
|
||||
T_i1()),
|
||||
copy_dst_cx.llbb,
|
||||
copy_src_cx.llbb);
|
||||
|
||||
|
||||
fn copy_elts(&@block_ctxt cx,
|
||||
ValueRef elt_tydesc,
|
||||
ValueRef dst,
|
||||
ValueRef src,
|
||||
ValueRef n_bytes) -> result {
|
||||
|
||||
auto src_lim = cx.build.GEP(src, [n_bytes]);
|
||||
maybe_name_value(cx.fcx.lcx.ccx, src_lim, "src_lim");
|
||||
|
||||
auto elt_llsz =
|
||||
cx.build.Load(cx.build.GEP(elt_tydesc,
|
||||
[C_int(0),
|
||||
C_int(abi::tydesc_field_size)]));
|
||||
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llsz");
|
||||
|
||||
auto elt_llalign =
|
||||
cx.build.Load(cx.build.GEP(elt_tydesc,
|
||||
[C_int(0),
|
||||
C_int(abi::tydesc_field_align)]));
|
||||
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llalign");
|
||||
|
||||
|
||||
fn take_one(ValueRef elt_tydesc,
|
||||
&@block_ctxt cx,
|
||||
ValueRef dst, ValueRef src) -> result {
|
||||
auto ti = none[@tydesc_info];
|
||||
call_tydesc_glue_full(cx, src,
|
||||
elt_tydesc,
|
||||
abi::tydesc_field_take_glue, ti);
|
||||
ret res(cx, src);
|
||||
}
|
||||
|
||||
auto bcx = iter_sequence_raw(cx, dst, src, src_lim,
|
||||
elt_llsz, bind take_one(elt_tydesc,
|
||||
_, _, _)).bcx;
|
||||
|
||||
ret call_memmove(bcx, dst, src, n_bytes, elt_llalign);
|
||||
}
|
||||
|
||||
// Copy any dst elements in, omitting null if doing str.
|
||||
|
||||
auto n_bytes = vec_fill_adjusted(copy_dst_cx, lldst_vec, llskipnull);
|
||||
maybe_name_value(copy_dst_cx.fcx.lcx.ccx, n_bytes, "n_bytes");
|
||||
|
||||
copy_dst_cx = copy_elts(copy_dst_cx,
|
||||
llelt_tydesc,
|
||||
vec_p0(copy_dst_cx, llnew_vec),
|
||||
vec_p0(copy_dst_cx, lldst_vec),
|
||||
n_bytes).bcx;
|
||||
|
||||
put_vec_fill(copy_dst_cx, llnew_vec, vec_fill(copy_dst_cx, lldst_vec));
|
||||
|
||||
copy_dst_cx.build.Store(vec_p1_adjusted(copy_dst_cx, llnew_vec,
|
||||
llskipnull), pp0);
|
||||
copy_dst_cx.build.Br(copy_src_cx.llbb);
|
||||
|
||||
|
||||
// Copy any src elements in, carrying along null if doing str.
|
||||
n_bytes = vec_fill(copy_src_cx, llsrc_vec);
|
||||
copy_src_cx = copy_elts(copy_src_cx,
|
||||
llelt_tydesc,
|
||||
copy_src_cx.build.Load(pp0),
|
||||
vec_p0(copy_src_cx, llsrc_vec),
|
||||
n_bytes).bcx;
|
||||
|
||||
put_vec_fill(copy_src_cx, llnew_vec,
|
||||
copy_src_cx.build.Add(vec_fill_adjusted(copy_src_cx,
|
||||
llnew_vec,
|
||||
llskipnull),
|
||||
n_bytes));
|
||||
|
||||
// Write new_vec back through the alias we were given.
|
||||
copy_src_cx.build.Store(llnew_vec, lldst_vec_ptr);
|
||||
copy_src_cx.build.RetVoid();
|
||||
|
||||
finish_fn(fcx, lltop);
|
||||
}
|
||||
|
||||
|
||||
fn make_glues(ModuleRef llmod, &type_names tn) -> @glue_fns {
|
||||
ret @rec(yield_glue = decl_glue(llmod, tn, abi::yield_glue_name()),
|
||||
no_op_type_glue = decl_no_op_type_glue(llmod, tn),
|
||||
|
|
@ -8279,7 +8138,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate,
|
|||
collect_tag_ctors(ccx, crate);
|
||||
trans_constants(ccx, crate);
|
||||
trans_mod(cx, crate.node.module);
|
||||
trans_vec_append_glue(cx, crate.span);
|
||||
auto crate_map = create_crate_map(ccx);
|
||||
if (!sess.get_opts().shared) {
|
||||
trans_main_fn(cx, crate_map);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue