From e3f652973e6e4fb7074b0bdc2291493e6cb8fae5 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 18 May 2018 19:46:24 +0000 Subject: Support: Simplify endian stream interface. NFCI. Provide some free functions to reduce verbosity of endian-writing a single value, and replace the endianness template parameter with a field. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47032 llvm-svn: 332757 --- clang/lib/Frontend/CacheTokens.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'clang/lib/Frontend/CacheTokens.cpp') diff --git a/clang/lib/Frontend/CacheTokens.cpp b/clang/lib/Frontend/CacheTokens.cpp index f3569edc695..c4504a14456 100644 --- a/clang/lib/Frontend/CacheTokens.cpp +++ b/clang/lib/Frontend/CacheTokens.cpp @@ -88,7 +88,7 @@ public: void EmitData(raw_ostream& Out) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); switch (Kind) { case IsFE: { // Emit stat information. @@ -135,7 +135,7 @@ public: EmitKeyDataLength(raw_ostream& Out, PTHEntryKeyVariant V, const PTHEntry& E) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); unsigned n = V.getString().size() + 1 + 1; LE.write(n); @@ -149,7 +149,7 @@ public: static void EmitKey(raw_ostream& Out, PTHEntryKeyVariant V, unsigned n){ using namespace llvm::support; // Emit the entry kind. - endian::Writer(Out).write((unsigned)V.getKind()); + Out << char(V.getKind()); // Emit the string. Out.write(V.getString().data(), n - 1); } @@ -157,7 +157,7 @@ public: static void EmitData(raw_ostream& Out, PTHEntryKeyVariant V, const PTHEntry& E, unsigned) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); // For file entries emit the offsets into the PTH file for token data // and the preprocessor blocks table. @@ -205,18 +205,17 @@ class PTHWriter { void EmitToken(const Token& T); void Emit8(uint32_t V) { - using namespace llvm::support; - endian::Writer(Out).write(V); + Out << char(V); } void Emit16(uint32_t V) { using namespace llvm::support; - endian::Writer(Out).write(V); + endian::write(Out, V, little); } void Emit32(uint32_t V) { using namespace llvm::support; - endian::Writer(Out).write(V); + endian::write(Out, V, little); } void EmitBuf(const char *Ptr, unsigned NumBytes) { @@ -225,7 +224,7 @@ class PTHWriter { void EmitString(StringRef V) { using namespace llvm::support; - endian::Writer(Out).write(V.size()); + endian::write(Out, V.size(), little); EmitBuf(V.data(), V.size()); } @@ -299,7 +298,7 @@ PTHEntry PTHWriter::LexTokens(Lexer& L) { // Pad 0's so that we emit tokens to a 4-byte alignment. // This speed up reading them back in. using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); uint32_t TokenOff = Out.tell(); for (uint64_t N = llvm::OffsetToAlignment(TokenOff, 4); N; --N, ++TokenOff) LE.write(0); @@ -632,7 +631,7 @@ public: EmitKeyDataLength(raw_ostream& Out, const PTHIdKey* key, uint32_t) { using namespace llvm::support; unsigned n = key->II->getLength() + 1; - endian::Writer(Out).write(n); + endian::write(Out, n, little); return std::make_pair(n, sizeof(uint32_t)); } @@ -646,7 +645,7 @@ public: static void EmitData(raw_ostream& Out, PTHIdKey*, uint32_t pID, unsigned) { using namespace llvm::support; - endian::Writer(Out).write(pID); + endian::write(Out, pID, little); } }; } // end anonymous namespace -- cgit v1.2.3