Index: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h =================================================================== --- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h +++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h @@ -121,8 +121,7 @@ public: MachObjectWriter(std::unique_ptr MOTW, raw_pwrite_stream &OS, bool IsLittleEndian) - : MCObjectWriter(OS, IsLittleEndian), - TargetObjectWriter(std::move(MOTW)), + : TargetObjectWriter(std::move(MOTW)), W(OS, IsLittleEndian ? support::little : support::big) {} support::endian::Writer W; Index: llvm/trunk/include/llvm/MC/MCObjectWriter.h =================================================================== --- llvm/trunk/include/llvm/MC/MCObjectWriter.h +++ llvm/trunk/include/llvm/MC/MCObjectWriter.h @@ -36,22 +36,9 @@ /// points. Once assembly is complete, the object writer is given the /// MCAssembler instance, which contains all the symbol and section data which /// should be emitted as part of writeObject(). -/// -/// The object writer also contains a number of helper methods for writing -/// binary data to the output stream. class MCObjectWriter { - raw_pwrite_stream *OS; - protected: - unsigned IsLittleEndian : 1; - - // Can only create subclasses. - MCObjectWriter(raw_pwrite_stream &OS, bool IsLittleEndian) - : OS(&OS), IsLittleEndian(IsLittleEndian) {} - - unsigned getInitialOffset() { - return OS->tell(); - } + MCObjectWriter() = default; public: MCObjectWriter(const MCObjectWriter &) = delete; @@ -61,11 +48,6 @@ /// lifetime management virtual void reset() {} - bool isLittleEndian() const { return IsLittleEndian; } - - raw_pwrite_stream &getStream() { return *OS; } - void setStream(raw_pwrite_stream &NewOS) { OS = &NewOS; } - /// \name High-Level API /// @{ @@ -117,82 +99,6 @@ virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0; /// @} - /// \name Binary Output - /// @{ - - void write8(uint8_t Value) { *OS << char(Value); } - - void writeLE16(uint16_t Value) { - support::endian::write(*OS, Value, support::little); - } - - void writeLE32(uint32_t Value) { - support::endian::write(*OS, Value, support::little); - } - - void writeLE64(uint64_t Value) { - support::endian::write(*OS, Value, support::little); - } - - void writeBE16(uint16_t Value) { - support::endian::write(*OS, Value, support::big); - } - - void writeBE32(uint32_t Value) { - support::endian::write(*OS, Value, support::big); - } - - void writeBE64(uint64_t Value) { - support::endian::write(*OS, Value, support::big); - } - - void write16(uint16_t Value) { - if (IsLittleEndian) - writeLE16(Value); - else - writeBE16(Value); - } - - void write32(uint32_t Value) { - if (IsLittleEndian) - writeLE32(Value); - else - writeBE32(Value); - } - - void write64(uint64_t Value) { - if (IsLittleEndian) - writeLE64(Value); - else - writeBE64(Value); - } - - void WriteZeros(unsigned N) { - const char Zeros[16] = {0}; - - for (unsigned i = 0, e = N / 16; i != e; ++i) - *OS << StringRef(Zeros, 16); - - *OS << StringRef(Zeros, N % 16); - } - - void writeBytes(const SmallVectorImpl &ByteVec, - unsigned ZeroFillSize = 0) { - writeBytes(StringRef(ByteVec.data(), ByteVec.size()), ZeroFillSize); - } - - void writeBytes(StringRef Str, unsigned ZeroFillSize = 0) { - // TODO: this version may need to go away once all fragment contents are - // converted to SmallVector - assert( - (ZeroFillSize == 0 || Str.size() <= ZeroFillSize) && - "data size greater than fill size, unexpected large write will occur"); - *OS << Str; - if (ZeroFillSize) - WriteZeros(ZeroFillSize - Str.size()); - } - - /// @} }; } // end namespace llvm Index: llvm/trunk/lib/MC/ELFObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/ELFObjectWriter.cpp +++ llvm/trunk/lib/MC/ELFObjectWriter.cpp @@ -164,7 +164,7 @@ ELFObjectWriter(std::unique_ptr MOTW, raw_pwrite_stream &OS, bool IsLittleEndian) - : MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(std::move(MOTW)), + : TargetObjectWriter(std::move(MOTW)), W(OS, IsLittleEndian ? support::little : support::big) {} ~ELFObjectWriter() override = default; Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -252,8 +252,7 @@ public: WasmObjectWriter(std::unique_ptr MOTW, raw_pwrite_stream &OS) - : MCObjectWriter(OS, /*IsLittleEndian=*/true), W(OS, support::little), - TargetObjectWriter(std::move(MOTW)) {} + : W(OS, support::little), TargetObjectWriter(std::move(MOTW)) {} ~WasmObjectWriter() override; Index: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp +++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp @@ -227,8 +227,7 @@ WinCOFFObjectWriter::WinCOFFObjectWriter( std::unique_ptr MOTW, raw_pwrite_stream &OS) - : MCObjectWriter(OS, true), W(OS, support::little), - TargetObjectWriter(std::move(MOTW)) { + : W(OS, support::little), TargetObjectWriter(std::move(MOTW)) { Header.Machine = TargetObjectWriter->getMachine(); }