Skip to content

Commit bde829b

Browse files
committed
---
yaml --- r: 847 b: refs/heads/master c: b2f07c6 h: refs/heads/master i: 845: 1641d4a 843: 793708d 839: 190cd3b 831: b3e7c8b v: v3
1 parent cad9b66 commit bde829b

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d4497e481e99af8806f78deaeb60c67cb88eb5c5
2+
refs/heads/master: b2f07c60564dc1dce5151cb45423371915f5f87b

trunk/src/comp/middle/trans.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ state type trans_ctxt = rec(session.session sess,
4545
hashmap[str, ValueRef] upcalls,
4646
hashmap[str, ValueRef] fn_names,
4747
hashmap[ast.def_id, ValueRef] fn_ids,
48+
hashmap[ast.def_id, @ast.item] items,
4849
@glue_fns glues,
4950
namegen names,
5051
str path);
@@ -974,27 +975,16 @@ fn new_fn_ctxt(@trans_ctxt cx,
974975
&ast._fn f,
975976
ast.def_id fid) -> @fn_ctxt {
976977

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);
989979
cx.fn_names.insert(cx.path, llfn);
990-
cx.fn_ids.insert(fid, llfn);
991980

992981
let ValueRef lloutptr = llvm.LLVMGetParam(llfn, 0u);
993982
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 1u);
994983

995984
let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
996985
let hashmap[ast.def_id, ValueRef] llargs = new_def_hash[ValueRef]();
997986

987+
let uint arg_n = 2u;
998988
for (ast.arg arg in f.inputs) {
999989
llargs.insert(arg.id, llvm.LLVMGetParam(llfn, arg_n));
1000990
arg_n += 1u;
@@ -1035,6 +1025,42 @@ fn trans_mod(@trans_ctxt cx, &ast._mod m) {
10351025
}
10361026

10371027

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+
10381064
fn p2i(ValueRef v) -> ValueRef {
10391065
ret llvm.LLVMConstPtrToInt(v, T_int());
10401066
}
@@ -1163,10 +1189,12 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
11631189
upcalls = new_str_hash[ValueRef](),
11641190
fn_names = new_str_hash[ValueRef](),
11651191
fn_ids = new_def_hash[ValueRef](),
1192+
items = new_def_hash[@ast.item](),
11661193
glues = glues,
11671194
names = namegen(0),
11681195
path = "_rust");
11691196

1197+
collect_items(cx, crate);
11701198
trans_mod(cx, crate.node.module);
11711199
trans_exit_task_glue(cx);
11721200
trans_main_fn(cx, crate_constant(cx));

0 commit comments

Comments
 (0)