Use read{le,be}{16,32}. NFC.

llvm-svn: 230728
This commit is contained in:
Rui Ueyama 2015-02-27 04:21:40 +00:00
parent 4a7e390c12
commit e088a0f989
1 changed files with 10 additions and 24 deletions

View File

@ -9,11 +9,11 @@
#include "MachONormalizedFile.h"
#include "lld/Core/Endian.h"
#include "lld/Core/Error.h"
#include "lld/Core/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/MachO.h"
@ -28,60 +28,46 @@ namespace normalized {
using llvm::sys::getSwappedBytes;
using llvm::support::ubig16_t;
using llvm::support::ubig32_t;
using llvm::support::ubig64_t;
using llvm::support::ulittle16_t;
using llvm::support::ulittle32_t;
using llvm::support::ulittle64_t;
template<typename T>
static inline uint16_t read16(const T *loc, bool isBig) {
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&
"invalid pointer alignment");
if (isBig)
return *(const ubig16_t *)loc;
return *(const ulittle16_t *)loc;
return isBig ? read16be(loc) : read16le(loc);
}
template<typename T>
static inline uint32_t read32(const T *loc, bool isBig) {
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&
"invalid pointer alignment");
if (isBig)
return *(const ubig32_t *)loc;
return *(const ulittle32_t *)loc;
return isBig ? read32be(loc) : read32le(loc);
}
template<typename T>
static inline uint64_t read64(const T *loc, bool isBig) {
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&
"invalid pointer alignment");
if (isBig)
return *(const ubig64_t *)loc;
return *(const ulittle64_t *)loc;
return isBig ? read64be(loc) : read64le(loc);
}
inline void write16(uint8_t *loc, uint16_t value, bool isBig) {
if (isBig)
*(ubig16_t *)loc = value;
write16be(loc, value);
else
*(ulittle16_t *)loc = value;
write16le(loc, value);
}
inline void write32(uint8_t *loc, uint32_t value, bool isBig) {
if (isBig)
*(ubig32_t *)loc = value;
write32be(loc, value);
else
*(ulittle32_t *)loc = value;
write32le(loc, value);
}
inline void write64(uint8_t *loc, uint64_t value, bool isBig) {
if (isBig)
*(ubig64_t *)loc = value;
write64be(loc, value);
else
*(ulittle64_t *)loc = value;
write64le(loc, value);
}
inline uint32_t