diff options
Diffstat (limited to 'clang/include/clang/Basic/OnDiskHashTable.h')
-rw-r--r-- | clang/include/clang/Basic/OnDiskHashTable.h | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/clang/include/clang/Basic/OnDiskHashTable.h b/clang/include/clang/Basic/OnDiskHashTable.h index 8c2cd8d5f3c..1c398d5772e 100644 --- a/clang/include/clang/Basic/OnDiskHashTable.h +++ b/clang/include/clang/Basic/OnDiskHashTable.h @@ -17,7 +17,6 @@ #include "clang/Basic/LLVM.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/DataTypes.h" -#include "llvm/Support/EndianStream.h" #include "llvm/Support/Host.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -30,11 +29,45 @@ namespace io { typedef uint32_t Offset; +inline void Emit8(raw_ostream& Out, uint32_t V) { + Out << (unsigned char)(V); +} + +inline void Emit16(raw_ostream& Out, uint32_t V) { + Out << (unsigned char)(V); + Out << (unsigned char)(V >> 8); + assert((V >> 16) == 0); +} + +inline void Emit24(raw_ostream& Out, uint32_t V) { + Out << (unsigned char)(V); + Out << (unsigned char)(V >> 8); + Out << (unsigned char)(V >> 16); + assert((V >> 24) == 0); +} + +inline void Emit32(raw_ostream& Out, uint32_t V) { + Out << (unsigned char)(V); + Out << (unsigned char)(V >> 8); + Out << (unsigned char)(V >> 16); + Out << (unsigned char)(V >> 24); +} + +inline void Emit64(raw_ostream& Out, uint64_t V) { + Out << (unsigned char)(V); + Out << (unsigned char)(V >> 8); + Out << (unsigned char)(V >> 16); + Out << (unsigned char)(V >> 24); + Out << (unsigned char)(V >> 32); + Out << (unsigned char)(V >> 40); + Out << (unsigned char)(V >> 48); + Out << (unsigned char)(V >> 56); +} + inline void Pad(raw_ostream& Out, unsigned A) { - using namespace llvm::support; Offset off = (Offset) Out.tell(); for (uint32_t n = llvm::OffsetToAlignment(off, A); n; --n) - endian::Writer<little>(Out).write<uint8_t>(0); + Emit8(Out, 0); } } // end namespace io @@ -116,8 +149,7 @@ public: } io::Offset Emit(raw_ostream &out, Info &InfoObj) { - using namespace llvm::support; - endian::Writer<little> LE(out); + using namespace clang::io; // Emit the payload of the table. for (unsigned i = 0; i < NumBuckets; ++i) { @@ -129,12 +161,12 @@ public: assert(B.off && "Cannot write a bucket at offset 0. Please add padding."); // Write out the number of items in the bucket. - LE.write<uint16_t>(B.length); + Emit16(out, B.length); assert(B.length != 0 && "Bucket has a head but zero length?"); // Write out the entries in the bucket. for (Item *I = B.head; I ; I = I->next) { - LE.write<uint32_t>(I->hash); + Emit32(out, I->hash); const std::pair<unsigned, unsigned>& Len = InfoObj.EmitKeyDataLength(out, I->key, I->data); InfoObj.EmitKey(out, I->key, Len.first); @@ -143,12 +175,11 @@ public: } // Emit the hashtable itself. - io::Pad(out, 4); + Pad(out, 4); io::Offset TableOff = out.tell(); - LE.write<uint32_t>(NumBuckets); - LE.write<uint32_t>(NumEntries); - for (unsigned i = 0; i < NumBuckets; ++i) - LE.write<uint32_t>(Buckets[i].off); + Emit32(out, NumBuckets); + Emit32(out, NumEntries); + for (unsigned i = 0; i < NumBuckets; ++i) Emit32(out, Buckets[i].off); return TableOff; } |