Don't assume little endian in StreamReader / StreamWriter.

In an effort to generalize this so it can be used by more than
just PDB code, we shouldn't assume little endian.

llvm-svn: 295525
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp
index 5d15e62..f2f25c2 100644
--- a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp
@@ -236,7 +236,7 @@
     return Error::success();
 
   StreamReader SCReader(SecContrSubstream);
-  if (auto EC = SCReader.readEnum(SectionContribVersion))
+  if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little))
     return EC;
 
   if (SectionContribVersion == DbiSecContribVer60)
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
index df6e9b0..0b56d05 100644
--- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
@@ -187,17 +187,21 @@
 
   uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModuleInfos.size());
   uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size());
-  if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules
+  if (auto EC = MetadataWriter.writeInteger(
+          ModiCount, llvm::support::little)) // NumModules
     return EC;
-  if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles
+  if (auto EC = MetadataWriter.writeInteger(
+          FileCount, llvm::support::little)) // NumSourceFiles
     return EC;
   for (uint16_t I = 0; I < ModiCount; ++I) {
-    if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices
+    if (auto EC = MetadataWriter.writeInteger(
+            I, llvm::support::little)) // Mod Indices
       return EC;
   }
   for (const auto MI : ModuleInfoList) {
     FileCount = static_cast<uint16_t>(MI->SourceFiles.size());
-    if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts
+    if (auto EC = MetadataWriter.writeInteger(
+            FileCount, llvm::support::little)) // Mod File Counts
       return EC;
   }
 
@@ -219,7 +223,8 @@
       if (Result == SourceFileNames.end())
         return make_error<RawError>(raw_error_code::no_entry,
                                     "The source file was not found.");
-      if (auto EC = MetadataWriter.writeInteger(Result->second))
+      if (auto EC = MetadataWriter.writeInteger(Result->second,
+                                                llvm::support::little))
         return EC;
     }
   }
@@ -373,7 +378,7 @@
     return EC;
 
   if (!SectionContribs.empty()) {
-    if (auto EC = Writer.writeEnum(DbiSecContribVer60))
+    if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little))
       return EC;
     if (auto EC = Writer.writeArray(SectionContribs))
       return EC;
@@ -392,7 +397,8 @@
     return EC;
 
   for (auto &Stream : DbgStreams)
-    if (auto EC = Writer.writeInteger(Stream.StreamNumber))
+    if (auto EC =
+            Writer.writeInteger(Stream.StreamNumber, llvm::support::little))
       return EC;
 
   for (auto &Stream : DbgStreams) {
diff --git a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp
index b3fe6fa..dd95c07 100644
--- a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp
@@ -48,9 +48,9 @@
                                 "Present bit vector interesects deleted!");
 
   for (uint32_t P : Present) {
-    if (auto EC = Stream.readInteger(Buckets[P].first))
+    if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little))
       return EC;
-    if (auto EC = Stream.readInteger(Buckets[P].second))
+    if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little))
       return EC;
   }
 
@@ -91,9 +91,9 @@
     return EC;
 
   for (const auto &Entry : *this) {
-    if (auto EC = Writer.writeInteger(Entry.first))
+    if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little))
       return EC;
-    if (auto EC = Writer.writeInteger(Entry.second))
+    if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little))
       return EC;
   }
   return Error::success();
