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