Author: labath Date: Mon Nov 13 07:57:20 2017 New Revision: 318046 URL: http://llvm.org/viewvc/llvm-project?rev=318046&view=rev Log: Remove last Host usage from ArchSpec
Summary: In D39387, I was quick to jump to conclusion that ArchSpec has no external dependencies. It turns there still was one call to HostInfo::GetArchitecture left -- for implementing the "systemArch32" architecture and friends. Since GetAugmentedArchSpec is the place we handle these "incomplete" triples that don't specify os or vendor and "systemArch" looks very much like an incomplete triple, I move its handling there. After this ArchSpec *really* does not have external dependencies, and I'll move it to the Utility module as a follow-up. Reviewers: zturner, clayborg, jingham Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D39896 Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h lldb/trunk/source/Core/ArchSpec.cpp lldb/trunk/source/Host/common/HostInfoBase.cpp lldb/trunk/source/Target/Platform.cpp lldb/trunk/unittests/Host/HostInfoTest.cpp Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=318046&r1=318045&r2=318046&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/HostInfoBase.h (original) +++ lldb/trunk/include/lldb/Host/HostInfoBase.h Mon Nov 13 07:57:20 2017 @@ -61,6 +61,8 @@ public: static const ArchSpec & GetArchitecture(ArchitectureKind arch_kind = eArchKindDefault); + static llvm::Optional<ArchitectureKind> ParseArchitectureKind(llvm::StringRef kind); + //------------------------------------------------------------------ /// Find a resource files that are related to LLDB. /// Modified: lldb/trunk/source/Core/ArchSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=318046&r1=318045&r2=318046&view=diff ============================================================================== --- lldb/trunk/source/Core/ArchSpec.cpp (original) +++ lldb/trunk/source/Core/ArchSpec.cpp Mon Nov 13 07:57:20 2017 @@ -9,7 +9,6 @@ #include "lldb/Core/ArchSpec.h" -#include "lldb/Host/HostInfo.h" #include "lldb/Utility/NameMatches.h" #include "lldb/Utility/Stream.h" // for Stream #include "lldb/Utility/StringList.h" @@ -874,17 +873,7 @@ bool ArchSpec::SetTriple(llvm::StringRef 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))); - } + SetTriple(llvm::Triple(llvm::Triple::normalize(triple))); return IsValid(); } Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=318046&r1=318045&r2=318046&view=diff ============================================================================== --- lldb/trunk/source/Host/common/HostInfoBase.cpp (original) +++ lldb/trunk/source/Host/common/HostInfoBase.cpp Mon Nov 13 07:57:20 2017 @@ -103,6 +103,14 @@ const ArchSpec &HostInfoBase::GetArchite : g_fields->m_host_arch_32; } +llvm::Optional<HostInfoBase::ArchitectureKind> HostInfoBase::ParseArchitectureKind(llvm::StringRef kind) { + return llvm::StringSwitch<llvm::Optional<ArchitectureKind>>(kind) + .Case(LLDB_ARCH_DEFAULT, eArchKindDefault) + .Case(LLDB_ARCH_DEFAULT_32BIT, eArchKind32) + .Case(LLDB_ARCH_DEFAULT_64BIT, eArchKind64) + .Default(llvm::None); +} + bool HostInfoBase::GetLLDBPath(lldb::PathType type, FileSpec &file_spec) { file_spec.Clear(); @@ -258,6 +266,9 @@ ArchSpec HostInfoBase::GetAugmentedArchS if (!ArchSpec::ContainsOnlyArch(normalized_triple)) return ArchSpec(triple); + if (auto kind = HostInfo::ParseArchitectureKind(triple)) + return HostInfo::GetArchitecture(*kind); + llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple()); if (normalized_triple.getVendorName().empty()) Modified: lldb/trunk/source/Target/Platform.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=318046&r1=318045&r2=318046&view=diff ============================================================================== --- lldb/trunk/source/Target/Platform.cpp (original) +++ lldb/trunk/source/Target/Platform.cpp Mon Nov 13 07:57:20 2017 @@ -976,6 +976,9 @@ ArchSpec Platform::GetAugmentedArchSpec( if (!ArchSpec::ContainsOnlyArch(normalized_triple)) return ArchSpec(triple); + if (auto kind = HostInfo::ParseArchitectureKind(triple)) + return HostInfo::GetArchitecture(*kind); + ArchSpec compatible_arch; ArchSpec raw_arch(triple); if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=318046&r1=318045&r2=318046&view=diff ============================================================================== --- lldb/trunk/unittests/Host/HostInfoTest.cpp (original) +++ lldb/trunk/unittests/Host/HostInfoTest.cpp Mon Nov 13 07:57:20 2017 @@ -1,4 +1,4 @@ -//===-- HostTest.cpp --------------------------------------------*- C++ -*-===// +//===-- HostInfoTest.cpp ----------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/HostInfo.h" +#include "lldb/lldb-defines.h" #include "gtest/gtest.h" using namespace lldb_private; @@ -37,4 +38,8 @@ TEST_F(HostInfoTest, GetAugmentedArchSpe EXPECT_EQ(spec.GetTriple().getOS(), triple.getOS()); EXPECT_EQ(spec.GetTriple().getVendor(), triple.getVendor()); EXPECT_EQ(spec.GetTriple().getEnvironment(), triple.getEnvironment()); + + // Test LLDB_ARCH_DEFAULT + EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(), + HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple()); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits