[lldb] Create an enum to specify the kind of ArchSpec matching

s/true/ArchSpec::ExactMatch
s/false/ArchSpec::CompatibleMatch

Differential Revision: https://reviews.llvm.org/D121290

GitOrigin-RevId: 6093a77caf44aad1bc62056295988d08e13cd421
diff --git a/include/lldb/Target/Platform.h b/include/lldb/Target/Platform.h
index aa09b34..868f106 100644
--- a/include/lldb/Target/Platform.h
+++ b/include/lldb/Target/Platform.h
@@ -329,7 +329,7 @@
   /// the target triple contained within.
   virtual bool IsCompatibleArchitecture(const ArchSpec &arch,
                                         const ArchSpec &process_host_arch,
-                                        bool exact_arch_match,
+                                        ArchSpec::MatchType match,
                                         ArchSpec *compatible_arch_ptr);
 
   /// Not all platforms will support debugging a process by spawning somehow
diff --git a/include/lldb/Utility/ArchSpec.h b/include/lldb/Utility/ArchSpec.h
index f67aced..aad5c27 100644
--- a/include/lldb/Utility/ArchSpec.h
+++ b/include/lldb/Utility/ArchSpec.h
@@ -488,19 +488,25 @@
   ///         architecture and false otherwise.
   bool CharIsSignedByDefault() const;
 
-  /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu type
-  /// match between them. e.g. armv7s is not an exact match with armv7 - this
-  /// would return false
+  enum MatchType : bool { CompatibleMatch, ExactMatch };
+
+  /// Compare this ArchSpec to another ArchSpec. \a match specifies the kind of
+  /// matching that is to be done. CompatibleMatch requires only a compatible
+  /// cpu type (e.g., armv7s is compatible with armv7). ExactMatch requires an
+  /// exact match (armv7s is not an exact match with armv7).
   ///
   /// \return true if the two ArchSpecs match.
-  bool IsExactMatch(const ArchSpec &rhs) const;
+  bool IsMatch(const ArchSpec &rhs, MatchType match) const;
 
-  /// Compare an ArchSpec to another ArchSpec, requiring a compatible cpu type
-  /// match between them. e.g. armv7s is compatible with armv7 - this method
-  /// would return true
-  ///
-  /// \return true if the two ArchSpecs are compatible
-  bool IsCompatibleMatch(const ArchSpec &rhs) const;
+  /// Shorthand for IsMatch(rhs, ExactMatch).
+  bool IsExactMatch(const ArchSpec &rhs) const {
+    return IsMatch(rhs, ExactMatch);
+  }
+
+  /// Shorthand for IsMatch(rhs, CompatibleMatch).
+  bool IsCompatibleMatch(const ArchSpec &rhs) const {
+    return IsMatch(rhs, CompatibleMatch);
+  }
 
   bool IsFullySpecifiedTriple() const;
 
@@ -529,7 +535,6 @@
   void SetFlags(const std::string &elf_abi);
 
 protected:
-  bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
   void UpdateCore();
 
   llvm::Triple m_triple;
