@@ -20,11 +20,7 @@ fn get_alloc(bcx: @block_ctxt, vptrptr: ValueRef) -> ValueRef {
20
20
}
21
21
fn get_dataptr ( bcx : @block_ctxt , vptrptr : ValueRef , unit_ty : TypeRef ) ->
22
22
ValueRef {
23
- ret get_dataptr_simple ( bcx, Load ( bcx, vptrptr) , unit_ty) ;
24
- }
25
- fn get_dataptr_simple ( bcx : @block_ctxt , vptr : ValueRef , unit_ty : TypeRef )
26
- -> ValueRef {
27
- let ptr = GEPi ( bcx, vptr, [ 0 , abi:: vec_elt_elems as int ] ) ;
23
+ let ptr = GEPi ( bcx, Load ( bcx, vptrptr) , [ 0 , abi:: vec_elt_elems as int ] ) ;
28
24
PointerCast ( bcx, ptr, T_ptr ( unit_ty) )
29
25
}
30
26
@@ -53,7 +49,8 @@ type alloc_result =
53
49
llunitsz : ValueRef ,
54
50
llunitty : TypeRef } ;
55
51
56
- fn alloc ( bcx : @block_ctxt , vec_ty : ty:: t , elts : uint ) -> alloc_result {
52
+ fn alloc ( bcx : @block_ctxt , vec_ty : ty:: t , elts : uint , dest : dest )
53
+ -> alloc_result {
57
54
let unit_ty = ty:: sequence_element_type ( bcx_tcx ( bcx) , vec_ty) ;
58
55
let llunitty = type_of_or_i8 ( bcx, unit_ty) ;
59
56
let llvecty = T_vec ( llunitty) ;
@@ -64,8 +61,11 @@ fn alloc(bcx: @block_ctxt, vec_ty: ty::t, elts: uint) -> alloc_result {
64
61
let { bcx: bcx , val : vptr } = alloc_raw ( bcx, fill, alloc) ;
65
62
let vptr = PointerCast ( bcx, vptr, T_ptr ( llvecty) ) ;
66
63
64
+ let vptrptr = alt dest { trans : : save_in ( a) { a } } ;
65
+ Store ( bcx, vptr, vptrptr) ;
66
+ // add_clean_temp(bcx, vptrptr, vec_ty);
67
67
ret { bcx : bcx,
68
- val : vptr ,
68
+ val : vptrptr ,
69
69
unit_ty : unit_ty,
70
70
llunitsz : unit_sz,
71
71
llunitty : llunitty} ;
@@ -110,15 +110,16 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id,
110
110
}
111
111
let vec_ty = node_id_type ( bcx_ccx ( bcx) , id) ;
112
112
let { bcx: bcx ,
113
- val : vptr ,
113
+ val : vptrptr ,
114
114
llunitsz : llunitsz ,
115
115
unit_ty : unit_ty ,
116
116
llunitty : llunitty } =
117
- alloc ( bcx, vec_ty, vec:: len ( args) ) ;
117
+ alloc ( bcx, vec_ty, vec:: len ( args) , dest ) ;
118
118
119
+ let vptr = Load ( bcx, vptrptr) ;
119
120
add_clean_free ( bcx, vptr, true ) ;
120
121
// Store the individual elements.
121
- let dataptr = get_dataptr_simple ( bcx, vptr , llunitty) ;
122
+ let dataptr = get_dataptr ( bcx, vptrptr , llunitty) ;
122
123
let i = 0 u, temp_cleanups = [ vptr] ;
123
124
for e in args {
124
125
let lv = trans_lval ( bcx, e) ;
@@ -132,28 +133,17 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id,
132
133
i += 1 u;
133
134
}
134
135
for clean in temp_cleanups { revoke_clean ( bcx, clean) ; }
135
- let vptrptr = alt dest {
136
- trans : : save_in ( a) { a }
137
- trans:: overwrite ( a, t) { bcx = trans:: drop_ty ( bcx, a, t) ; a }
138
- } ;
139
- Store ( bcx, vptr, vptrptr) ;
140
136
ret bcx;
141
137
}
142
-
143
138
fn trans_str ( bcx : @block_ctxt , s : str , dest : dest ) -> @block_ctxt {
144
139
let veclen = std:: str:: byte_len ( s) + 1 u; // +1 for \0
145
- let { bcx: bcx , val : sptr , _} =
146
- alloc ( bcx, ty:: mk_str ( bcx_tcx ( bcx) ) , veclen) ;
140
+ let { bcx: bcx , val : sptrptr , _} =
141
+ alloc ( bcx, ty:: mk_str ( bcx_tcx ( bcx) ) , veclen, dest ) ;
147
142
148
143
let llcstr = C_cstr ( bcx_ccx ( bcx) , s) ;
149
144
let bcx =
150
- call_memmove ( bcx, get_dataptr_simple ( bcx, sptr , T_i8 ( ) ) , llcstr,
145
+ call_memmove ( bcx, get_dataptr ( bcx, sptrptr , T_i8 ( ) ) , llcstr,
151
146
C_uint ( veclen) ) . bcx ;
152
- let sptrptr = alt dest {
153
- trans : : save_in ( a) { a }
154
- trans:: overwrite ( a, t) { bcx = trans:: drop_ty ( bcx, a, t) ; a }
155
- } ;
156
- Store ( bcx, sptr, sptrptr) ;
157
147
ret bcx;
158
148
}
159
149
@@ -247,9 +237,11 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
247
237
let new_fill = Add ( bcx, lhs_fill, rhs_fill) ;
248
238
let { bcx: bcx , val : new_vec_ptr } = alloc_raw ( bcx, new_fill, new_fill) ;
249
239
new_vec_ptr = PointerCast ( bcx, new_vec_ptr, T_ptr ( T_vec ( llunitty) ) ) ;
240
+ let new_vec_ptr_ptr = alt dest { trans : : save_in ( a) { a } } ;
241
+ Store ( bcx, new_vec_ptr, new_vec_ptr_ptr) ;
250
242
251
- let write_ptr_ptr = do_spill_noroot
252
- ( bcx, get_dataptr_simple ( bcx, new_vec_ptr , llunitty) ) ;
243
+ let write_ptr_ptr =
244
+ do_spill_noroot ( bcx, get_dataptr ( bcx, new_vec_ptr_ptr , llunitty) ) ;
253
245
let copy_fn =
254
246
bind fn ( bcx: @block_ctxt, addr: ValueRef , _ty: ty:: t,
255
247
write_ptr_ptr: ValueRef , unit_ty: ty:: t, llunitsz: ValueRef )
@@ -267,15 +259,7 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
267
259
} ( _, _, _, write_ptr_ptr, unit_ty, llunitsz) ;
268
260
269
261
let bcx = iter_vec_raw ( bcx, lhsptr, vec_ty, lhs_fill, copy_fn) ;
270
- bcx = iter_vec_raw ( bcx, rhsptr, vec_ty, rhs_fill, copy_fn) ;
271
- alt dest {
272
- trans : : save_in ( a) { Store ( bcx, new_vec_ptr, a) ; }
273
- trans:: overwrite ( a, t) {
274
- bcx = trans:: drop_ty ( bcx, a, t) ;
275
- Store ( bcx, new_vec_ptr, a) ;
276
- }
277
- }
278
- ret bcx;
262
+ ret iter_vec_raw ( bcx, rhsptr, vec_ty, rhs_fill, copy_fn) ;
279
263
}
280
264
281
265
type val_and_ty_fn = fn ( @block_ctxt , ValueRef , ty:: t ) -> result ;
0 commit comments