@@ -77,8 +77,8 @@ pub fn get_dataptr(bcx: @mut Block, vptr: ValueRef) -> ValueRef {
77
77
GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_elems, 0 u] )
78
78
}
79
79
80
- pub fn pointer_add ( bcx : @mut Block , ptr : ValueRef , bytes : ValueRef ) -> ValueRef {
81
- let _icx = push_ctxt ( "tvec::pointer_add " ) ;
80
+ pub fn pointer_add_byte ( bcx : @mut Block , ptr : ValueRef , bytes : ValueRef ) -> ValueRef {
81
+ let _icx = push_ctxt ( "tvec::pointer_add_byte " ) ;
82
82
let old_ty = val_ty ( ptr) ;
83
83
let bptr = PointerCast ( bcx, ptr, Type :: i8p ( ) ) ;
84
84
return PointerCast ( bcx, InBoundsGEP ( bcx, bptr, [ bytes] ) , old_ty) ;
@@ -501,8 +501,7 @@ pub fn elements_required(bcx: @mut Block, content_expr: &ast::Expr) -> uint {
501
501
}
502
502
}
503
503
504
- pub fn get_base_and_byte_len ( bcx : @mut Block ,
505
- llval : ValueRef ,
504
+ pub fn get_base_and_byte_len ( bcx : @mut Block , llval : ValueRef ,
506
505
vec_ty : ty:: t ) -> ( ValueRef , ValueRef ) {
507
506
//!
508
507
//
@@ -539,6 +538,40 @@ pub fn get_base_and_byte_len(bcx: @mut Block,
539
538
}
540
539
}
541
540
541
+ pub fn get_base_and_len ( bcx : @mut Block , llval : ValueRef , vec_ty : ty:: t ) -> ( ValueRef , ValueRef ) {
542
+ //!
543
+ //
544
+ // Converts a vector into the slice pair. The vector should be stored in
545
+ // `llval` which should be either immediate or by-ref as appropriate for
546
+ // the vector type. If you have a datum, you would probably prefer to
547
+ // call `Datum::get_base_and_len()` which will handle any conversions for
548
+ // you.
549
+
550
+ let ccx = bcx. ccx ( ) ;
551
+ let vt = vec_types ( bcx, vec_ty) ;
552
+
553
+ let vstore = match ty:: get ( vt. vec_ty ) . sty {
554
+ ty:: ty_estr( vst) | ty:: ty_evec( _, vst) => vst,
555
+ _ => ty:: vstore_uniq
556
+ } ;
557
+
558
+ match vstore {
559
+ ty:: vstore_fixed( n) => {
560
+ let base = GEPi ( bcx, llval, [ 0 u, 0 u] ) ;
561
+ ( base, C_uint ( ccx, n) )
562
+ }
563
+ ty:: vstore_slice( _) => {
564
+ let base = Load ( bcx, GEPi ( bcx, llval, [ 0 u, abi:: slice_elt_base] ) ) ;
565
+ let count = Load ( bcx, GEPi ( bcx, llval, [ 0 u, abi:: slice_elt_len] ) ) ;
566
+ ( base, count)
567
+ }
568
+ ty:: vstore_uniq | ty:: vstore_box => {
569
+ let body = get_bodyptr ( bcx, llval, vec_ty) ;
570
+ ( get_dataptr ( bcx, body) , UDiv ( bcx, get_fill ( bcx, body) , vt. llunit_size ) )
571
+ }
572
+ }
573
+ }
574
+
542
575
pub type iter_vec_block < ' self > = & ' self fn ( @mut Block , ValueRef , ty:: t ) -> @mut Block ;
543
576
544
577
pub fn iter_vec_raw ( bcx : @mut Block , data_ptr : ValueRef , vec_ty : ty:: t ,
@@ -551,7 +584,7 @@ pub fn iter_vec_raw(bcx: @mut Block, data_ptr: ValueRef, vec_ty: ty::t,
551
584
// FIXME (#3729): Optimize this when the size of the unit type is
552
585
// statically known to not use pointer casts, which tend to confuse
553
586
// LLVM.
554
- let data_end_ptr = pointer_add ( bcx, data_ptr, fill) ;
587
+ let data_end_ptr = pointer_add_byte ( bcx, data_ptr, fill) ;
555
588
556
589
// Now perform the iteration.
557
590
let header_bcx = base:: sub_block ( bcx, "iter_vec_loop_header" ) ;
0 commit comments