2017-03-16 02:27:40 +00:00
|
|
|
/// Module-level assembly support.
|
|
|
|
///
|
|
|
|
/// The macro defined here allows you to specify "top-level",
|
|
|
|
/// "file-scoped", or "module-level" assembly. These synonyms
|
|
|
|
/// all correspond to LLVM's module-level inline assembly instruction.
|
|
|
|
///
|
2018-05-08 13:10:16 +00:00
|
|
|
/// For example, `global_asm!("some assembly here")` codegens to
|
2017-03-16 02:27:40 +00:00
|
|
|
/// LLVM's `module asm "some assembly here"`. All of LLVM's caveats
|
|
|
|
/// therefore apply.
|
|
|
|
|
|
|
|
use syntax::ast;
|
2018-08-18 10:14:03 +00:00
|
|
|
use syntax::source_map::respan;
|
2017-03-16 02:27:40 +00:00
|
|
|
use syntax::ext::base;
|
|
|
|
use syntax::ext::base::*;
|
|
|
|
use syntax::feature_gate;
|
|
|
|
use syntax::ptr::P;
|
|
|
|
use syntax::symbol::Symbol;
|
|
|
|
use syntax_pos::Span;
|
|
|
|
use syntax::tokenstream;
|
|
|
|
|
2018-12-04 11:46:10 +00:00
|
|
|
pub const MACRO: &str = "global_asm";
|
2017-03-16 02:27:40 +00:00
|
|
|
|
|
|
|
pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
|
|
|
|
sp: Span,
|
2018-07-12 09:58:16 +00:00
|
|
|
tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> {
|
2017-03-16 02:27:40 +00:00
|
|
|
if !cx.ecfg.enable_global_asm() {
|
|
|
|
feature_gate::emit_feature_err(&cx.parse_sess,
|
|
|
|
MACRO,
|
|
|
|
sp,
|
|
|
|
feature_gate::GateIssue::Language,
|
|
|
|
feature_gate::EXPLAIN_GLOBAL_ASM);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut p = cx.new_parser_from_tts(tts);
|
|
|
|
let (asm, _) = match expr_to_string(cx,
|
|
|
|
panictry!(p.parse_expr()),
|
|
|
|
"inline assembly must be a string literal") {
|
|
|
|
Some((s, st)) => (s, st),
|
|
|
|
None => return DummyResult::any(sp),
|
|
|
|
};
|
|
|
|
|
2018-08-13 19:15:16 +00:00
|
|
|
MacEager::items(smallvec![P(ast::Item {
|
2017-03-16 02:27:40 +00:00
|
|
|
ident: ast::Ident::with_empty_ctxt(Symbol::intern("")),
|
|
|
|
attrs: Vec::new(),
|
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
node: ast::ItemKind::GlobalAsm(P(ast::GlobalAsm {
|
2017-08-07 05:54:09 +00:00
|
|
|
asm,
|
2017-03-16 02:27:40 +00:00
|
|
|
ctxt: cx.backtrace(),
|
|
|
|
})),
|
2018-03-10 14:45:47 +00:00
|
|
|
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
2017-03-16 02:27:40 +00:00
|
|
|
span: sp,
|
2017-07-11 00:44:46 +00:00
|
|
|
tokens: None,
|
2018-08-13 19:15:16 +00:00
|
|
|
})])
|
2017-03-16 02:27:40 +00:00
|
|
|
}
|