Skip to content

Commit

Permalink
Implement att_syntax option
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed May 18, 2020
1 parent 3590f4c commit 0882254
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/librustc_ast_lowering/expr.rs
Expand Up @@ -980,6 +980,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
struct_span_err!(self.sess, sp, E0472, "asm! is unsupported on this target").emit();
return hir::ExprKind::Err;
};
if asm.options.contains(asm::InlineAsmOptions::ATT_SYNTAX) {
match asm_arch {
asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64 => {}
_ => self
.sess
.struct_span_err(sp, "the `att_syntax` option is only supported on x86")
.emit(),
}
}

// Lower operands to HIR, filter_map skips any operands with invalid
// register classes.
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_ast_pretty/pprust.rs
Expand Up @@ -2118,6 +2118,9 @@ impl<'a> State<'a> {
if opts.contains(InlineAsmOptions::NOSTACK) {
options.push("nostack");
}
if opts.contains(InlineAsmOptions::ATT_SYNTAX) {
options.push("att_syntax");
}
s.commasep(Inconsistent, &options, |s, &opt| {
s.word(opt);
});
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_builtin_macros/asm.rs
Expand Up @@ -279,9 +279,11 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
args.options |= InlineAsmOptions::PRESERVES_FLAGS;
} else if p.eat(&token::Ident(sym::noreturn, false)) {
args.options |= InlineAsmOptions::NORETURN;
} else {
p.expect(&token::Ident(sym::nostack, false))?;
} else if p.eat(&token::Ident(sym::nostack, false)) {
args.options |= InlineAsmOptions::NOSTACK;
} else {
p.expect(&token::Ident(sym::att_syntax, false))?;
args.options |= InlineAsmOptions::ATT_SYNTAX;
}

// Allow trailing commas
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_codegen_llvm/asm.rs
Expand Up @@ -269,7 +269,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
tys => self.type_struct(&tys, false),
};
let dialect = match asm_arch {
InlineAsmArch::X86 | InlineAsmArch::X86_64 => LlvmAsmDialect::Intel,
InlineAsmArch::X86 | InlineAsmArch::X86_64
if !options.contains(InlineAsmOptions::ATT_SYNTAX) =>
{
LlvmAsmDialect::Intel
}
_ => LlvmAsmDialect::Att,
};
let result = inline_asm_call(
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_hir_pretty/lib.rs
Expand Up @@ -1503,6 +1503,9 @@ impl<'a> State<'a> {
if opts.contains(InlineAsmOptions::NOSTACK) {
options.push("nostack");
}
if opts.contains(InlineAsmOptions::ATT_SYNTAX) {
options.push("att_syntax");
}
s.commasep(Inconsistent, &options, |s, &opt| {
s.word(opt);
});
Expand Down
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Expand Up @@ -160,6 +160,7 @@ symbols! {
attr,
attributes,
attr_literals,
att_syntax,
augmented_assignments,
automatically_derived,
avx512_target_feature,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/asm/mod.rs
Expand Up @@ -426,6 +426,7 @@ bitflags::bitflags! {
const PRESERVES_FLAGS = 1 << 3;
const NORETURN = 1 << 4;
const NOSTACK = 1 << 5;
const ATT_SYNTAX = 1 << 6;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/asm/parse-error.stderr
Expand Up @@ -64,23 +64,23 @@ error: argument to `sym` must be a path expression
LL | asm!("{}", sym foo + bar);
| ^^^^^^^^^

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

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

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

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

0 comments on commit 0882254

Please sign in to comment.