mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 23:51:56 +00:00
[Driver] Move PS4/PS5 header search path management to the driver
This follows how OpenBSD, FreeBSD, and NetBSD now work. (See D138183 and D140817 for those cases.) It also tidies up some code duplication that wasn't exactly right.
This commit is contained in:
parent
97d51e3fa8
commit
ecb3cd0946
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "PS4CPU.h"
|
#include "PS4CPU.h"
|
||||||
#include "CommonArgs.h"
|
#include "CommonArgs.h"
|
||||||
|
#include "clang/Config/config.h"
|
||||||
#include "clang/Driver/Compilation.h"
|
#include "clang/Driver/Compilation.h"
|
||||||
#include "clang/Driver/Driver.h"
|
#include "clang/Driver/Driver.h"
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
#include "clang/Driver/DriverDiagnostic.h"
|
||||||
@ -253,15 +254,14 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
|
|||||||
// SDK include or lib directories. This behavior could be changed if
|
// SDK include or lib directories. This behavior could be changed if
|
||||||
// -Weverything or -Winvalid-or-nonexistent-directory options are passed.
|
// -Weverything or -Winvalid-or-nonexistent-directory options are passed.
|
||||||
// If -isysroot was passed, use that as the SDK base path.
|
// If -isysroot was passed, use that as the SDK base path.
|
||||||
std::string PrefixDir;
|
|
||||||
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
|
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
|
||||||
PrefixDir = A->getValue();
|
SDKRootDir = A->getValue();
|
||||||
if (!llvm::sys::fs::exists(PrefixDir))
|
if (!llvm::sys::fs::exists(SDKRootDir))
|
||||||
D.Diag(clang::diag::warn_missing_sysroot) << PrefixDir;
|
D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
|
||||||
} else
|
} else
|
||||||
PrefixDir = std::string(SDKDir.str());
|
SDKRootDir = std::string(SDKDir.str());
|
||||||
|
|
||||||
SmallString<512> SDKIncludeDir(PrefixDir);
|
SmallString<512> SDKIncludeDir(SDKRootDir);
|
||||||
llvm::sys::path::append(SDKIncludeDir, "target/include");
|
llvm::sys::path::append(SDKIncludeDir, "target/include");
|
||||||
if (!Args.hasArg(options::OPT_nostdinc) &&
|
if (!Args.hasArg(options::OPT_nostdinc) &&
|
||||||
!Args.hasArg(options::OPT_nostdlibinc) &&
|
!Args.hasArg(options::OPT_nostdlibinc) &&
|
||||||
@ -272,7 +272,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
|
|||||||
<< Twine(Platform, " system headers").str() << SDKIncludeDir;
|
<< Twine(Platform, " system headers").str() << SDKIncludeDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallString<512> SDKLibDir(SDKDir);
|
SmallString<512> SDKLibDir(SDKRootDir);
|
||||||
llvm::sys::path::append(SDKLibDir, "target/lib");
|
llvm::sys::path::append(SDKLibDir, "target/lib");
|
||||||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||||
!Args.hasArg(options::OPT_nodefaultlibs) &&
|
!Args.hasArg(options::OPT_nodefaultlibs) &&
|
||||||
@ -287,6 +287,42 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
|
|||||||
getFilePaths().push_back(std::string(SDKLibDir.str()));
|
getFilePaths().push_back(std::string(SDKLibDir.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
|
||||||
|
const ArgList &DriverArgs,
|
||||||
|
ArgStringList &CC1Args) const {
|
||||||
|
const Driver &D = getDriver();
|
||||||
|
|
||||||
|
if (DriverArgs.hasArg(options::OPT_nostdinc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
|
||||||
|
SmallString<128> Dir(D.ResourceDir);
|
||||||
|
llvm::sys::path::append(Dir, "include");
|
||||||
|
addSystemInclude(DriverArgs, CC1Args, Dir.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Add dirs specified via 'configure --with-c-include-dirs'.
|
||||||
|
StringRef CIncludeDirs(C_INCLUDE_DIRS);
|
||||||
|
if (!CIncludeDirs.empty()) {
|
||||||
|
SmallVector<StringRef, 5> dirs;
|
||||||
|
CIncludeDirs.split(dirs, ":");
|
||||||
|
for (StringRef dir : dirs) {
|
||||||
|
StringRef Prefix =
|
||||||
|
llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
|
||||||
|
addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addExternCSystemInclude(DriverArgs, CC1Args,
|
||||||
|
SDKRootDir + "/target/include");
|
||||||
|
addExternCSystemInclude(DriverArgs, CC1Args,
|
||||||
|
SDKRootDir + "/target/include_common");
|
||||||
|
}
|
||||||
|
|
||||||
Tool *toolchains::PS4CPU::buildAssembler() const {
|
Tool *toolchains::PS4CPU::buildAssembler() const {
|
||||||
return new tools::PScpu::Assembler(*this);
|
return new tools::PScpu::Assembler(*this);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,9 @@ public:
|
|||||||
const llvm::opt::ArgList &Args, StringRef Platform,
|
const llvm::opt::ArgList &Args, StringRef Platform,
|
||||||
const char *EnvVar);
|
const char *EnvVar);
|
||||||
|
|
||||||
|
void
|
||||||
|
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
||||||
|
llvm::opt::ArgStringList &CC1Args) const override;
|
||||||
// No support for finding a C++ standard library yet.
|
// No support for finding a C++ standard library yet.
|
||||||
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
|
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
|
||||||
llvm::opt::ArgStringList &CC1Args) const override {
|
llvm::opt::ArgStringList &CC1Args) const override {
|
||||||
@ -111,6 +114,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Tool *buildLinker() const override;
|
Tool *buildLinker() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// We compute the SDK root dir in the ctor, and use it later.
|
||||||
|
std::string SDKRootDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
// PS4-specific Toolchain class.
|
// PS4-specific Toolchain class.
|
||||||
|
@ -233,8 +233,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|||||||
switch (os) {
|
switch (os) {
|
||||||
case llvm::Triple::CloudABI:
|
case llvm::Triple::CloudABI:
|
||||||
case llvm::Triple::NaCl:
|
case llvm::Triple::NaCl:
|
||||||
case llvm::Triple::PS4:
|
|
||||||
case llvm::Triple::PS5:
|
|
||||||
case llvm::Triple::ELFIAMCU:
|
case llvm::Triple::ELFIAMCU:
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::Win32:
|
case llvm::Triple::Win32:
|
||||||
@ -339,31 +337,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|||||||
case llvm::Triple::NaCl:
|
case llvm::Triple::NaCl:
|
||||||
case llvm::Triple::ELFIAMCU:
|
case llvm::Triple::ELFIAMCU:
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::PS4:
|
|
||||||
case llvm::Triple::PS5: {
|
|
||||||
// <isysroot> gets prepended later in AddPath().
|
|
||||||
std::string BaseSDKPath;
|
|
||||||
if (!HasSysroot) {
|
|
||||||
const char *EnvVar = (os == llvm::Triple::PS4) ? "SCE_ORBIS_SDK_DIR"
|
|
||||||
: "SCE_PROSPERO_SDK_DIR";
|
|
||||||
const char *envValue = getenv(EnvVar);
|
|
||||||
if (envValue)
|
|
||||||
BaseSDKPath = envValue;
|
|
||||||
else {
|
|
||||||
// HSOpts.ResourceDir variable contains the location of Clang's
|
|
||||||
// resource files.
|
|
||||||
// Assuming that Clang is configured for PS4 without
|
|
||||||
// --with-clang-resource-dir option, the location of Clang's resource
|
|
||||||
// files is <SDK_DIR>/host_tools/lib/clang
|
|
||||||
SmallString<128> P = StringRef(HSOpts.ResourceDir);
|
|
||||||
llvm::sys::path::append(P, "../../..");
|
|
||||||
BaseSDKPath = std::string(P.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AddPath(BaseSDKPath + "/target/include", System, false);
|
|
||||||
AddPath(BaseSDKPath + "/target/include_common", System, false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
AddPath("/usr/include", ExternCSystem, false);
|
AddPath("/usr/include", ExternCSystem, false);
|
||||||
break;
|
break;
|
||||||
@ -412,6 +385,8 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
|
|||||||
case llvm::Triple::FreeBSD:
|
case llvm::Triple::FreeBSD:
|
||||||
case llvm::Triple::NetBSD:
|
case llvm::Triple::NetBSD:
|
||||||
case llvm::Triple::OpenBSD:
|
case llvm::Triple::OpenBSD:
|
||||||
|
case llvm::Triple::PS4:
|
||||||
|
case llvm::Triple::PS5:
|
||||||
case llvm::Triple::Fuchsia:
|
case llvm::Triple::Fuchsia:
|
||||||
case llvm::Triple::Hurd:
|
case llvm::Triple::Hurd:
|
||||||
case llvm::Triple::Linux:
|
case llvm::Triple::Linux:
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/// PS4 and PS5 use the same SDK layout, so use the same tree for both.
|
/// PS4 and PS5 use the same SDK layout, so use the same tree for both.
|
||||||
// RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-scei-ps4 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
|
// RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-scei-ps4 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
|
||||||
// RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-sie-ps5 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
|
// RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-sie-ps5 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
|
||||||
// ENVPS4: Inputs/scei-ps4_tree/target/include{{$}}
|
// ENVPS4: Inputs/scei-ps4_tree/target/include
|
||||||
// ENVPS4: Inputs/scei-ps4_tree/target/include_common{{$}}
|
// ENVPS4: Inputs/scei-ps4_tree/target/include_common
|
||||||
// ENVPS4-NOT: /usr/include
|
// ENVPS4-NOT: /usr/include
|
||||||
|
|
||||||
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
|
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
|
||||||
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
|
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
|
||||||
// SYSROOTPS4: "{{[^"]*}}clang{{[^"]*}}"
|
// SYSROOTPS4: "{{[^"]*}}clang{{[^"]*}}"
|
||||||
// SYSROOTPS4: Inputs/scei-ps4_tree/target/include{{$}}
|
// SYSROOTPS4: Inputs/scei-ps4_tree/target/include
|
||||||
// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common{{$}}
|
// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common
|
||||||
// SYSROOTPS4-NOT: /usr/include
|
// SYSROOTPS4-NOT: /usr/include
|
||||||
|
Loading…
Reference in New Issue
Block a user