@@ -42,16 +42,17 @@ type glue_fns = rec(ValueRef activate_glue,
42
42
43
43
state type trans_ctxt = rec ( session. session sess,
44
44
ModuleRef llmod,
45
- hashmap[ str, ValueRef ] upcalls,
46
- hashmap[ str, ValueRef ] fn_names,
47
- hashmap[ ast. def_id , ValueRef ] fn_ids,
45
+ hashmap[ str, ValueRef ] upcalls,
46
+ hashmap[ str, ValueRef ] fn_names,
47
+ hashmap[ ast. def_id , ValueRef ] fn_ids,
48
48
@glue_fns glues,
49
49
namegen names,
50
50
str path) ;
51
51
52
52
state type fn_ctxt = rec ( ValueRef llfn,
53
53
ValueRef lloutptr,
54
54
ValueRef lltaskptr ,
55
+ hashmap[ ast. def_id, ValueRef ] llargs ,
55
56
hashmap[ ast. def_id, ValueRef ] lllocals ,
56
57
@trans_ctxt tcx ) ;
57
58
@@ -659,17 +660,25 @@ fn trans_if(@block_ctxt cx, &ast.expr cond,
659
660
ret res( next_cx, phi) ;
660
661
}
661
662
662
- fn trans_lval ( @block_ctxt cx , & ast . expr e) -> result {
663
+ // The additional bool returned indicates whether it's a local
664
+ // (that is represented as an alloca, hence needs a 'load' to be
665
+ // used as an rval).
666
+
667
+ fn trans_lval ( @block_ctxt cx , & ast . expr e) -> tup ( result , bool ) {
663
668
alt ( e. node ) {
664
669
case ( ast. expr_name ( ?n, ?dopt, _) ) {
665
670
alt ( dopt) {
666
671
case ( some[ ast. def ] ( ?def) ) {
667
672
alt ( def) {
673
+ case ( ast. def_arg ( ?did) ) {
674
+ ret tup ( res ( cx, cx. fcx . llargs . get ( did) ) , false ) ;
675
+ }
668
676
case ( ast. def_local ( ?did) ) {
669
- ret res ( cx, cx. fcx . lllocals . get ( did) ) ;
677
+ ret tup ( res ( cx, cx. fcx . lllocals . get ( did) ) , true ) ;
670
678
}
671
679
case ( ast. def_fn ( ?did) ) {
672
- ret res ( cx, cx. fcx . tcx . fn_ids . get ( did) ) ;
680
+ ret tup ( res ( cx, cx. fcx . tcx . fn_ids . get ( did) ) ,
681
+ false ) ;
673
682
}
674
683
case ( _) {
675
684
cx. fcx . tcx . sess . unimpl ( "def variant in trans" ) ;
@@ -731,24 +740,30 @@ fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
731
740
732
741
case ( ast. expr_name ( _, _, _) ) {
733
742
auto sub = trans_lval ( cx, e) ;
734
- ret res( sub. bcx , cx. build . Load ( sub. val ) ) ;
743
+ if ( sub. _1 ) {
744
+ ret res ( sub. _0 . bcx , cx. build . Load ( sub. _0 . val ) ) ;
745
+ } else {
746
+ ret sub. _0 ;
747
+ }
735
748
}
736
749
737
750
case ( ast. expr_assign ( ?dst, ?src, _) ) {
738
751
auto lhs_res = trans_lval ( cx, * dst) ;
739
- auto rhs_res = trans_expr ( lhs_res. bcx , * src) ;
752
+ check ( lhs_res. _1 ) ;
753
+ auto rhs_res = trans_expr ( lhs_res. _0 . bcx , * src) ;
740
754
ret res ( rhs_res. bcx ,
741
- cx. build . Store ( rhs_res. val , lhs_res. val ) ) ;
755
+ cx. build . Store ( rhs_res. val , lhs_res. _0 . val ) ) ;
742
756
}
743
757
744
758
case ( ast. expr_call ( ?f, ?args, _) ) {
745
759
auto f_res = trans_lval ( cx, * f) ;
746
- auto args_res = trans_exprs ( f_res. bcx , args) ;
760
+ check ( ! f_res. _1 ) ;
761
+ auto args_res = trans_exprs ( f_res. _0 . bcx , args) ;
747
762
auto llargs = vec ( cx. fcx . lloutptr ,
748
763
cx. fcx . lltaskptr ) ;
749
764
llargs += args_res. _1 ;
750
765
ret res ( args_res. _0 ,
751
- cx. build . Call ( f_res. val , llargs) ) ;
766
+ cx. build . Call ( f_res. _0 . val , llargs) ) ;
752
767
}
753
768
754
769
}
@@ -923,31 +938,46 @@ fn trans_block(@block_ctxt cx, &ast.block b) -> result {
923
938
924
939
fn new_fn_ctxt ( @trans_ctxt cx ,
925
940
str name ,
926
- ast. def_id fid ,
927
- TypeRef T_out ,
928
- vec [ TypeRef ] T_explicit_args ) -> @ fn_ctxt {
929
- let vec[ TypeRef ] args = vec ( T_ptr ( T_out ) , // outptr.
941
+ & ast . _fn f ,
942
+ ast . def_id fid ) -> @ fn_ctxt {
943
+
944
+ let vec[ TypeRef ] args = vec ( T_ptr ( type_of ( cx , f . output ) ) , // outptr.
930
945
T_taskptr ( ) // taskptr
931
946
) ;
947
+ let uint arg_n = _vec. len [ TypeRef ] ( args) ;
948
+
949
+ let vec[ TypeRef ] T_explicit_args = vec ( ) ;
950
+ for ( ast. arg arg in f. inputs ) {
951
+ T_explicit_args += type_of ( cx, arg. ty ) ;
952
+ }
932
953
args += T_explicit_args ;
954
+
933
955
let ValueRef llfn = decl_cdecl_fn ( cx. llmod , name, args, T_void ( ) ) ;
934
956
cx. fn_names . insert ( cx. path , llfn) ;
935
957
cx. fn_ids . insert ( fid, llfn) ;
958
+
936
959
let ValueRef lloutptr = llvm. LLVMGetParam ( llfn, 0 u) ;
937
960
let ValueRef lltaskptr = llvm. LLVMGetParam ( llfn, 1 u) ;
961
+
938
962
let hashmap[ ast. def_id , ValueRef ] lllocals = new_def_hash[ ValueRef ] ( ) ;
963
+ let hashmap[ ast. def_id , ValueRef ] llargs = new_def_hash[ ValueRef ] ( ) ;
964
+
965
+ for ( ast. arg arg in f. inputs ) {
966
+ llargs. insert ( arg. id , llvm. LLVMGetParam ( llfn, arg_n) ) ;
967
+ arg_n += 1 u;
968
+ }
969
+
939
970
ret @rec( llfn=llfn,
940
971
lloutptr=lloutptr,
941
972
lltaskptr=lltaskptr,
973
+ llargs=llargs,
942
974
lllocals=lllocals,
943
975
tcx=cx) ;
944
976
}
945
977
946
978
fn trans_fn ( @trans_ctxt cx , & ast . _fn f, ast. def_id fid ) {
947
- let TypeRef out = T_int ( ) ;
948
- let vec[ TypeRef ] args = vec ( ) ;
949
979
950
- auto fcx = new_fn_ctxt ( cx, cx. path , fid , out , args ) ;
980
+ auto fcx = new_fn_ctxt ( cx, cx. path , f , fid ) ;
951
981
952
982
trans_block ( new_top_block_ctxt ( fcx) , f. body ) ;
953
983
}
@@ -986,6 +1016,7 @@ fn trans_exit_task_glue(@trans_ctxt cx) {
986
1016
auto fcx = @rec ( llfn=llfn,
987
1017
lloutptr=lloutptr,
988
1018
lltaskptr=lltaskptr,
1019
+ llargs=new_def_hash[ ValueRef ] ( ) ,
989
1020
lllocals=new_def_hash[ ValueRef ] ( ) ,
990
1021
tcx=cx) ;
991
1022
0 commit comments