[llvm] r332864 - MC: Remove stream and output functions from MCObjectWriter. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon May 21 11:28:57 PDT 2018
Author: pcc
Date: Mon May 21 11:28:57 2018
New Revision: 332864
URL: http://llvm.org/viewvc/llvm-project?rev=332864&view=rev
Log:
MC: Remove stream and output functions from MCObjectWriter. NFCI.
Part of PR37466.
Differential Revision: https://reviews.llvm.org/D47043
Modified:
llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
llvm/trunk/include/llvm/MC/MCObjectWriter.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
Modified: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=332864&r1=332863&r2=332864&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Mon May 21 11:28:57 2018
@@ -121,8 +121,7 @@ class MachObjectWriter : public MCObject
public:
MachObjectWriter(std::unique_ptr<MCMachObjectTargetWriter> 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;
Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=332864&r1=332863&r2=332864&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Mon May 21 11:28:57 2018
@@ -36,22 +36,9 @@ class MCValue;
/// 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 @@ public:
/// 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 @@ public:
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<char> &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<char, N>
- 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
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=332864&r1=332863&r2=332864&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon May 21 11:28:57 2018
@@ -164,7 +164,7 @@ public:
ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> 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;
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=332864&r1=332863&r2=332864&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Mon May 21 11:28:57 2018
@@ -252,8 +252,7 @@ class WasmObjectWriter : public MCObject
public:
WasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> 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;
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=332864&r1=332863&r2=332864&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Mon May 21 11:28:57 2018
@@ -227,8 +227,7 @@ void COFFSymbol::set_name_offset(uint32_
WinCOFFObjectWriter::WinCOFFObjectWriter(
std::unique_ptr<MCWinCOFFObjectTargetWriter> 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();
}
More information about the llvm-commits
mailing list