1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 /// Module-level assembly support.
13 /// The macro defined here allows you to specify "top-level",
14 /// "file-scoped", or "module-level" assembly. These synonyms
15 /// all correspond to LLVM's module-level inline assembly instruction.
17 /// For example, `global_asm!("some assembly here")` translates to
18 /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats
22 use syntax::ext::base;
23 use syntax::ext::base::*;
24 use syntax::feature_gate;
26 use syntax::symbol::Symbol;
28 use syntax::tokenstream;
30 use syntax::util::small_vector::SmallVector;
32 pub const MACRO: &'static str = "global_asm";
34 pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
36 tts: &[tokenstream::TokenTree]) -> Box<base::MacResult + 'cx> {
37 if !cx.ecfg.enable_global_asm() {
38 feature_gate::emit_feature_err(&cx.parse_sess,
41 feature_gate::GateIssue::Language,
42 feature_gate::EXPLAIN_GLOBAL_ASM);
43 return DummyResult::any(sp);
46 let mut p = cx.new_parser_from_tts(tts);
47 let (asm, _) = match expr_to_string(cx,
48 panictry!(p.parse_expr()),
49 "inline assembly must be a string literal") {
50 Some((s, st)) => (s, st),
51 None => return DummyResult::any(sp),
54 MacEager::items(SmallVector::one(P(ast::Item {
55 ident: ast::Ident::with_empty_ctxt(Symbol::intern("")),
57 id: ast::DUMMY_NODE_ID,
58 node: ast::ItemKind::GlobalAsm(P(ast::GlobalAsm {
62 vis: ast::Visibility::Inherited,