From: Simon Atanasyan Date: Thu, 28 Mar 2013 11:36:22 +0000 (+0000) Subject: [Mips] Handle pseudo-target flags '-EL' and '-EB' and properly adjust X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=286f3e638fd842619f853127907398859367a464;p=clang [Mips] Handle pseudo-target flags '-EL' and '-EB' and properly adjust toolchain flags for MIPS targets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178232 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 0a364bb56c..0d75b8eb2f 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -822,6 +822,8 @@ def keep__private__externs : Flag<["-"], "keep_private_externs">; def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>; def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>; def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>; +def EL : Flag<["-"], "EL">, Flags<[DriverOption]>; +def EB : Flag<["-"], "EB">, Flags<[DriverOption]>; def m32 : Flag<["-"], "m32">, Group, Flags<[DriverOption]>; def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group, Flags<[DriverOption,CC1Option]>, HelpText<"Enable hexagon-qdsp6 backward compatibility">; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 29ed5cffaa..4fb5502a48 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1653,6 +1653,21 @@ static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple, } } + // Handle pseudo-target flags '-EL' and '-EB'. + if (Arg *A = Args.getLastArg(options::OPT_EL, options::OPT_EB)) { + if (A->getOption().matches(options::OPT_EL)) { + if (Target.getArch() == llvm::Triple::mips) + Target.setArch(llvm::Triple::mipsel); + else if (Target.getArch() == llvm::Triple::mips64) + Target.setArch(llvm::Triple::mips64el); + } else { + if (Target.getArch() == llvm::Triple::mipsel) + Target.setArch(llvm::Triple::mips); + else if (Target.getArch() == llvm::Triple::mips64el) + Target.setArch(llvm::Triple::mips64); + } + } + // Skip further flag support on OSes which don't support '-m32' or '-m64'. if (Target.getArchName() == "tce" || Target.getOS() == llvm::Triple::AuroraUX || diff --git a/test/Driver/mips-eleb.c b/test/Driver/mips-eleb.c new file mode 100644 index 0000000000..8afe44f51c --- /dev/null +++ b/test/Driver/mips-eleb.c @@ -0,0 +1,31 @@ +// REQUIRES: mips-registered-target +// +// Check that -EL/-EB options adjust the toolchain flags. +// +// RUN: %clang -target mips-unknown-linux-gnu -### \ +// RUN: -EL -no-integrated-as %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS32-EL %s +// MIPS32-EL: "{{.*}}clang{{.*}}" "-cc1" "-triple" "mipsel-unknown-linux-gnu" +// MIPS32-EL: "{{.*}}as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EL" +// MIPS32-EL: "{{.*}}ld{{(.exe)?}}" {{.*}} "-m" "elf32ltsmip" +// +// RUN: %clang -target mips64-unknown-linux-gnu -### \ +// RUN: -EL -no-integrated-as %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS64-EL %s +// MIPS64-EL: "{{.*}}clang{{.*}}" "-cc1" "-triple" "mips64el-unknown-linux-gnu" +// MIPS64-EL: "{{.*}}as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EL" +// MIPS64-EL: "{{.*}}ld{{(.exe)?}}" {{.*}} "-m" "elf64ltsmip" +// +// RUN: %clang -target mipsel-unknown-linux-gnu -### \ +// RUN: -EB -no-integrated-as %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS32-EB %s +// MIPS32-EB: "{{.*}}clang{{.*}}" "-cc1" "-triple" "mips-unknown-linux-gnu" +// MIPS32-EB: "{{.*}}as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB" +// MIPS32-EB: "{{.*}}ld{{(.exe)?}}" {{.*}} "-m" "elf32btsmip" +// +// RUN: %clang -target mips64el-unknown-linux-gnu -### \ +// RUN: -EB -no-integrated-as %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS64-EB %s +// MIPS64-EB: "{{.*}}clang{{.*}}" "-cc1" "-triple" "mips64-unknown-linux-gnu" +// MIPS64-EB: "{{.*}}as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EB" +// MIPS64-EB: "{{.*}}ld{{(.exe)?}}" {{.*}} "-m" "elf64btsmip"