Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0882254

Browse files
committed
Implement att_syntax option
1 parent 3590f4c commit 0882254

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

src/librustc_ast_lowering/expr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
980980
struct_span_err!(self.sess, sp, E0472, "asm! is unsupported on this target").emit();
981981
return hir::ExprKind::Err;
982982
};
983+
if asm.options.contains(asm::InlineAsmOptions::ATT_SYNTAX) {
984+
match asm_arch {
985+
asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64 => {}
986+
_ => self
987+
.sess
988+
.struct_span_err(sp, "the `att_syntax` option is only supported on x86")
989+
.emit(),
990+
}
991+
}
983992

984993
// Lower operands to HIR, filter_map skips any operands with invalid
985994
// register classes.

src/librustc_ast_pretty/pprust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,9 @@ impl<'a> State<'a> {
21182118
if opts.contains(InlineAsmOptions::NOSTACK) {
21192119
options.push("nostack");
21202120
}
2121+
if opts.contains(InlineAsmOptions::ATT_SYNTAX) {
2122+
options.push("att_syntax");
2123+
}
21212124
s.commasep(Inconsistent, &options, |s, &opt| {
21222125
s.word(opt);
21232126
});

src/librustc_builtin_macros/asm.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
279279
args.options |= InlineAsmOptions::PRESERVES_FLAGS;
280280
} else if p.eat(&token::Ident(sym::noreturn, false)) {
281281
args.options |= InlineAsmOptions::NORETURN;
282-
} else {
283-
p.expect(&token::Ident(sym::nostack, false))?;
282+
} else if p.eat(&token::Ident(sym::nostack, false)) {
284283
args.options |= InlineAsmOptions::NOSTACK;
284+
} else {
285+
p.expect(&token::Ident(sym::att_syntax, false))?;
286+
args.options |= InlineAsmOptions::ATT_SYNTAX;
285287
}
286288

287289
// Allow trailing commas

src/librustc_codegen_llvm/asm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
269269
tys => self.type_struct(&tys, false),
270270
};
271271
let dialect = match asm_arch {
272-
InlineAsmArch::X86 | InlineAsmArch::X86_64 => LlvmAsmDialect::Intel,
272+
InlineAsmArch::X86 | InlineAsmArch::X86_64
273+
if !options.contains(InlineAsmOptions::ATT_SYNTAX) =>
274+
{
275+
LlvmAsmDialect::Intel
276+
}
273277
_ => LlvmAsmDialect::Att,
274278
};
275279
let result = inline_asm_call(

src/librustc_hir_pretty/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,9 @@ impl<'a> State<'a> {
15031503
if opts.contains(InlineAsmOptions::NOSTACK) {
15041504
options.push("nostack");
15051505
}
1506+
if opts.contains(InlineAsmOptions::ATT_SYNTAX) {
1507+
options.push("att_syntax");
1508+
}
15061509
s.commasep(Inconsistent, &options, |s, &opt| {
15071510
s.word(opt);
15081511
});

src/librustc_span/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ symbols! {
160160
attr,
161161
attributes,
162162
attr_literals,
163+
att_syntax,
163164
augmented_assignments,
164165
automatically_derived,
165166
avx512_target_feature,

src/librustc_target/asm/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ bitflags::bitflags! {
426426
const PRESERVES_FLAGS = 1 << 3;
427427
const NORETURN = 1 << 4;
428428
const NOSTACK = 1 << 5;
429+
const ATT_SYNTAX = 1 << 6;
429430
}
430431
}
431432

src/test/ui/asm/parse-error.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ error: argument to `sym` must be a path expression
6464
LL | asm!("{}", sym foo + bar);
6565
| ^^^^^^^^^
6666

67-
error: expected one of `)`, `nomem`, `noreturn`, `nostack`, `preserves_flags`, `pure`, or `readonly`, found `foo`
67+
error: expected one of `)`, `att_syntax`, `nomem`, `noreturn`, `nostack`, `preserves_flags`, `pure`, or `readonly`, found `foo`
6868
--> $DIR/parse-error.rs:31:26
6969
|
7070
LL | asm!("", options(foo));
71-
| ^^^ expected one of 7 possible tokens
71+
| ^^^ expected one of 8 possible tokens
7272

7373
error: expected one of `)` or `,`, found `foo`
7474
--> $DIR/parse-error.rs:33:32
7575
|
7676
LL | asm!("", options(nomem foo));
7777
| ^^^ expected one of `)` or `,`
7878

79-
error: expected one of `)`, `nomem`, `noreturn`, `nostack`, `preserves_flags`, `pure`, or `readonly`, found `foo`
79+
error: expected one of `)`, `att_syntax`, `nomem`, `noreturn`, `nostack`, `preserves_flags`, `pure`, or `readonly`, found `foo`
8080
--> $DIR/parse-error.rs:35:33
8181
|
8282
LL | asm!("", options(nomem, foo));
83-
| ^^^ expected one of 7 possible tokens
83+
| ^^^ expected one of 8 possible tokens
8484

8585
error: asm options cannot be specified multiple times
8686
--> $DIR/parse-error.rs:37:29

0 commit comments

Comments
 (0)