Skip to content

Commit b3e7c8b

Browse files
committed
---
yaml --- r: 831 b: refs/heads/master c: 3f80e79 h: refs/heads/master i: 829: 731b370 827: 81f2d99 823: 6f66da4 815: 7cc4543 799: 75d9334 767: bcfd006 v: v3
1 parent 537b864 commit b3e7c8b

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
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: 67477b85ae7404508e3a963d68dbfb09a3d247f9
2+
refs/heads/master: 3f80e79efc6feaabea960793af1ff5baa1d2f141

trunk/src/comp/middle/trans.rs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ type glue_fns = rec(ValueRef activate_glue,
4242

4343
state type trans_ctxt = rec(session.session sess,
4444
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,
4848
@glue_fns glues,
4949
namegen names,
5050
str path);
5151

5252
state type fn_ctxt = rec(ValueRef llfn,
5353
ValueRef lloutptr,
5454
ValueRef lltaskptr,
55+
hashmap[ast.def_id, ValueRef] llargs,
5556
hashmap[ast.def_id, ValueRef] lllocals,
5657
@trans_ctxt tcx);
5758

@@ -659,17 +660,25 @@ fn trans_if(@block_ctxt cx, &ast.expr cond,
659660
ret res(next_cx, phi);
660661
}
661662

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) {
663668
alt (e.node) {
664669
case (ast.expr_name(?n, ?dopt, _)) {
665670
alt (dopt) {
666671
case (some[ast.def](?def)) {
667672
alt (def) {
673+
case (ast.def_arg(?did)) {
674+
ret tup(res(cx, cx.fcx.llargs.get(did)), false);
675+
}
668676
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);
670678
}
671679
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);
673682
}
674683
case (_) {
675684
cx.fcx.tcx.sess.unimpl("def variant in trans");
@@ -731,24 +740,30 @@ fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
731740

732741
case (ast.expr_name(_,_,_)) {
733742
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+
}
735748
}
736749

737750
case (ast.expr_assign(?dst, ?src, _)) {
738751
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);
740754
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));
742756
}
743757

744758
case (ast.expr_call(?f, ?args, _)) {
745759
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);
747762
auto llargs = vec(cx.fcx.lloutptr,
748763
cx.fcx.lltaskptr);
749764
llargs += args_res._1;
750765
ret res(args_res._0,
751-
cx.build.Call(f_res.val, llargs));
766+
cx.build.Call(f_res._0.val, llargs));
752767
}
753768

754769
}
@@ -923,31 +938,46 @@ fn trans_block(@block_ctxt cx, &ast.block b) -> result {
923938

924939
fn new_fn_ctxt(@trans_ctxt cx,
925940
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.
930945
T_taskptr() // taskptr
931946
);
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+
}
932953
args += T_explicit_args;
954+
933955
let ValueRef llfn = decl_cdecl_fn(cx.llmod, name, args, T_void());
934956
cx.fn_names.insert(cx.path, llfn);
935957
cx.fn_ids.insert(fid, llfn);
958+
936959
let ValueRef lloutptr = llvm.LLVMGetParam(llfn, 0u);
937960
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 1u);
961+
938962
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 += 1u;
968+
}
969+
939970
ret @rec(llfn=llfn,
940971
lloutptr=lloutptr,
941972
lltaskptr=lltaskptr,
973+
llargs=llargs,
942974
lllocals=lllocals,
943975
tcx=cx);
944976
}
945977

946978
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();
949979

950-
auto fcx = new_fn_ctxt(cx, cx.path, fid, out, args);
980+
auto fcx = new_fn_ctxt(cx, cx.path, f, fid);
951981

952982
trans_block(new_top_block_ctxt(fcx), f.body);
953983
}
@@ -986,6 +1016,7 @@ fn trans_exit_task_glue(@trans_ctxt cx) {
9861016
auto fcx = @rec(llfn=llfn,
9871017
lloutptr=lloutptr,
9881018
lltaskptr=lltaskptr,
1019+
llargs=new_def_hash[ValueRef](),
9891020
lllocals=new_def_hash[ValueRef](),
9901021
tcx=cx);
9911022

0 commit comments

Comments
 (0)