forked from OSchip/llvm-project
parent
e13ffee009
commit
aa9f1c59d2
|
@ -257,7 +257,9 @@ public:
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
explicit ArchSpec(const llvm::Triple &triple);
|
explicit ArchSpec(const llvm::Triple &triple);
|
||||||
explicit ArchSpec(const char *triple_cstr);
|
explicit ArchSpec(const char *triple_cstr);
|
||||||
explicit ArchSpec(const char *triple_cstr, Platform *platform);
|
explicit ArchSpec(llvm::StringRef triple_str);
|
||||||
|
ArchSpec(const char *triple_cstr, Platform *platform);
|
||||||
|
ArchSpec(llvm::StringRef triple_str, Platform *platform);
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
/// Constructor over architecture name.
|
/// Constructor over architecture name.
|
||||||
///
|
///
|
||||||
|
@ -505,8 +507,10 @@ public:
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
bool SetTriple(const llvm::Triple &triple);
|
bool SetTriple(const llvm::Triple &triple);
|
||||||
|
|
||||||
bool SetTriple(const char *triple_cstr);
|
bool SetTriple(llvm::StringRef triple_str);
|
||||||
|
bool SetTriple(llvm::StringRef triple_str, Platform *platform);
|
||||||
|
|
||||||
|
bool SetTriple(const char *triple_cstr);
|
||||||
bool SetTriple(const char *triple_cstr, Platform *platform);
|
bool SetTriple(const char *triple_cstr, Platform *platform);
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
@ -596,13 +600,13 @@ protected:
|
||||||
bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
|
bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
|
||||||
|
|
||||||
llvm::Triple m_triple;
|
llvm::Triple m_triple;
|
||||||
Core m_core;
|
Core m_core = kCore_invalid;
|
||||||
lldb::ByteOrder m_byte_order;
|
lldb::ByteOrder m_byte_order = lldb::eByteOrderInvalid;
|
||||||
|
|
||||||
// Additional arch flags which we cannot get from triple and core
|
// Additional arch flags which we cannot get from triple and core
|
||||||
// For MIPS these are application specific extensions like
|
// For MIPS these are application specific extensions like
|
||||||
// micromips, mips16 etc.
|
// micromips, mips16 etc.
|
||||||
uint32_t m_flags;
|
uint32_t m_flags = 0;
|
||||||
|
|
||||||
ConstString m_distribution_id;
|
ConstString m_distribution_id;
|
||||||
|
|
||||||
|
|
|
@ -555,33 +555,27 @@ FindArchDefinitionEntry(const ArchDefinition *def, ArchSpec::Core core) {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
|
|
||||||
ArchSpec::ArchSpec()
|
ArchSpec::ArchSpec() {}
|
||||||
: m_triple(), m_core(kCore_invalid), m_byte_order(eByteOrderInvalid),
|
|
||||||
m_flags(0), m_distribution_id() {}
|
|
||||||
|
|
||||||
ArchSpec::ArchSpec(const char *triple_cstr, Platform *platform)
|
ArchSpec::ArchSpec(const char *triple_cstr, Platform *platform) {
|
||||||
: m_triple(), m_core(kCore_invalid), m_byte_order(eByteOrderInvalid),
|
|
||||||
m_flags(0), m_distribution_id() {
|
|
||||||
if (triple_cstr)
|
if (triple_cstr)
|
||||||
SetTriple(triple_cstr, platform);
|
SetTriple(triple_cstr, platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSpec::ArchSpec(const char *triple_cstr)
|
ArchSpec::ArchSpec(llvm::StringRef triple_str, Platform *platform) {
|
||||||
: m_triple(), m_core(kCore_invalid), m_byte_order(eByteOrderInvalid),
|
SetTriple(triple_str, platform);
|
||||||
m_flags(0), m_distribution_id() {
|
}
|
||||||
|
|
||||||
|
ArchSpec::ArchSpec(const char *triple_cstr) {
|
||||||
if (triple_cstr)
|
if (triple_cstr)
|
||||||
SetTriple(triple_cstr);
|
SetTriple(triple_cstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSpec::ArchSpec(const llvm::Triple &triple)
|
ArchSpec::ArchSpec(llvm::StringRef triple_str) { SetTriple(triple_str); }
|
||||||
: m_triple(), m_core(kCore_invalid), m_byte_order(eByteOrderInvalid),
|
|
||||||
m_flags(0), m_distribution_id() {
|
|
||||||
SetTriple(triple);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArchSpec::ArchSpec(ArchitectureType arch_type, uint32_t cpu, uint32_t subtype)
|
ArchSpec::ArchSpec(const llvm::Triple &triple) { SetTriple(triple); }
|
||||||
: m_triple(), m_core(kCore_invalid), m_byte_order(eByteOrderInvalid),
|
|
||||||
m_flags(0), m_distribution_id() {
|
ArchSpec::ArchSpec(ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) {
|
||||||
SetArchitecture(arch_type, cpu, subtype);
|
SetArchitecture(arch_type, cpu, subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,99 +851,104 @@ bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, Arc
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchSpec::SetTriple(const char *triple_cstr) {
|
bool ArchSpec::SetTriple(const char *triple_cstr) {
|
||||||
if (triple_cstr && triple_cstr[0]) {
|
llvm::StringRef str(triple_cstr ? triple_cstr : "");
|
||||||
llvm::StringRef triple_stref(triple_cstr);
|
return SetTriple(str);
|
||||||
|
|
||||||
if (ParseMachCPUDashSubtypeTriple(triple_stref, *this))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (triple_stref.startswith(LLDB_ARCH_DEFAULT)) {
|
|
||||||
// Special case for the current host default architectures...
|
|
||||||
if (triple_stref.equals(LLDB_ARCH_DEFAULT_32BIT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
|
|
||||||
else if (triple_stref.equals(LLDB_ARCH_DEFAULT_64BIT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
|
|
||||||
else if (triple_stref.equals(LLDB_ARCH_DEFAULT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
|
|
||||||
} else {
|
|
||||||
std::string normalized_triple_sstr(llvm::Triple::normalize(triple_stref));
|
|
||||||
triple_stref = normalized_triple_sstr;
|
|
||||||
SetTriple(llvm::Triple(triple_stref));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
Clear();
|
|
||||||
return IsValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchSpec::SetTriple(const char *triple_cstr, Platform *platform) {
|
bool ArchSpec::SetTriple(const char *triple_cstr, Platform *platform) {
|
||||||
if (triple_cstr && triple_cstr[0]) {
|
llvm::StringRef str(triple_cstr ? triple_cstr : "");
|
||||||
if (ParseMachCPUDashSubtypeTriple(triple_cstr, *this))
|
return SetTriple(str, platform);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
llvm::StringRef triple_stref(triple_cstr);
|
bool ArchSpec::SetTriple(llvm::StringRef triple) {
|
||||||
if (triple_stref.startswith(LLDB_ARCH_DEFAULT)) {
|
if (triple.empty()) {
|
||||||
// Special case for the current host default architectures...
|
|
||||||
if (triple_stref.equals(LLDB_ARCH_DEFAULT_32BIT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
|
|
||||||
else if (triple_stref.equals(LLDB_ARCH_DEFAULT_64BIT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
|
|
||||||
else if (triple_stref.equals(LLDB_ARCH_DEFAULT))
|
|
||||||
*this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
|
|
||||||
} else {
|
|
||||||
ArchSpec raw_arch(triple_cstr);
|
|
||||||
|
|
||||||
std::string normalized_triple_sstr(llvm::Triple::normalize(triple_stref));
|
|
||||||
triple_stref = normalized_triple_sstr;
|
|
||||||
llvm::Triple normalized_triple(triple_stref);
|
|
||||||
|
|
||||||
const bool os_specified = normalized_triple.getOSName().size() > 0;
|
|
||||||
const bool vendor_specified =
|
|
||||||
normalized_triple.getVendorName().size() > 0;
|
|
||||||
const bool env_specified =
|
|
||||||
normalized_triple.getEnvironmentName().size() > 0;
|
|
||||||
|
|
||||||
// If we got an arch only, then default the vendor, os, environment
|
|
||||||
// to match the platform if one is supplied
|
|
||||||
if (!(os_specified || vendor_specified || env_specified)) {
|
|
||||||
if (platform) {
|
|
||||||
// If we were given a platform, use the platform's system
|
|
||||||
// architecture. If this is not available (might not be
|
|
||||||
// connected) use the first supported architecture.
|
|
||||||
ArchSpec compatible_arch;
|
|
||||||
if (platform->IsCompatibleArchitecture(raw_arch, false,
|
|
||||||
&compatible_arch)) {
|
|
||||||
if (compatible_arch.IsValid()) {
|
|
||||||
const llvm::Triple &compatible_triple =
|
|
||||||
compatible_arch.GetTriple();
|
|
||||||
if (!vendor_specified)
|
|
||||||
normalized_triple.setVendor(compatible_triple.getVendor());
|
|
||||||
if (!os_specified)
|
|
||||||
normalized_triple.setOS(compatible_triple.getOS());
|
|
||||||
if (!env_specified &&
|
|
||||||
compatible_triple.getEnvironmentName().size())
|
|
||||||
normalized_triple.setEnvironment(
|
|
||||||
compatible_triple.getEnvironment());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*this = raw_arch;
|
|
||||||
return IsValid();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No platform specified, fall back to the host system for
|
|
||||||
// the default vendor, os, and environment.
|
|
||||||
llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
|
|
||||||
if (!vendor_specified)
|
|
||||||
normalized_triple.setVendor(host_triple.getVendor());
|
|
||||||
if (!vendor_specified)
|
|
||||||
normalized_triple.setOS(host_triple.getOS());
|
|
||||||
if (!env_specified && host_triple.getEnvironmentName().size())
|
|
||||||
normalized_triple.setEnvironment(host_triple.getEnvironment());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SetTriple(normalized_triple);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
Clear();
|
Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ParseMachCPUDashSubtypeTriple(triple, *this))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (triple.startswith(LLDB_ARCH_DEFAULT)) {
|
||||||
|
// Special case for the current host default architectures...
|
||||||
|
if (triple.equals(LLDB_ARCH_DEFAULT_32BIT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
|
||||||
|
else if (triple.equals(LLDB_ARCH_DEFAULT_64BIT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
|
||||||
|
else if (triple.equals(LLDB_ARCH_DEFAULT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
|
||||||
|
} else {
|
||||||
|
SetTriple(llvm::Triple(llvm::Triple::normalize(triple)));
|
||||||
|
}
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ArchSpec::SetTriple(llvm::StringRef triple, Platform *platform) {
|
||||||
|
if (triple.empty()) {
|
||||||
|
Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ParseMachCPUDashSubtypeTriple(triple, *this))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (triple.startswith(LLDB_ARCH_DEFAULT)) {
|
||||||
|
// Special case for the current host default architectures...
|
||||||
|
if (triple.equals(LLDB_ARCH_DEFAULT_32BIT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
|
||||||
|
else if (triple.equals(LLDB_ARCH_DEFAULT_64BIT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
|
||||||
|
else if (triple.equals(LLDB_ARCH_DEFAULT))
|
||||||
|
*this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArchSpec raw_arch(triple);
|
||||||
|
|
||||||
|
llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
|
||||||
|
|
||||||
|
const bool os_specified = !normalized_triple.getOSName().empty();
|
||||||
|
const bool vendor_specified = !normalized_triple.getVendorName().empty();
|
||||||
|
const bool env_specified = !normalized_triple.getEnvironmentName().empty();
|
||||||
|
|
||||||
|
if (os_specified || vendor_specified || env_specified) {
|
||||||
|
SetTriple(normalized_triple);
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We got an arch only. If there is no platform, fallback to the host system
|
||||||
|
// for defaults.
|
||||||
|
if (!platform) {
|
||||||
|
llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
|
||||||
|
if (!vendor_specified)
|
||||||
|
normalized_triple.setVendor(host_triple.getVendor());
|
||||||
|
if (!vendor_specified)
|
||||||
|
normalized_triple.setOS(host_triple.getOS());
|
||||||
|
if (!env_specified && host_triple.getEnvironmentName().size())
|
||||||
|
normalized_triple.setEnvironment(host_triple.getEnvironment());
|
||||||
|
SetTriple(normalized_triple);
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we were given a platform, use the platform's system architecture. If
|
||||||
|
// this is not available (might not be connected) use the first supported
|
||||||
|
// architecture.
|
||||||
|
ArchSpec compatible_arch;
|
||||||
|
if (!platform->IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) {
|
||||||
|
*this = raw_arch;
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compatible_arch.IsValid()) {
|
||||||
|
const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
|
||||||
|
if (!vendor_specified)
|
||||||
|
normalized_triple.setVendor(compatible_triple.getVendor());
|
||||||
|
if (!os_specified)
|
||||||
|
normalized_triple.setOS(compatible_triple.getOS());
|
||||||
|
if (!env_specified && compatible_triple.hasEnvironment())
|
||||||
|
normalized_triple.setEnvironment(compatible_triple.getEnvironment());
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTriple(normalized_triple);
|
||||||
return IsValid();
|
return IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include "lldb/Core/ArchSpec.h"
|
#include "lldb/Core/ArchSpec.h"
|
||||||
|
|
||||||
|
#include "llvm/Support/MachO.h"
|
||||||
|
|
||||||
using namespace lldb;
|
using namespace lldb;
|
||||||
using namespace lldb_private;
|
using namespace lldb_private;
|
||||||
|
|
||||||
|
@ -93,3 +95,42 @@ TEST(ArchSpecTest, TestParseMachCPUDashSubtypeTripleExtra) {
|
||||||
EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("12-10.10", AS));
|
EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("12-10.10", AS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ArchSpecTest, TestSetTriple) {
|
||||||
|
ArchSpec AS;
|
||||||
|
|
||||||
|
// Various flavors of valid triples.
|
||||||
|
EXPECT_TRUE(AS.SetTriple("12-10-apple-darwin"));
|
||||||
|
EXPECT_EQ(llvm::MachO::CPU_TYPE_ARM, AS.GetMachOCPUType());
|
||||||
|
EXPECT_EQ(10, AS.GetMachOCPUSubType());
|
||||||
|
EXPECT_TRUE(llvm::StringRef(AS.GetTriple().str())
|
||||||
|
.consume_front("armv7f-apple-darwin"));
|
||||||
|
EXPECT_EQ(ArchSpec::eCore_arm_armv7f, AS.GetCore());
|
||||||
|
|
||||||
|
AS = ArchSpec();
|
||||||
|
EXPECT_TRUE(AS.SetTriple("18.100-apple-darwin"));
|
||||||
|
EXPECT_EQ(llvm::MachO::CPU_TYPE_POWERPC, AS.GetMachOCPUType());
|
||||||
|
EXPECT_EQ(100, AS.GetMachOCPUSubType());
|
||||||
|
EXPECT_TRUE(llvm::StringRef(AS.GetTriple().str())
|
||||||
|
.consume_front("powerpc-apple-darwin"));
|
||||||
|
EXPECT_EQ(ArchSpec::eCore_ppc_ppc970, AS.GetCore());
|
||||||
|
|
||||||
|
AS = ArchSpec();
|
||||||
|
EXPECT_TRUE(AS.SetTriple("i686-pc-windows"));
|
||||||
|
EXPECT_EQ(llvm::Triple::x86, AS.GetTriple().getArch());
|
||||||
|
EXPECT_EQ(llvm::Triple::PC, AS.GetTriple().getVendor());
|
||||||
|
EXPECT_EQ(llvm::Triple::Win32, AS.GetTriple().getOS());
|
||||||
|
EXPECT_TRUE(
|
||||||
|
llvm::StringRef(AS.GetTriple().str()).consume_front("i686-pc-windows"));
|
||||||
|
EXPECT_STREQ("i686", AS.GetArchitectureName());
|
||||||
|
EXPECT_EQ(ArchSpec::eCore_x86_32_i686, AS.GetCore());
|
||||||
|
|
||||||
|
// Various flavors of invalid triples.
|
||||||
|
AS = ArchSpec();
|
||||||
|
EXPECT_FALSE(AS.SetTriple("unknown-unknown-unknown"));
|
||||||
|
|
||||||
|
AS = ArchSpec();
|
||||||
|
EXPECT_FALSE(AS.SetTriple("unknown"));
|
||||||
|
|
||||||
|
AS = ArchSpec();
|
||||||
|
EXPECT_FALSE(AS.SetTriple(""));
|
||||||
|
}
|
Loading…
Reference in New Issue