@@ -45,6 +45,7 @@ state type trans_ctxt = rec(session.session sess,
45
45
hashmap[ str, ValueRef ] upcalls,
46
46
hashmap[ str, ValueRef ] fn_names,
47
47
hashmap[ ast. def_id , ValueRef ] fn_ids,
48
+ hashmap[ ast. def_id , @ast. item ] items,
48
49
@glue_fns glues,
49
50
namegen names,
50
51
str path) ;
@@ -974,27 +975,16 @@ fn new_fn_ctxt(@trans_ctxt cx,
974
975
& ast . _fn f,
975
976
ast. def_id fid ) -> @fn_ctxt {
976
977
977
- let vec[ TypeRef ] args = vec ( T_ptr ( type_of ( cx, f. output ) ) , // outptr.
978
- T_taskptr ( ) // taskptr
979
- ) ;
980
- let uint arg_n = _vec. len [ TypeRef ] ( args) ;
981
-
982
- let vec[ TypeRef ] T_explicit_args = vec ( ) ;
983
- for ( ast. arg arg in f. inputs ) {
984
- T_explicit_args += type_of ( cx, arg. ty ) ;
985
- }
986
- args += T_explicit_args ;
987
-
988
- let ValueRef llfn = decl_cdecl_fn ( cx. llmod , name, args, T_void ( ) ) ;
978
+ let ValueRef llfn = cx. fn_ids . get ( fid) ;
989
979
cx. fn_names . insert ( cx. path , llfn) ;
990
- cx. fn_ids . insert ( fid, llfn) ;
991
980
992
981
let ValueRef lloutptr = llvm. LLVMGetParam ( llfn, 0 u) ;
993
982
let ValueRef lltaskptr = llvm. LLVMGetParam ( llfn, 1 u) ;
994
983
995
984
let hashmap[ ast. def_id , ValueRef ] lllocals = new_def_hash[ ValueRef ] ( ) ;
996
985
let hashmap[ ast. def_id , ValueRef ] llargs = new_def_hash[ ValueRef ] ( ) ;
997
986
987
+ let uint arg_n = 2 u;
998
988
for ( ast. arg arg in f. inputs ) {
999
989
llargs. insert ( arg. id , llvm. LLVMGetParam ( llfn, arg_n) ) ;
1000
990
arg_n += 1 u;
@@ -1035,6 +1025,42 @@ fn trans_mod(@trans_ctxt cx, &ast._mod m) {
1035
1025
}
1036
1026
1037
1027
1028
+ fn collect_item ( & @trans_ctxt cx , @ast. item i ) -> @trans_ctxt {
1029
+ alt ( i. node ) {
1030
+ case ( ast. item_fn ( ?name, ?f, ?fid) ) {
1031
+ cx. items . insert ( fid, i) ;
1032
+ let vec[ TypeRef ] args = vec ( T_ptr ( type_of ( cx, f. output ) ) , // outptr.
1033
+ T_taskptr ( ) // taskptr
1034
+ ) ;
1035
+ let vec[ TypeRef ] T_explicit_args = vec ( ) ;
1036
+ for ( ast. arg arg in f. inputs ) {
1037
+ T_explicit_args += type_of ( cx, arg. ty ) ;
1038
+ }
1039
+ args += T_explicit_args ;
1040
+
1041
+ let str s = cx. names . next ( "_rust_fn" ) + "." + name;
1042
+ let ValueRef llfn = decl_cdecl_fn ( cx. llmod , s, args, T_void ( ) ) ;
1043
+ cx. fn_ids . insert ( fid, llfn) ;
1044
+ }
1045
+
1046
+ case ( ast. item_mod ( ?name, ?m, ?mid) ) {
1047
+ cx. items . insert ( mid, i) ;
1048
+ }
1049
+ }
1050
+ ret cx;
1051
+ }
1052
+
1053
+
1054
+ fn collect_items ( @trans_ctxt cx , @ast. crate crate) {
1055
+
1056
+ let fold. ast_fold[ @trans_ctxt] fld = fold. new_identity_fold [ @trans_ctxt] ( ) ;
1057
+
1058
+ fld = @rec ( update_env_for_item = bind collect_item ( _, _)
1059
+ with * fld ) ;
1060
+
1061
+ fold. fold_crate [ @trans_ctxt] ( cx, fld, crate ) ;
1062
+ }
1063
+
1038
1064
fn p2i ( ValueRef v) -> ValueRef {
1039
1065
ret llvm. LLVMConstPtrToInt ( v, T_int ( ) ) ;
1040
1066
}
@@ -1163,10 +1189,12 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
1163
1189
upcalls = new_str_hash[ ValueRef ] ( ) ,
1164
1190
fn_names = new_str_hash[ ValueRef ] ( ) ,
1165
1191
fn_ids = new_def_hash[ ValueRef ] ( ) ,
1192
+ items = new_def_hash[ @ast. item ] ( ) ,
1166
1193
glues = glues,
1167
1194
names = namegen ( 0 ) ,
1168
1195
path = "_rust" ) ;
1169
1196
1197
+ collect_items ( cx, crate ) ;
1170
1198
trans_mod ( cx, crate . node. module ) ;
1171
1199
trans_exit_task_glue ( cx) ;
1172
1200
trans_main_fn ( cx, crate_constant ( cx) ) ;
0 commit comments