Use llvm::VersionTuple instead of manual version marshalling

Summary:
This has multiple advantages:
- we need only one function argument/instance variable instead of three
- no need to default initialize variables
- no custom parsing code
- VersionTuple has comparison operators, which makes version comparisons much
  simpler

Reviewers: zturner, friss, clayborg, jingham

Subscribers: emaste, lldb-commits

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

llvm-svn: 334950
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index ce62077..0aa0fc9 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5549,8 +5549,7 @@
   return eStrataUnknown;
 }
 
-uint32_t ObjectFileMachO::GetVersion(uint32_t *versions,
-                                     uint32_t num_versions) {
+llvm::VersionTuple ObjectFileMachO::GetVersion() {
   ModuleSP module_sp(GetModule());
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
@@ -5578,23 +5577,13 @@
     }
 
     if (version_cmd == LC_ID_DYLIB) {
-      if (versions != NULL && num_versions > 0) {
-        if (num_versions > 0)
-          versions[0] = (version & 0xFFFF0000ull) >> 16;
-        if (num_versions > 1)
-          versions[1] = (version & 0x0000FF00ull) >> 8;
-        if (num_versions > 2)
-          versions[2] = (version & 0x000000FFull);
-        // Fill in an remaining version numbers with invalid values
-        for (i = 3; i < num_versions; ++i)
-          versions[i] = UINT32_MAX;
-      }
-      // The LC_ID_DYLIB load command has a version with 3 version numbers in
-      // it, so always return 3
-      return 3;
+      unsigned major = (version & 0xFFFF0000ull) >> 16;
+      unsigned minor = (version & 0x0000FF00ull) >> 8;
+      unsigned subminor = (version & 0x000000FFull);
+      return llvm::VersionTuple(major, minor, subminor);
     }
   }
-  return false;
+  return llvm::VersionTuple();
 }
 
 bool ObjectFileMachO::GetArchitecture(ArchSpec &arch) {
@@ -5708,12 +5697,10 @@
 #endif
 }
 
-uint32_t ObjectFileMachO::GetMinimumOSVersion(uint32_t *versions,
-                                              uint32_t num_versions) {
-  if (m_min_os_versions.empty()) {
+llvm::VersionTuple ObjectFileMachO::GetMinimumOSVersion() {
+  if (!m_min_os_version) {
     lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-    bool success = false;
-    for (uint32_t i = 0; success == false && i < m_header.ncmds; ++i) {
+    for (uint32_t i = 0; i < m_header.ncmds; ++i) {
       const lldb::offset_t load_cmd_offset = offset;
 
       version_min_command lc;
@@ -5729,35 +5716,21 @@
           const uint32_t yy = (lc.version >> 8) & 0xffu;
           const uint32_t zz = lc.version & 0xffu;
           if (xxxx) {
-            m_min_os_versions.push_back(xxxx);
-            m_min_os_versions.push_back(yy);
-            m_min_os_versions.push_back(zz);
+            m_min_os_version = llvm::VersionTuple(xxxx, yy, zz);
+            break;
           }
-          success = true;
         }
       }
       offset = load_cmd_offset + lc.cmdsize;
     }
 
-    if (success == false) {
-      // Push an invalid value so we don't keep trying to
-      m_min_os_versions.push_back(UINT32_MAX);
+    if (!m_min_os_version) {
+      // Set version to an empty value so we don't keep trying to
+      m_min_os_version = llvm::VersionTuple();
     }
   }
 
-  if (m_min_os_versions.size() > 1 || m_min_os_versions[0] != UINT32_MAX) {
-    if (versions != NULL && num_versions > 0) {
-      for (size_t i = 0; i < num_versions; ++i) {
-        if (i < m_min_os_versions.size())
-          versions[i] = m_min_os_versions[i];
-        else
-          versions[i] = 0;
-      }
-    }
-    return m_min_os_versions.size();
-  }
-  // Call the superclasses version that will empty out the data
-  return ObjectFile::GetMinimumOSVersion(versions, num_versions);
+  return *m_min_os_version;
 }
 
 uint32_t ObjectFileMachO::GetSDKVersion(uint32_t *versions,