Skip to content

Commit 203d691

Browse files
committed
libsyntax: use a struct for inline asm in ast.
1 parent 727a565 commit 203d691

File tree

10 files changed

+68
-49
lines changed

10 files changed

+68
-49
lines changed

src/librustc/middle/liveness.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,11 +1346,11 @@ pub impl Liveness {
13461346
self.propagate_through_expr(e, succ)
13471347
}
13481348

1349-
expr_inline_asm(_, ref ins, ref outs, _, _, _) =>{
1350-
let succ = do ins.foldr(succ) |&(_, expr), succ| {
1349+
expr_inline_asm(ref ia) =>{
1350+
let succ = do ia.inputs.foldr(succ) |&(_, expr), succ| {
13511351
self.propagate_through_expr(expr, succ)
13521352
};
1353-
do outs.foldr(succ) |&(_, expr), succ| {
1353+
do ia.outputs.foldr(succ) |&(_, expr), succ| {
13541354
self.propagate_through_expr(expr, succ)
13551355
}
13561356
}
@@ -1620,14 +1620,19 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
16201620
visit::visit_expr(expr, self, vt);
16211621
}
16221622

1623-
expr_inline_asm(_, ref ins, ref outs, _, _, _) => {
1624-
for ins.each |&(_, in)| {
1623+
expr_inline_asm(ref ia) => {
1624+
for ia.inputs.each |&(_, in)| {
16251625
(vt.visit_expr)(in, self, vt);
16261626
}
16271627

16281628
// Output operands must be lvalues
1629-
for outs.each |&(_, out)| {
1630-
self.check_lvalue(out, vt);
1629+
for ia.outputs.each |&(_, out)| {
1630+
match out.node {
1631+
expr_addr_of(_, inner) => {
1632+
self.check_lvalue(inner, vt);
1633+
}
1634+
_ => {}
1635+
}
16311636
(vt.visit_expr)(out, self, vt);
16321637
}
16331638

src/librustc/middle/trans/asm.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ use middle::trans::common::*;
2121
use middle::ty;
2222

2323
use syntax::ast;
24-
use syntax::ast::*;
2524

2625
// Take an inline assembly expression and splat it out via LLVM
27-
pub fn trans_inline_asm(bcx: block, asm: @~str, ins: &[(@~str, @expr)], outs: &[(@~str, @expr)],
28-
clobs: @~str, volatile: bool, alignstack: bool) -> block {
26+
pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
2927

3028
let mut bcx = bcx;
3129
let mut constraints = ~[];
3230
let mut cleanups = ~[];
3331
let mut aoutputs = ~[];
3432

3533
// Prepare the output operands
36-
let outputs = do outs.map |&(c, out)| {
34+
let outputs = do ia.outputs.map |&(c, out)| {
3735
constraints.push(copy *c);
3836

3937
let aoutty = ty::arg {
@@ -66,7 +64,7 @@ pub fn trans_inline_asm(bcx: block, asm: @~str, ins: &[(@~str, @expr)], outs: &[
6664
cleanups.clear();
6765
6866
// Now the input operands
69-
let inputs = do ins.map |&(c, in)| {
67+
let inputs = do ia.inputs.map |&(c, in)| {
7068
constraints.push(copy *c);
7169
7270
let inty = ty::arg {
@@ -87,10 +85,10 @@ pub fn trans_inline_asm(bcx: block, asm: @~str, ins: &[(@~str, @expr)], outs: &[
8785
let mut constraints = str::connect(constraints, ",");
8886
8987
// Add the clobbers to our constraints list
90-
if *clobs != ~"" && constraints != ~"" {
91-
constraints += ~"," + *clobs;
88+
if *ia.clobbers != ~"" && constraints != ~"" {
89+
constraints += ~"," + *ia.clobbers;
9290
} else {
93-
constraints += *clobs;
91+
constraints += *ia.clobbers;
9492
}
9593
9694
debug!("Asm Constraints: %?", constraints);
@@ -106,10 +104,10 @@ pub fn trans_inline_asm(bcx: block, asm: @~str, ins: &[(@~str, @expr)], outs: &[
106104
T_struct(outputs.map(|o| val_ty(*o)))
107105
};
108106

109-
let r = do str::as_c_str(*asm) |a| {
107+
let r = do str::as_c_str(*ia.asm) |a| {
110108
do str::as_c_str(constraints) |c| {
111109
// XXX: Allow selection of at&t or intel
112-
InlineAsmCall(bcx, a, c, inputs, output, volatile, alignstack, lib::llvm::AD_ATT)
110+
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, lib::llvm::AD_ATT)
113111
}
114112
};
115113

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,8 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
558558
ast::expr_paren(a) => {
559559
return trans_rvalue_stmt_unadjusted(bcx, a);
560560
}
561-
ast::expr_inline_asm(asm, ref ins, ref outs,
562-
clobs, volatile, alignstack) => {
563-
return asm::trans_inline_asm(bcx, asm, *ins, *outs, clobs, volatile, alignstack);
561+
ast::expr_inline_asm(ref a) => {
562+
return asm::trans_inline_asm(bcx, a);
564563
}
565564
_ => {
566565
bcx.tcx().sess.span_bug(

src/librustc/middle/trans/type_use.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
360360
mark_for_method_call(cx, e.id, e.callee_id);
361361
}
362362

363-
expr_inline_asm(_, ref ins, ref outs, _, _, _) => {
364-
for ins.each |&(_, in)| {
363+
expr_inline_asm(ref ia) => {
364+
for ia.inputs.each |&(_, in)| {
365365
node_type_needs(cx, use_repr, in.id);
366366
}
367-
for outs.each |&(_, out)| {
367+
for ia.outputs.each |&(_, out)| {
368368
node_type_needs(cx, use_repr, out.id);
369369
}
370370
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,13 +2332,13 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
23322332
let region_lb = ty::re_scope(expr.id);
23332333
instantiate_path(fcx, pth, tpt, expr.span, expr.id, region_lb);
23342334
}
2335-
ast::expr_inline_asm(_, ref ins, ref outs, _, _, _) => {
2335+
ast::expr_inline_asm(ref ia) => {
23362336
fcx.require_unsafe(expr.span, ~"use of inline assembly");
23372337

2338-
for ins.each |&(_, in)| {
2338+
for ia.inputs.each |&(_, in)| {
23392339
check_expr(fcx, in);
23402340
}
2341-
for outs.each |&(_, out)| {
2341+
for ia.outputs.each |&(_, out)| {
23422342
check_expr(fcx, out);
23432343
}
23442344
fcx.write_nil(id);

src/libsyntax/ast.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,7 @@ pub enum expr_ {
600600
expr_ret(Option<@expr>),
601601
expr_log(log_level, @expr, @expr),
602602
603-
expr_inline_asm(@~str, // asm
604-
~[(@~str, @expr)], // inputs
605-
~[(@~str, @expr)], // outputs
606-
@~str, bool, bool), // clobbers, volatile, align stack
603+
expr_inline_asm(inline_asm),
607604
608605
expr_mac(mac),
609606
@@ -937,6 +934,18 @@ impl to_bytes::IterBytes for Ty {
937934
}
938935
}
939936
937+
#[auto_encode]
938+
#[auto_decode]
939+
#[deriving(Eq)]
940+
pub struct inline_asm {
941+
asm: @~str,
942+
clobbers: @~str,
943+
inputs: ~[(@~str, @expr)],
944+
outputs: ~[(@~str, @expr)],
945+
volatile: bool,
946+
alignstack: bool
947+
}
948+
940949
#[auto_encode]
941950
#[auto_decode]
942951
#[deriving(Eq)]

src/libsyntax/ext/asm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
5959
match state {
6060
Asm => {
6161
asm = expr_to_str(cx, p.parse_expr(),
62-
~"inline assembly must be a string literal.");
62+
~"inline assembly must be a string literal.");
6363
}
6464
Outputs => {
6565
while *p.token != token::EOF &&
@@ -163,8 +163,14 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
163163
MRExpr(@ast::expr {
164164
id: cx.next_id(),
165165
callee_id: cx.next_id(),
166-
node: ast::expr_inline_asm(@asm, inputs, outputs,
167-
@cons, volatile, alignstack),
166+
node: ast::expr_inline_asm(ast::inline_asm {
167+
asm: @asm,
168+
clobbers: @cons,
169+
inputs: inputs,
170+
outputs: outputs,
171+
volatile: volatile,
172+
alignstack: alignstack
173+
}),
168174
span: sp
169175
})
170176
}

src/libsyntax/fold.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,15 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
559559
fld.fold_expr(e)
560560
)
561561
}
562-
expr_inline_asm(asm, ins, outs, c, v, a) => {
563-
expr_inline_asm(
564-
asm,
565-
ins.map(|&(c, in)| (c, fld.fold_expr(in))),
566-
outs.map(|&(c, out)| (c, fld.fold_expr(out))),
567-
c, v, a
568-
)
562+
expr_inline_asm(a) => {
563+
expr_inline_asm(inline_asm {
564+
asm: a.asm,
565+
clobbers: a.clobbers,
566+
inputs: a.inputs.map(|&(c, in)| (c, fld.fold_expr(in))),
567+
outputs: a.outputs.map(|&(c, out)| (c, fld.fold_expr(out))),
568+
volatile: a.volatile,
569+
alignstack: a.alignstack
570+
})
569571
}
570572
expr_mac(ref mac) => expr_mac(fold_mac((*mac))),
571573
expr_struct(path, ref fields, maybe_expr) => {

src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,32 +1406,32 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
14061406
}
14071407
}
14081408
}
1409-
ast::expr_inline_asm(a, in, out, c, v, _) => {
1410-
if v {
1409+
ast::expr_inline_asm(a) => {
1410+
if a.volatile {
14111411
word(s.s, ~"__volatile__ asm!");
14121412
} else {
14131413
word(s.s, ~"asm!");
14141414
}
14151415
popen(s);
1416-
print_string(s, *a);
1416+
print_string(s, *a.asm);
14171417
word_space(s, ~":");
1418-
for out.each |&(co, o)| {
1418+
for a.outputs.each |&(co, o)| {
14191419
print_string(s, *co);
14201420
popen(s);
14211421
print_expr(s, o);
14221422
pclose(s);
14231423
word_space(s, ~",");
14241424
}
14251425
word_space(s, ~":");
1426-
for in.each |&(co, o)| {
1426+
for a.inputs.each |&(co, o)| {
14271427
print_string(s, *co);
14281428
popen(s);
14291429
print_expr(s, o);
14301430
pclose(s);
14311431
word_space(s, ~",");
14321432
}
14331433
word_space(s, ~":");
1434-
print_string(s, *c);
1434+
print_string(s, *a.clobbers);
14351435
pclose(s);
14361436
}
14371437
ast::expr_mac(ref m) => print_mac(s, (*m)),

src/libsyntax/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
565565
}
566566
expr_mac(ref mac) => visit_mac((*mac), e, v),
567567
expr_paren(x) => (v.visit_expr)(x, e, v),
568-
expr_inline_asm(_, ins, outs, _, _, _) => {
569-
for ins.each |&(_, in)| {
568+
expr_inline_asm(ref a) => {
569+
for a.inputs.each |&(_, in)| {
570570
(v.visit_expr)(in, e, v);
571571
}
572-
for outs.each |&(_, out)| {
572+
for a.outputs.each |&(_, out)| {
573573
(v.visit_expr)(out, e, v);
574574
}
575575
}

0 commit comments

Comments
 (0)