Skip to content

Commit 02d74a4

Browse files
committed
Make trans_arg_datum fill a destination vector instead of returning its result
This makes it easier to support translating a single rust argument to more than one llvm argument value later.
1 parent dea5a96 commit 02d74a4

File tree

2 files changed

+57
-61
lines changed

2 files changed

+57
-61
lines changed

src/librustc_trans/trans/asm.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,31 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
4545
output_types.push(type_of::type_of(bcx.ccx(), out_datum.ty));
4646
let val = out_datum.val;
4747
if is_rw {
48-
ext_inputs.push(unpack_result!(bcx, {
49-
callee::trans_arg_datum(bcx,
50-
expr_ty(bcx, &**out),
51-
out_datum,
52-
cleanup::CustomScope(temp_scope),
53-
callee::DontAutorefArg)
54-
}));
48+
bcx = callee::trans_arg_datum(bcx,
49+
expr_ty(bcx, &**out),
50+
out_datum,
51+
cleanup::CustomScope(temp_scope),
52+
callee::DontAutorefArg,
53+
&mut ext_inputs);
5554
ext_constraints.push(i.to_string());
5655
}
5756
val
5857

5958
}).collect::<Vec<_>>();
6059

6160
// Now the input operands
62-
let mut inputs = ia.inputs.iter().map(|&(ref c, ref input)| {
61+
let mut inputs = Vec::new();
62+
for &(ref c, ref input) in &ia.inputs {
6363
constraints.push((*c).clone());
6464

6565
let in_datum = unpack_datum!(bcx, expr::trans(bcx, &**input));
66-
unpack_result!(bcx, {
67-
callee::trans_arg_datum(bcx,
66+
bcx = callee::trans_arg_datum(bcx,
6867
expr_ty(bcx, &**input),
6968
in_datum,
7069
cleanup::CustomScope(temp_scope),
71-
callee::DontAutorefArg)
72-
})
73-
}).collect::<Vec<_>>();
70+
callee::DontAutorefArg,
71+
&mut inputs);
72+
}
7473
inputs.push_all(&ext_inputs[..]);
7574

7675
// no failure occurred preparing operands, no need to cleanup

src/librustc_trans/trans/callee.rs

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -921,13 +921,12 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
921921
// Translate the `self` argument first.
922922
if !ignore_self {
923923
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0]));
924-
llargs.push(unpack_result!(bcx, {
925-
trans_arg_datum(bcx,
926-
args[0],
927-
arg_datum,
928-
arg_cleanup_scope,
929-
DontAutorefArg)
930-
}))
924+
bcx = trans_arg_datum(bcx,
925+
args[0],
926+
arg_datum,
927+
arg_cleanup_scope,
928+
DontAutorefArg,
929+
llargs);
931930
}
932931