@@ -212,7 +212,7 @@
 Error HashTable::readSparseBitVector(msf::StreamReader &Stream,
                                      SparseBitVector<> &V) {
   uint32_t NumWords;
-  if (auto EC = Stream.readInteger(NumWords))
+  if (auto EC = Stream.readInteger(NumWords, llvm::support::little))
     return joinErrors(
         std::move(EC),
         make_error<RawError>(raw_error_code::corrupt_file,
@@ -220,7 +220,7 @@
 
   for (uint32_t I = 0; I != NumWords; ++I) {
     uint32_t Word;
-    if (auto EC = Stream.readInteger(Word))
+    if (auto EC = Stream.readInteger(Word, llvm::support::little))
       return joinErrors(std::move(EC),
                         make_error<RawError>(raw_error_code::corrupt_file,
                                              "Expected hash table word"));
@@ -235,7 +235,7 @@
                                       SparseBitVector<> &Vec) {
   int ReqBits = Vec.find_last() + 1;
   uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t);
-  if (auto EC = Writer.writeInteger(NumWords))
+  if (auto EC = Writer.writeInteger(NumWords, llvm::support::little))
     return joinErrors(
         std::move(EC),
         make_error<RawError>(raw_error_code::corrupt_file,
@@ -248,7 +248,7 @@
       if (Vec.test(Idx))
         Word |= (1 << WordIdx);
     }
-    if (auto EC = Writer.writeInteger(Word))
+    if (auto EC = Writer.writeInteger(Word, llvm::support::little))
       return joinErrors(std::move(EC), make_error<RawError>(
                                            raw_error_code::corrupt_file,
                                            "Could not write linear map word"));
diff --git a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp
index 25370f2..ee8374f 100644
--- a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp
@@ -43,7 +43,7 @@
 
   ReadableStreamRef S;
 
-  if (auto EC = Reader.readInteger(Signature))
+  if (auto EC = Reader.readInteger(Signature, llvm::support::little))
     return EC;
   if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
     return EC;
@@ -58,7 +58,7 @@
     return EC;
 
   uint32_t GlobalRefsSize;
-  if (auto EC = Reader.readInteger(GlobalRefsSize))
+  if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little))
     return EC;
   if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
     return EC;
diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
index 47fd0e1..8a9579c 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
@@ -32,7 +32,7 @@
   FinalizedInfo.reset();
 
   uint32_t StringBufferSize;
-  if (auto EC = Stream.readInteger(StringBufferSize))
+  if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little))
     return joinErrors(std::move(EC),
                       make_error<RawError>(raw_error_code::corrupt_file,
                                            "Expected string buffer size"));
@@ -71,8 +71,8 @@
   assert(FinalizedInfo.hasValue());
 
   // The first field is the number of bytes of string data.
-  if (auto EC = Writer.writeInteger(
-          FinalizedInfo->StringDataBytes)) // Number of bytes of string data
+  if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes,
+                                    llvm::support::little))
     return EC;
 
   // Now all of the string data itself.
diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp
index 3a3692d..26d9e0e 100644
--- a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp
@@ -186,7 +186,7 @@
   // been parsed, we can avoid this and reuse MappedBlockStream.
   auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer);
   StreamReader Reader(*DS);
-  if (auto EC = Reader.readInteger(NumStreams))
+  if (auto EC = Reader.readInteger(NumStreams, llvm::support::little))
     return EC;
 
   if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams))
diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
index 57ca2ba..fb8e34e 100644
--- a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
@@ -132,8 +132,8 @@
   auto DirStream =
       WritableMappedBlockStream::createDirectoryStream(Layout, Buffer);
   StreamWriter DW(*DirStream);
-  if (auto EC =
-          DW.writeInteger(static_cast<uint32_t>(Layout.StreamSizes.size())))
+  if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size(),
+                                          llvm::support::little))
     return EC;
 
   if (auto EC = DW.writeArray(Layout.StreamSizes))
diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp
index 5b8ae9b..34f2b48 100644
--- a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp
@@ -55,7 +55,7 @@
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Missing name count");
 
-  if (auto EC = Stream.readInteger(NameCount))
+  if (auto EC = Stream.readInteger(NameCount, llvm::support::little))
     return EC;
   return Error::success();
 }
diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
index ef9caee..304f3a6 100644
--- a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
@@ -74,7 +74,7 @@
 
   // Write a hash table.
   uint32_t BucketCount = computeBucketCount(Strings.size());
-  if (auto EC = Writer.writeInteger(BucketCount))
+  if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little))
     return EC;
   std::vector<ulittle32_t> Buckets(BucketCount);
 
@@ -96,7 +96,8 @@
 
   if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
     return EC;
-  if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
+  if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()),
+                                    llvm::support::little))
     return EC;
   return Error::success();
 }