Skip to content

Commit c0cc1eb

Browse files
committed
---
yaml --- r: 4891 b: refs/heads/master c: fd8ca2c h: refs/heads/master i: 4889: 588f9bb 4887: e11b462 v: v3
1 parent 1de35ff commit c0cc1eb

File tree

4 files changed

+42
-56
lines changed

4 files changed

+42
-56
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: 0a93a48ff50c62d4d830f63a913256fefacb742f
2+
refs/heads/master: fd8ca2cf5d11dac095bc9153bd32b442ac481cb1

trunk/src/comp/middle/trans.rs

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,61 +2444,30 @@ fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef,
24442444
}
24452445

24462446
fn trans_lit_istr(cx: &@block_ctxt, s: str) -> result {
2447-
let llstackpart = alloca(cx, T_ivec(T_i8()));
2448-
let len = str::byte_len(s);
2449-
2450-
let bcx;
2451-
if len < 3u { // 3 because of the \0
2452-
cx.build.Store(C_uint(len + 1u),
2453-
cx.build.InBoundsGEP(llstackpart,
2454-
[C_int(0), C_int(0)]));
2455-
cx.build.Store(C_int(4),
2456-
cx.build.InBoundsGEP(llstackpart,
2457-
[C_int(0), C_int(1)]));
2458-
let i = 0u;
2459-
while i < len {
2460-
cx.build.Store(C_u8(s[i] as uint),
2461-
cx.build.InBoundsGEP(llstackpart,
2462-
[C_int(0), C_int(2),
2463-
C_uint(i)]));
2464-
i += 1u;
2465-
}
2466-
cx.build.Store(C_u8(0u),
2467-
cx.build.InBoundsGEP(llstackpart,
2468-
[C_int(0), C_int(2),
2469-
C_uint(len)]));
2447+
let vec_ty = ty::mk_vec(bcx_tcx(cx),
2448+
{ty: ty::mk_mach(bcx_tcx(cx), ast::ty_u8),
2449+
mut: ast::imm});
2450+
let strlen = str::byte_len(s);
2451+
let veclen = strlen + 1u; // +1 for \0
2452+
let alloc_res = trans_ivec::alloc_with_heap(cx, vec_ty, veclen);
2453+
2454+
let bcx = alloc_res.bcx;
2455+
let llvecptr = alloc_res.llptr;
2456+
let llfirsteltptr = alloc_res.llfirsteltptr;
2457+
2458+
// FIXME: Do something smarter here to load the string
2459+
let i = 0u;
2460+
while i < strlen {
2461+
bcx.build.Store(C_u8(s[i] as uint),
2462+
bcx.build.InBoundsGEP(llfirsteltptr,
2463+
[C_uint(i)]));
2464+
i += 1u;
2465+
}
2466+
bcx.build.Store(C_u8(0u),
2467+
bcx.build.InBoundsGEP(llfirsteltptr,
2468+
[C_uint(strlen)]));
24702469

2471-
bcx = cx;
2472-
} else {
2473-
let r =
2474-
trans_shared_malloc(cx, T_ptr(T_ivec_heap_part(T_i8())),
2475-
llsize_of(T_struct([T_int(),
2476-
T_array(T_i8(),
2477-
len + 1u)])));
2478-
bcx = r.bcx;
2479-
let llheappart = r.val;
2480-
2481-
bcx.build.Store(C_uint(len + 1u),
2482-
bcx.build.InBoundsGEP(llheappart,
2483-
[C_int(0), C_int(0)]));
2484-
bcx.build.Store(llvm::LLVMConstString(str::buf(s), len, False),
2485-
bcx.build.InBoundsGEP(llheappart,
2486-
[C_int(0), C_int(1)]));
2487-
2488-
let llspilledstackpart =
2489-
bcx.build.PointerCast(llstackpart, T_ptr(T_ivec_heap(T_i8())));
2490-
bcx.build.Store(C_int(0),
2491-
bcx.build.InBoundsGEP(llspilledstackpart,
2492-
[C_int(0), C_int(0)]));
2493-
bcx.build.Store(C_uint(len + 1u),
2494-
bcx.build.InBoundsGEP(llspilledstackpart,
2495-
[C_int(0), C_int(1)]));
2496-
bcx.build.Store(llheappart,
2497-
bcx.build.InBoundsGEP(llspilledstackpart,
2498-
[C_int(0), C_int(2)]));
2499-
}
2500-
2501-
ret rslt(bcx, llstackpart);
2470+
ret rslt(bcx, llvecptr);
25022471
}
25032472

25042473
fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef {

trunk/src/comp/middle/trans_ivec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import trans::{call_memmove, trans_shared_malloc, llsize_of,
1212
import trans_common::*;
1313

1414
export trans_ivec, get_len_and_data, duplicate_heap_part, trans_add,
15-
trans_append;
15+
trans_append, alloc_with_heap;
1616

1717
fn alloc_with_heap(bcx: @block_ctxt, typ: &ty::t, vecsz: uint) ->
1818
{bcx: @block_ctxt,

trunk/src/test/run-pass/istr.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fn test_stack_assign() {
2+
let s: istr = ~"a";
3+
log s;
4+
let t: istr = ~"a";
5+
assert s == t;
6+
let u: istr = ~"b";
7+
assert s != u;
8+
}
9+
10+
fn test_heap_lit() {
11+
~"a big string";
12+
}
13+
14+
fn main() {
15+
test_stack_assign();
16+
test_heap_lit();
17+
}

0 commit comments

Comments
 (0)