Index: clang/lib/Frontend/CacheTokens.cpp =================================================================== --- clang/lib/Frontend/CacheTokens.cpp +++ clang/lib/Frontend/CacheTokens.cpp @@ -88,7 +88,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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 @@ 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 @@ 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 Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -1955,7 +1955,7 @@ EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; LE.write(KeyLen); unsigned DataLen = 1 + 2 + 4 + 4; @@ -1971,7 +1971,7 @@ void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); LE.write(key.Size); KeyLen -= 8; LE.write(key.ModTime); @@ -1983,7 +1983,7 @@ data_type_ref Data, unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); uint64_t Start = Out.tell(); (void)Start; unsigned char Flags = (Data.HFI.isImport << 5) @@ -2153,7 +2153,7 @@ llvm::raw_svector_ostream Out(TableData); // Make sure that no bucket is at offset 0 - endian::Writer(Out).write(0); + endian::write(Out, 0, little); BucketOffset = Generator.Emit(Out, GeneratorTrait); } @@ -3292,7 +3292,7 @@ data_type_ref Methods) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); LE.write(KeyLen); unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts @@ -3311,7 +3311,7 @@ void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); uint64_t Start = Out.tell(); assert((Start >> 32) == 0 && "Selector key offset too large"); Writer.SetSelectorOffset(Sel, Start); @@ -3328,7 +3328,7 @@ data_type_ref Methods, unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); uint64_t Start = Out.tell(); (void)Start; LE.write(Methods.ID); unsigned NumInstanceMethods = 0; @@ -3440,7 +3440,7 @@ ASTMethodPoolTrait Trait(*this); llvm::raw_svector_ostream Out(MethodPool); // Make sure that no bucket is at offset 0 - endian::Writer(Out).write(0); + endian::write(Out, 0, little); BucketOffset = Generator.Emit(Out, Trait); } @@ -3622,7 +3622,7 @@ using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); LE.write(DataLen); @@ -3651,7 +3651,7 @@ IdentID ID, unsigned) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); auto MacroOffset = Writer.getMacroDirectivesOffset(II); if (!isInterestingIdentifier(II, MacroOffset)) { @@ -3755,7 +3755,7 @@ llvm::raw_svector_ostream Out(IdentifierTable); // Make sure that no bucket is at offset 0 - endian::Writer(Out).write(0); + endian::write(Out, 0, little); BucketOffset = Generator.Emit(Out, Trait); } @@ -3851,8 +3851,7 @@ using namespace llvm::support; - endian::Writer(Out) - .write(Writer.getChain()->getModuleFileID(F)); + endian::write(Out, Writer.getChain()->getModuleFileID(F), little); } std::pair EmitKeyDataLength(raw_ostream &Out, @@ -3860,7 +3859,7 @@ data_type_ref Lookup) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); unsigned KeyLen = 1; switch (Name.getKind()) { case DeclarationName::Identifier: @@ -3894,7 +3893,7 @@ void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); LE.write(Name.getKind()); switch (Name.getKind()) { case DeclarationName::Identifier: @@ -3926,7 +3925,7 @@ unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); uint64_t Start = Out.tell(); (void)Start; for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) LE.write(DeclIDs[I]); @@ -4921,7 +4920,7 @@ for (ModuleFile &M : Chain->ModuleMgr) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); LE.write(static_cast(M.Kind)); StringRef Name = M.Kind == MK_PrebuiltModule || M.Kind == MK_ExplicitModule Index: clang/lib/Serialization/GlobalModuleIndex.cpp =================================================================== --- clang/lib/Serialization/GlobalModuleIndex.cpp +++ clang/lib/Serialization/GlobalModuleIndex.cpp @@ -703,7 +703,7 @@ std::pair EmitKeyDataLength(raw_ostream& Out, key_type_ref Key, data_type_ref Data) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); unsigned KeyLen = Key.size(); unsigned DataLen = Data.size() * 4; LE.write(KeyLen); @@ -719,7 +719,7 @@ unsigned DataLen) { using namespace llvm::support; for (unsigned I = 0, N = Data.size(); I != N; ++I) - endian::Writer(Out).write(Data[I]); + endian::write(Out, Data[I], little); } }; @@ -797,7 +797,7 @@ using namespace llvm::support; llvm::raw_svector_ostream Out(IdentifierTable); // Make sure that no bucket is at offset 0 - endian::Writer(Out).write(0); + endian::write(Out, 0, little); BucketOffset = Generator.Emit(Out, Trait); } Index: clang/lib/Serialization/MultiOnDiskHashTable.h =================================================================== --- clang/lib/Serialization/MultiOnDiskHashTable.h +++ clang/lib/Serialization/MultiOnDiskHashTable.h @@ -312,7 +312,7 @@ // Write our header information. { - endian::Writer Writer(OutStream); + endian::Writer Writer(OutStream, little); // Reserve four bytes for the bucket offset. Writer.write(0); Index: lld/wasm/WriterUtils.cpp =================================================================== --- lld/wasm/WriterUtils.cpp +++ lld/wasm/WriterUtils.cpp @@ -70,7 +70,7 @@ void wasm::writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg) { debugWrite(OS.tell(), Msg + "[0x" + utohexstr(Number) + "]"); - support::endian::Writer(OS).write(Number); + support::endian::write(OS, Number, support::little); } void wasm::writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg) { Index: llvm/include/llvm/MC/MCObjectWriter.h =================================================================== --- llvm/include/llvm/MC/MCObjectWriter.h +++ llvm/include/llvm/MC/MCObjectWriter.h @@ -123,27 +123,27 @@ void write8(uint8_t Value) { *OS << char(Value); } void writeLE16(uint16_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::little); } void writeLE32(uint32_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::little); } void writeLE64(uint64_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::little); } void writeBE16(uint16_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::big); } void writeBE32(uint32_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::big); } void writeBE64(uint64_t Value) { - support::endian::Writer(*OS).write(Value); + support::endian::write(*OS, Value, support::big); } void write16(uint16_t Value) { Index: llvm/include/llvm/Support/EndianStream.h =================================================================== --- llvm/include/llvm/Support/EndianStream.h +++ llvm/include/llvm/Support/EndianStream.h @@ -23,44 +23,44 @@ namespace support { namespace endian { -/// Adapter to write values to a stream in a particular byte order. -template struct Writer { - raw_ostream &OS; - Writer(raw_ostream &OS) : OS(OS) {} - template void write(ArrayRef Vals) { - for (value_type V : Vals) - write(V); - } - template void write(value_type Val) { - Val = byte_swap(Val); - OS.write((const char *)&Val, sizeof(value_type)); - } -}; -template <> -template <> -inline void Writer::write(float Val) { - write(FloatToBits(Val)); +template +inline void write(raw_ostream &os, value_type value, endianness endian) { + value = byte_swap(value, endian); + os.write((const char *)&value, sizeof(value_type)); } template <> -template <> -inline void Writer::write(double Val) { - write(DoubleToBits(Val)); +inline void write(raw_ostream &os, float value, endianness endian) { + write(os, FloatToBits(value), endian); } template <> -template <> -inline void Writer::write(float Val) { - write(FloatToBits(Val)); +inline void write(raw_ostream &os, double value, + endianness endian) { + write(os, DoubleToBits(value), endian); } -template <> -template <> -inline void Writer::write(double Val) { - write(DoubleToBits(Val)); +template +inline void write(raw_ostream &os, ArrayRef vals, + endianness endian) { + for (value_type v : vals) + write(os, v, endian); } +/// Adapter to write values to a stream in a particular byte order. +struct Writer { + raw_ostream &OS; + endianness Endian; + Writer(raw_ostream &OS, endianness Endian) : OS(OS), Endian(Endian) {} + template void write(ArrayRef Val) { + endian::write(OS, Val, Endian); + } + template void write(value_type Val) { + endian::write(OS, Val, Endian); + } +}; + } // end namespace endian } // end namespace support Index: llvm/include/llvm/Support/OnDiskHashTable.h =================================================================== --- llvm/include/llvm/Support/OnDiskHashTable.h +++ llvm/include/llvm/Support/OnDiskHashTable.h @@ -150,7 +150,7 @@ /// Uses the provided Info instead of a stack allocated one. offset_type Emit(raw_ostream &Out, Info &InfoObj) { using namespace llvm::support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); // Now we're done adding entries, resize the bucket list if it's // significantly too large. (This only happens if the number of Index: llvm/lib/MC/ELFObjectWriter.cpp =================================================================== --- llvm/lib/MC/ELFObjectWriter.cpp +++ llvm/lib/MC/ELFObjectWriter.cpp @@ -183,10 +183,8 @@ } template void write(T Val) { - if (IsLittleEndian) - support::endian::Writer(getStream()).write(Val); - else - support::endian::Writer(getStream()).write(Val); + support::endian::write(getStream(), Val, + IsLittleEndian ? support::little : support::big); } void writeHeader(const MCAssembler &Asm); Index: llvm/lib/MC/MCCodeView.cpp =================================================================== --- llvm/lib/MC/MCCodeView.cpp +++ llvm/lib/MC/MCCodeView.cpp @@ -632,7 +632,7 @@ } unsigned NumGaps = J - I - 1; - support::endian::Writer LEWriter(OS); + support::endian::Writer LEWriter(OS, support::little); unsigned Bias = 0; // We must split the range into chunks of MaxDefRange, this is a fundamental Index: llvm/lib/MC/MCDwarf.cpp =================================================================== --- llvm/lib/MC/MCDwarf.cpp +++ llvm/lib/MC/MCDwarf.cpp @@ -1798,6 +1798,8 @@ // Scale the address delta by the minimum instruction length. AddrDelta = ScaleAddrDelta(Context, AddrDelta); + support::endianness E = + Context.getAsmInfo()->isLittleEndian() ? support::little : support::big; if (AddrDelta == 0) { } else if (isUIntN(6, AddrDelta)) { uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta; @@ -1807,16 +1809,10 @@ OS << uint8_t(AddrDelta); } else if (isUInt<16>(AddrDelta)) { OS << uint8_t(dwarf::DW_CFA_advance_loc2); - if (Context.getAsmInfo()->isLittleEndian()) - support::endian::Writer(OS).write(AddrDelta); - else - support::endian::Writer(OS).write(AddrDelta); + support::endian::write(OS, AddrDelta, E); } else { assert(isUInt<32>(AddrDelta)); OS << uint8_t(dwarf::DW_CFA_advance_loc4); - if (Context.getAsmInfo()->isLittleEndian()) - support::endian::Writer(OS).write(AddrDelta); - else - support::endian::Writer(OS).write(AddrDelta); + support::endian::write(OS, AddrDelta, E); } } Index: llvm/lib/Object/ArchiveWriter.cpp =================================================================== --- llvm/lib/Object/ArchiveWriter.cpp +++ llvm/lib/Object/ArchiveWriter.cpp @@ -136,10 +136,8 @@ template static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val) { - if (isBSDLike(Kind)) - support::endian::Writer(Out).write(Val); - else - support::endian::Writer(Out).write(Val); + support::endian::write(Out, Val, + isBSDLike(Kind) ? support::little : support::big); } static void printRestOfMemberHeader( Index: llvm/lib/ProfileData/InstrProfWriter.cpp =================================================================== --- llvm/lib/ProfileData/InstrProfWriter.cpp +++ llvm/lib/ProfileData/InstrProfWriter.cpp @@ -48,9 +48,10 @@ // back patching. class ProfOStream { public: - ProfOStream(raw_fd_ostream &FD) : IsFDOStream(true), OS(FD), LE(FD) {} + ProfOStream(raw_fd_ostream &FD) + : IsFDOStream(true), OS(FD), LE(FD, support::little) {} ProfOStream(raw_string_ostream &STR) - : IsFDOStream(false), OS(STR), LE(STR) {} + : IsFDOStream(false), OS(STR), LE(STR, support::little) {} uint64_t tell() { return OS.tell(); } void write(uint64_t V) { LE.write(V); } @@ -85,7 +86,7 @@ // true. Otherwise, \c OS will be an raw_string_ostream. bool IsFDOStream; raw_ostream &OS; - support::endian::Writer LE; + support::endian::Writer LE; }; class InstrProfRecordWriterTrait { @@ -112,7 +113,7 @@ EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) { using namespace support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); offset_type N = K.size(); LE.write(N); @@ -139,7 +140,7 @@ void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type) { using namespace support; - endian::Writer LE(Out); + endian::Writer LE(Out, little); for (const auto &ProfileData : *V) { const InstrProfRecord &ProfRecord = ProfileData.second; SummaryBuilder->addRecord(ProfRecord); Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp +++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp @@ -572,7 +572,7 @@ } uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI); - support::endian::Writer(OS).write(Binary); + support::endian::write(OS, Binary, support::little); ++MCNumEmitted; // Keep track of the # of mi's emitted. } Index: llvm/lib/Target/AMDGPU/MCTargetDesc/R600MCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/AMDGPU/MCTargetDesc/R600MCCodeEmitter.cpp +++ llvm/lib/Target/AMDGPU/MCTargetDesc/R600MCCodeEmitter.cpp @@ -148,11 +148,11 @@ } void R600MCCodeEmitter::Emit(uint32_t Value, raw_ostream &OS) const { - support::endian::Writer(OS).write(Value); + support::endian::write(OS, Value, support::little); } void R600MCCodeEmitter::Emit(uint64_t Value, raw_ostream &OS) const { - support::endian::Writer(OS).write(Value); + support::endian::write(OS, Value, support::little); } unsigned R600MCCodeEmitter::getHWReg(unsigned RegNo) const { Index: llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp +++ llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp @@ -122,44 +122,35 @@ computeAvailableFeatures(STI.getFeatureBits())); unsigned Opcode = MI.getOpcode(); - support::endian::Writer LE(OS); - support::endian::Writer BE(OS); + support::endian::Writer OSE(OS, + IsLittleEndian ? support::little : support::big); if (Opcode == BPF::LD_imm64 || Opcode == BPF::LD_pseudo) { uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI); - LE.write(Value >> 56); + OS << char(Value >> 56); if (IsLittleEndian) - LE.write((Value >> 48) & 0xff); + OS << char((Value >> 48) & 0xff); else - LE.write(SwapBits((Value >> 48) & 0xff)); - LE.write(0); - if (IsLittleEndian) - LE.write(Value & 0xffffFFFF); - else - BE.write(Value & 0xffffFFFF); + OS << char(SwapBits((Value >> 48) & 0xff)); + OSE.write(0); + OSE.write(Value & 0xffffFFFF); const MCOperand &MO = MI.getOperand(1); uint64_t Imm = MO.isImm() ? MO.getImm() : 0; - LE.write(0); - LE.write(0); - LE.write(0); - if (IsLittleEndian) - LE.write(Imm >> 32); - else - BE.write(Imm >> 32); + OSE.write(0); + OSE.write(0); + OSE.write(0); + OSE.write(Imm >> 32); } else { // Get instruction encoding and emit it uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI); - LE.write(Value >> 56); - if (IsLittleEndian) { - LE.write((Value >> 48) & 0xff); - LE.write((Value >> 32) & 0xffff); - LE.write(Value & 0xffffFFFF); - } else { - LE.write(SwapBits((Value >> 48) & 0xff)); - BE.write((Value >> 32) & 0xffff); - BE.write(Value & 0xffffFFFF); - } + OS << char(Value >> 56); + if (IsLittleEndian) + OS << char((Value >> 48) & 0xff); + else + OS << char(SwapBits((Value >> 48) & 0xff)); + OSE.write((Value >> 32) & 0xffff); + OSE.write(Value & 0xffffFFFF); } } Index: llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp +++ llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp @@ -452,7 +452,7 @@ Binary |= SubBits0 | (SubBits1 << 16); } - support::endian::Writer(OS).write(Binary); + support::endian::write(OS, Binary, support::little); ++MCNumEmitted; } Index: llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp +++ llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp @@ -122,25 +122,18 @@ // Output the constant in big/little endian byte order. unsigned Size = Desc.getSize(); + support::endianness E = IsLittleEndian ? support::little : support::big; switch (Size) { case 0: break; case 4: - if (IsLittleEndian) { - support::endian::Writer(OS).write(Bits); - } else { - support::endian::Writer(OS).write(Bits); - } + support::endian::write(OS, Bits, E); break; case 8: // If we emit a pair of instructions, the first one is // always in the top 32 bits, even on little-endian. - if (IsLittleEndian) { - uint64_t Swapped = (Bits << 32) | (Bits >> 32); - support::endian::Writer(OS).write(Swapped); - } else { - support::endian::Writer(OS).write(Bits); - } + support::endian::write(OS, Bits >> 32, E); + support::endian::write(OS, Bits, E); break; default: llvm_unreachable("Invalid instruction size"); Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp +++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp @@ -113,12 +113,12 @@ .addReg(Ra) .addOperand(MCOperand::createExpr(CallExpr)); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - support::endian::Writer(OS).write(Binary); + support::endian::write(OS, Binary, support::little); // Emit JALR Ra, Ra, 0 TmpInst = MCInstBuilder(RISCV::JALR).addReg(Ra).addReg(Ra).addImm(0); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - support::endian::Writer(OS).write(Binary); + support::endian::write(OS, Binary, support::little); } void RISCVMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, @@ -140,12 +140,12 @@ llvm_unreachable("Unhandled encodeInstruction length!"); case 2: { uint16_t Bits = getBinaryCodeForInstr(MI, Fixups, STI); - support::endian::Writer(OS).write(Bits); + support::endian::write(OS, Bits, support::little); break; } case 4: { uint32_t Bits = getBinaryCodeForInstr(MI, Fixups, STI); - support::endian::Writer(OS).write(Bits); + support::endian::write(OS, Bits, support::little); break; } } Index: llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp +++ llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp @@ -98,14 +98,9 @@ computeAvailableFeatures(STI.getFeatureBits())); unsigned Bits = getBinaryCodeForInstr(MI, Fixups, STI); - - if (Ctx.getAsmInfo()->isLittleEndian()) { - // Output the bits in little-endian byte order. - support::endian::Writer(OS).write(Bits); - } else { - // Output the bits in big-endian byte order. - support::endian::Writer(OS).write(Bits); - } + support::endian::write(OS, Bits, + Ctx.getAsmInfo()->isLittleEndian() ? support::little + : support::big); unsigned tlsOpNo = 0; switch (MI.getOpcode()) { default: break; Index: llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp =================================================================== --- llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp +++ llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp @@ -118,11 +118,11 @@ // TODO: MC converts all floating point immediate operands to double. // This is fine for numeric values, but may cause NaNs to change bits. float f = float(MO.getFPImm()); - support::endian::Writer(OS).write(f); + support::endian::write(OS, f, support::little); } else { assert(Info.OperandType == WebAssembly::OPERAND_F64IMM); double d = MO.getFPImm(); - support::endian::Writer(OS).write(d); + support::endian::write(OS, d, support::little); } } else if (MO.isExpr()) { const MCOperandInfo &Info = Desc.OpInfo[i]; Index: llvm/tools/llvm-xray/xray-converter.cpp =================================================================== --- llvm/tools/llvm-xray/xray-converter.cpp +++ llvm/tools/llvm-xray/xray-converter.cpp @@ -100,7 +100,7 @@ void TraceConverter::exportAsRAWv1(const Trace &Records, raw_ostream &OS) { // First write out the file header, in the correct endian-appropriate format // (XRay assumes currently little endian). - support::endian::Writer Writer(OS); + support::endian::Writer Writer(OS, support::endianness::little); const auto &FH = Records.getFileHeader(); Writer.write(FH.Version); Writer.write(FH.Type); Index: llvm/unittests/Support/EndianStreamTest.cpp =================================================================== --- llvm/unittests/Support/EndianStreamTest.cpp +++ llvm/unittests/Support/EndianStreamTest.cpp @@ -21,7 +21,7 @@ { raw_svector_ostream OS(data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write(static_cast(-1362446643)); } @@ -36,7 +36,7 @@ { raw_svector_ostream OS(data); - endian::Writer BE(OS); + endian::Writer BE(OS, big); BE.write(static_cast(-1362446643)); } @@ -52,7 +52,7 @@ { raw_svector_ostream OS(data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write(12345.0f); } @@ -67,7 +67,7 @@ { raw_svector_ostream OS(data); - endian::Writer BE(OS); + endian::Writer BE(OS, big); BE.write(12345.0f); } @@ -82,7 +82,7 @@ { raw_svector_ostream OS(data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write(static_cast(-136244664332342323)); } @@ -101,7 +101,7 @@ { raw_svector_ostream OS(data); - endian::Writer BE(OS); + endian::Writer BE(OS, big); BE.write(static_cast(-136244664332342323)); } @@ -120,7 +120,7 @@ { raw_svector_ostream OS(data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write(-2349214918.58107); } @@ -139,7 +139,7 @@ { raw_svector_ostream OS(data); - endian::Writer BE(OS); + endian::Writer BE(OS, big); BE.write(-2349214918.58107); } @@ -158,7 +158,7 @@ { raw_svector_ostream OS(Data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write({0x1234, 0x5678}); } @@ -173,7 +173,7 @@ { raw_svector_ostream OS(Data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); std::vector Vec{0x1234, 0x5678}; LE.write(Vec); } @@ -189,7 +189,7 @@ { raw_svector_ostream OS(Data); - endian::Writer LE(OS); + endian::Writer LE(OS, little); LE.write({12345.0f, 12346.0f}); }