Skip to content

Commit bfc2b65

Browse files
committed
---
yaml --- r: 4888 b: refs/heads/master c: 179658e h: refs/heads/master v: v3
1 parent ff67097 commit bfc2b65

File tree

2 files changed

+94
-96
lines changed

2 files changed

+94
-96
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3a5bfae9d99186391f4269c37a34cf284d84bf68
2+
refs/heads/master: 179658e20fa299b4f7405ea72affd1c8d175d95b

trunk/src/comp/middle/trans.rs

Lines changed: 93 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,98 @@ fn trans_evec_append(cx: &@block_ctxt, t: ty::t, lhs: ValueRef,
26432643
}
26442644

26452645
mod ivec {
2646+
fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
2647+
result {
2648+
let typ = node_id_type(bcx_ccx(bcx), id);
2649+
let unit_ty;
2650+
alt ty::struct(bcx_tcx(bcx), typ) {
2651+
ty::ty_vec(mt) { unit_ty = mt.ty; }
2652+
_ { bcx_ccx(bcx).sess.bug("non-ivec type in trans_ivec"); }
2653+
}
2654+
let llunitty = type_of_or_i8(bcx, unit_ty);
2655+
2656+
let ares = ivec::alloc(bcx, unit_ty);
2657+
bcx = ares.bcx;
2658+
let llvecptr = ares.llptr;
2659+
let unit_sz = ares.llunitsz;
2660+
let llalen = ares.llalen;
2661+
2662+
add_clean_temp(bcx, llvecptr, typ);
2663+
2664+
let lllen = bcx.build.Mul(C_uint(std::vec::len(args)), unit_sz);
2665+
// Allocate the vector pieces and store length and allocated length.
2666+
2667+
let llfirsteltptr;
2668+
if std::vec::len(args) > 0u &&
2669+
std::vec::len(args) <= abi::ivec_default_length {
2670+
// Interior case.
2671+
2672+
bcx.build.Store(lllen,
2673+
bcx.build.InBoundsGEP(llvecptr,
2674+
[C_int(0),
2675+
C_uint(abi::ivec_elt_len)]));
2676+
bcx.build.Store(llalen,
2677+
bcx.build.InBoundsGEP(llvecptr,
2678+
[C_int(0),
2679+
C_uint(abi::ivec_elt_alen)]));
2680+
llfirsteltptr =
2681+
bcx.build.InBoundsGEP(llvecptr,
2682+
[C_int(0), C_uint(abi::ivec_elt_elems),
2683+
C_int(0)]);
2684+
} else {
2685+
// Heap case.
2686+
2687+
let stub_z = [C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
2688+
let stub_a = [C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
2689+
let stub_p = [C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
2690+
let llstubty = T_ivec_heap(llunitty);
2691+
let llstubptr = bcx.build.PointerCast(llvecptr, T_ptr(llstubty));
2692+
bcx.build.Store(C_int(0), bcx.build.InBoundsGEP(llstubptr, stub_z));
2693+
let llheapty = T_ivec_heap_part(llunitty);
2694+
if std::vec::len(args) == 0u {
2695+
// Null heap pointer indicates a zero-length vector.
2696+
2697+
bcx.build.Store(llalen, bcx.build.InBoundsGEP(llstubptr, stub_a));
2698+
bcx.build.Store(C_null(T_ptr(llheapty)),
2699+
bcx.build.InBoundsGEP(llstubptr, stub_p));
2700+
llfirsteltptr = C_null(T_ptr(llunitty));
2701+
} else {
2702+
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llstubptr, stub_a));
2703+
2704+
let llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
2705+
let rslt = trans_shared_malloc(bcx, T_ptr(llheapty), llheapsz);
2706+
bcx = rslt.bcx;
2707+
let llheapptr = rslt.val;
2708+
bcx.build.Store(llheapptr,
2709+
bcx.build.InBoundsGEP(llstubptr, stub_p));
2710+
let heap_l = [C_int(0), C_uint(abi::ivec_heap_elt_len)];
2711+
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llheapptr, heap_l));
2712+
llfirsteltptr =
2713+
bcx.build.InBoundsGEP(llheapptr,
2714+
[C_int(0),
2715+
C_uint(abi::ivec_heap_elt_elems),
2716+
C_int(0)]);
2717+
}
2718+
}
2719+
// Store the individual elements.
2720+
2721+
let i = 0u;
2722+
for e: @ast::expr in args {
2723+
let lv = trans_lval(bcx, e);
2724+
bcx = lv.res.bcx;
2725+
let lleltptr;
2726+
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
2727+
lleltptr =
2728+
bcx.build.InBoundsGEP(llfirsteltptr,
2729+
[bcx.build.Mul(C_uint(i), unit_sz)]);
2730+
} else {
2731+
lleltptr = bcx.build.InBoundsGEP(llfirsteltptr, [C_uint(i)]);
2732+
}
2733+
bcx = move_val_if_temp(bcx, INIT, lleltptr, lv, unit_ty);
2734+
i += 1u;
2735+
}
2736+
ret rslt(bcx, llvecptr);
2737+
}
26462738

26472739
// Returns the length of an interior vector and a pointer to its first
26482740
// element, in that order.
@@ -4821,100 +4913,6 @@ fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id) ->
48214913
ret rslt(bcx, tup_val);
48224914
}
48234915

