Skip to content

Use the reference grammar for inline assembly #1807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Apr 30, 2025

This updates the inline assembly grammar description to use the grammar style used in the rest of the reference, which also supports diagrams.

See the commit message for a detailed breakdown.

ehuss added 2 commits April 30, 2025 14:09
This rule doesn't just apply to `asm!` but all of the macros.
This updates the inline assembly grammar description to use the grammar
style used in the rest of the reference, which also supports diagrams. I
also appreciate that this is more precisely defined using existing
grammar productions.

I realize that this is not as compressed as before. If that is a real
problem, then I think we can look at improving that throughout the
reference in general.

I did not change other parts of the chapter even though they mention
things like `in(<reg>) <expr>`. I could rewrite those, though I'm not
sure if that would help a lot.

There are restrictions not captured in the grammar which are explained
in the text. For example, global_asm and naked_asm do not allow
clobber_abi. I think I'm fine with the grammar not including everything
since there isn't the concept of an AST here.

This is not a direct translation because the old grammar was not
entirely precise or match with the existing grammar. This also renames
the rules to use PascalCase. The exhaustive list of differences:

Removed:
- Removed the `asm`, `naked_asm` and `global_asm` rules since I don't
  think they really added anything, and the macro names aren't exactly
  part of the grammar being described here. Instead it is just
  `AsmArgs`.
- Removed the explicit `_` since that is now a normal Expression.

New:
- FormatString added MacroInvocation because that is supported.
- Defined AbiString.
- Defined RegisterClass.
- Defined ExplicitRegister.

Changed:
- Renamed option and options to AsmOption and AsmOptions (since our
  namespace is global).
- Clarified the meaning of "ident".
	- ArgName allows ident, keywords, and raw identifiers.
    - RegisterClass allows ident, keywords, but NOT raw identifiers.
- Split DirSpec into two, since there is a separate
  `Expression => Expression` syntax that is only valid for a subset
  of DirSpecs.
- Clarified that `sym` takes a PathExpression.
- Clarified that label's block doesn't allow inner attributes.
- Fixed sym/const/label which weren't properly quoted.
- Fixed some ambiguous precedence like alternation in reg_operand.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants