From 57ba0b228d2ea8c16e3306694188275fb867236f Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 28 Mar 2014 22:03:24 +0000 Subject: [PATCH] Reapply "OnDiskHashTable: Use Endian.h to read little endian ostreams" Committed this by accident before it was done last time. Original message: 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: 205062 --- clang/include/clang/Basic/OnDiskHashTable.h | 61 ++------ clang/lib/Lex/PTHLexer.cpp | 86 ++++++++---- clang/lib/Serialization/ASTReader.cpp | 132 ++++++++++-------- clang/lib/Serialization/GlobalModuleIndex.cpp | 14 +- 4 files changed, 154 insertions(+), 139 deletions(-) diff --git a/clang/include/clang/Basic/OnDiskHashTable.h b/clang/include/clang/Basic/OnDiskHashTable.h index 5916f0127aa2..8c2cd8d5f3c9 100644 --- a/clang/include/clang/Basic/OnDiskHashTable.h +++ b/clang/include/clang/Basic/OnDiskHashTable.h @@ -37,45 +37,6 @@ inline void Pad(raw_ostream& Out, unsigned A) { endian::Writer(Out).write(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 @@ -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(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(Items); for (unsigned i = 0; i < len; ++i) { // Read the hash. - uint32_t item_hash = ReadUnalignedLE32(Items); + uint32_t item_hash = endian::readNext(Items); // Determine the length of the key and the data. const std::pair& 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(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(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(buckets) & 0x3) == 0 && "buckets should be 4-byte aligned."); - unsigned numBuckets = ReadLE32(buckets); - unsigned numEntries = ReadLE32(buckets); + unsigned numBuckets = endian::readNext(buckets); + unsigned numEntries = endian::readNext(buckets); return new OnDiskChainedHashTable(numBuckets, numEntries, buckets, base, InfoObj); } diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index b671f9b4c18a..1ca16d39b4df 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -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(CurPtrShadow); + uint32_t IdentifierID = + endian::readNext(CurPtrShadow); + uint32_t FileOffset = + endian::readNext(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(CurPPCondPtr); // Read the target table index from the side-table. - TableIdx = ReadLE32(CurPPCondPtr); + TableIdx = endian::readNext(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(NextPPCondPtr); if (HashEntryJ <= LastHashTokPtr) { // Jump directly to the next entry in the side table. HashEntryI = HashEntryJ; - TableIdx = ReadLE32(NextPPCondPtr); + TableIdx = endian::readNext(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(NextPPCondPtr); + uint32_t NextIdx = endian::readNext(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(OffsetPtr); return FileStartLoc.getLocWithOffset(Offset); } @@ -318,7 +326,9 @@ public: static std::pair ReadKeyDataLength(const unsigned char*& d) { - unsigned keyLen = (unsigned) ReadUnalignedLE16(d); + using namespace llvm::support; + unsigned keyLen = + (unsigned)endian::readNext(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(d); + uint32_t y = endian::readNext(d); return PTHFileData(x, y); } }; @@ -377,7 +388,10 @@ public: static std::pair 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(d), + sizeof(uint32_t)); } static std::pair @@ -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(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(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(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(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(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(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(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(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(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(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(d); + uint64_t Device = endian::readNext(d); llvm::sys::fs::UniqueID UniqueID(File, Device); - time_t ModTime = ReadUnalignedLE64(d); - uint64_t Size = ReadUnalignedLE64(d); + time_t ModTime = endian::readNext(d); + uint64_t Size = endian::readNext(d); return data_type(Size, ModTime, UniqueID, IsDirectory); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 2d3408c58411..ff0b1dd62949 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -470,19 +470,19 @@ unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { std::pair 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(d); + unsigned DataLen = endian::readNext(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(d); + IdentifierInfo *FirstII = Reader.getLocalIdentifier( + F, endian::readNext(d)); if (N == 0) return SelTable.getNullarySelector(FirstII); else if (N == 1) @@ -491,7 +491,8 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { SmallVector 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(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(d)); + unsigned NumInstanceMethodsAndBits = + endian::readNext(d); + unsigned NumFactoryMethodsAndBits = + endian::readNext(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(F, ReadUnalignedLE32(d))) + if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( + F, endian::readNext(d))) Result.Instance.push_back(Method); } // Load factory methods for (unsigned I = 0; I != NumFactoryMethods; ++I) { - if (ObjCMethodDecl *Method - = Reader.GetLocalDeclAs(F, ReadUnalignedLE32(d))) + if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( + F, endian::readNext(d))) Result.Factory.push_back(Method); } @@ -534,9 +538,9 @@ unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { std::pair 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(d); + unsigned KeyLen = endian::readNext(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(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(d); + unsigned Bits = endian::readNext(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(d); DataLen -= 4; SmallVector LocalMacroIDs; if (hasSubmoduleMacros) { - while (uint32_t LocalMacroID = ReadUnalignedLE32(d)) { + while (uint32_t LocalMacroID = + endian::readNext(d)) { DataLen -= 4; LocalMacroIDs.push_back(LocalMacroID); } @@ -688,7 +694,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, if (DataLen > 0) { SmallVector DeclIDs; for (; DataLen > 0; DataLen -= 4) - DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); + DeclIDs.push_back(Reader.getGlobalDeclID( + F, endian::readNext(d))); Reader.SetGloballyVisibleDecls(II, DeclIDs); } @@ -756,34 +763,37 @@ ASTDeclContextNameLookupTrait::GetInternalKey( std::pair 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(d); + unsigned DataLen = endian::readNext(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(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( + 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(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(d); LE32DeclID *Start = reinterpret_cast( const_cast(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 HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { - unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); + using namespace llvm::support; + unsigned KeyLen = (unsigned) endian::readNext(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(d)); + ikey.ModTime = time_t(endian::readNext(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 @@ -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(d); + HFI.ControllingMacroID = Reader.getGlobalIdentifierID( + M, endian::readNext(d)); + if (unsigned FrameworkOffset = + endian::readNext(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(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::Builder TypeRemap(F.TypeRemap); while(Data < DataEnd) { - uint16_t Len = io::ReadUnalignedLE16(Data); + using namespace llvm::support; + uint16_t Len = endian::readNext(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(Data); + uint32_t IdentifierIDOffset = + endian::readNext(Data); + uint32_t MacroIDOffset = + endian::readNext(Data); + uint32_t PreprocessedEntityIDOffset = + endian::readNext(Data); + uint32_t SubmoduleIDOffset = + endian::readNext(Data); + uint32_t SelectorIDOffset = + endian::readNext(Data); + uint32_t DeclIDOffset = + endian::readNext(Data); + uint32_t TypeIndexOffset = + endian::readNext(Data); + // Source location offset is mapped to OM->SLocEntryBaseOffset. SLocRemap.insert(std::make_pair(SLocOffset, static_cast(OM->SLocEntryBaseOffset - SLocOffset))); diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index b4793610123c..14b149f078c6 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -82,9 +82,9 @@ public: static std::pair 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(d); + unsigned DataLen = endian::readNext(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(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(d); bool IsInteresting = RawID & 0x01; return std::make_pair(k, IsInteresting); } -- 2.34.1