933932
// Now untuple the rest of the arguments.
@@ -945,21 +944,20 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
945944
tuple_expr.id));
946945
let repr = adt::represent_type(bcx.ccx(), tuple_type);
947946
let repr_ptr = &*repr;
948-
llargs.extend(field_types.iter().enumerate().map(|(i, field_type)| {
947+
for (i, field_type) in field_types.iter().enumerate() {
949948
let arg_datum = tuple_lvalue_datum.get_element(
950949
bcx,
951950
field_type,
952951
|srcval| {
953952
adt::trans_field_ptr(bcx, repr_ptr, srcval, 0, i)
954953
}).to_expr_datum();
955-
unpack_result!(bcx, trans_arg_datum(
956-
bcx,
957-
field_type,
958-
arg_datum,
959-
arg_cleanup_scope,
960-
DontAutorefArg)
961-
)
962-
}));
954+
bcx = trans_arg_datum(bcx,
955+
field_type,
956+
arg_datum,
957+
arg_cleanup_scope,
958+
DontAutorefArg,
959+
llargs);
960+
}
963961
}
964962
_ => {
965963
bcx.sess().span_bug(tuple_expr.span,
@@ -982,13 +980,12 @@ fn trans_overloaded_call_args<'blk, 'tcx>(
982980
let arg_tys = ty::erase_late_bound_regions(bcx.tcx(), &ty::ty_fn_args(fn_ty));
983981
if !ignore_self {
984982
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, arg_exprs[0]));
985-
llargs.push(unpack_result!(bcx, {
986-
trans_arg_datum(bcx,
987-
arg_tys[0],
988-
arg_datum,
989-
arg_cleanup_scope,
990-
DontAutorefArg)
991-
}))
983+
bcx = trans_arg_datum(bcx,
984+
arg_tys[0],
985+
arg_datum,
986+
arg_cleanup_scope,
987+
DontAutorefArg,
988+
llargs);
992989
}
993990

994991
// Now untuple the rest of the arguments.
@@ -998,13 +995,12 @@ fn trans_overloaded_call_args<'blk, 'tcx>(
998995
for (i, &field_type) in field_types.iter().enumerate() {
999996
let arg_datum =
1000997
unpack_datum!(bcx, expr::trans(bcx, arg_exprs[i + 1]));
1001-
llargs.push(unpack_result!(bcx, {
1002-
trans_arg_datum(bcx,
1003-
field_type,
1004-
arg_datum,
1005-
arg_cleanup_scope,
1006-
DontAutorefArg)
1007-
}))
998+
bcx = trans_arg_datum(bcx,
999+
field_type,
1000+
arg_datum,
1001+
arg_cleanup_scope,
1002+
DontAutorefArg,
1003+
llargs);
10081004
}
10091005
}
10101006
_ => {
@@ -1061,11 +1057,10 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
10611057
};
10621058

10631059
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &**arg_expr));
1064-
llargs.push(unpack_result!(bcx, {
1065-
trans_arg_datum(bcx, arg_ty, arg_datum,
1066-
arg_cleanup_scope,
1067-
DontAutorefArg)
1068-
}));
1060+
bcx = trans_arg_datum(bcx, arg_ty, arg_datum,
1061+
arg_cleanup_scope,
1062+
DontAutorefArg,
1063+
llargs);
10691064
}
10701065
}
10711066
ArgOverloadedCall(arg_exprs) => {
@@ -1079,19 +1074,17 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
10791074
ArgOverloadedOp(lhs, rhs, autoref) => {
10801075
assert!(!variadic);
10811076

1082-
llargs.push(unpack_result!(bcx, {
1083-
trans_arg_datum(bcx, arg_tys[0], lhs,
1084-
arg_cleanup_scope,
1085-
DontAutorefArg)
1086-
}));
1077+
bcx = trans_arg_datum(bcx, arg_tys[0], lhs,
1078+
arg_cleanup_scope,
1079+
DontAutorefArg,
1080+
llargs);
10871081

10881082
assert_eq!(arg_tys.len(), 1 + rhs.len());
10891083
for (rhs, rhs_id) in rhs {
1090-
llargs.push(unpack_result!(bcx, {
1091-
trans_arg_datum(bcx, arg_tys[1], rhs,
1092-
arg_cleanup_scope,
1093-
if autoref { DoAutorefArg(rhs_id) } else { DontAutorefArg })
1094-
}));
1084+
bcx = trans_arg_datum(bcx, arg_tys[1], rhs,
1085+
arg_cleanup_scope,
1086+
if autoref { DoAutorefArg(rhs_id) } else { DontAutorefArg },
1087+
llargs);
10951088
}
10961089
}
10971090
ArgVals(vs) => {
@@ -1112,8 +1105,9 @@ pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11121105
formal_arg_ty: Ty<'tcx>,
11131106
arg_datum: Datum<'tcx, Expr>,
11141107
arg_cleanup_scope: cleanup::ScopeId,
1115-
autoref_arg: AutorefArg)
1116-
-> Result<'blk, 'tcx> {
1108+
autoref_arg: AutorefArg,
1109+
llargs: &mut Vec<ValueRef>)
1110+
-> Block<'blk, 'tcx> {
11171111
let _icx = push_ctxt("trans_arg_datum");
11181112
let mut bcx = bcx;
11191113
let ccx = bcx.ccx();
@@ -1164,5 +1158,8 @@ pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11641158
}
11651159

11661160
debug!("--- trans_arg_datum passing {}", bcx.val_to_string(val));
1167-
Result::new(bcx, val)
1161+
1162+
llargs.push(val);
1163+
1164+
bcx
11681165
}

0 commit comments

Comments
 (0)