Skip to content

Commit 6d078db

Browse files
committed
Actually pass inline asm operands around.
1 parent 471d2b1 commit 6d078db

File tree

10 files changed

+100
-24
lines changed

10 files changed

+100
-24
lines changed

src/librustc/middle/liveness.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,15 @@ pub impl Liveness {
13471347
self.propagate_through_expr(e, succ)
13481348
}
13491349
1350-
expr_inline_asm(*) |
1350+
expr_inline_asm(_, ins, outs, _, _, _) =>{
1351+
let succ = do ins.foldr(succ) |&(_, expr), succ| {
1352+
self.propagate_through_expr(expr, succ)
1353+
};
1354+
do outs.foldr(succ) |&(_, expr), succ| {
1355+
self.propagate_through_expr(expr, succ)
1356+
}
1357+
}
1358+
13511359
expr_lit(*) => {
13521360
succ
13531361
}
@@ -1613,6 +1621,20 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
16131621
visit::visit_expr(expr, self, vt);
16141622
}
16151623

1624+
expr_inline_asm(_, ins, outs, _, _, _) => {
1625+
for ins.each |&(_, in)| {
1626+
(vt.visit_expr)(in, self, vt);
1627+
}
1628+
1629+
// Output operands must be lvalues
1630+
for outs.each |&(_, out)| {
1631+
self.check_lvalue(out, vt);
1632+
(vt.visit_expr)(out, self, vt);
1633+
}
1634+
1635+
visit::visit_expr(expr, self, vt);
1636+
}
1637+
16161638
// no correctness conditions related to liveness
16171639
expr_call(*) | expr_method_call(*) | expr_if(*) | expr_match(*) |
16181640
expr_while(*) | expr_loop(*) | expr_index(*) | expr_field(*) |
@@ -1621,7 +1643,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
16211643
expr_cast(*) | expr_unary(*) | expr_ret(*) | expr_break(*) |
16221644
expr_again(*) | expr_lit(_) | expr_block(*) | expr_swap(*) |
16231645
expr_mac(*) | expr_addr_of(*) | expr_struct(*) | expr_repeat(*) |
1624-
expr_paren(*) | expr_inline_asm(*) => {
1646+
expr_paren(*) => {
16251647
visit::visit_expr(expr, self, vt);
16261648
}
16271649
}

src/librustc/middle/moves.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,18 @@ pub impl VisitContext {
558558
self.use_expr(base, Read, visitor);
559559
}
560560

561+
expr_inline_asm(_, ref ins, ref outs, _, _, _) => {
562+
for ins.each |&(c, in)| {
563+
// XXX: Do something?
564+
}
565+
for outs.each |&(c, out)| {
566+
// XXX: Do something?
567+
}
568+
}
569+
561570
expr_break(*) |
562571
expr_again(*) |
563-
expr_lit(*) |
564-
expr_inline_asm(*) => {}
572+
expr_lit(*) => {}
565573

566574
expr_loop(ref blk, _) => {
567575
self.consume_block(blk, visitor);

src/librustc/middle/trans/expr.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,18 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
557557
ast::expr_paren(a) => {
558558
return trans_rvalue_stmt_unadjusted(bcx, a);
559559
}
560+
ast::expr_inline_asm(asm, ref ins, ref outs,
561+
cons, volatile, alignstack) => {
562+
// XXX: cons doesn't actual contain ALL the stuff we should
563+
// be passing since the constraints for in/outputs aren't included
564+
do str::as_c_str(*asm) |a| {
565+
do str::as_c_str(*cons) |c| {
566+
InlineAsmCall(bcx, a, c, volatile, alignstack,
567+
lib::llvm::AD_ATT);
568+
}
569+
}
570+
return bcx;
571+
}
560572
_ => {
561573
bcx.tcx().sess.span_bug(
562574
expr.span,
@@ -691,17 +703,6 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
691703
ast::expr_assign_op(op, dst, src) => {
692704
return trans_assign_op(bcx, expr, op, dst, src);
693705
}
694-
ast::expr_inline_asm(asm, cons, volatile, alignstack) => {
695-
// XXX: cons doesn't actual contain ALL the stuff we should
696-
// be passing since the constraints for in/outputs aren't included
697-
do str::as_c_str(*asm) |a| {
698-
do str::as_c_str(*cons) |c| {
699-
InlineAsmCall(bcx, a, c, volatile, alignstack,
700-
lib::llvm::AD_ATT);
701-
}
702-
}
703-
return bcx;
704-
}
705706
_ => {
706707
bcx.tcx().sess.span_bug(
707708
expr.span,

src/librustc/middle/trans/type_use.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,17 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
348348
}
349349
mark_for_method_call(cx, e.id, e.callee_id);
350350
}
351+
352+
expr_inline_asm(_, ref ins, ref outs, _, _, _) => {
353+
// XXX Do something, maybe?
354+
}
355+
351356
expr_paren(e) => mark_for_expr(cx, e),
352357

353358
expr_match(*) | expr_block(_) | expr_if(*) | expr_while(*) |
354359
expr_break(_) | expr_again(_) | expr_unary(_, _) | expr_lit(_) |
355360
expr_mac(_) | expr_addr_of(_, _) | expr_ret(_) | expr_loop(_, _) |
356-
expr_loop_body(_) | expr_do_body(_) | expr_inline_asm(*) => ()
361+
expr_loop_body(_) | expr_do_body(_) => ()
357362
}
358363
}
359364

src/librustc/middle/typeck/check/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,8 +2317,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
23172317
let region_lb = ty::re_scope(expr.id);
23182318
instantiate_path(fcx, pth, tpt, expr.span, expr.id, region_lb);
23192319
}
2320-
ast::expr_inline_asm(*) => {
2320+
ast::expr_inline_asm(_, ins, outs, _, _, _) => {
23212321
fcx.require_unsafe(expr.span, ~"use of inline assembly");
2322+
2323+
for ins.each |&(_, in)| {
2324+
check_expr(fcx, in);
2325+
}
2326+
for outs.each |&(_, out)| {
2327+
check_expr(fcx, out);
2328+
}
23222329
fcx.write_nil(id);
23232330
}
23242331
ast::expr_mac(_) => tcx.sess.bug(~"unexpanded macro"),

src/libsyntax/ast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,10 @@ pub enum expr_ {
601601
expr_ret(Option<@expr>),
602602
expr_log(log_level, @expr, @expr),
603603
604-
/* asm, clobbers + constraints, volatile, align stack */
605-
expr_inline_asm(@~str, @~str, bool, bool),
604+
expr_inline_asm(@~str, // asm
605+
~[(@~str, @expr)], // inputs
606+
~[(@~str, @expr)], // outputs
607+
@~str, bool, bool), // clobbers, volatile, align stack
606608
607609
expr_mac(mac),
608610

src/libsyntax/ext/asm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
156156
MRExpr(@ast::expr {
157157
id: cx.next_id(),
158158
callee_id: cx.next_id(),
159-
node: ast::expr_inline_asm(@asm, @cons, volatile, alignstack),
159+
node: ast::expr_inline_asm(@asm, inputs, outputs,
160+
@cons, volatile, alignstack),
160161
span: sp
161162
})
162163
}

src/libsyntax/fold.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,14 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
560560
fld.fold_expr(e)
561561
)
562562
}
563-
expr_inline_asm(*) => copy *e,
563+
expr_inline_asm(asm, ins, outs, c, v, a) => {
564+
expr_inline_asm(
565+
asm,
566+
ins.map(|&(c, in)| (c, fld.fold_expr(in))),
567+
outs.map(|&(c, out)| (c, fld.fold_expr(out))),
568+
c, v, a
569+
)
570+
}
564571
expr_mac(ref mac) => expr_mac(fold_mac((*mac))),
565572
expr_struct(path, ref fields, maybe_expr) => {
566573
expr_struct(

src/libsyntax/print/pprust.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,15 +1403,31 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
14031403
}
14041404
}
14051405
}
1406-
ast::expr_inline_asm(a, c, v, _) => {
1406+
ast::expr_inline_asm(a, in, out, c, v, _) => {
14071407
if v {
14081408
word(s.s, ~"__volatile__ asm!");
14091409
} else {
14101410
word(s.s, ~"asm!");
14111411
}
14121412
popen(s);
14131413
print_string(s, *a);
1414-
word_space(s, ~",");
1414+
word_space(s, ~":");
1415+
for out.each |&(co, o)| {
1416+
print_string(s, *co);
1417+
popen(s);
1418+
print_expr(s, o);
1419+
pclose(s);
1420+
word_space(s, ~",");
1421+
}
1422+
word_space(s, ~":");
1423+
for in.each |&(co, o)| {
1424+
print_string(s, *co);
1425+
popen(s);
1426+
print_expr(s, o);
1427+
pclose(s);
1428+
word_space(s, ~",");
1429+
}
1430+
word_space(s, ~":");
14151431
print_string(s, *c);
14161432
pclose(s);
14171433
}

src/libsyntax/visit.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,14 @@ pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
562562
}
563563
expr_mac(ref mac) => visit_mac((*mac), e, v),
564564
expr_paren(x) => (v.visit_expr)(x, e, v),
565-
expr_inline_asm(*) => (),
565+
expr_inline_asm(_, ins, outs, _, _, _) => {
566+
for ins.each |&(c, in)| {
567+
(v.visit_expr)(in, e, v);
568+
}
569+
for outs.each |&(c, out)| {
570+
(v.visit_expr)(out, e, v);
571+
}
572+
}
566573
}
567574
(v.visit_expr_post)(ex, e, v);
568575
}

0 commit comments

Comments
 (0)