diff --git a/source/Interpreter/OptionGroupPlatform.cpp b/source/Interpreter/OptionGroupPlatform.cpp
index acdf3f2..60107eb 100644
--- a/source/Interpreter/OptionGroupPlatform.cpp
+++ b/source/Interpreter/OptionGroupPlatform.cpp
@@ -30,8 +30,9 @@
           m_platform_name);
     }
     if (platform_sp) {
-      if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(
-                                         arch, {}, false, &platform_arch)) {
+      if (platform_arch.IsValid() &&
+          !platform_sp->IsCompatibleArchitecture(
+              arch, {}, ArchSpec::CompatibleMatch, &platform_arch)) {
         error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",
                                         platform_sp->GetPluginName(),
                                         arch.GetTriple().getTriple());
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 61c4cba..b9b32bf 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -929,7 +929,8 @@
 
   ArchSpec compatible_arch;
   ArchSpec raw_arch(triple);
-  if (!IsCompatibleArchitecture(raw_arch, {}, false, &compatible_arch))
+  if (!IsCompatibleArchitecture(raw_arch, {}, ArchSpec::CompatibleMatch,
+                                &compatible_arch))
     return raw_arch;
 
   if (!compatible_arch.IsValid())
@@ -1156,16 +1157,14 @@
 /// architecture and the target triple contained within.
 bool Platform::IsCompatibleArchitecture(const ArchSpec &arch,
                                         const ArchSpec &process_host_arch,
-                                        bool exact_arch_match,
+                                        ArchSpec::MatchType match,
                                         ArchSpec *compatible_arch_ptr) {
   // If the architecture is invalid, we must answer true...
   if (arch.IsValid()) {
     ArchSpec platform_arch;
-    auto match = exact_arch_match ? &ArchSpec::IsExactMatch
-                                  : &ArchSpec::IsCompatibleMatch;
     for (const ArchSpec &platform_arch :
          GetSupportedArchitectures(process_host_arch)) {
-      if ((arch.*match)(platform_arch)) {
+      if (arch.IsMatch(platform_arch, match)) {
         if (compatible_arch_ptr)
           *compatible_arch_ptr = platform_arch;
         return true;
@@ -1966,14 +1965,15 @@
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
   // First try exact arch matches across all platforms already created
   for (const auto &platform_sp : m_platforms) {
-    if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch, true,
-                                              platform_arch_ptr))
+    if (platform_sp->IsCompatibleArchitecture(
+            arch, process_host_arch, ArchSpec::ExactMatch, platform_arch_ptr))
       return platform_sp;
   }
 
   // Next try compatible arch matches across all platforms already created
   for (const auto &platform_sp : m_platforms) {
-    if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch, false,
+    if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
+                                              ArchSpec::CompatibleMatch,
                                               platform_arch_ptr))
       return platform_sp;
   }
@@ -1985,8 +1985,9 @@
        (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx));
        ++idx) {
     PlatformSP platform_sp = create_callback(false, &arch);
-    if (platform_sp && platform_sp->IsCompatibleArchitecture(
-                           arch, process_host_arch, true, platform_arch_ptr)) {
+    if (platform_sp &&
+        platform_sp->IsCompatibleArchitecture(
+            arch, process_host_arch, ArchSpec::ExactMatch, platform_arch_ptr)) {
       m_platforms.push_back(platform_sp);
       return platform_sp;
     }
@@ -1997,7 +1998,8 @@
        ++idx) {
     PlatformSP platform_sp = create_callback(false, &arch);
     if (platform_sp && platform_sp->IsCompatibleArchitecture(
-                           arch, process_host_arch, false, platform_arch_ptr)) {
+                           arch, process_host_arch, ArchSpec::CompatibleMatch,
+                           platform_arch_ptr)) {
       m_platforms.push_back(platform_sp);
       return platform_sp;
     }
@@ -2031,7 +2033,7 @@
   if (m_selected_platform_sp) {
     for (const ArchSpec &arch : archs) {
       if (m_selected_platform_sp->IsCompatibleArchitecture(
-              arch, process_host_arch, false, nullptr))
+              arch, process_host_arch, ArchSpec::CompatibleMatch, nullptr))
         return m_selected_platform_sp;
     }
   }
