Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang fixes #7

Merged
merged 5 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,14 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
}

case llvm::Triple::m680x0:
case llvm::Triple::m68k:
return new M680x0TargetInfo(Triple, Opts);
switch (os) {
case llvm::Triple::Linux:
return new LinuxTargetInfo<M680x0TargetInfo>(Triple, Opts);
case llvm::Triple::NetBSD:
return new NetBSDTargetInfo<M680x0TargetInfo>(Triple, Opts);
default:
return new M680x0TargetInfo(Triple, Opts);
}

case llvm::Triple::le32:
switch (os) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_clang_library(clangDriver
ToolChain.cpp
ToolChains/Arch/AArch64.cpp
ToolChains/Arch/ARM.cpp
ToolChains/Arch/M680x0.cpp
ToolChains/Arch/Mips.cpp
ToolChains/Arch/PPC.cpp
ToolChains/Arch/RISCV.cpp
Expand Down
88 changes: 88 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/M680x0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//===--- M680x0.cpp - M680x0 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 "M680x0.h"
#include "ToolChains/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Host.h"

using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;

/// getM680x0TargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting.
std::string m680x0::getM680x0TargetCPU(const ArgList &Args) {
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
StringRef CPUName = A->getValue();

if (CPUName == "native") {
std::string CPU = std::string(llvm::sys::getHostCPUName());
if (!CPU.empty() && CPU != "generic")
return CPU;
else
return "";
}

return llvm::StringSwitch<const char *>(CPUName)
.Case("common", "generic")
.Case("68000", "68000")
.Case("68010", "68000")
.Case("68020", "68000")
.Case("68030", "68000")
.Case("68040", "68000")
.Case("68060", "68000")
.Default("");
}

return "";
}

const char *m680x0::getM680x0AsmModeForCPU(StringRef Name) {
return llvm::StringSwitch<const char *>(Name)
.Case("68000", "-m68000")
.Case("68010", "-m60010")
.Case("68020", "-m68020")
.Case("68030", "-m68030")
.Case("68040", "-m68040")
.Case("68060", "-m68060")
.Default("-many");
}

void m680x0::getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector<StringRef> &Features) {

m680x0::FloatABI FloatABI = m680x0::getM680x0FloatABI(D, Args);
if (FloatABI == m680x0::FloatABI::Soft)
Features.push_back("-hard-float");

}

m680x0::FloatABI m680x0::getM680x0FloatABI(const Driver &D, const ArgList &Args) {
m680x0::FloatABI ABI = m680x0::FloatABI::Invalid;
if (Arg *A =
Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) {

if (A->getOption().matches(options::OPT_msoft_float))
ABI = m680x0::FloatABI::Soft;
else if (A->getOption().matches(options::OPT_mhard_float))
ABI = m680x0::FloatABI::Hard;
}

// If unspecified, choose the default based on the platform.
if (ABI == m680x0::FloatABI::Invalid) {
ABI = m680x0::FloatABI::Hard;
}

return ABI;
}
43 changes: 43 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/M680x0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===--- M680x0.h - M680x0-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 <string>
#include <vector>

namespace clang {
namespace driver {
namespace tools {
namespace m680x0 {

enum class FloatABI {
Invalid,
Soft,
Hard,
};

FloatABI getM680x0FloatABI(const Driver &D, const llvm::opt::ArgList &Args);

std::string getM680x0TargetCPU(const llvm::opt::ArgList &Args);
const char *getM680x0AsmModeForCPU(StringRef Name);

void getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args,
std::vector<llvm::StringRef> &Features);

} // end namespace m680x0
} // end namespace target
} // end namespace driver
} // end namespace clang

#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
10 changes: 10 additions & 0 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
case llvm::Triple::armeb:
case llvm::Triple::thumbeb:
return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi";
case llvm::Triple::m680x0:
return "m68kelf";
case llvm::Triple::ppc:
return "elf32ppclinux";
case llvm::Triple::ppc64:
Expand Down Expand Up @@ -2042,6 +2044,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
"i686-linux-android", "i386-gnu", "i486-gnu",
"i586-gnu", "i686-gnu"};

static const char *const M680x0LibDirs[] = {"/lib"};
static const char *const M680x0Triples[] = {
"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",
Expand Down Expand Up @@ -2275,6 +2281,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
}
break;
case llvm::Triple::m680x0:
LibDirs.append(begin(M680x0LibDirs), end(M680x0LibDirs));
TripleAliases.append(begin(M680x0Triples), end(M680x0Triples));
break;
case llvm::Triple::mips:
LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Driver/ToolChains/Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
return "aarch64_be-linux-gnu";
break;

case llvm::Triple::m680x0:
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))
Expand Down Expand Up @@ -468,6 +474,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
break;
}
case llvm::Triple::m680x0:
LibDir = "lib";
Loader = "ld.so.1";
break;
case llvm::Triple::mips:
case llvm::Triple::mipsel:
case llvm::Triple::mips64:
Expand Down Expand Up @@ -610,6 +620,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
"/usr/include/armeb-linux-gnueabi"};
const StringRef ARMEBHFMultiarchIncludeDirs[] = {
"/usr/include/armeb-linux-gnueabihf"};
const StringRef M680x0MultiarchIncludeDirs[] = {
"/usr/include/m68k-linux-gnu"};
const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
const StringRef MIPSELMultiarchIncludeDirs[] = {
"/usr/include/mipsel-linux-gnu"};
Expand Down Expand Up @@ -672,6 +684,9 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
else
MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs;
break;
case llvm::Triple::m680x0:
MultiarchIncludeDirs = M680x0MultiarchIncludeDirs;
break;
case llvm::Triple::mips:
if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6)
MultiarchIncludeDirs = MIPSR6MultiarchIncludeDirs;
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6029,7 +6029,6 @@ static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
handleMipsInterruptAttr(S, D, AL);
break;
case llvm::Triple::m680x0:
case llvm::Triple::m68k:
handleM680x0InterruptAttr(S, D, AL);
break;
case llvm::Triple::x86:
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class Triple {
tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele
thumb, // Thumb (little endian): thumb, thumbv.*
thumbeb, // Thumb (big endian): thumbeb
m68k, // M680x0: Motorola 680x0 family
m680x0, // M680x0: Motorola 680x0 family
x86, // X86: i[3-9]86
x86_64, // X86-64: amd64, x86_64
Expand Down
15 changes: 3 additions & 12 deletions llvm/lib/Support/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ StringRef Triple::getArchTypeName(ArchType Kind) {
case wasm32: return "wasm32";
case wasm64: return "wasm64";
case m680x0: return "m680x0";
case m68k: return "m68k";
case x86: return "i386";
case x86_64: return "x86_64";
case xcore: return "xcore";
Expand Down Expand Up @@ -152,8 +151,7 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
case riscv64: return "riscv";

case ve: return "ve";
case m68k:
case m680x0: return "m68k";
case m680x0: return "m68k";
}
}

Expand Down Expand Up @@ -325,7 +323,6 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("renderscript64", renderscript64)
.Case("ve", ve)
.Case("m680x0", m680x0)
.Case("m68k", m68k)
.Default(UnknownArch);
}

Expand Down Expand Up @@ -425,8 +422,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
"mips64r6", "mipsn32r6", Triple::mips64)
.Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
"mipsn32r6el", Triple::mips64el)
.Case("m680x0", Triple::m680x0)
.Case("m68k", Triple::m68k)
.Cases("m680x0", "m68k", Triple::m680x0)
.Case("r600", Triple::r600)
.Case("amdgcn", Triple::amdgcn)
.Case("riscv32", Triple::riscv32)
Expand Down Expand Up @@ -672,8 +668,6 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
case Triple::thumb:
case Triple::x86:
case Triple::x86_64:
case Triple::m680x0:
case Triple::m68k:
if (T.isOSDarwin())
return Triple::MachO;
else if (T.isOSWindows())
Expand All @@ -696,6 +690,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
case Triple::lanai:
case Triple::le32:
case Triple::le64:
case Triple::m680x0:
case Triple::mips64:
case Triple::mips64el:
case Triple::mips:
Expand Down Expand Up @@ -1276,7 +1271,6 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::xcore:
case llvm::Triple::wasm32:
case llvm::Triple::m680x0:
case llvm::Triple::m68k:
return 32;

case llvm::Triple::aarch64:
Expand Down Expand Up @@ -1361,7 +1355,6 @@ Triple Triple::get32BitArchVariant() const {
case Triple::x86:
case Triple::xcore:
case Triple::m680x0:
case Triple::m68k:
// Already 32-bit.
break;

Expand Down Expand Up @@ -1401,7 +1394,6 @@ Triple Triple::get64BitArchVariant() const {
case Triple::tcele:
case Triple::xcore:
case Triple::m680x0:
case Triple::m68k:
T.setArch(UnknownArch);
break;

Expand Down Expand Up @@ -1518,7 +1510,6 @@ Triple Triple::getLittleEndianArchVariant() const {
case Triple::sparcv9:
case Triple::systemz:
case Triple::m680x0:
case Triple::m68k:

// ARM is intentionally unsupported here, changing the architecture would
// drop any arch suffixes.
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/M680x0/TargetInfo/M680x0TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ Target llvm::TheM680x0Target;
extern "C" void LLVMInitializeM680x0TargetInfo() {
RegisterTarget<Triple::m680x0, /*HasJIT=*/true> X(
TheM680x0Target, "m680x0", "Motorola 68000 family", "M680x0");
RegisterTarget<Triple::m68k, /*HasJIT=*/true> K(
TheM680x0Target, "m68k", "Motorola 68000 family", "M680x0");
}