Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1277,6 +1277,8 @@ def m64 : Flag<["-"], "m64">, Group, Flags<[DriverOption, CoreOption]>; def mx32 : Flag<["-"], "mx32">, Group, Flags<[DriverOption, CoreOption]>; def mabi_EQ : Joined<["-"], "mabi=">, Group; +def miamcu : Flag<["-"], "miamcu">, Group, Flags<[DriverOption, CoreOption]>, + HelpText<"Use Intel MCU ABI.">; def malign_functions_EQ : Joined<["-"], "malign-functions=">, Group; def malign_loops_EQ : Joined<["-"], "malign-loops=">, Group; def malign_jumps_EQ : Joined<["-"], "malign-jumps=">, Group; Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -210,6 +210,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { DerivedArgList *DAL = new DerivedArgList(Args); + bool HasMiamcu = Args.hasArg(options::OPT_miamcu); bool HasNostdlib = Args.hasArg(options::OPT_nostdlib); bool HasNodefaultlib = Args.hasArg(options::OPT_nodefaultlibs); for (Arg *A : Args) { @@ -275,9 +276,19 @@ continue; } + // Ignore -dynamic if -miamcu is present. + if (A->getOption().matches(options::OPT_dynamic) && HasMiamcu) { + Diag(diag::warn_drv_unused_argument) << "-dynamic"; + continue; + } + DAL->append(A); } + // Enforce -static if -miamcu is present. + if (HasMiamcu) + DAL->AddFlagArg(0, Opts->getOption(options::OPT_static)); + // Add a default value of -mlinker-version=, if one was given and the user // didn't specify one. #if defined(HOST_LINK_VERSION) @@ -296,7 +307,8 @@ /// /// This routine provides the logic to compute a target triple from various /// args passed to the driver and the default triple string. -static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple, +static llvm::Triple computeTargetTriple(const Driver &D, + StringRef DefaultTargetTriple, const ArgList &Args, StringRef DarwinArchName = "") { // FIXME: Already done in Compilation *Driver::BuildCompilation @@ -341,8 +353,9 @@ return Target; // Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'. - if (Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32, - options::OPT_m32, options::OPT_m16)) { + Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32, + options::OPT_m32, options::OPT_m16); + if (A) { llvm::Triple::ArchType AT = llvm::Triple::UnknownArch; if (A->getOption().matches(options::OPT_m64)) { @@ -367,6 +380,21 @@ Target.setArch(AT); } + // Handle -miamcu flag. + if (Args.hasArg(options::OPT_miamcu)) { + if (A && !A->getOption().matches(options::OPT_m32)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << "-miamcu" << A->getBaseArg().getAsString(Args); + + Target.setArch(llvm::Triple::x86); + Target.setArchName("i586"); + Target.setEnvironment(llvm::Triple::UnknownEnvironment); + Target.setEnvironmentName(""); + Target.setOS(llvm::Triple::ELFIAMCU); + Target.setVendor(llvm::Triple::UnknownVendor); + Target.setVendorName("intel"); + } + return Target; } @@ -501,8 +529,8 @@ DerivedArgList *TranslatedArgs = TranslateInputArgs(*UArgs); // Owned by the host. - const ToolChain &TC = - getToolChain(*UArgs, computeTargetTriple(DefaultTargetTriple, *UArgs)); + const ToolChain &TC = getToolChain( + *UArgs, computeTargetTriple(*this, DefaultTargetTriple, *UArgs)); // The compilation takes ownership of Args. Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs); @@ -1957,9 +1985,9 @@ const char *ArchName = BAA->getArchName(); if (ArchName) - TC = &getToolChain( - C.getArgs(), - computeTargetTriple(DefaultTargetTriple, C.getArgs(), ArchName)); + TC = &getToolChain(C.getArgs(), + computeTargetTriple(*this, DefaultTargetTriple, + C.getArgs(), ArchName)); else TC = &C.getDefaultToolChain(); Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2119,6 +2119,13 @@ << A->getOption().getName() << Value; } } + + // Set flags to support MCU ABI. + if (Args.hasArg(options::OPT_miamcu)) { + CmdArgs.push_back("-mfloat-abi"); + CmdArgs.push_back("soft"); + CmdArgs.push_back("-mstack-alignment=4"); + } } void Clang::AddHexagonTargetArgs(const ArgList &Args, Index: test/Driver/miamcu-opt.c =================================================================== --- /dev/null +++ test/Driver/miamcu-opt.c @@ -0,0 +1,18 @@ +// RUN: %clang -miamcu %s -### -o %t.o 2>&1 | FileCheck %s +// RUN: %clang -miamcu -m32 %s -### -o %t.o 2>&1 | FileCheck %s +// RUN: %clang -miamcu -target x86_64-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck %s +// RUN: %clang -miamcu -m64 %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=ERROR +// RUN: %clang -miamcu -dynamic %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=DYNAMIC %s + +// ERROR: error: invalid argument '-miamcu' not allowed with '-m64' + +// DYNAMIC: warning: argument unused during compilation: '-dynamic' + +// CHECK: "-cc1" +// CHECK: "-triple" "i586-intel-elfiamcu" +// CHECK: "-static-define" +// CHECK: "-mfloat-abi" "soft" +// CHECK: "-mstack-alignment=4" + +// CHECK: bin/gcc +// CHECK: "-static"