forked from OSchip/llvm-project
OnDiskHashTable: Use Endian.h to read little endian ostreams
Rather than rolling our own functions to read little endian data from a buffer, we can use the support in llvm's Endian.h. No functional change. llvm-svn: 205045
This commit is contained in:
parent
a06321efdd
commit
498d82ee3e
|
@ -37,45 +37,6 @@ inline void Pad(raw_ostream& Out, unsigned A) {
|
|||
endian::Writer<little>(Out).write<uint8_t>(0);
|
||||
}
|
||||
|
||||
inline uint16_t ReadUnalignedLE16(const unsigned char *&Data) {
|
||||
uint16_t V = ((uint16_t)Data[0]) |
|
||||
((uint16_t)Data[1] << 8);
|
||||
Data += 2;
|
||||
return V;
|
||||
}
|
||||
|
||||
inline uint32_t ReadUnalignedLE32(const unsigned char *&Data) {
|
||||
uint32_t V = ((uint32_t)Data[0]) |
|
||||
((uint32_t)Data[1] << 8) |
|
||||
((uint32_t)Data[2] << 16) |
|
||||
((uint32_t)Data[3] << 24);
|
||||
Data += 4;
|
||||
return V;
|
||||
}
|
||||
|
||||
inline uint64_t ReadUnalignedLE64(const unsigned char *&Data) {
|
||||
uint64_t V = ((uint64_t)Data[0]) |
|
||||
((uint64_t)Data[1] << 8) |
|
||||
((uint64_t)Data[2] << 16) |
|
||||
((uint64_t)Data[3] << 24) |
|
||||
((uint64_t)Data[4] << 32) |
|
||||
((uint64_t)Data[5] << 40) |
|
||||
((uint64_t)Data[6] << 48) |
|
||||
((uint64_t)Data[7] << 56);
|
||||
Data += 8;
|
||||
return V;
|
||||
}
|
||||
|
||||
inline uint32_t ReadLE32(const unsigned char *&Data) {
|
||||
// Hosts that directly support little-endian 32-bit loads can just
|
||||
// use them. Big-endian hosts need a bswap.
|
||||
uint32_t V = *((const uint32_t*)Data);
|
||||
if (llvm::sys::IsBigEndianHost)
|
||||
V = llvm::ByteSwap_32(V);
|
||||
Data += 4;
|
||||
return V;
|
||||
}
|
||||
|
||||
} // end namespace io
|
||||
|
||||
template<typename Info>
|
||||
|
@ -255,7 +216,7 @@ public:
|
|||
if (!InfoPtr)
|
||||
InfoPtr = &InfoObj;
|
||||
|
||||
using namespace io;
|
||||
using namespace llvm::support;
|
||||
const internal_key_type& iKey = InfoObj.GetInternalKey(eKey);
|
||||
unsigned key_hash = InfoObj.ComputeHash(iKey);
|
||||
|
||||
|
@ -263,17 +224,17 @@ public:
|
|||
unsigned idx = key_hash & (NumBuckets - 1);
|
||||
const unsigned char* Bucket = Buckets + sizeof(uint32_t)*idx;
|
||||
|
||||
unsigned offset = ReadLE32(Bucket);
|
||||
unsigned offset = endian::readNext<uint32_t, little, aligned>(Bucket);
|
||||
if (offset == 0) return iterator(); // Empty bucket.
|
||||
const unsigned char* Items = Base + offset;
|
||||
|
||||
// 'Items' starts with a 16-bit unsigned integer representing the
|
||||
// number of items in this bucket.
|
||||
unsigned len = ReadUnalignedLE16(Items);
|
||||
unsigned len = endian::readNext<uint16_t, little, unaligned>(Items);
|
||||
|
||||
for (unsigned i = 0; i < len; ++i) {
|
||||
// Read the hash.
|
||||
uint32_t item_hash = ReadUnalignedLE32(Items);
|
||||
uint32_t item_hash = endian::readNext<uint32_t, little, unaligned>(Items);
|
||||
|
||||
// Determine the length of the key and the data.
|
||||
const std::pair<unsigned, unsigned>& L = Info::ReadKeyDataLength(Items);
|
||||
|
@ -328,10 +289,12 @@ public:
|
|||
}
|
||||
|
||||
key_iterator& operator++() { // Preincrement
|
||||
using namespace llvm::support;
|
||||
if (!NumItemsInBucketLeft) {
|
||||
// 'Items' starts with a 16-bit unsigned integer representing the
|
||||
// number of items in this bucket.
|
||||
NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr);
|
||||
NumItemsInBucketLeft =
|
||||
endian::readNext<uint16_t, little, unaligned>(Ptr);
|
||||
}
|
||||
Ptr += 4; // Skip the hash.
|
||||
// Determine the length of the key and the data.
|
||||
|
@ -392,10 +355,12 @@ public:
|
|||
}
|
||||
|
||||
data_iterator& operator++() { // Preincrement
|
||||
using namespace llvm::support;
|
||||
if (!NumItemsInBucketLeft) {
|
||||
// 'Items' starts with a 16-bit unsigned integer representing the
|
||||
// number of items in this bucket.
|
||||
NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr);
|
||||
NumItemsInBucketLeft =
|
||||
endian::readNext<uint16_t, little, unaligned>(Ptr);
|
||||
}
|
||||
Ptr += 4; // Skip the hash.
|
||||
// Determine the length of the key and the data.
|
||||
|
@ -437,13 +402,13 @@ public:
|
|||
static OnDiskChainedHashTable* Create(const unsigned char* buckets,
|
||||
const unsigned char* const base,
|
||||
const Info &InfoObj = Info()) {
|
||||
using namespace io;
|
||||
using namespace llvm::support;
|
||||
assert(buckets > base);
|
||||
assert((reinterpret_cast<uintptr_t>(buckets) & 0x3) == 0 &&
|
||||
"buckets should be 4-byte aligned.");
|
||||
|
||||
unsigned numBuckets = ReadLE32(buckets);
|
||||
unsigned numEntries = ReadLE32(buckets);
|
||||
unsigned numBuckets = endian::readNext<uint32_t, little, aligned>(buckets);
|
||||
unsigned numEntries = endian::readNext<uint32_t, little, aligned>(buckets);
|
||||
return new OnDiskChainedHashTable<Info>(numBuckets, numEntries, buckets,
|
||||
base, InfoObj);
|
||||
}
|
||||
|
|
|
@ -48,14 +48,17 @@ bool PTHLexer::Lex(Token& Tok) {
|
|||
//===--------------------------------------==//
|
||||
// Read the raw token data.
|
||||
//===--------------------------------------==//
|
||||
using namespace llvm::support;
|
||||
|
||||
// Shadow CurPtr into an automatic variable.
|
||||
const unsigned char *CurPtrShadow = CurPtr;
|
||||
|
||||
// Read in the data for the token.
|
||||
unsigned Word0 = ReadLE32(CurPtrShadow);
|
||||
uint32_t IdentifierID = ReadLE32(CurPtrShadow);
|
||||
uint32_t FileOffset = ReadLE32(CurPtrShadow);
|
||||
unsigned Word0 = endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
|
||||
uint32_t IdentifierID =
|
||||
endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
|
||||
uint32_t FileOffset =
|
||||
endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
|
||||
|
||||
tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF);
|
||||
Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF);
|
||||
|
@ -185,6 +188,7 @@ void PTHLexer::DiscardToEndOfLine() {
|
|||
|
||||
/// SkipBlock - Used by Preprocessor to skip the current conditional block.
|
||||
bool PTHLexer::SkipBlock() {
|
||||
using namespace llvm::support;
|
||||
assert(CurPPCondPtr && "No cached PP conditional information.");
|
||||
assert(LastHashTokPtr && "No known '#' token.");
|
||||
|
||||
|
@ -193,10 +197,10 @@ bool PTHLexer::SkipBlock() {
|
|||
|
||||
do {
|
||||
// Read the token offset from the side-table.
|
||||
uint32_t Offset = ReadLE32(CurPPCondPtr);
|
||||
uint32_t Offset = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
|
||||
|
||||
// Read the target table index from the side-table.
|
||||
TableIdx = ReadLE32(CurPPCondPtr);
|
||||
TableIdx = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
|
||||
|
||||
// Compute the actual memory address of the '#' token data for this entry.
|
||||
HashEntryI = TokBuf + Offset;
|
||||
|
@ -213,12 +217,13 @@ bool PTHLexer::SkipBlock() {
|
|||
PPCond + TableIdx*(sizeof(uint32_t)*2);
|
||||
assert(NextPPCondPtr >= CurPPCondPtr);
|
||||
// Read where we should jump to.
|
||||
const unsigned char* HashEntryJ = TokBuf + ReadLE32(NextPPCondPtr);
|
||||
const unsigned char *HashEntryJ =
|
||||
TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
|
||||
|
||||
if (HashEntryJ <= LastHashTokPtr) {
|
||||
// Jump directly to the next entry in the side table.
|
||||
HashEntryI = HashEntryJ;
|
||||
TableIdx = ReadLE32(NextPPCondPtr);
|
||||
TableIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
|
||||
CurPPCondPtr = NextPPCondPtr;
|
||||
}
|
||||
}
|
||||
|
@ -233,8 +238,9 @@ bool PTHLexer::SkipBlock() {
|
|||
CurPPCondPtr = NextPPCondPtr;
|
||||
|
||||
// Read where we should jump to.
|
||||
HashEntryI = TokBuf + ReadLE32(NextPPCondPtr);
|
||||
uint32_t NextIdx = ReadLE32(NextPPCondPtr);
|
||||
HashEntryI =
|
||||
TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
|
||||
uint32_t NextIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
|
||||
|
||||
// By construction NextIdx will be zero if this is a #endif. This is useful
|
||||
// to know to obviate lexing another token.
|
||||
|
@ -283,8 +289,10 @@ SourceLocation PTHLexer::getSourceLocation() {
|
|||
// handling a #included file. Just read the necessary data from the token
|
||||
// data buffer to construct the SourceLocation object.
|
||||
// NOTE: This is a virtual function; hence it is defined out-of-line.
|
||||
using namespace llvm::support;
|
||||
|
||||
const unsigned char *OffsetPtr = CurPtr + (DISK_TOKEN_SIZE - 4);
|
||||
uint32_t Offset = ReadLE32(OffsetPtr);
|
||||
uint32_t Offset = endian::readNext<uint32_t, little, aligned>(OffsetPtr);
|
||||
return FileStartLoc.getLocWithOffset(Offset);
|
||||
}
|
||||
|
||||
|
@ -318,7 +326,9 @@ public:
|
|||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ReadKeyDataLength(const unsigned char*& d) {
|
||||
unsigned keyLen = (unsigned) ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned keyLen =
|
||||
(unsigned)endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned dataLen = (unsigned) *(d++);
|
||||
return std::make_pair(keyLen, dataLen);
|
||||
}
|
||||
|
@ -345,8 +355,9 @@ public:
|
|||
static PTHFileData ReadData(const internal_key_type& k,
|
||||
const unsigned char* d, unsigned) {
|
||||
assert(k.first == 0x1 && "Only file lookups can match!");
|
||||
uint32_t x = ::ReadUnalignedLE32(d);
|
||||
uint32_t y = ::ReadUnalignedLE32(d);
|
||||
using namespace llvm::support;
|
||||
uint32_t x = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
uint32_t y = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
return PTHFileData(x, y);
|
||||
}
|
||||
};
|
||||
|
@ -377,7 +388,10 @@ public:
|
|||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ReadKeyDataLength(const unsigned char*& d) {
|
||||
return std::make_pair((unsigned) ReadUnalignedLE16(d), sizeof(uint32_t));
|
||||
using namespace llvm::support;
|
||||
return std::make_pair(
|
||||
(unsigned)endian::readNext<uint16_t, little, unaligned>(d),
|
||||
sizeof(uint32_t));
|
||||
}
|
||||
|
||||
static std::pair<const char*, unsigned>
|
||||
|
@ -388,7 +402,8 @@ public:
|
|||
|
||||
static uint32_t ReadData(const internal_key_type& k, const unsigned char* d,
|
||||
unsigned) {
|
||||
return ::ReadUnalignedLE32(d);
|
||||
using namespace llvm::support;
|
||||
return endian::readNext<uint32_t, little, unaligned>(d);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -434,6 +449,8 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
return 0;
|
||||
}
|
||||
|
||||
using namespace llvm::support;
|
||||
|
||||
// Get the buffer ranges and check if there are at least three 32-bit
|
||||
// words at the end of the file.
|
||||
const unsigned char *BufBeg = (const unsigned char*)File->getBufferStart();
|
||||
|
@ -448,7 +465,7 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
|
||||
// Read the PTH version.
|
||||
const unsigned char *p = BufBeg + (sizeof("cfe-pth"));
|
||||
unsigned Version = ReadLE32(p);
|
||||
unsigned Version = endian::readNext<uint32_t, little, aligned>(p);
|
||||
|
||||
if (Version < PTHManager::Version) {
|
||||
InvalidPTH(Diags,
|
||||
|
@ -469,7 +486,8 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
// Construct the file lookup table. This will be used for mapping from
|
||||
// FileEntry*'s to cached tokens.
|
||||
const unsigned char* FileTableOffset = PrologueOffset + sizeof(uint32_t)*2;
|
||||
const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset);
|
||||
const unsigned char *FileTable =
|
||||
BufBeg + endian::readNext<uint32_t, little, aligned>(FileTableOffset);
|
||||
|
||||
if (!(FileTable > BufBeg && FileTable < BufEnd)) {
|
||||
Diags.Report(diag::err_invalid_pth_file) << file;
|
||||
|
@ -486,7 +504,8 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
// Get the location of the table mapping from persistent ids to the
|
||||
// data needed to reconstruct identifiers.
|
||||
const unsigned char* IDTableOffset = PrologueOffset + sizeof(uint32_t)*0;
|
||||
const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset);
|
||||
const unsigned char *IData =
|
||||
BufBeg + endian::readNext<uint32_t, little, aligned>(IDTableOffset);
|
||||
|
||||
if (!(IData >= BufBeg && IData < BufEnd)) {
|
||||
Diags.Report(diag::err_invalid_pth_file) << file;
|
||||
|
@ -496,7 +515,8 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
// Get the location of the hashtable mapping between strings and
|
||||
// persistent IDs.
|
||||
const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
|
||||
const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset);
|
||||
const unsigned char *StringIdTable =
|
||||
BufBeg + endian::readNext<uint32_t, little, aligned>(StringIdTableOffset);
|
||||
if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
|
||||
Diags.Report(diag::err_invalid_pth_file) << file;
|
||||
return 0;
|
||||
|
@ -507,14 +527,15 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
|
||||
// Get the location of the spelling cache.
|
||||
const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
|
||||
const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset);
|
||||
const unsigned char *spellingBase =
|
||||
BufBeg + endian::readNext<uint32_t, little, aligned>(spellingBaseOffset);
|
||||
if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
|
||||
Diags.Report(diag::err_invalid_pth_file) << file;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the number of IdentifierInfos and pre-allocate the identifier cache.
|
||||
uint32_t NumIds = ReadLE32(IData);
|
||||
uint32_t NumIds = endian::readNext<uint32_t, little, aligned>(IData);
|
||||
|
||||
// Pre-allocate the persistent ID -> IdentifierInfo* cache. We use calloc()
|
||||
// so that we in the best case only zero out memory once when the OS returns
|
||||
|
@ -531,7 +552,8 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
|
||||
// Compute the address of the original source file.
|
||||
const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4;
|
||||
unsigned len = ReadUnalignedLE16(originalSourceBase);
|
||||
unsigned len =
|
||||
endian::readNext<uint16_t, little, unaligned>(originalSourceBase);
|
||||
if (!len) originalSourceBase = 0;
|
||||
|
||||
// Create the new PTHManager.
|
||||
|
@ -541,10 +563,12 @@ PTHManager *PTHManager::Create(const std::string &file,
|
|||
}
|
||||
|
||||
IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
|
||||
using namespace llvm::support;
|
||||
// Look in the PTH file for the string data for the IdentifierInfo object.
|
||||
const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID;
|
||||
const unsigned char* IDData =
|
||||
(const unsigned char*)Buf->getBufferStart() + ReadLE32(TableEntry);
|
||||
const unsigned char *IDData =
|
||||
(const unsigned char *)Buf->getBufferStart() +
|
||||
endian::readNext<uint32_t, little, aligned>(TableEntry);
|
||||
assert(IDData < (const unsigned char*)Buf->getBufferEnd());
|
||||
|
||||
// Allocate the object.
|
||||
|
@ -580,6 +604,8 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) {
|
|||
if (!FE)
|
||||
return 0;
|
||||
|
||||
using namespace llvm::support;
|
||||
|
||||
// Lookup the FileEntry object in our file lookup data structure. It will
|
||||
// return a variant that indicates whether or not there is an offset within
|
||||
// the PTH file that contains cached tokens.
|
||||
|
@ -597,7 +623,7 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) {
|
|||
|
||||
// Get the location of pp-conditional table.
|
||||
const unsigned char* ppcond = BufStart + FileData.getPPCondOffset();
|
||||
uint32_t Len = ReadLE32(ppcond);
|
||||
uint32_t Len = endian::readNext<uint32_t, little, aligned>(ppcond);
|
||||
if (Len == 0) ppcond = 0;
|
||||
|
||||
assert(PP && "No preprocessor set yet!");
|
||||
|
@ -651,11 +677,13 @@ public:
|
|||
d += 4 * 2; // Skip the first 2 words.
|
||||
}
|
||||
|
||||
uint64_t File = ReadUnalignedLE64(d);
|
||||
uint64_t Device = ReadUnalignedLE64(d);
|
||||
using namespace llvm::support;
|
||||
|
||||
uint64_t File = endian::readNext<uint64_t, little, unaligned>(d);
|
||||
uint64_t Device = endian::readNext<uint64_t, little, unaligned>(d);
|
||||
llvm::sys::fs::UniqueID UniqueID(File, Device);
|
||||
time_t ModTime = ReadUnalignedLE64(d);
|
||||
uint64_t Size = ReadUnalignedLE64(d);
|
||||
time_t ModTime = endian::readNext<uint64_t, little, unaligned>(d);
|
||||
uint64_t Size = endian::readNext<uint64_t, little, unaligned>(d);
|
||||
return data_type(Size, ModTime, UniqueID, IsDirectory);
|
||||
}
|
||||
|
||||
|
|
|
@ -470,19 +470,19 @@ unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) {
|
|||
|
||||
std::pair<unsigned, unsigned>
|
||||
ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
|
||||
using namespace clang::io;
|
||||
unsigned KeyLen = ReadUnalignedLE16(d);
|
||||
unsigned DataLen = ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
ASTSelectorLookupTrait::internal_key_type
|
||||
ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
|
||||
using namespace clang::io;
|
||||
using namespace llvm::support;
|
||||
SelectorTable &SelTable = Reader.getContext().Selectors;
|
||||
unsigned N = ReadUnalignedLE16(d);
|
||||
IdentifierInfo *FirstII
|
||||
= Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
|
||||
unsigned N = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
IdentifierInfo *FirstII = Reader.getLocalIdentifier(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d));
|
||||
if (N == 0)
|
||||
return SelTable.getNullarySelector(FirstII);
|
||||
else if (N == 1)
|
||||
|
@ -491,7 +491,8 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
|
|||
SmallVector<IdentifierInfo *, 16> Args;
|
||||
Args.push_back(FirstII);
|
||||
for (unsigned I = 1; I != N; ++I)
|
||||
Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)));
|
||||
Args.push_back(Reader.getLocalIdentifier(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d)));
|
||||
|
||||
return SelTable.getSelector(N, Args.data());
|
||||
}
|
||||
|
@ -499,13 +500,16 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
|
|||
ASTSelectorLookupTrait::data_type
|
||||
ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d,
|
||||
unsigned DataLen) {
|
||||
using namespace clang::io;
|
||||
using namespace llvm::support;
|
||||
|
||||
data_type Result;
|
||||
|
||||
Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d));
|
||||
unsigned NumInstanceMethodsAndBits = ReadUnalignedLE16(d);
|
||||
unsigned NumFactoryMethodsAndBits = ReadUnalignedLE16(d);
|
||||
Result.ID = Reader.getGlobalSelectorID(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d));
|
||||
unsigned NumInstanceMethodsAndBits =
|
||||
endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned NumFactoryMethodsAndBits =
|
||||
endian::readNext<uint16_t, little, unaligned>(d);
|
||||
Result.InstanceBits = NumInstanceMethodsAndBits & 0x3;
|
||||
Result.FactoryBits = NumFactoryMethodsAndBits & 0x3;
|
||||
unsigned NumInstanceMethods = NumInstanceMethodsAndBits >> 2;
|
||||
|
@ -513,15 +517,15 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d,
|
|||
|
||||
// Load instance methods
|
||||
for (unsigned I = 0; I != NumInstanceMethods; ++I) {
|
||||
if (ObjCMethodDecl *Method
|
||||
= Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)))
|
||||
if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d)))
|
||||
Result.Instance.push_back(Method);
|
||||
}
|
||||
|
||||
// Load factory methods
|
||||
for (unsigned I = 0; I != NumFactoryMethods; ++I) {
|
||||
if (ObjCMethodDecl *Method
|
||||
= Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)))
|
||||
if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d)))
|
||||
Result.Factory.push_back(Method);
|
||||
}
|
||||
|
||||
|
@ -534,9 +538,9 @@ unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) {
|
|||
|
||||
std::pair<unsigned, unsigned>
|
||||
ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) {
|
||||
using namespace clang::io;
|
||||
unsigned DataLen = ReadUnalignedLE16(d);
|
||||
unsigned KeyLen = ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
|
@ -559,8 +563,8 @@ static bool isInterestingIdentifier(IdentifierInfo &II) {
|
|||
IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
||||
const unsigned char* d,
|
||||
unsigned DataLen) {
|
||||
using namespace clang::io;
|
||||
unsigned RawID = ReadUnalignedLE32(d);
|
||||
using namespace llvm::support;
|
||||
unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
bool IsInteresting = RawID & 0x01;
|
||||
|
||||
// Wipe out the "is interesting" bit.
|
||||
|
@ -586,8 +590,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
|||
return II;
|
||||
}
|
||||
|
||||
unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d);
|
||||
unsigned Bits = ReadUnalignedLE16(d);
|
||||
unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
bool CPlusPlusOperatorKeyword = Bits & 0x01;
|
||||
Bits >>= 1;
|
||||
bool HasRevertedTokenIDToIdentifier = Bits & 0x01;
|
||||
|
@ -636,11 +640,13 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
|||
// If this identifier is a macro, deserialize the macro
|
||||
// definition.
|
||||
if (hadMacroDefinition) {
|
||||
uint32_t MacroDirectivesOffset = ReadUnalignedLE32(d);
|
||||
uint32_t MacroDirectivesOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(d);
|
||||
DataLen -= 4;
|
||||
SmallVector<uint32_t, 8> LocalMacroIDs;
|
||||
if (hasSubmoduleMacros) {
|
||||
while (uint32_t LocalMacroID = ReadUnalignedLE32(d)) {
|
||||
while (uint32_t LocalMacroID =
|
||||
endian::readNext<uint32_t, little, unaligned>(d)) {
|
||||
DataLen -= 4;
|
||||
LocalMacroIDs.push_back(LocalMacroID);
|
||||
}
|
||||
|
@ -688,7 +694,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
|||
if (DataLen > 0) {
|
||||
SmallVector<uint32_t, 4> DeclIDs;
|
||||
for (; DataLen > 0; DataLen -= 4)
|
||||
DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d)));
|
||||
DeclIDs.push_back(Reader.getGlobalDeclID(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d)));
|
||||
Reader.SetGloballyVisibleDecls(II, DeclIDs);
|
||||
}
|
||||
|
||||
|
@ -756,34 +763,37 @@ ASTDeclContextNameLookupTrait::GetInternalKey(
|
|||
|
||||
std::pair<unsigned, unsigned>
|
||||
ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
|
||||
using namespace clang::io;
|
||||
unsigned KeyLen = ReadUnalignedLE16(d);
|
||||
unsigned DataLen = ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
ASTDeclContextNameLookupTrait::internal_key_type
|
||||
ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) {
|
||||
using namespace clang::io;
|
||||
using namespace llvm::support;
|
||||
|
||||
DeclNameKey Key;
|
||||
Key.Kind = (DeclarationName::NameKind)*d++;
|
||||
switch (Key.Kind) {
|
||||
case DeclarationName::Identifier:
|
||||
Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
|
||||
Key.Data = (uint64_t)Reader.getLocalIdentifier(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d));
|
||||
break;
|
||||
case DeclarationName::ObjCZeroArgSelector:
|
||||
case DeclarationName::ObjCOneArgSelector:
|
||||
case DeclarationName::ObjCMultiArgSelector:
|
||||
Key.Data =
|
||||
(uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d))
|
||||
.getAsOpaquePtr();
|
||||
(uint64_t)Reader.getLocalSelector(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(
|
||||
d)).getAsOpaquePtr();
|
||||
break;
|
||||
case DeclarationName::CXXOperatorName:
|
||||
Key.Data = *d++; // OverloadedOperatorKind
|
||||
break;
|
||||
case DeclarationName::CXXLiteralOperatorName:
|
||||
Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
|
||||
Key.Data = (uint64_t)Reader.getLocalIdentifier(
|
||||
F, endian::readNext<uint32_t, little, unaligned>(d));
|
||||
break;
|
||||
case DeclarationName::CXXConstructorName:
|
||||
case DeclarationName::CXXDestructorName:
|
||||
|
@ -800,8 +810,8 @@ ASTDeclContextNameLookupTrait::data_type
|
|||
ASTDeclContextNameLookupTrait::ReadData(internal_key_type,
|
||||
const unsigned char* d,
|
||||
unsigned DataLen) {
|
||||
using namespace clang::io;
|
||||
unsigned NumDecls = ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned NumDecls = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
LE32DeclID *Start = reinterpret_cast<LE32DeclID *>(
|
||||
const_cast<unsigned char *>(d));
|
||||
return std::make_pair(Start, Start + NumDecls);
|
||||
|
@ -1354,16 +1364,18 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
|
|||
|
||||
std::pair<unsigned, unsigned>
|
||||
HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) {
|
||||
unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned DataLen = (unsigned) *d++;
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
HeaderFileInfoTrait::internal_key_type
|
||||
HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) {
|
||||
using namespace llvm::support;
|
||||
internal_key_type ikey;
|
||||
ikey.Size = off_t(clang::io::ReadUnalignedLE64(d));
|
||||
ikey.ModTime = time_t(clang::io::ReadUnalignedLE64(d));
|
||||
ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d));
|
||||
ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d));
|
||||
ikey.Filename = (const char *)d;
|
||||
return ikey;
|
||||
}
|
||||
|
@ -1372,7 +1384,7 @@ HeaderFileInfoTrait::data_type
|
|||
HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
|
||||
unsigned DataLen) {
|
||||
const unsigned char *End = d + DataLen;
|
||||
using namespace clang::io;
|
||||
using namespace llvm::support;
|
||||
HeaderFileInfo HFI;
|
||||
unsigned Flags = *d++;
|
||||
HFI.HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>
|
||||
|
@ -1382,10 +1394,11 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
|
|||
HFI.DirInfo = (Flags >> 2) & 0x03;
|
||||
HFI.Resolved = (Flags >> 1) & 0x01;
|
||||
HFI.IndexHeaderMapHeader = Flags & 0x01;
|
||||
HFI.NumIncludes = ReadUnalignedLE16(d);
|
||||
HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M,
|
||||
ReadUnalignedLE32(d));
|
||||
if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) {
|
||||
HFI.NumIncludes = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
|
||||
M, endian::readNext<uint32_t, little, unaligned>(d));
|
||||
if (unsigned FrameworkOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(d)) {
|
||||
// The framework offset is 1 greater than the actual offset,
|
||||
// since 0 is used as an indicator for "no framework name".
|
||||
StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1);
|
||||
|
@ -1393,7 +1406,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
|
|||
}
|
||||
|
||||
if (d != End) {
|
||||
uint32_t LocalSMID = ReadUnalignedLE32(d);
|
||||
uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
if (LocalSMID) {
|
||||
// This header is part of a module. Associate it with the module to enable
|
||||
// implicit module import.
|
||||
|
@ -2737,7 +2750,8 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
|
|||
ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap);
|
||||
|
||||
while(Data < DataEnd) {
|
||||
uint16_t Len = io::ReadUnalignedLE16(Data);
|
||||
using namespace llvm::support;
|
||||
uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data);
|
||||
StringRef Name = StringRef((const char*)Data, Len);
|
||||
Data += Len;
|
||||
ModuleFile *OM = ModuleMgr.lookup(Name);
|
||||
|
@ -2746,15 +2760,23 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
|
|||
return true;
|
||||
}
|
||||
|
||||
uint32_t SLocOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data);
|
||||
uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data);
|
||||
|
||||
uint32_t SLocOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t IdentifierIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t MacroIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t PreprocessedEntityIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t SubmoduleIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t SelectorIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t DeclIDOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
uint32_t TypeIndexOffset =
|
||||
endian::readNext<uint32_t, little, unaligned>(Data);
|
||||
|
||||
// Source location offset is mapped to OM->SLocEntryBaseOffset.
|
||||
SLocRemap.insert(std::make_pair(SLocOffset,
|
||||
static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset)));
|
||||
|
|
|
@ -82,9 +82,9 @@ public:
|
|||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ReadKeyDataLength(const unsigned char*& d) {
|
||||
using namespace clang::io;
|
||||
unsigned KeyLen = ReadUnalignedLE16(d);
|
||||
unsigned DataLen = ReadUnalignedLE16(d);
|
||||
using namespace llvm::support;
|
||||
unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
|
@ -101,11 +101,11 @@ public:
|
|||
static data_type ReadData(const internal_key_type& k,
|
||||
const unsigned char* d,
|
||||
unsigned DataLen) {
|
||||
using namespace clang::io;
|
||||
using namespace llvm::support;
|
||||
|
||||
data_type Result;
|
||||
while (DataLen > 0) {
|
||||
unsigned ID = ReadUnalignedLE32(d);
|
||||
unsigned ID = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
Result.push_back(ID);
|
||||
DataLen -= 4;
|
||||
}
|
||||
|
@ -459,8 +459,8 @@ namespace {
|
|||
unsigned DataLen) {
|
||||
// The first bit indicates whether this identifier is interesting.
|
||||
// That's all we care about.
|
||||
using namespace clang::io;
|
||||
unsigned RawID = ReadUnalignedLE32(d);
|
||||
using namespace llvm::support;
|
||||
unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
|
||||
bool IsInteresting = RawID & 0x01;
|
||||
return std::make_pair(k, IsInteresting);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue