Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfe][driver][M68k](8/8) Clang driver support
Add M68k-specific toolchain and driver configurations / options. Authors: myhsu, m4yers, glaubitz Differential Revision: https://reviews.llvm.org/D88394
- Loading branch information
1 parent
5eb7a58
commit 5509748
Showing
10 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <sstream> | ||
|
||
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<std::string>(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<StringRef> &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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <string> | ||
#include <vector> | ||
|
||
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<llvm::StringRef> &Features); | ||
|
||
} // end namespace m68k | ||
} // end namespace tools | ||
} // end namespace driver | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |