[lld] r190451 - Remove PackedVersion from MachOLinkingContext and replace with uint32_t
Nick Kledzik
kledzik at apple.com
Tue Sep 10 16:46:58 PDT 2013
Author: kledzik
Date: Tue Sep 10 18:46:57 2013
New Revision: 190451
URL: http://llvm.org/viewvc/llvm-project?rev=190451&view=rev
Log:
Remove PackedVersion from MachOLinkingContext and replace with uint32_t
and a parsePackedVersion() utility.
Patch by Joe Ranieri
Modified:
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=190451&r1=190450&r2=190451&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Tue Sep 10 18:46:57 2013
@@ -77,29 +77,19 @@ public:
static uint32_t cpuTypeFromArch(Arch arch);
static uint32_t cpuSubtypeFromArch(Arch arch);
+ /// Construct 32-bit value from string "X.Y.Z" where
+ /// bits are xxxx.yy.zz. Largest number is 65535.255.255
+ static bool parsePackedVersion(StringRef str, uint32_t &result);
+
private:
virtual Writer &writer() const;
- /// 32-bit packed encoding of "X.Y.Z" where nibbles are xxxx.yy.zz.
- struct PackedVersion {
- PackedVersion(StringRef);
- static bool parse(StringRef, PackedVersion &);
- bool operator<(const PackedVersion &) const;
- bool operator>=(const PackedVersion &) const;
- bool operator==(const PackedVersion &) const;
-
- private:
- PackedVersion(uint32_t v) : _value(v) {}
-
- uint32_t _value;
- };
-
uint32_t _outputFileType; // e.g MH_EXECUTE
bool _outputFileTypeStatic; // Disambiguate static vs dynamic prog
bool _doNothing; // for -help and -v which just print info
Arch _arch;
OS _os;
- PackedVersion _osMinVersion;
+ uint32_t _osMinVersion;
uint64_t _pageZeroSize;
mutable std::unique_ptr<mach_o::KindHandler> _kindHandler;
mutable std::unique_ptr<Reader> _machoReader;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=190451&r1=190450&r2=190451&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Tue Sep 10 18:46:57 2013
@@ -25,16 +25,8 @@ using lld::mach_o::KindHandler;
namespace lld {
-MachOLinkingContext::PackedVersion::PackedVersion(StringRef str) {
- if (parse(str, *this))
- llvm_unreachable("bad version string");
-}
-
-/// Construct 32-bit PackedVersion from string "X.Y.Z" where
-/// bits are xxxx.yy.zz. Largest number is 65535.255.255
-bool MachOLinkingContext::PackedVersion::parse(
- StringRef str, MachOLinkingContext::PackedVersion &result) {
- result._value = 0;
+bool MachOLinkingContext::parsePackedVersion(StringRef str, uint32_t &result) {
+ result = 0;
if (str.empty())
return false;
@@ -47,14 +39,14 @@ bool MachOLinkingContext::PackedVersion:
return true;
if (num > 65535)
return true;
- result._value = num << 16;
+ result = num << 16;
if (parts.size() > 1) {
if (llvm::getAsUnsignedInteger(parts[1], 10, num))
return true;
if (num > 255)
return true;
- result._value |= (num << 8);
+ result |= (num << 8);
}
if (parts.size() > 2) {
@@ -62,27 +54,12 @@ bool MachOLinkingContext::PackedVersion:
return true;
if (num > 255)
return true;
- result._value |= num;
+ result |= num;
}
return false;
}
-bool MachOLinkingContext::PackedVersion::
-operator<(const PackedVersion &rhs) const {
- return _value < rhs._value;
-}
-
-bool MachOLinkingContext::PackedVersion::
-operator>=(const PackedVersion &rhs) const {
- return _value >= rhs._value;
-}
-
-bool MachOLinkingContext::PackedVersion::
-operator==(const PackedVersion &rhs) const {
- return _value == rhs._value;
-}
-
struct ArchInfo {
StringRef archName;
MachOLinkingContext::Arch arch;
@@ -146,8 +123,8 @@ uint32_t MachOLinkingContext::cpuSubtype
MachOLinkingContext::MachOLinkingContext()
: _outputFileType(mach_o::MH_EXECUTE), _outputFileTypeStatic(false),
- _doNothing(false), _arch(arch_unknown), _os(OS::macOSX),
- _osMinVersion("0.0"), _pageZeroSize(0x1000), _kindHandler(nullptr) {}
+ _doNothing(false), _arch(arch_unknown), _os(OS::macOSX), _osMinVersion(0),
+ _pageZeroSize(0x1000), _kindHandler(nullptr) {}
MachOLinkingContext::~MachOLinkingContext() {}
@@ -172,11 +149,19 @@ bool MachOLinkingContext::outputTypeHasE
bool MachOLinkingContext::minOS(StringRef mac, StringRef iOS) const {
switch (_os) {
- case OS::macOSX:
- return (_osMinVersion >= PackedVersion(mac));
+ case OS::macOSX: {
+ uint32_t parsedVersion;
+ if (parsePackedVersion(mac, parsedVersion))
+ return false;
+ return _osMinVersion >= parsedVersion;
+ }
case OS::iOS:
- case OS::iOS_simulator:
- return (_osMinVersion >= PackedVersion(iOS));
+ case OS::iOS_simulator: {
+ uint32_t parsedVersion;
+ if (parsePackedVersion(iOS, parsedVersion))
+ return false;
+ return _osMinVersion >= parsedVersion;
+ }
}
llvm_unreachable("target not configured for iOS or MacOSX");
}
@@ -224,7 +209,7 @@ bool MachOLinkingContext::validateImpl(r
bool MachOLinkingContext::setOS(OS os, StringRef minOSVersion) {
_os = os;
- return PackedVersion::parse(minOSVersion, _osMinVersion);
+ return parsePackedVersion(minOSVersion, _osMinVersion);
}
void MachOLinkingContext::addPasses(PassManager &pm) const {
More information about the llvm-commits
mailing list