diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2021-06-24 16:25:44 +0100 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2021-06-24 23:42:15 +0100 |
| commit | d0443bb7c2c42d03e7a329e2e18eef779bd2e0e9 (patch) | |
| tree | baec681a45de19b8b31ef187b89e0ed1119911a3 /compiler | |
| parent | 1e13a9bb33debb931d603278b7f1a706b0d11660 (diff) | |
| download | rust-d0443bb7c2c42d03e7a329e2e18eef779bd2e0e9.tar.gz rust-d0443bb7c2c42d03e7a329e2e18eef779bd2e0e9.zip | |
Add a "raw" option for asm! which ignores format string specifiers
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/asm.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_hir_pretty/src/lib.rs | 3 |
4 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index b3bac1d7ecd..352385ca1f2 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1933,6 +1933,7 @@ bitflags::bitflags! { const NORETURN = 1 << 4; const NOSTACK = 1 << 5; const ATT_SYNTAX = 1 << 6; + const RAW = 1 << 7; } } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b7bb896f318..f9b735fc69d 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -2274,6 +2274,9 @@ impl<'a> State<'a> { if opts.contains(InlineAsmOptions::ATT_SYNTAX) { options.push("att_syntax"); } + if opts.contains(InlineAsmOptions::RAW) { + options.push("raw"); + } s.commasep(Inconsistent, &options, |s, &opt| { s.word(opt); }); diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index b28c6f0d99c..97e07d52cc3 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -356,6 +356,8 @@ fn parse_options<'a>( try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK); } else if p.eat_keyword(sym::att_syntax) { try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX); + } else if p.eat_keyword(kw::Raw) { + try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW); } else { return p.unexpected(); } @@ -467,6 +469,14 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl } } + // Don't treat raw asm as a format string. + if args.options.contains(ast::InlineAsmOptions::RAW) { + template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string())); + let template_num_lines = 1 + template_str.matches('\n').count(); + line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines)); + continue; + } + let mut parser = parse::Parser::new( template_str, str_style, diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 2b932b7c953..ad12620c5e4 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1446,6 +1446,9 @@ impl<'a> State<'a> { if opts.contains(ast::InlineAsmOptions::ATT_SYNTAX) { options.push("att_syntax"); } + if opts.contains(ast::InlineAsmOptions::RAW) { + options.push("raw"); + } s.commasep(Inconsistent, &options, |s, &opt| { s.word(opt); }); |