@@ -2039,8 +2041,8 @@
   // Prefer the host platform if it matches at least one architecture.
   if (host_platform_sp) {
     for (const ArchSpec &arch : archs) {
-      if (host_platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
-                                                     false, nullptr))
+      if (host_platform_sp->IsCompatibleArchitecture(
+              arch, process_host_arch, ArchSpec::CompatibleMatch, nullptr))
         return host_platform_sp;
     }
   }
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index b2f1318..1b8df33 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -2905,9 +2905,9 @@
   ArchSpec process_host_arch = GetSystemArchitecture();
   if (platform_sp) {
     const ArchSpec &target_arch = GetTarget().GetArchitecture();
-    if (target_arch.IsValid() &&
-        !platform_sp->IsCompatibleArchitecture(target_arch, process_host_arch,
-                                               false, nullptr)) {
+    if (target_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(
+                                     target_arch, process_host_arch,
+                                     ArchSpec::CompatibleMatch, nullptr)) {
       ArchSpec platform_arch;
       platform_sp = GetTarget().GetDebugger().GetPlatformList().GetOrCreate(
           target_arch, process_host_arch, &platform_arch);
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index af511d6..6f361a4 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -1488,8 +1488,8 @@
   if (set_platform) {
     if (other.IsValid()) {
       auto platform_sp = GetPlatform();
-      if (!platform_sp ||
-          !platform_sp->IsCompatibleArchitecture(other, {}, false, nullptr)) {
+      if (!platform_sp || !platform_sp->IsCompatibleArchitecture(
+                              other, {}, ArchSpec::CompatibleMatch, nullptr)) {
         ArchSpec platform_arch;
         if (PlatformSP arch_platform_sp =
                 GetDebugger().GetPlatformList().GetOrCreate(other, {},
diff --git a/source/Target/TargetList.cpp b/source/Target/TargetList.cpp
index 5d60c1e..8ce2ae8 100644
--- a/source/Target/TargetList.cpp
+++ b/source/Target/TargetList.cpp
@@ -216,7 +216,8 @@
   // If we have a valid architecture, make sure the current platform is
   // compatible with that architecture.
   if (!prefer_platform_arch && arch.IsValid()) {
-    if (!platform_sp->IsCompatibleArchitecture(arch, {}, false, nullptr)) {
+    if (!platform_sp->IsCompatibleArchitecture(
+            arch, {}, ArchSpec::CompatibleMatch, nullptr)) {
       platform_sp = platform_list.GetOrCreate(arch, {}, &platform_arch);
       if (platform_sp)
         platform_list.SetSelectedPlatform(platform_sp);
@@ -225,7 +226,8 @@
     // If "arch" isn't valid, yet "platform_arch" is, it means we have an
     // executable file with a single architecture which should be used.
     ArchSpec fixed_platform_arch;
-    if (!platform_sp->IsCompatibleArchitecture(platform_arch, {}, false, nullptr)) {
+    if (!platform_sp->IsCompatibleArchitecture(
+            platform_arch, {}, ArchSpec::CompatibleMatch, nullptr)) {
       platform_sp =
           platform_list.GetOrCreate(platform_arch, {}, &fixed_platform_arch);
       if (platform_sp)
@@ -256,8 +258,8 @@
   ArchSpec arch(specified_arch);
 
   if (arch.IsValid()) {
-    if (!platform_sp ||
-        !platform_sp->IsCompatibleArchitecture(arch, {}, false, nullptr))
+    if (!platform_sp || !platform_sp->IsCompatibleArchitecture(
+                            arch, {}, ArchSpec::CompatibleMatch, nullptr))
       platform_sp =
           debugger.GetPlatformList().GetOrCreate(specified_arch, {}, &arch);
   }
diff --git a/source/Utility/ArchSpec.cpp b/source/Utility/ArchSpec.cpp
index a99aed8..7ea76c3 100644
--- a/source/Utility/ArchSpec.cpp
+++ b/source/Utility/ArchSpec.cpp
@@ -928,14 +928,6 @@
   return 0;
 }
 
-bool ArchSpec::IsExactMatch(const ArchSpec &rhs) const {
-  return IsEqualTo(rhs, true);
-}
-
-bool ArchSpec::IsCompatibleMatch(const ArchSpec &rhs) const {
-  return IsEqualTo(rhs, false);
-}
-
 static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
                                     llvm::Triple::EnvironmentType rhs) {
   if (lhs == rhs)
@@ -967,11 +959,11 @@
   return false;
 }
 
-bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const {
+bool ArchSpec::IsMatch(const ArchSpec &rhs, MatchType match) const {
   // explicitly ignoring m_distribution_id in this method.
 
   if (GetByteOrder() != rhs.GetByteOrder() ||
-      !cores_match(GetCore(), rhs.GetCore(), true, exact_match))
+      !cores_match(GetCore(), rhs.GetCore(), true, match == ExactMatch))
     return false;
 
   const llvm::Triple &lhs_triple = GetTriple();
@@ -988,7 +980,7 @@
   // On Windows, the vendor field doesn't have any practical effect, but
   // it is often set to either "pc" or "w64".
   if ((lhs_triple_vendor != rhs_triple_vendor) &&
-      (exact_match || !both_windows)) {
+      (match == ExactMatch || !both_windows)) {
     const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
     const bool lhs_vendor_specified = TripleVendorWasSpecified();
     // Both architectures had the vendor specified, so if they aren't equal
@@ -1007,7 +999,7 @@
   const llvm::Triple::EnvironmentType rhs_triple_env =
       rhs_triple.getEnvironment();
 
-  if (!exact_match) {
+  if (match == CompatibleMatch) {
     // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
     if ((lhs_triple_os == llvm::Triple::IOS &&
          lhs_triple_env == llvm::Triple::MacABI &&
@@ -1034,12 +1026,13 @@
       return false;
 
     // If the pair of os+env is both unspecified, match any other os+env combo.
-    if (!exact_match && ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
-                         (!rhs_os_specified && !rhs_triple.hasEnvironment())))
+    if (match == CompatibleMatch &&
+        ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
+         (!rhs_os_specified && !rhs_triple.hasEnvironment())))
       return true;
   }
 
-  if (!exact_match && both_windows)
+  if (match == CompatibleMatch && both_windows)
     return true; // The Windows environments (MSVC vs GNU) are compatible
 
   return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env);