Skip to content

Commit 1de35ff

Browse files
committed
---
yaml --- r: 4890 b: refs/heads/master c: 0a93a48 h: refs/heads/master v: v3
1 parent 588f9bb commit 1de35ff

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
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: 309a7534d7ebf39f5a62bac36749d35272fe0a3e
2+
refs/heads/master: 0a93a48ff50c62d4d830f63a913256fefacb742f

trunk/src/comp/middle/trans_ivec.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import std::vec;
12
import std::option::none;
23
import syntax::ast;
34
import lib::llvm::llvm::{ValueRef, TypeRef};
@@ -13,9 +14,13 @@ import trans_common::*;
1314
export trans_ivec, get_len_and_data, duplicate_heap_part, trans_add,
1415
trans_append;
1516

16-
fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
17-
result {
18-
let typ = node_id_type(bcx_ccx(bcx), id);
17+
fn alloc_with_heap(bcx: @block_ctxt, typ: &ty::t, vecsz: uint) ->
18+
{bcx: @block_ctxt,
19+
unit_ty: ty::t,
20+
llunitsz: ValueRef,
21+
llptr: ValueRef,
22+
llfirsteltptr: ValueRef} {
23+
1924
let unit_ty;
2025
alt ty::struct(bcx_tcx(bcx), typ) {
2126
ty::ty_vec(mt) { unit_ty = mt.ty; }
@@ -31,12 +36,11 @@ fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
3136

3237
add_clean_temp(bcx, llvecptr, typ);
3338

34-
let lllen = bcx.build.Mul(C_uint(std::vec::len(args)), unit_sz);
39+
let lllen = bcx.build.Mul(C_uint(vecsz), unit_sz);
3540
// Allocate the vector pieces and store length and allocated length.
3641

3742
let llfirsteltptr;
38-
if std::vec::len(args) > 0u &&
39-
std::vec::len(args) <= abi::ivec_default_length {
43+
if vecsz > 0u && vecsz <= abi::ivec_default_length {
4044
// Interior case.
4145

4246
bcx.build.Store(lllen,
@@ -61,7 +65,7 @@ fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
6165
let llstubptr = bcx.build.PointerCast(llvecptr, T_ptr(llstubty));
6266
bcx.build.Store(C_int(0), bcx.build.InBoundsGEP(llstubptr, stub_z));
6367
let llheapty = T_ivec_heap_part(llunitty);
64-
if std::vec::len(args) == 0u {
68+
if vecsz == 0u {
6569
// Null heap pointer indicates a zero-length vector.
6670

6771
bcx.build.Store(llalen, bcx.build.InBoundsGEP(llstubptr, stub_a));
@@ -86,8 +90,27 @@ fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
8690
C_int(0)]);
8791
}
8892
}
89-
// Store the individual elements.
93+
ret {
94+
bcx: bcx,
95+
unit_ty: unit_ty,
96+
llunitsz: unit_sz,
97+
llptr: llvecptr,
98+
llfirsteltptr: llfirsteltptr};
99+
}
100+
101+
fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr],
102+
id: ast::node_id) -> result {
103+
104+
let typ = node_id_type(bcx_ccx(bcx), id);
105+
let alloc_res = alloc_with_heap(bcx, typ, vec::len(args));
106+
107+
let bcx = alloc_res.bcx;
108+
let unit_ty = alloc_res.unit_ty;
109+
let llunitsz = alloc_res.llunitsz;
110+
let llvecptr = alloc_res.llptr;
111+
let llfirsteltptr = alloc_res.llfirsteltptr;
90112

113+
// Store the individual elements.
91114
let i = 0u;
92115
for e: @ast::expr in args {
93116
let lv = trans_lval(bcx, e);
@@ -96,7 +119,7 @@ fn trans_ivec(bcx: @block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
96119
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
97120
lleltptr =
98121
bcx.build.InBoundsGEP(llfirsteltptr,
99-
[bcx.build.Mul(C_uint(i), unit_sz)]);
122+
[bcx.build.Mul(C_uint(i), llunitsz)]);
100123
} else {
101124
lleltptr = bcx.build.InBoundsGEP(llfirsteltptr, [C_uint(i)]);
102125
}

0 commit comments

Comments
 (0)