@@ -549,13 +549,21 @@ fn find_scope_cx(@block_ctxt cx) -> @block_ctxt {
549
549
}
550
550
}
551
551
552
+ fn size_of ( TypeRef t) -> ValueRef {
553
+ ret llvm. LLVMConstIntCast ( lib. llvm . llvm . LLVMSizeOf ( t) , T_int ( ) , False ) ;
554
+ }
555
+
556
+ fn align_of ( TypeRef t) -> ValueRef {
557
+ ret llvm. LLVMConstIntCast ( lib. llvm . llvm . LLVMAlignOf ( t) , T_int ( ) , False ) ;
558
+ }
559
+
552
560
fn trans_malloc ( @block_ctxt cx , @typeck. ty t ) -> result {
553
561
auto scope_cx = find_scope_cx ( cx) ;
554
562
auto ptr_ty = type_of ( cx. fcx . ccx , t) ;
555
563
auto body_ty = lib. llvm . llvm . LLVMGetElementType ( ptr_ty) ;
556
564
// FIXME: need a table to collect tydesc globals.
557
565
auto tydesc = C_int ( 0 ) ;
558
- auto sz = cx . build . IntCast ( lib . llvm . llvm . LLVMSizeOf ( body_ty) , T_int ( ) ) ;
566
+ auto sz = size_of ( body_ty) ;
559
567
auto sub = trans_upcall ( cx, "upcall_malloc" , vec ( sz, tydesc) ) ;
560
568
sub. val = sub. bcx . build . IntToPtr ( sub. val , ptr_ty) ;
561
569
scope_cx. cleanups += clean ( bind drop_ty ( _, sub. val , t) ) ;
@@ -590,8 +598,8 @@ fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) {
590
598
auto pvoid = T_ptr ( T_i8 ( ) ) ;
591
599
auto glue_fn_ty = T_ptr ( T_fn ( vec ( T_taskptr ( ) , pvoid) , T_void ( ) ) ) ;
592
600
auto tydesc = C_struct ( vec ( C_null ( pvoid) ,
593
- llvm . LLVMSizeOf ( llty) ,
594
- llvm . LLVMAlignOf ( llty) ,
601
+ size_of ( llty) ,
602
+ align_of ( llty) ,
595
603
take_glue, // copy_glue_off
596
604
drop_glue, // drop_glue_off
597
605
C_null ( glue_fn_ty) , // free_glue_off
@@ -924,8 +932,7 @@ fn iter_sequence(@block_ctxt cx,
924
932
C_int ( abi. vec_elt_fill) ) ) ;
925
933
926
934
auto llunit_ty = type_of( cx. fcx. ccx, elt_ty) ;
927
- auto unit_sz = llvm. LLVMConstIntCast ( llvm. LLVMSizeOf ( llunit_ty) ,
928
- T_int( ) , False ) ;
935
+ auto unit_sz = size_of( llunit_ty) ;
929
936
930
937
auto len = cx. build. Load ( lenptr) ;
931
938
if ( trailing_null) {
@@ -1599,8 +1606,8 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
1599
1606
fail;
1600
1607
}
1601
1608
1602
- fn trans_field( @block_ctxt cx, & ast. span sp, @ast. expr base,
1603
- & ast. ident field, & ast. ann ann) -> tup( result, bool) {
1609
+ impure fn trans_field( @block_ctxt cx, & ast. span sp, @ast. expr base,
1610
+ & ast. ident field, & ast. ann ann) -> tup( result, bool) {
1604
1611
auto lv = trans_lval( cx, base) ;
1605
1612
auto r = lv. _0;
1606
1613
auto ty = typeck. expr_ty( base) ;
@@ -1621,16 +1628,15 @@ fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
1621
1628
fail;
1622
1629
}
1623
1630
1624
- fn trans_index( @block_ctxt cx, & ast. span sp, @ast. expr base,
1625
- @ast. expr idx, & ast. ann ann) -> tup( result, bool) {
1631
+ impure fn trans_index( @block_ctxt cx, & ast. span sp, @ast. expr base,
1632
+ @ast. expr idx, & ast. ann ann) -> tup( result, bool) {
1626
1633
1627
1634
auto lv = trans_expr( cx, base) ;
1628
1635
auto ix = trans_expr( lv. bcx, idx) ;
1629
1636
auto v = lv. val;
1630
1637
1631
1638
auto llunit_ty = node_type( cx. fcx. ccx, ann) ;
1632
- auto unit_sz = ix. bcx. build. IntCast ( lib. llvm. llvm. LLVMSizeOf ( llunit_ty) ,
1633
- T_int ( ) ) ;
1639
+ auto unit_sz = size_of( llunit_ty) ;
1634
1640
auto scaled_ix = ix. bcx. build. Mul ( ix. val, unit_sz) ;
1635
1641
1636
1642
auto lim = ix. bcx. build. GEP ( v, vec( C_int ( 0 ) , C_int ( abi. vec_elt_fill) ) ) ;
@@ -1660,7 +1666,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
1660
1666
// represented as an alloca or heap, hence needs a 'load' to be used as an
1661
1667
// immediate).
1662
1668
1663
- fn trans_lval( @block_ctxt cx, @ast. expr e) -> tup( result, bool) {
1669
+ impure fn trans_lval( @block_ctxt cx, @ast. expr e) -> tup( result, bool) {
1664
1670
alt ( e. node) {
1665
1671
case ( ast. expr_name( ?n, ?dopt, _) ) {
1666
1672
ret trans_name( cx, n, dopt) ;
@@ -1828,8 +1834,7 @@ impure fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
1828
1834
}
1829
1835
1830
1836
auto llunit_ty = type_of( cx. fcx. ccx, unit_ty) ;
1831
- auto unit_sz = llvm. LLVMConstIntCast ( llvm. LLVMSizeOf ( llunit_ty) ,
1832
- T_int ( ) , False ) ;
1837
+ auto unit_sz = size_of( llunit_ty) ;
1833
1838
auto data_sz = llvm. LLVMConstMul ( C_int ( _vec. len[ @ast. expr] ( args) as int) ,
1834
1839
unit_sz) ;
1835
1840
0 commit comments