diff options
| author | bors <bors@rust-lang.org> | 2013-03-28 18:18:46 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-28 18:18:46 -0700 |
| commit | f81459211d0cf2738ed02f5c7fe24f56c8032960 (patch) | |
| tree | d67a85c098dd7a2af05bd4ef4a3155f115565169 /src/libsyntax | |
| parent | 943d7adedc2401b54e103ea3635d0e50b1822d5a (diff) | |
| parent | a3996c1626003472437b9c29e179583daf9e53bf (diff) | |
| download | rust-f81459211d0cf2738ed02f5c7fe24f56c8032960.tar.gz rust-f81459211d0cf2738ed02f5c7fe24f56c8032960.zip | |
auto merge of #5593 : luqmana/rust/inline-asm, r=catamorphism
Clean things up a bit. Also, allow selecting intel syntax in addition to the default AT&T dialect.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/ext/asm.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 6 |
5 files changed, 50 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7304eb20bca..c2f098f3c3e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -593,10 +593,7 @@ pub enum expr_ { expr_ret(Option<@expr>), expr_log(@expr, @expr), - expr_inline_asm(@~str, // asm - ~[(@~str, @expr)], // inputs - ~[(@~str, @expr)], // outputs - @~str, bool, bool), // clobbers, volatile, align stack + expr_inline_asm(inline_asm), expr_mac(mac), @@ -933,6 +930,27 @@ impl to_bytes::IterBytes for Ty { #[auto_encode] #[auto_decode] #[deriving(Eq)] +pub enum asm_dialect { + asm_att, + asm_intel +} + +#[auto_encode] +#[auto_decode] +#[deriving(Eq)] +pub struct inline_asm { + asm: @~str, + clobbers: @~str, + inputs: ~[(@~str, @expr)], + outputs: ~[(@~str, @expr)], + volatile: bool, + alignstack: bool, + dialect: asm_dialect +} + +#[auto_encode] +#[auto_decode] +#[deriving(Eq)] pub struct arg { mode: mode, is_mutbl: bool, diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index a014d8ccb8b..b070948d405 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -53,13 +53,14 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) let mut cons = ~""; let mut volatile = false; let mut alignstack = false; + let mut dialect = ast::asm_att; let mut state = Asm; loop outer: { match state { Asm => { asm = expr_to_str(cx, p.parse_expr(), - ~"inline assembly must be a string literal."); + ~"inline assembly must be a string literal."); } Outputs => { while *p.token != token::EOF && @@ -125,6 +126,8 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) volatile = true; } else if option == ~"alignstack" { alignstack = true; + } else if option == ~"intel" { + dialect = ast::asm_intel; } if *p.token == token::COMMA { @@ -163,8 +166,15 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) MRExpr(@ast::expr { id: cx.next_id(), callee_id: cx.next_id(), - node: ast::expr_inline_asm(@asm, inputs, outputs, - @cons, volatile, alignstack), + node: ast::expr_inline_asm(ast::inline_asm { + asm: @asm, + clobbers: @cons, + inputs: inputs, + outputs: outputs, + volatile: volatile, + alignstack: alignstack, + dialect: dialect + }), span: sp }) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index f0885afa580..f43e541052e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -555,13 +555,12 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { fld.fold_expr(e) ) } - expr_inline_asm(asm, ins, outs, c, v, a) => { - expr_inline_asm( - asm, - ins.map(|&(c, in)| (c, fld.fold_expr(in))), - outs.map(|&(c, out)| (c, fld.fold_expr(out))), - c, v, a - ) + expr_inline_asm(a) => { + expr_inline_asm(inline_asm { + inputs: a.inputs.map(|&(c, in)| (c, fld.fold_expr(in))), + outputs: a.outputs.map(|&(c, out)| (c, fld.fold_expr(out))), + .. a + }) } expr_mac(ref mac) => expr_mac(fold_mac((*mac))), expr_struct(path, ref fields, maybe_expr) => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 58fbba752f5..242156f2d7e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1388,16 +1388,16 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { print_expr(s, expr); pclose(s); } - ast::expr_inline_asm(a, in, out, c, v, _) => { - if v { + ast::expr_inline_asm(a) => { + if a.volatile { word(s.s, ~"__volatile__ asm!"); } else { word(s.s, ~"asm!"); } popen(s); - print_string(s, *a); + print_string(s, *a.asm); word_space(s, ~":"); - for out.each |&(co, o)| { + for a.outputs.each |&(co, o)| { print_string(s, *co); popen(s); print_expr(s, o); @@ -1405,7 +1405,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { word_space(s, ~","); } word_space(s, ~":"); - for in.each |&(co, o)| { + for a.inputs.each |&(co, o)| { print_string(s, *co); popen(s); print_expr(s, o); @@ -1413,7 +1413,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { word_space(s, ~","); } word_space(s, ~":"); - print_string(s, *c); + print_string(s, *a.clobbers); pclose(s); } ast::expr_mac(ref m) => print_mac(s, (*m)), diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 33b345e2d11..dd724948b32 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -562,11 +562,11 @@ pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } expr_mac(ref mac) => visit_mac((*mac), e, v), expr_paren(x) => (v.visit_expr)(x, e, v), - expr_inline_asm(_, ins, outs, _, _, _) => { - for ins.each |&(_, in)| { + expr_inline_asm(ref a) => { + for a.inputs.each |&(_, in)| { (v.visit_expr)(in, e, v); } - for outs.each |&(_, out)| { + for a.outputs.each |&(_, out)| { (v.visit_expr)(out, e, v); } } |
