]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Make `asm!` clobbers a proper vector.
authorKang Seonghoon <public+git@mearie.org>
Sun, 30 Nov 2014 02:56:31 +0000 (11:56 +0900)
committerKang Seonghoon <public+git@mearie.org>
Sun, 30 Nov 2014 02:58:23 +0000 (11:58 +0900)
Otherwise `--pretty expanded` diverges.

src/librustc_trans/trans/asm.rs
src/libsyntax/ast.rs
src/libsyntax/ext/asm.rs
src/libsyntax/print/pprust.rs
src/test/pretty/asm-clobbers.rs [new file with mode: 0644]

index 024df2a63adb5c7ef92d8ee500353ef9ef96f06a..58bb42f3d6702fdacf96db8d3b91bc3d225796e2 100644 (file)
@@ -85,11 +85,18 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
                                     .connect(",")
                                     .as_slice());
 
-    let mut clobbers = get_clobbers();
-    if !ia.clobbers.get().is_empty() && !clobbers.is_empty() {
-        clobbers = format!("{},{}", ia.clobbers.get(), clobbers);
-    } else {
-        clobbers.push_str(ia.clobbers.get());
+    let mut clobbers =
+        String::from_str(ia.clobbers.iter()
+                                    .map(|s| format!("~{{{}}}", s.get()))
+                                    .collect::<Vec<String>>()
+                                    .connect(",")
+                                    .as_slice());
+    let more_clobbers = get_clobbers();
+    if !more_clobbers.is_empty() {
+        if !clobbers.is_empty() {
+            clobbers.push(',');
+        }
+        clobbers.push_str(more_clobbers.as_slice());
     }
 
     // Add the clobbers to our constraints list
index 28d5fbb96898d4c26e44681a5c706061f5a986c1..7e421df505d6c8c98426fc86c9e554528fa002ee 100644 (file)
@@ -1177,7 +1177,7 @@ pub struct InlineAsm {
     pub asm_str_style: StrStyle,
     pub outputs: Vec<(InternedString, P<Expr>, bool)>,
     pub inputs: Vec<(InternedString, P<Expr>)>,
-    pub clobbers: InternedString,
+    pub clobbers: Vec<InternedString>,
     pub volatile: bool,
     pub alignstack: bool,
     pub dialect: AsmDialect,
index d04144ef26e596c121cbd9602eacad23128680ae..a1c4c0a0a10c54320ea169b8f543e6ff0a614f37 100644 (file)
@@ -53,7 +53,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
     let mut asm_str_style = None;
     let mut outputs = Vec::new();
     let mut inputs = Vec::new();
-    let mut cons = "".to_string();
+    let mut clobs = Vec::new();
     let mut volatile = false;
     let mut alignstack = false;
     let mut dialect = ast::AsmAtt;
@@ -138,7 +138,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                 }
             }
             Clobbers => {
-                let mut clobs = Vec::new();
                 while p.token != token::Eof &&
                       p.token != token::Colon &&
                       p.token != token::ModSep {
@@ -148,15 +147,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                     }
 
                     let (s, _str_style) = p.parse_str();
-                    let clob = format!("~{{{}}}", s);
-                    clobs.push(clob);
 
                     if OPTIONS.iter().any(|opt| s.equiv(opt)) {
                         cx.span_warn(p.last_span, "expected a clobber, found an option");
                     }
+                    clobs.push(s);
                 }
-
-                cons = clobs.connect(",");
             }
             Options => {
                 let (option, _str_style) = p.parse_str();
@@ -216,7 +212,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
             asm_str_style: asm_str_style.unwrap(),
             outputs: outputs,
             inputs: inputs,
-            clobbers: token::intern_and_get_ident(cons.as_slice()),
+            clobbers: clobs,
             volatile: volatile,
             alignstack: alignstack,
             dialect: dialect,
index c12c3098279a97252f585b3b0d59853849862cc8..b2c783b4bd91b9fba1b0db72ff65c26ff3134010 100644 (file)
@@ -1839,7 +1839,11 @@ pub fn print_expr(&mut self, expr: &ast::Expr) -> IoResult<()> {
                 try!(space(&mut self.s));
                 try!(self.word_space(":"));
 
-                try!(self.print_string(a.clobbers.get(), ast::CookedStr));
+                try!(self.commasep(Inconsistent, a.clobbers.as_slice(),
+                                   |s, co| {
+                    try!(s.print_string(co.get(), ast::CookedStr));
+                    Ok(())
+                }));
                 try!(self.pclose());
             }
             ast::ExprMac(ref m) => try!(self.print_mac(m)),
diff --git a/src/test/pretty/asm-clobbers.rs b/src/test/pretty/asm-clobbers.rs
new file mode 100644 (file)
index 0000000..20a3ac2
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(asm)]
+
+pub fn main() { unsafe { asm!("" : : : "hello", "world") }; }
+