4824-
// TODO: Move me to ivec::
4825-
fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
4826-
result {
4827-
let typ = node_id_type(bcx_ccx(bcx), id);
4828-
let unit_ty;
4829-
alt ty::struct(bcx_tcx(bcx), typ) {
4830-
ty::ty_vec(mt) { unit_ty = mt.ty; }
4831-
_ { bcx_ccx(bcx).sess.bug("non-ivec type in trans_ivec"); }
4832-
}
4833-
let llunitty = type_of_or_i8(bcx, unit_ty);
4834-
4835-
let ares = ivec::alloc(bcx, unit_ty);
4836-
bcx = ares.bcx;
4837-
let llvecptr = ares.llptr;
4838-
let unit_sz = ares.llunitsz;
4839-
let llalen = ares.llalen;
4840-
4841-
add_clean_temp(bcx, llvecptr, typ);
4842-
4843-
let lllen = bcx.build.Mul(C_uint(std::vec::len(args)), unit_sz);
4844-
// Allocate the vector pieces and store length and allocated length.
4845-
4846-
let llfirsteltptr;
4847-
if std::vec::len(args) > 0u &&
4848-
std::vec::len(args) <= abi::ivec_default_length {
4849-
// Interior case.
4850-
4851-
bcx.build.Store(lllen,
4852-
bcx.build.InBoundsGEP(llvecptr,
4853-
[C_int(0),
4854-
C_uint(abi::ivec_elt_len)]));
4855-
bcx.build.Store(llalen,
4856-
bcx.build.InBoundsGEP(llvecptr,
4857-
[C_int(0),
4858-
C_uint(abi::ivec_elt_alen)]));
4859-
llfirsteltptr =
4860-
bcx.build.InBoundsGEP(llvecptr,
4861-
[C_int(0), C_uint(abi::ivec_elt_elems),
4862-
C_int(0)]);
4863-
} else {
4864-
// Heap case.
4865-
4866-
let stub_z = [C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
4867-
let stub_a = [C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
4868-
let stub_p = [C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
4869-
let llstubty = T_ivec_heap(llunitty);
4870-
let llstubptr = bcx.build.PointerCast(llvecptr, T_ptr(llstubty));
4871-
bcx.build.Store(C_int(0), bcx.build.InBoundsGEP(llstubptr, stub_z));
4872-
let llheapty = T_ivec_heap_part(llunitty);
4873-
if std::vec::len(args) == 0u {
4874-
// Null heap pointer indicates a zero-length vector.
4875-
4876-
bcx.build.Store(llalen, bcx.build.InBoundsGEP(llstubptr, stub_a));
4877-
bcx.build.Store(C_null(T_ptr(llheapty)),
4878-
bcx.build.InBoundsGEP(llstubptr, stub_p));
4879-
llfirsteltptr = C_null(T_ptr(llunitty));
4880-
} else {
4881-
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llstubptr, stub_a));
4882-
4883-
let llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
4884-
let rslt = trans_shared_malloc(bcx, T_ptr(llheapty), llheapsz);
4885-
bcx = rslt.bcx;
4886-
let llheapptr = rslt.val;
4887-
bcx.build.Store(llheapptr,
4888-
bcx.build.InBoundsGEP(llstubptr, stub_p));
4889-
let heap_l = [C_int(0), C_uint(abi::ivec_heap_elt_len)];
4890-
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llheapptr, heap_l));
4891-
llfirsteltptr =
4892-
bcx.build.InBoundsGEP(llheapptr,
4893-
[C_int(0),
4894-
C_uint(abi::ivec_heap_elt_elems),
4895-
C_int(0)]);
4896-
}
4897-
}
4898-
// Store the individual elements.
4899-
4900-
let i = 0u;
4901-
for e: @ast::expr in args {
4902-
let lv = trans_lval(bcx, e);
4903-
bcx = lv.res.bcx;
4904-
let lleltptr;
4905-
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
4906-
lleltptr =
4907-
bcx.build.InBoundsGEP(llfirsteltptr,
4908-
[bcx.build.Mul(C_uint(i), unit_sz)]);
4909-
} else {
4910-
lleltptr = bcx.build.InBoundsGEP(llfirsteltptr, [C_uint(i)]);
4911-
}
4912-
bcx = move_val_if_temp(bcx, INIT, lleltptr, lv, unit_ty);
4913-
i += 1u;
4914-
}
4915-
ret rslt(bcx, llvecptr);
4916-
}
4917-
49184916
fn trans_rec(cx: &@block_ctxt, fields: &[ast::field],
49194917
base: &option::t<@ast::expr>, id: ast::node_id) -> result {
49204918
let bcx = cx;
@@ -5103,7 +5101,7 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
51035101
ret trans_call(cx, f, none::<ValueRef>, args, e.id);
51045102
}
51055103
ast::expr_cast(val, _) { ret trans_cast(cx, val, e.id); }
5106-
ast::expr_vec(args, _) { ret trans_ivec(cx, args, e.id); }
5104+
ast::expr_vec(args, _) { ret ivec::trans_ivec(cx, args, e.id); }
51075105
ast::expr_rec(args, base) { ret trans_rec(cx, args, base, e.id); }
51085106
ast::expr_tup(args) { ret trans_tup(cx, args, e.id); }
51095107
ast::expr_mac(_) { ret bcx_ccx(cx).sess.bug("unexpanded macro"); }

0 commit comments

Comments
 (0)