Skip to content

Commit

Permalink
[lldb] Remove PlatformDarwin::GetCompatibleArch helper
Browse files Browse the repository at this point in the history
This also removes the corresponding unit tests. I wrote them to sanity
check my original refactoring and checked them in because why not. The
current implementation, without the added complexity of indices, is
simple enough that we can do without it.
  • Loading branch information
JDevlieghere committed Jan 15, 2022
1 parent 5c5bde1 commit ff85dcb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 107 deletions.
16 changes: 2 additions & 14 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Expand Up @@ -631,28 +631,16 @@ static llvm::ArrayRef<const char *> GetCompatibleArchs(ArchSpec::Core core) {
return {};
}

const char *PlatformDarwin::GetCompatibleArch(ArchSpec::Core core, size_t idx) {
llvm::ArrayRef<const char *> compatible_archs = GetCompatibleArchs(core);
if (!compatible_archs.data())
return nullptr;
if (idx < compatible_archs.size())
return compatible_archs[idx];
return nullptr;
}

/// The architecture selection rules for arm processors These cpu subtypes have
/// distinct names (e.g. armv7f) but armv7 binaries run fine on an armv7f
/// processor.
void PlatformDarwin::ARMGetSupportedArchitectures(
std::vector<ArchSpec> &archs, llvm::Optional<llvm::Triple::OSType> os) {
const ArchSpec system_arch = GetSystemArchitecture();
const ArchSpec::Core system_core = system_arch.GetCore();

const char *compatible_arch;
for (unsigned idx = 0;
(compatible_arch = GetCompatibleArch(system_core, idx)); ++idx) {
for (const char *arch : GetCompatibleArchs(system_core)) {
llvm::Triple triple;
triple.setArchName(compatible_arch);
triple.setArchName(arch);
triple.setVendor(llvm::Triple::VendorType::Apple);
if (os)
triple.setOS(*os);
Expand Down
93 changes: 0 additions & 93 deletions lldb/unittests/Platform/PlatformDarwinTest.cpp
Expand Up @@ -20,7 +20,6 @@ using namespace lldb_private;
struct PlatformDarwinTester : public PlatformDarwin {
public:
using PlatformDarwin::FindComponentInPath;
using PlatformDarwin::GetCompatibleArch;
};

TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
Expand Down Expand Up @@ -67,95 +66,3 @@ TEST(PlatformDarwinTest, FindComponentInPath) {
EXPECT_EQ("",
PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar"));
}

TEST(PlatformDarwinTest, GetCompatibleArchARM64) {
const ArchSpec::Core core = ArchSpec::eCore_arm_arm64;
EXPECT_STREQ("arm64", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 10));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 11));
EXPECT_STREQ("thumbv7", PlatformDarwinTester::GetCompatibleArch(core, 12));
EXPECT_STREQ("thumbv4t", PlatformDarwinTester::GetCompatibleArch(core, 21));
EXPECT_STREQ("thumb", PlatformDarwinTester::GetCompatibleArch(core, 22));
EXPECT_EQ(nullptr, PlatformDarwinTester::GetCompatibleArch(core, 23));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7f) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7f;
EXPECT_STREQ("armv7f", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6));
EXPECT_STREQ("thumbv7f", PlatformDarwinTester::GetCompatibleArch(core, 7));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7k) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7k;
EXPECT_STREQ("armv7k", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6));
EXPECT_STREQ("thumbv7k", PlatformDarwinTester::GetCompatibleArch(core, 7));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7s) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7s;
EXPECT_STREQ("armv7s", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6));
EXPECT_STREQ("thumbv7s", PlatformDarwinTester::GetCompatibleArch(core, 7));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7m) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7m;
EXPECT_STREQ("armv7m", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6));
EXPECT_STREQ("thumbv7m", PlatformDarwinTester::GetCompatibleArch(core, 7));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7em) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7em;
EXPECT_STREQ("armv7em", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6));
EXPECT_STREQ("thumbv7em", PlatformDarwinTester::GetCompatibleArch(core, 7));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv7) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv7;
EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv6m", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 5));
EXPECT_STREQ("thumbv7", PlatformDarwinTester::GetCompatibleArch(core, 6));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv6m) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv6m;
EXPECT_STREQ("armv6m", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv6", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 4));
EXPECT_STREQ("thumbv6m", PlatformDarwinTester::GetCompatibleArch(core, 5));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv6) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv6;
EXPECT_STREQ("armv6", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv5", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 3));
EXPECT_STREQ("thumbv6", PlatformDarwinTester::GetCompatibleArch(core, 4));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv5) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv5;
EXPECT_STREQ("armv5", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 2));
EXPECT_STREQ("thumbv5", PlatformDarwinTester::GetCompatibleArch(core, 3));
}

TEST(PlatformDarwinTest, GetCompatibleArchARMv4) {
const ArchSpec::Core core = ArchSpec::eCore_arm_armv4;
EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 0));
EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 1));
EXPECT_STREQ("thumbv4t", PlatformDarwinTester::GetCompatibleArch(core, 2));
EXPECT_STREQ("thumb", PlatformDarwinTester::GetCompatibleArch(core, 3));
}

0 comments on commit ff85dcb

Please sign in to comment.