Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:37

0001 //===- llvm/TextAPI/PackedVersion.h - PackedVersion -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Defines the Mach-O packed version format.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_TEXTAPI_PACKEDVERSION_H
0014 #define LLVM_TEXTAPI_PACKEDVERSION_H
0015 
0016 #include "llvm/Support/VersionTuple.h"
0017 #include <cstdint>
0018 #include <string>
0019 #include <utility>
0020 
0021 namespace llvm {
0022 class raw_ostream;
0023 class StringRef;
0024 
0025 namespace MachO {
0026 
0027 class PackedVersion {
0028   uint32_t Version{0};
0029 
0030 public:
0031   constexpr PackedVersion() = default;
0032   constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
0033   PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
0034       : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
0035 
0036   PackedVersion(VersionTuple VT) {
0037     unsigned Minor = 0, Subminor = 0;
0038     if (auto VTMinor = VT.getMinor())
0039       Minor = *VTMinor;
0040     if (auto VTSub = VT.getSubminor())
0041       Subminor = *VTSub;
0042     *this = PackedVersion(VT.getMajor(), Minor, Subminor);
0043   }
0044 
0045   bool empty() const { return Version == 0; }
0046 
0047   /// Retrieve the major version number.
0048   unsigned getMajor() const { return Version >> 16; }
0049 
0050   /// Retrieve the minor version number, if provided.
0051   unsigned getMinor() const { return (Version >> 8) & 0xff; }
0052 
0053   /// Retrieve the subminor version number, if provided.
0054   unsigned getSubminor() const { return Version & 0xff; }
0055 
0056   bool parse32(StringRef Str);
0057   std::pair<bool, bool> parse64(StringRef Str);
0058 
0059   bool operator<(const PackedVersion &O) const { return Version < O.Version; }
0060 
0061   bool operator==(const PackedVersion &O) const { return Version == O.Version; }
0062 
0063   bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
0064 
0065   uint32_t rawValue() const { return Version; }
0066 
0067   operator std::string() const;
0068 
0069   void print(raw_ostream &OS) const;
0070 };
0071 
0072 inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
0073   Version.print(OS);
0074   return OS;
0075 }
0076 
0077 } // end namespace MachO.
0078 } // end namespace llvm.
0079 
0080 #endif // LLVM_TEXTAPI_PACKEDVERSION_H