implement naked_asm
macro
This commit is contained in:
parent
96d9d8aa7d
commit
aa5bbf05f4
5 changed files with 160 additions and 68 deletions
|
@ -12,9 +12,9 @@ builtin_macros_asm_duplicate_arg = duplicate argument named `{$name}`
|
||||||
builtin_macros_asm_expected_comma = expected token: `,`
|
builtin_macros_asm_expected_comma = expected token: `,`
|
||||||
.label = expected `,`
|
.label = expected `,`
|
||||||
|
|
||||||
builtin_macros_asm_expected_other = expected operand, {$is_global_asm ->
|
builtin_macros_asm_expected_other = expected operand, {$is_inline_asm ->
|
||||||
[true] options
|
[false] options
|
||||||
*[false] clobber_abi, options
|
*[true] clobber_abi, options
|
||||||
}, or additional template string
|
}, or additional template string
|
||||||
|
|
||||||
builtin_macros_asm_expected_string_literal = expected string literal
|
builtin_macros_asm_expected_string_literal = expected string literal
|
||||||
|
@ -51,6 +51,15 @@ builtin_macros_asm_sym_no_path = expected a path for argument to `sym`
|
||||||
|
|
||||||
builtin_macros_asm_underscore_input = _ cannot be used for input operands
|
builtin_macros_asm_underscore_input = _ cannot be used for input operands
|
||||||
|
|
||||||
|
builtin_macros_asm_unsupported_clobber_abi = `clobber_abi` cannot be used with `{$macro_name}!`
|
||||||
|
|
||||||
|
builtin_macros_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `{$macro_name}!`
|
||||||
|
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
|
||||||
|
|
||||||
|
builtin_macros_asm_unsupported_option = the `{$symbol}` option cannot be used with `{$macro_name}!`
|
||||||
|
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
|
||||||
|
.suggestion = remove this option
|
||||||
|
|
||||||
builtin_macros_assert_missing_comma = unexpected string literal
|
builtin_macros_assert_missing_comma = unexpected string literal
|
||||||
.suggestion = try adding a comma
|
.suggestion = try adding a comma
|
||||||
|
|
||||||
|
@ -194,15 +203,6 @@ builtin_macros_format_unused_args = multiple unused formatting arguments
|
||||||
|
|
||||||
builtin_macros_format_use_positional = consider using a positional formatting argument instead
|
builtin_macros_format_use_positional = consider using a positional formatting argument instead
|
||||||
|
|
||||||
builtin_macros_global_asm_clobber_abi = `clobber_abi` cannot be used with `global_asm!`
|
|
||||||
|
|
||||||
builtin_macros_global_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `global_asm!`
|
|
||||||
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
|
|
||||||
|
|
||||||
builtin_macros_global_asm_unsupported_option = the `{$symbol}` option cannot be used with `global_asm!`
|
|
||||||
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
|
|
||||||
.suggestion = remove this option
|
|
||||||
|
|
||||||
builtin_macros_invalid_crate_attribute = invalid crate attribute
|
builtin_macros_invalid_crate_attribute = invalid crate attribute
|
||||||
|
|
||||||
builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
|
builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
|
||||||
|
|
|
@ -37,29 +37,66 @@ pub struct AsmArgs {
|
||||||
/// - `Ok(true)` if the current token matches the keyword, and was expected
|
/// - `Ok(true)` if the current token matches the keyword, and was expected
|
||||||
/// - `Ok(false)` if the current token does not match the keyword
|
/// - `Ok(false)` if the current token does not match the keyword
|
||||||
/// - `Err(_)` if the current token matches the keyword, but was not expected
|
/// - `Err(_)` if the current token matches the keyword, but was not expected
|
||||||
fn eat_operand_keyword<'a>(p: &mut Parser<'a>, symbol: Symbol, expect: bool) -> PResult<'a, bool> {
|
fn eat_operand_keyword<'a>(
|
||||||
if expect {
|
p: &mut Parser<'a>,
|
||||||
|
symbol: Symbol,
|
||||||
|
asm_macro: AsmMacro,
|
||||||
|
) -> PResult<'a, bool> {
|
||||||
|
if matches!(asm_macro, AsmMacro::Asm) {
|
||||||
Ok(p.eat_keyword(symbol))
|
Ok(p.eat_keyword(symbol))
|
||||||
} else {
|
} else {
|
||||||
let span = p.token.span;
|
let span = p.token.span;
|
||||||
if p.eat_keyword_noexpect(symbol) {
|
if p.eat_keyword_noexpect(symbol) {
|
||||||
// in gets printed as `r#in` otherwise
|
// in gets printed as `r#in` otherwise
|
||||||
let symbol = if symbol == kw::In { "in" } else { symbol.as_str() };
|
let symbol = if symbol == kw::In { "in" } else { symbol.as_str() };
|
||||||
Err(p.dcx().create_err(errors::GlobalAsmUnsupportedOperand { span, symbol }))
|
Err(p.dcx().create_err(errors::AsmUnsupportedOperand {
|
||||||
|
span,
|
||||||
|
symbol,
|
||||||
|
macro_name: asm_macro.macro_name(),
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Public for rustfmt consumption.
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub enum AsmMacro {
|
||||||
|
/// The `asm!` macro
|
||||||
|
Asm,
|
||||||
|
/// The `global_asm!` macro
|
||||||
|
GlobalAsm,
|
||||||
|
/// The `naked_asm!` macro
|
||||||
|
NakedAsm,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsmMacro {
|
||||||
|
const fn macro_name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
AsmMacro::Asm => "asm",
|
||||||
|
AsmMacro::GlobalAsm => "global_asm",
|
||||||
|
AsmMacro::NakedAsm => "naked_asm",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn is_supported_option(&self, option: ast::InlineAsmOptions) -> bool {
|
||||||
|
match self {
|
||||||
|
AsmMacro::Asm => true,
|
||||||
|
AsmMacro::GlobalAsm => ast::InlineAsmOptions::GLOBAL_OPTIONS.contains(option),
|
||||||
|
AsmMacro::NakedAsm => ast::InlineAsmOptions::NAKED_OPTIONS.contains(option),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_args<'a>(
|
fn parse_args<'a>(
|
||||||
ecx: &ExtCtxt<'a>,
|
ecx: &ExtCtxt<'a>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
is_global_asm: bool,
|
asm_macro: AsmMacro,
|
||||||
) -> PResult<'a, AsmArgs> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
let mut p = ecx.new_parser_from_tts(tts);
|
let mut p = ecx.new_parser_from_tts(tts);
|
||||||
parse_asm_args(&mut p, sp, is_global_asm)
|
parse_asm_args(&mut p, sp, asm_macro)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Primarily public for rustfmt consumption.
|
// Primarily public for rustfmt consumption.
|
||||||
|
@ -67,7 +104,7 @@ fn parse_args<'a>(
|
||||||
pub fn parse_asm_args<'a>(
|
pub fn parse_asm_args<'a>(
|
||||||
p: &mut Parser<'a>,
|
p: &mut Parser<'a>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
is_global_asm: bool,
|
asm_macro: AsmMacro,
|
||||||
) -> PResult<'a, AsmArgs> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
let dcx = p.dcx();
|
let dcx = p.dcx();
|
||||||
|
|
||||||
|
@ -110,7 +147,7 @@ pub fn parse_asm_args<'a>(
|
||||||
|
|
||||||
// Parse options
|
// Parse options
|
||||||
if p.eat_keyword(sym::options) {
|
if p.eat_keyword(sym::options) {
|
||||||
parse_options(p, &mut args, is_global_asm)?;
|
parse_options(p, &mut args, asm_macro)?;
|
||||||
allow_templates = false;
|
allow_templates = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +166,7 @@ pub fn parse_asm_args<'a>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut explicit_reg = false;
|
let mut explicit_reg = false;
|
||||||
let op = if eat_operand_keyword(p, kw::In, !is_global_asm)? {
|
let op = if eat_operand_keyword(p, kw::In, asm_macro)? {
|
||||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||||
if p.eat_keyword(kw::Underscore) {
|
if p.eat_keyword(kw::Underscore) {
|
||||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||||
|
@ -137,15 +174,15 @@ pub fn parse_asm_args<'a>(
|
||||||
}
|
}
|
||||||
let expr = p.parse_expr()?;
|
let expr = p.parse_expr()?;
|
||||||
ast::InlineAsmOperand::In { reg, expr }
|
ast::InlineAsmOperand::In { reg, expr }
|
||||||
} else if eat_operand_keyword(p, sym::out, !is_global_asm)? {
|
} else if eat_operand_keyword(p, sym::out, asm_macro)? {
|
||||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||||
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
||||||
ast::InlineAsmOperand::Out { reg, expr, late: false }
|
ast::InlineAsmOperand::Out { reg, expr, late: false }
|
||||||
} else if eat_operand_keyword(p, sym::lateout, !is_global_asm)? {
|
} else if eat_operand_keyword(p, sym::lateout, asm_macro)? {
|
||||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||||
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
||||||
ast::InlineAsmOperand::Out { reg, expr, late: true }
|
ast::InlineAsmOperand::Out { reg, expr, late: true }
|
||||||
} else if eat_operand_keyword(p, sym::inout, !is_global_asm)? {
|
} else if eat_operand_keyword(p, sym::inout, asm_macro)? {
|
||||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||||
if p.eat_keyword(kw::Underscore) {
|
if p.eat_keyword(kw::Underscore) {
|
||||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||||
|
@ -159,7 +196,7 @@ pub fn parse_asm_args<'a>(
|
||||||
} else {
|
} else {
|
||||||
ast::InlineAsmOperand::InOut { reg, expr, late: false }
|
ast::InlineAsmOperand::InOut { reg, expr, late: false }
|
||||||
}
|
}
|
||||||
} else if eat_operand_keyword(p, sym::inlateout, !is_global_asm)? {
|
} else if eat_operand_keyword(p, sym::inlateout, asm_macro)? {
|
||||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||||
if p.eat_keyword(kw::Underscore) {
|
if p.eat_keyword(kw::Underscore) {
|
||||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||||
|
@ -173,7 +210,7 @@ pub fn parse_asm_args<'a>(
|
||||||
} else {
|
} else {
|
||||||
ast::InlineAsmOperand::InOut { reg, expr, late: true }
|
ast::InlineAsmOperand::InOut { reg, expr, late: true }
|
||||||
}
|
}
|
||||||
} else if eat_operand_keyword(p, sym::label, !is_global_asm)? {
|
} else if eat_operand_keyword(p, sym::label, asm_macro)? {
|
||||||
let block = p.parse_block()?;
|
let block = p.parse_block()?;
|
||||||
ast::InlineAsmOperand::Label { block }
|
ast::InlineAsmOperand::Label { block }
|
||||||
} else if p.eat_keyword(kw::Const) {
|
} else if p.eat_keyword(kw::Const) {
|
||||||
|
@ -205,7 +242,7 @@ pub fn parse_asm_args<'a>(
|
||||||
_ => {
|
_ => {
|
||||||
let err = dcx.create_err(errors::AsmExpectedOther {
|
let err = dcx.create_err(errors::AsmExpectedOther {
|
||||||
span: template.span,
|
span: template.span,
|
||||||
is_global_asm,
|
is_inline_asm: matches!(asm_macro, AsmMacro::Asm),
|
||||||
});
|
});
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
@ -301,20 +338,25 @@ pub fn parse_asm_args<'a>(
|
||||||
dcx.emit_err(errors::AsmMayUnwind { labels_sp });
|
dcx.emit_err(errors::AsmMayUnwind { labels_sp });
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.clobber_abis.len() > 0 {
|
if !args.clobber_abis.is_empty() {
|
||||||
if is_global_asm {
|
match asm_macro {
|
||||||
let err = dcx.create_err(errors::GlobalAsmClobberAbi {
|
AsmMacro::GlobalAsm | AsmMacro::NakedAsm => {
|
||||||
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
let err = dcx.create_err(errors::AsmUnsupportedClobberAbi {
|
||||||
});
|
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||||
|
macro_name: asm_macro.macro_name(),
|
||||||
|
});
|
||||||
|
|
||||||
// Bail out now since this is likely to confuse later stages
|
// Bail out now since this is likely to confuse later stages
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if !regclass_outputs.is_empty() {
|
AsmMacro::Asm => {
|
||||||
dcx.emit_err(errors::AsmClobberNoReg {
|
if !regclass_outputs.is_empty() {
|
||||||
spans: regclass_outputs,
|
dcx.emit_err(errors::AsmClobberNoReg {
|
||||||
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
spans: regclass_outputs,
|
||||||
});
|
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,10 +377,15 @@ fn err_duplicate_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
||||||
///
|
///
|
||||||
/// This function must be called immediately after the option token is parsed.
|
/// This function must be called immediately after the option token is parsed.
|
||||||
/// Otherwise, the suggestion will be incorrect.
|
/// Otherwise, the suggestion will be incorrect.
|
||||||
fn err_unsupported_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
fn err_unsupported_option(p: &Parser<'_>, asm_macro: AsmMacro, symbol: Symbol, span: Span) {
|
||||||
// Tool-only output
|
// Tool-only output
|
||||||
let full_span = if p.token == token::Comma { span.to(p.token.span) } else { span };
|
let full_span = if p.token == token::Comma { span.to(p.token.span) } else { span };
|
||||||
p.dcx().emit_err(errors::GlobalAsmUnsupportedOption { span, symbol, full_span });
|
p.dcx().emit_err(errors::AsmUnsupportedOption {
|
||||||
|
span,
|
||||||
|
symbol,
|
||||||
|
full_span,
|
||||||
|
macro_name: asm_macro.macro_name(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to set the provided option in the provided `AsmArgs`.
|
/// Try to set the provided option in the provided `AsmArgs`.
|
||||||
|
@ -349,12 +396,12 @@ fn err_unsupported_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
||||||
fn try_set_option<'a>(
|
fn try_set_option<'a>(
|
||||||
p: &Parser<'a>,
|
p: &Parser<'a>,
|
||||||
args: &mut AsmArgs,
|
args: &mut AsmArgs,
|
||||||
is_global_asm: bool,
|
asm_macro: AsmMacro,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
option: ast::InlineAsmOptions,
|
option: ast::InlineAsmOptions,
|
||||||
) {
|
) {
|
||||||
if is_global_asm && !ast::InlineAsmOptions::GLOBAL_OPTIONS.contains(option) {
|
if !asm_macro.is_supported_option(option) {
|
||||||
err_unsupported_option(p, symbol, p.prev_token.span);
|
err_unsupported_option(p, asm_macro, symbol, p.prev_token.span);
|
||||||
} else if args.options.contains(option) {
|
} else if args.options.contains(option) {
|
||||||
err_duplicate_option(p, symbol, p.prev_token.span);
|
err_duplicate_option(p, symbol, p.prev_token.span);
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,7 +412,7 @@ fn try_set_option<'a>(
|
||||||
fn parse_options<'a>(
|
fn parse_options<'a>(
|
||||||
p: &mut Parser<'a>,
|
p: &mut Parser<'a>,
|
||||||
args: &mut AsmArgs,
|
args: &mut AsmArgs,
|
||||||
is_global_asm: bool,
|
asm_macro: AsmMacro,
|
||||||
) -> PResult<'a, ()> {
|
) -> PResult<'a, ()> {
|
||||||
let span_start = p.prev_token.span;
|
let span_start = p.prev_token.span;
|
||||||
|
|
||||||
|
@ -386,15 +433,14 @@ fn parse_options<'a>(
|
||||||
|
|
||||||
'blk: {
|
'blk: {
|
||||||
for (symbol, option) in OPTIONS {
|
for (symbol, option) in OPTIONS {
|
||||||
let kw_matched =
|
let kw_matched = if asm_macro.is_supported_option(option) {
|
||||||
if !is_global_asm || ast::InlineAsmOptions::GLOBAL_OPTIONS.contains(option) {
|
p.eat_keyword(symbol)
|
||||||
p.eat_keyword(symbol)
|
} else {
|
||||||
} else {
|
p.eat_keyword_noexpect(symbol)
|
||||||
p.eat_keyword_noexpect(symbol)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if kw_matched {
|
if kw_matched {
|
||||||
try_set_option(p, args, is_global_asm, symbol, option);
|
try_set_option(p, args, asm_macro, symbol, option);
|
||||||
break 'blk;
|
break 'blk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -797,7 +843,7 @@ pub(super) fn expand_asm<'cx>(
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> MacroExpanderResult<'cx> {
|
) -> MacroExpanderResult<'cx> {
|
||||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, false) {
|
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::Asm) {
|
||||||
Ok(args) => {
|
Ok(args) => {
|
||||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::Asm, args) else {
|
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::Asm, args) else {
|
||||||
return ExpandResult::Retry(());
|
return ExpandResult::Retry(());
|
||||||
|
@ -865,7 +911,7 @@ pub(super) fn expand_global_asm<'cx>(
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> MacroExpanderResult<'cx> {
|
) -> MacroExpanderResult<'cx> {
|
||||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, true) {
|
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::GlobalAsm) {
|
||||||
Ok(args) => {
|
Ok(args) => {
|
||||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::GlobalAsm, args)
|
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::GlobalAsm, args)
|
||||||
else {
|
else {
|
||||||
|
@ -894,3 +940,32 @@ pub(super) fn expand_global_asm<'cx>(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn expand_naked_asm<'cx>(
|
||||||
|
ecx: &'cx mut ExtCtxt<'_>,
|
||||||
|
sp: Span,
|
||||||
|
tts: TokenStream,
|
||||||
|
) -> MacroExpanderResult<'cx> {
|
||||||
|
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::NakedAsm) {
|
||||||
|
Ok(args) => {
|
||||||
|
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, args) else {
|
||||||
|
return ExpandResult::Retry(());
|
||||||
|
};
|
||||||
|
let expr = match mac {
|
||||||
|
Ok(inline_asm) => P(ast::Expr {
|
||||||
|
id: ast::DUMMY_NODE_ID,
|
||||||
|
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
|
||||||
|
span: sp,
|
||||||
|
attrs: ast::AttrVec::new(),
|
||||||
|
tokens: None,
|
||||||
|
}),
|
||||||
|
Err(guar) => DummyResult::raw_expr(sp, Some(guar)),
|
||||||
|
};
|
||||||
|
MacEager::expr(expr)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
let guar = err.emit();
|
||||||
|
DummyResult::any(sp, guar)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -751,7 +751,7 @@ pub(crate) struct AsmExpectedOther {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label(builtin_macros_asm_expected_other)]
|
#[label(builtin_macros_asm_expected_other)]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) is_global_asm: bool,
|
pub(crate) is_inline_asm: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -799,13 +799,6 @@ pub(crate) struct AsmMayUnwind {
|
||||||
pub(crate) labels_sp: Vec<Span>,
|
pub(crate) labels_sp: Vec<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
|
||||||
#[diag(builtin_macros_global_asm_clobber_abi)]
|
|
||||||
pub(crate) struct GlobalAsmClobberAbi {
|
|
||||||
#[primary_span]
|
|
||||||
pub(crate) spans: Vec<Span>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct AsmClobberNoReg {
|
pub(crate) struct AsmClobberNoReg {
|
||||||
pub(crate) spans: Vec<Span>,
|
pub(crate) spans: Vec<Span>,
|
||||||
pub(crate) clobbers: Vec<Span>,
|
pub(crate) clobbers: Vec<Span>,
|
||||||
|
@ -841,23 +834,33 @@ pub(crate) struct AsmOptAlreadyprovided {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(builtin_macros_global_asm_unsupported_option)]
|
#[diag(builtin_macros_asm_unsupported_option)]
|
||||||
pub(crate) struct GlobalAsmUnsupportedOption {
|
pub(crate) struct AsmUnsupportedOption {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) symbol: Symbol,
|
pub(crate) symbol: Symbol,
|
||||||
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
|
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
|
||||||
pub(crate) full_span: Span,
|
pub(crate) full_span: Span,
|
||||||
|
pub(crate) macro_name: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(builtin_macros_global_asm_unsupported_operand)]
|
#[diag(builtin_macros_asm_unsupported_operand)]
|
||||||
pub(crate) struct GlobalAsmUnsupportedOperand<'a> {
|
pub(crate) struct AsmUnsupportedOperand<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) symbol: &'a str,
|
pub(crate) symbol: &'a str,
|
||||||
|
pub(crate) macro_name: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_asm_unsupported_clobber_abi)]
|
||||||
|
pub(crate) struct AsmUnsupportedClobberAbi {
|
||||||
|
#[primary_span]
|
||||||
|
pub(crate) spans: Vec<Span>,
|
||||||
|
pub(crate) macro_name: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
|
@ -77,3 +77,17 @@ pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?)
|
||||||
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
|
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
|
||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inline assembly used in combination with `#[naked]` functions.
|
||||||
|
///
|
||||||
|
/// Refer to [Rust By Example] for a usage guide and the [reference] for
|
||||||
|
/// detailed information about the syntax and available options.
|
||||||
|
///
|
||||||
|
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
|
||||||
|
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
|
||||||
|
#[unstable(feature = "naked_functions", issue = "90957")]
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
|
||||||
|
/* compiler built-in */
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_builtin_macros::asm::{AsmArgs, parse_asm_args};
|
use rustc_builtin_macros::asm::{parse_asm_args, AsmArgs, AsmMacro};
|
||||||
|
|
||||||
use crate::rewrite::RewriteContext;
|
use crate::rewrite::RewriteContext;
|
||||||
|
|
||||||
|
@ -7,5 +7,5 @@ use crate::rewrite::RewriteContext;
|
||||||
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
|
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
|
||||||
let ts = mac.args.tokens.clone();
|
let ts = mac.args.tokens.clone();
|
||||||
let mut parser = super::build_parser(context, ts);
|
let mut parser = super::build_parser(context, ts);
|
||||||
parse_asm_args(&mut parser, mac.span(), false).ok()
|
parse_asm_args(&mut parser, mac.span(), AsmMacro::Asm).ok()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue