@@ -18,7 +18,7 @@ Support for inline assembly is stable on the following architectures:
1818- LoongArch
1919- s390x
2020
21- The compiler will emit an error if ` asm! ` is used on an unsupported target.
21+ The compiler will emit an error if an assembly macro is used on an unsupported target.
2222
2323r[ asm.example]
2424## Example
@@ -46,21 +46,62 @@ assert_eq!(x, 4 * 6);
4646r[ asm.syntax]
4747## Syntax
4848
49- The following ABNF specifies the general syntax:
50-
51- ``` text
52- format_string := STRING_LITERAL / RAW_STRING_LITERAL
53- dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
54- reg_spec := <register class> / "\"" <explicit register> "\""
55- operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
56- reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr> / label <block>
57- clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
58- option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
59- options := "options(" option *("," option) [","] ")"
60- operand := reg_operand / clobber_abi / options
61- asm := "asm!(" format_string *("," format_string) *("," operand) [","] ")"
62- naked_asm := "naked_asm!(" format_string *("," format_string) *("," operand) [","] ")"
63- global_asm := "global_asm!(" format_string *("," format_string) *("," operand) [","] ")"
49+ The following grammar specifies the arguments that can be passed to the ` asm! ` , ` global_asm! ` and ` naked_asm! ` macros.
50+
51+ ``` grammar,assembly
52+ @root AsmArgs -> FormatString (`,` FormatString)* (`,` AsmOperand)* `,`?
53+
54+ FormatString -> STRING_LITERAL | RAW_STRING_LITERAL | MacroInvocation
55+
56+ AsmOperand ->
57+ ClobberAbi
58+ | AsmOptions
59+ | RegOperand
60+
61+ ClobberAbi -> `clobber_abi` `(` Abi (`,` Abi)* `,`? `)`
62+
63+ AsmOptions ->
64+ `options` `(` ( AsmOption (`,` AsmOption)* `,`? )? `)`
65+
66+ AsmOption ->
67+ `pure`
68+ | `nomem`
69+ | `readonly`
70+ | `preserves_flags`
71+ | `noreturn`
72+ | `nostack`
73+ | `att_syntax`
74+ | `raw`
75+
76+ RegOperand -> (ParamName `=`)?
77+ (
78+ DirSpec `(` RegSpec `)` Expression
79+ | DualDirSpec `(` RegSpec `)` DualDirSpecExpression
80+ | `sym` PathExpression
81+ | `const` Expression
82+ | `label` `{` Statements? `}`
83+ )
84+
85+ ParamName -> IDENTIFIER_OR_KEYWORD | RAW_IDENTIFIER
86+
87+ DualDirSpecExpression ->
88+ Expression
89+ | Expression `=>` Expression
90+
91+ RegSpec -> RegisterClass | ExplicitRegister
92+
93+ RegisterClass -> IDENTIFIER_OR_KEYWORD
94+
95+ ExplicitRegister -> STRING_LITERAL
96+
97+ DirSpec ->
98+ `in`
99+ | `out`
100+ | `lateout`
101+
102+ DualDirSpec ->
103+ `inout`
104+ | `inlateout`
64105```
65106
66107r[ asm.scope]
0 commit comments