From: Nico Weber Date: Tue, 13 May 2014 11:11:24 +0000 (+0000) Subject: Support -masm= flag for x86 targets. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8277d9c9466d42daef6bae7d195f144901a31cd4;p=clang Support -masm= flag for x86 targets. `clang -S -o - file.c -masm=att` will write assembly to stdout in at&t syntax (the default), `-masm=intel` will instead output intel style asm. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208683 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 2cd7a216d0..0e251aa6b1 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1005,6 +1005,7 @@ def m3dnow : Flag<["-"], "m3dnow">, Group; def m64 : Flag<["-"], "m64">, Group, Flags<[DriverOption, CoreOption]>; def mabi_EQ : Joined<["-"], "mabi=">, Group; def march_EQ : Joined<["-"], "march=">, Group; +def masm_EQ : Joined<["-"], "masm=">, Group, Flags<[DriverOption]>; def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group; def mconstant_cfstrings : Flag<["-"], "mconstant-cfstrings">, Group; def mcpu_EQ : Joined<["-"], "mcpu=">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index fcd1275d6b..1f9e12bb53 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1486,6 +1486,17 @@ void Clang::AddX86TargetArgs(const ArgList &Args, } if (NoImplicitFloat) CmdArgs.push_back("-no-implicit-float"); + + if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) { + StringRef Value = A->getValue(); + if (Value == "intel" || Value == "att") { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Args.MakeArgString("-x86-asm-syntax=" + Value)); + } else { + getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Value; + } + } } static inline bool HasPICArg(const ArgList &Args) { diff --git a/test/Driver/masm.c b/test/Driver/masm.c new file mode 100644 index 0000000000..e9e4422aed --- /dev/null +++ b/test/Driver/masm.c @@ -0,0 +1,12 @@ +// RUN: %clang -target i386-unknown-linux -masm=intel %s -S -o - | FileCheck --check-prefix=CHECK-INTEL %s +// RUN: %clang -target i386-unknown-linux -masm=att %s -S -o - | FileCheck --check-prefix=CHECK-ATT %s +// RUN: not %clang -target i386-unknown-linux -masm=somerequired %s -S -o - 2>&1 | FileCheck --check-prefix=CHECK-SOMEREQUIRED %s +// RUN: %clang -target arm-unknown-eabi -masm=intel %s -S -o - 2>&1 | FileCheck --check-prefix=CHECK-ARM %s + +int f() { +// CHECK-ATT: movl $0, %eax +// CHECK-INTEL: mov eax, 0 +// CHECK-SOMEREQUIRED: error: unsupported argument 'somerequired' to option 'masm=' +// CHECK-ARM: warning: argument unused during compilation: '-masm=intel' + return 0; +}