Skip to content

Commit 65707df

Browse files
committed
Use a struct instead of a tuple for inline asm output operands
1 parent ce5b035 commit 65707df

File tree

16 files changed

+87
-52
lines changed

16 files changed

+87
-52
lines changed

src/librustc/middle/cfg/construct.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
368368
}), pred);
369369
let post_outputs = self.exprs(outputs.map(|a| {
370370
debug!("cfg::construct InlineAsm id:{} output:{:?}", expr.id, a);
371-
let &(_, ref expr, _, _) = a;
372-
&**expr
371+
&*a.expr
373372
}), post_inputs);
374373
self.add_ast_node(expr.id, &[post_outputs])
375374
}

src/librustc/middle/expr_use_visitor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
458458
self.consume_expr(&**input);
459459
}
460460

461-
for &(_, ref output, is_rw, is_indirect) in &ia.outputs {
462-
if is_indirect {
463-
self.consume_expr(&**output);
461+
for output in &ia.outputs {
462+
if output.is_indirect {
463+
self.consume_expr(&*output.expr);
464464
} else {
465-
self.mutate_expr(expr, &**output,
466-
if is_rw { WriteAndRead } else { JustWrite });
465+
self.mutate_expr(expr, &*output.expr,
466+
if output.is_rw { WriteAndRead } else { JustWrite });
467467
}
468468
}
469469
}

src/librustc/middle/liveness.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1167,15 +1167,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11671167
hir::ExprInlineAsm(ref ia) => {
11681168

11691169
let succ = ia.outputs.iter().rev().fold(succ,
1170-
|succ, &(_, ref expr, is_rw, is_indirect)| {
1170+
|succ, out| {
11711171
// see comment on lvalues
11721172
// in propagate_through_lvalue_components()
1173-
if is_indirect {
1174-
self.propagate_through_expr(&**expr, succ)
1173+
if out.is_indirect {
1174+
self.propagate_through_expr(&*out.expr, succ)
11751175
} else {
1176-
let acc = if is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE };
1177-
let succ = self.write_lvalue(&**expr, succ, acc);
1178-
self.propagate_through_lvalue_components(&**expr, succ)
1176+
let acc = if out.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE };
1177+
let succ = self.write_lvalue(&*out.expr, succ, acc);
1178+
self.propagate_through_lvalue_components(&*out.expr, succ)
11791179
}
11801180
}
11811181
);
@@ -1423,11 +1423,11 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14231423
}
14241424

14251425
// Output operands must be lvalues
1426-
for &(_, ref out, _, is_indirect) in &ia.outputs {
1427-
if !is_indirect {
1428-
this.check_lvalue(&**out);
1426+
for out in &ia.outputs {
1427+
if !out.is_indirect {
1428+
this.check_lvalue(&*out.expr);
14291429
}
1430-
this.visit_expr(&**out);
1430+
this.visit_expr(&*out.expr);
14311431
}
14321432

14331433
intravisit::walk_expr(this, expr);

src/librustc_front/fold.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,13 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
11271127
expn_id,
11281128
}) => ExprInlineAsm(InlineAsm {
11291129
inputs: inputs.move_map(|(c, input)| (c, folder.fold_expr(input))),
1130-
outputs: outputs.move_map(|(c, out, is_rw, is_indirect)| {
1131-
(c, folder.fold_expr(out), is_rw, is_indirect)
1130+
outputs: outputs.move_map(|out| {
1131+
InlineAsmOutput {
1132+
constraint: out.constraint,
1133+
expr: folder.fold_expr(out.expr),
1134+
is_rw: out.is_rw,
1135+
is_indirect: out.is_indirect,
1136+
}
11321137
}),
11331138
asm: asm,
11341139
asm_str_style: asm_str_style,

src/librustc_front/hir.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,19 @@ pub enum Ty_ {
887887
TyInfer,
888888
}
889889

890+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
891+
pub struct InlineAsmOutput {
892+
pub constraint: InternedString,
893+
pub expr: P<Expr>,
894+
pub is_rw: bool,
895+
pub is_indirect: bool,
896+
}
897+
890898
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
891899
pub struct InlineAsm {
892900
pub asm: InternedString,
893901
pub asm_str_style: StrStyle,
894-
pub outputs: Vec<(InternedString, P<Expr>, bool, bool)>,
902+
pub outputs: Vec<InlineAsmOutput>,
895903
pub inputs: Vec<(InternedString, P<Expr>)>,
896904
pub clobbers: Vec<InternedString>,
897905
pub volatile: bool,

src/librustc_front/intravisit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
803803
for &(_, ref input) in &ia.inputs {
804804
visitor.visit_expr(&input)
805805
}
806-
for &(_, ref output, _, _) in &ia.outputs {
807-
visitor.visit_expr(&output)
806+
for output in &ia.outputs {
807+
visitor.visit_expr(&output.expr)
808808
}
809809
}
810810
}

src/librustc_front/lowering.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,13 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
12021202
.map(|&(ref c, ref input)| (c.clone(), lower_expr(lctx, input)))
12031203
.collect(),
12041204
outputs: outputs.iter()
1205-
.map(|&(ref c, ref out, is_rw, is_indirect)| {
1206-
(c.clone(), lower_expr(lctx, out), is_rw, is_indirect)
1205+
.map(|out| {
1206+
hir::InlineAsmOutput {
1207+
constraint: out.constraint.clone(),
1208+
expr: lower_expr(lctx, &out.expr),
1209+
is_rw: out.is_rw,
1210+
is_indirect: out.is_indirect,
1211+
}
12071212
})
12081213
.collect(),
12091214
asm: asm.clone(),

src/librustc_front/print/pprust.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1502,15 +1502,15 @@ impl<'a> State<'a> {
15021502
try!(self.print_string(&a.asm, a.asm_str_style));
15031503
try!(self.word_space(":"));
15041504

1505-
try!(self.commasep(Inconsistent, &a.outputs, |s, &(ref co, ref o, is_rw, _)| {
1506-
match co.slice_shift_char() {
1507-
Some(('=', operand)) if is_rw => {
1505+
try!(self.commasep(Inconsistent, &a.outputs, |s, out| {
1506+
match out.constraint.slice_shift_char() {
1507+
Some(('=', operand)) if out.is_rw => {
15081508
try!(s.print_string(&format!("+{}", operand), ast::CookedStr))
15091509
}
1510-
_ => try!(s.print_string(&co, ast::CookedStr)),
1510+
_ => try!(s.print_string(&out.constraint, ast::CookedStr)),
15111511
}
15121512
try!(s.popen());
1513-
try!(s.print_expr(&**o));
1513+
try!(s.print_expr(&*out.expr));
15141514
try!(s.pclose());
15151515
Ok(())
15161516
}));

src/librustc_trans/trans/asm.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
4141
// Prepare the output operands
4242
let mut outputs = Vec::new();
4343
let mut inputs = Vec::new();
44-
for (i, &(ref c, ref out, is_rw, is_indirect)) in ia.outputs.iter().enumerate() {
45-
constraints.push((*c).clone());
44+
for (i, out) in ia.outputs.iter().enumerate() {
45+
constraints.push(out.constraint.clone());
4646

47-
let out_datum = unpack_datum!(bcx, expr::trans(bcx, &**out));
48-
if is_indirect {
47+
let out_datum = unpack_datum!(bcx, expr::trans(bcx, &*out.expr));
48+
if out.is_indirect {
4949
bcx = callee::trans_arg_datum(bcx,
50-
expr_ty(bcx, &**out),
50+
expr_ty(bcx, &*out.expr),
5151
out_datum,
5252
cleanup::CustomScope(temp_scope),
5353
callee::DontAutorefArg,
5454
&mut inputs);
55-
if is_rw {
55+
if out.is_rw {
5656
ext_inputs.push(*inputs.last().unwrap());
5757
ext_constraints.push(i.to_string());
5858
}
5959
} else {
6060
output_types.push(type_of::type_of(bcx.ccx(), out_datum.ty));
6161
outputs.push(out_datum.val);
62-
if is_rw {
62+
if out.is_rw {
6363
bcx = callee::trans_arg_datum(bcx,
64-
expr_ty(bcx, &**out),
64+
expr_ty(bcx, &*out.expr),
6565
out_datum,
6666
cleanup::CustomScope(temp_scope),
6767
callee::DontAutorefArg,

src/librustc_trans/trans/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ fn walk_expr(cx: &CrateContext,
480480
walk_expr(cx, &**exp, scope_stack, scope_map);
481481
}
482482

483-
for &(_, ref exp, _, _) in outputs {
484-
walk_expr(cx, &**exp, scope_stack, scope_map);
483+
for out in outputs {
484+
walk_expr(cx, &*out.expr, scope_stack, scope_map);
485485
}
486486
}
487487
}

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3393,8 +3393,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
33933393
for &(_, ref input) in &ia.inputs {
33943394
check_expr(fcx, &**input);
33953395
}
3396-
for &(_, ref out, _, _) in &ia.outputs {
3397-
check_expr(fcx, &**out);
3396+
for out in &ia.outputs {
3397+
check_expr(fcx, &*out.expr);
33983398
}
33993399
fcx.write_nil(id);
34003400
}

src/libsyntax/ast.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,19 @@ pub enum AsmDialect {
14581458
Intel,
14591459
}
14601460

1461+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1462+
pub struct InlineAsmOutput {
1463+
pub constraint: InternedString,
1464+
pub expr: P<Expr>,
1465+
pub is_rw: bool,
1466+
pub is_indirect: bool,
1467+
}
1468+
14611469
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14621470
pub struct InlineAsm {
14631471
pub asm: InternedString,
14641472
pub asm_str_style: StrStyle,
1465-
pub outputs: Vec<(InternedString, P<Expr>, bool, bool)>,
1473+
pub outputs: Vec<InlineAsmOutput>,
14661474
pub inputs: Vec<(InternedString, P<Expr>)>,
14671475
pub clobbers: Vec<InternedString>,
14681476
pub volatile: bool,

src/libsyntax/ext/asm.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
126126

127127
let is_rw = output.is_some();
128128
let is_indirect = constraint.contains("*");
129-
outputs.push((output.unwrap_or(constraint), out, is_rw, is_indirect));
129+
outputs.push(ast::InlineAsmOutput {
130+
constraint: output.unwrap_or(constraint),
131+
expr: out,
132+
is_rw: is_rw,
133+
is_indirect: is_indirect,
134+
});
130135
}
131136
}
132137
Inputs => {

src/libsyntax/fold.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,13 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
13031303
inputs: inputs.move_map(|(c, input)| {
13041304
(c, folder.fold_expr(input))
13051305
}),
1306-
outputs: outputs.move_map(|(c, out, is_rw, is_indirect)| {
1307-
(c, folder.fold_expr(out), is_rw, is_indirect)
1306+
outputs: outputs.move_map(|out| {
1307+
InlineAsmOutput {
1308+
constraint: out.constraint,
1309+
expr: folder.fold_expr(out.expr),
1310+
is_rw: out.is_rw,
1311+
is_indirect: out.is_indirect,
1312+
}
13081313
}),
13091314
asm: asm,
13101315
asm_str_style: asm_str_style,

src/libsyntax/print/pprust.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2221,16 +2221,16 @@ impl<'a> State<'a> {
22212221
try!(self.word_space(":"));
22222222

22232223
try!(self.commasep(Inconsistent, &a.outputs,
2224-
|s, &(ref co, ref o, is_rw, _)| {
2225-
match co.slice_shift_char() {
2226-
Some(('=', operand)) if is_rw => {
2224+
|s, out| {
2225+
match out.constraint.slice_shift_char() {
2226+
Some(('=', operand)) if out.is_rw => {
22272227
try!(s.print_string(&format!("+{}", operand),
22282228
ast::CookedStr))
22292229
}
2230-
_ => try!(s.print_string(&co, ast::CookedStr))
2230+
_ => try!(s.print_string(&out.constraint, ast::CookedStr))
22312231
}
22322232
try!(s.popen());
2233-
try!(s.print_expr(&**o));
2233+
try!(s.print_expr(&*out.expr));
22342234
try!(s.pclose());
22352235
Ok(())
22362236
}));

src/libsyntax/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
786786
for &(_, ref input) in &ia.inputs {
787787
visitor.visit_expr(&input)
788788
}
789-
for &(_, ref output, _, _) in &ia.outputs {
790-
visitor.visit_expr(&output)
789+
for output in &ia.outputs {
790+
visitor.visit_expr(&output.expr)
791791
}
792792
}
793793
}

0 commit comments

Comments
 (0)