]> git.lizzy.rs Git - rust.git/commitdiff
Create asm! syntax extension.
authorLuqman Aden <me@luqman.ca>
Mon, 11 Mar 2013 05:08:38 +0000 (22:08 -0700)
committerLuqman Aden <me@luqman.ca>
Tue, 12 Mar 2013 08:03:34 +0000 (01:03 -0700)
src/libsyntax/ext/asm.rs [new file with mode: 0644]
src/libsyntax/ext/base.rs
src/libsyntax/print/pprust.rs
src/libsyntax/syntax.rc

diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs
new file mode 100644 (file)
index 0000000..bbf4238
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright 2012 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.
+
+
+
+/*
+ * Inline assembly support.
+ */
+
+use core::prelude::*;
+
+use ast;
+use codemap::span;
+use ext::base;
+use ext::base::*;
+
+pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+    -> base::MacResult {
+    let args = get_exprs_from_tts(cx, tts);
+    if args.len() == 0 {
+        cx.span_fatal(sp, "ast! takes at least 1 argument.");
+    }
+    let asm =
+        expr_to_str(cx, args[0],
+                    ~"inline assembly must be a string literal.");
+    let cons = if args.len() > 1 {
+        expr_to_str(cx, args[1],
+                    ~"constraints must be a string literal.")
+    } else { ~"" };
+
+    MRExpr(@ast::expr {
+        id: cx.next_id(),
+        callee_id: cx.next_id(),
+        node: ast::expr_inline_asm(@asm, @cons),
+        span: sp
+    })
+}
+
+//
+// Local Variables:
+// mode: rust
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
+//
index 23cabc099462f78f8f99d7b3808611fe822892f0..1eae4b84cc99206156812aafa0f7dc79703e3823 100644 (file)
@@ -198,6 +198,8 @@ fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> @Transformer {
                                 ext::source_util::expand_mod));
     syntax_expanders.insert(@~"proto",
                             builtin_item_tt(ext::pipes::expand_proto));
+    syntax_expanders.insert(@~"asm",
+                            builtin_normal_tt(ext::asm::expand_asm));
     syntax_expanders.insert(
         @~"trace_macros",
         builtin_normal_tt(ext::trace_macros::expand_trace_macros));
index 350ab0cf9b29732168fcd74c8406e0cdf86eba01..25c18adb2fb96fb114d3845bebd7d46d73e4250c 100644 (file)
@@ -1402,7 +1402,7 @@ fn print_field(s: @ps, field: ast::field) {
         word(s.s, ~"__asm__");
         popen(s);
         print_string(s, *a);
-        word_space(s, ~", ");
+        word_space(s, ~",");
         print_string(s, *c);
         pclose(s);
       }
index 7f84d6a3010d913b99e4c2c0b6823b0935aee3de..e13ef976d976b2ddbe556c972990ff55706e0726 100644 (file)
@@ -60,6 +60,7 @@ pub mod print {
 }
 
 pub mod ext {
+    pub mod asm;
     pub mod base;
     pub mod expand;