Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -160,6 +160,8 @@ // These are explicitly handled. def m_hexagon_Features_HVX_Group : OptionGroup<"">, Group, DocName<"Hexagon">; +def m_m68k_Features_Group: OptionGroup<"">, + Group, DocName<"M68k">; def m_mips_Features_Group : OptionGroup<"">, Group, DocName<"MIPS">; def m_ppc_Features_Group : OptionGroup<"">, @@ -3227,6 +3229,13 @@ def mno_nvs : Flag<["-"], "mno-nvs">, Group, Flags<[CC1Option]>, HelpText<"Disable generation of new-value stores">; +// M68k features flags +def m68000 : Flag<["-"], "m68000">, Group; +def m68010 : Flag<["-"], "m68010">, Group; +def m68020 : Flag<["-"], "m68020">, Group; +def m68030 : Flag<["-"], "m68030">, Group; +def m68040 : Flag<["-"], "m68040">, Group; +def m68060 : Flag<["-"], "m68060">, Group; // X86 feature flags def mx87 : Flag<["-"], "mx87">, Group; Index: clang/lib/Driver/CMakeLists.txt =================================================================== --- clang/lib/Driver/CMakeLists.txt +++ clang/lib/Driver/CMakeLists.txt @@ -26,6 +26,7 @@ ToolChain.cpp ToolChains/Arch/AArch64.cpp ToolChains/Arch/ARM.cpp + ToolChains/Arch/M68k.cpp ToolChains/Arch/Mips.cpp ToolChains/Arch/PPC.cpp ToolChains/Arch/RISCV.cpp Index: clang/lib/Driver/ToolChains/Arch/M68k.h =================================================================== --- /dev/null +++ clang/lib/Driver/ToolChains/Arch/M68k.h @@ -0,0 +1,42 @@ +//===--- M68k.h - M68k-specific Tool Helpers -----------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H +#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H + +#include "clang/Driver/Driver.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Option/Option.h" +#include +#include + +namespace clang { +namespace driver { +namespace tools { +namespace m68k { + +enum class FloatABI { + Invalid, + Soft, + Hard, +}; + +FloatABI getM68kFloatABI(const Driver &D, const llvm::opt::ArgList &Args); + +std::string getM68kTargetCPU(const llvm::opt::ArgList &Args); + +void getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args, + std::vector &Features); + +} // end namespace m68k +} // end namespace tools +} // end namespace driver +} // end namespace clang + +#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H Index: clang/lib/Driver/ToolChains/Arch/M68k.cpp =================================================================== --- /dev/null +++ clang/lib/Driver/ToolChains/Arch/M68k.cpp @@ -0,0 +1,93 @@ +//===--- M68k.cpp - M68k Helpers for Tools -------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "M68k.h" +#include "ToolChains/CommonArgs.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/Options.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/Regex.h" +#include + +using namespace clang::driver; +using namespace clang::driver::tools; +using namespace clang; +using namespace llvm::opt; + +/// getM68kTargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting. +std::string m68k::getM68kTargetCPU(const ArgList &Args) { + if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { + // The canonical CPU name is captalize. However, we allow + // starting with lower case or numbers only + StringRef CPUName = A->getValue(); + + if (CPUName == "native") { + std::string CPU = std::string(llvm::sys::getHostCPUName()); + if (!CPU.empty() && CPU != "generic") + return CPU; + } + + if (CPUName == "common") + return "generic"; + + return llvm::StringSwitch(CPUName) + .Cases("m68000", "68000", "M68000") + .Cases("m68010", "68010", "M68010") + .Cases("m68020", "68020", "M68020") + .Cases("m68030", "68030", "M68030") + .Cases("m68040", "68040", "M68040") + .Cases("m68060", "68060", "M68060") + .Default(CPUName.str()); + } + // FIXME: Throw error when multiple sub-architecture flag exist + if (Args.hasArg(clang::driver::options::OPT_m68000)) + return "M68000"; + if (Args.hasArg(clang::driver::options::OPT_m68010)) + return "M68010"; + if (Args.hasArg(clang::driver::options::OPT_m68020)) + return "M68020"; + if (Args.hasArg(clang::driver::options::OPT_m68030)) + return "M68030"; + if (Args.hasArg(clang::driver::options::OPT_m68040)) + return "M68040"; + if (Args.hasArg(clang::driver::options::OPT_m68060)) + return "M68060"; + + return ""; +} + +void m68k::getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args, + std::vector &Features) { + + m68k::FloatABI FloatABI = m68k::getM68kFloatABI(D, Args); + if (FloatABI == m68k::FloatABI::Soft) + Features.push_back("-hard-float"); +} + +m68k::FloatABI m68k::getM68kFloatABI(const Driver &D, const ArgList &Args) { + m68k::FloatABI ABI = m68k::FloatABI::Invalid; + if (Arg *A = + Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) { + + if (A->getOption().matches(options::OPT_msoft_float)) + ABI = m68k::FloatABI::Soft; + else if (A->getOption().matches(options::OPT_mhard_float)) + ABI = m68k::FloatABI::Hard; + } + + // If unspecified, choose the default based on the platform. + if (ABI == m68k::FloatABI::Invalid) + ABI = m68k::FloatABI::Hard; + + return ABI; +} Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -10,6 +10,7 @@ #include "AMDGPU.h" #include "Arch/AArch64.h" #include "Arch/ARM.h" +#include "Arch/M68k.h" #include "Arch/Mips.h" #include "Arch/PPC.h" #include "Arch/RISCV.h" @@ -368,6 +369,9 @@ case llvm::Triple::amdgcn: amdgpu::getAMDGPUTargetFeatures(D, Triple, Args, Features); break; + case llvm::Triple::m68k: + m68k::getM68kTargetFeatures(D, Triple, Args, Features); + break; case llvm::Triple::msp430: msp430::getMSP430TargetFeatures(D, Args, Features); break; Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -9,6 +9,7 @@ #include "CommonArgs.h" #include "Arch/AArch64.h" #include "Arch/ARM.h" +#include "Arch/M68k.h" #include "Arch/Mips.h" #include "Arch/PPC.h" #include "Arch/SystemZ.h" @@ -371,6 +372,9 @@ return A->getValue(); return ""; + case llvm::Triple::m68k: + return m68k::getM68kTargetCPU(Args); + case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: Index: clang/lib/Driver/ToolChains/Gnu.cpp =================================================================== --- clang/lib/Driver/ToolChains/Gnu.cpp +++ clang/lib/Driver/ToolChains/Gnu.cpp @@ -253,6 +253,8 @@ case llvm::Triple::armeb: case llvm::Triple::thumbeb: return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi"; + case llvm::Triple::m68k: + return "m68kelf"; case llvm::Triple::ppc: return "elf32ppclinux"; case llvm::Triple::ppc64: @@ -2096,6 +2098,10 @@ "i686-linux-android", "i386-gnu", "i486-gnu", "i586-gnu", "i686-gnu"}; + static const char *const M68kLibDirs[] = {"/lib"}; + static const char *const M68kTriples[] = { + "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"}; + static const char *const MIPSLibDirs[] = {"/lib"}; static const char *const MIPSTriples[] = { "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu", @@ -2329,6 +2335,10 @@ BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); } break; + case llvm::Triple::m68k: + LibDirs.append(begin(M68kLibDirs), end(M68kLibDirs)); + TripleAliases.append(begin(M68kTriples), end(M68kTriples)); + break; case llvm::Triple::mips: LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); @@ -2717,6 +2727,7 @@ case llvm::Triple::mips64: case llvm::Triple::mips64el: case llvm::Triple::msp430: + case llvm::Triple::m68k: return true; case llvm::Triple::sparc: case llvm::Triple::sparcel: Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -102,6 +102,12 @@ if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) return "aarch64_be-linux-gnu"; break; + + case llvm::Triple::m68k: + if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu")) + return "m68k-linux-gnu"; + break; + case llvm::Triple::mips: { std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu"; if (D.getVFS().exists(SysRoot + "/lib/" + MT)) @@ -472,6 +478,10 @@ Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3"; break; } + case llvm::Triple::m68k: + LibDir = "lib"; + Loader = "ld.so.1"; + break; case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: @@ -616,6 +626,7 @@ "/usr/include/armeb-linux-gnueabi"}; const StringRef ARMEBHFMultiarchIncludeDirs[] = { "/usr/include/armeb-linux-gnueabihf"}; + const StringRef M68kMultiarchIncludeDirs[] = {"/usr/include/m68k-linux-gnu"}; const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; const StringRef MIPSELMultiarchIncludeDirs[] = { "/usr/include/mipsel-linux-gnu"}; @@ -678,6 +689,9 @@ else MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; break; + case llvm::Triple::m68k: + MultiarchIncludeDirs = M68kMultiarchIncludeDirs; + break; case llvm::Triple::mips: if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6) MultiarchIncludeDirs = MIPSR6MultiarchIncludeDirs; Index: clang/test/Driver/m68k-features.cpp =================================================================== --- /dev/null +++ clang/test/Driver/m68k-features.cpp @@ -0,0 +1,45 @@ +// Check macro definitions +// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s +// CHECK-MX: #define __mc68000 1 +// CHECK-MX: #define __mc68000__ 1 +// CHECK-MX: #define mc68000 1 + +// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s +// CHECK-MX10: #define __mc68000 1 +// CHECK-MX10: #define __mc68000__ 1 +// CHECK-MX10: #define __mc68010 1 +// CHECK-MX10: #define __mc68010__ 1 +// CHECK-MX10: #define mc68000 1 +// CHECK-MX10: #define mc68010 1 + +// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s +// CHECK-MX20: #define __mc68000 1 +// CHECK-MX20: #define __mc68000__ 1 +// CHECK-MX20: #define __mc68020 1 +// CHECK-MX20: #define __mc68020__ 1 +// CHECK-MX20: #define mc68000 1 +// CHECK-MX20: #define mc68020 1 + +// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s +// CHECK-MX30: #define __mc68000 1 +// CHECK-MX30: #define __mc68000__ 1 +// CHECK-MX30: #define __mc68030 1 +// CHECK-MX30: #define __mc68030__ 1 +// CHECK-MX30: #define mc68000 1 +// CHECK-MX30: #define mc68030 1 + +// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s +// CHECK-MX40: #define __mc68000 1 +// CHECK-MX40: #define __mc68000__ 1 +// CHECK-MX40: #define __mc68040 1 +// CHECK-MX40: #define __mc68040__ 1 +// CHECK-MX40: #define mc68000 1 +// CHECK-MX40: #define mc68040 1 + +// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s +// CHECK-MX60: #define __mc68000 1 +// CHECK-MX60: #define __mc68000__ 1 +// CHECK-MX60: #define __mc68060 1 +// CHECK-MX60: #define __mc68060__ 1 +// CHECK-MX60: #define mc68000 1 +// CHECK-MX60: #define mc68060 1 Index: clang/test/Driver/m68k-sub-archs.cpp =================================================================== --- /dev/null +++ clang/test/Driver/m68k-sub-archs.cpp @@ -0,0 +1,35 @@ +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// CHECK-M00: "-target-cpu" "M68000" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// CHECK-M10: "-target-cpu" "M68010" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// CHECK-M20: "-target-cpu" "M68020" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// CHECK-M30: "-target-cpu" "M68030" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// CHECK-M40: "-target-cpu" "M68040" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// CHECK-M60: "-target-cpu" "M68060"