diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index a308030ff6b..e2ba91de2a7 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -113,8 +113,8 @@ public: typedef SmallVectorImpl::const_iterator const_fixup_iterator; typedef SmallVectorImpl::iterator fixup_iterator; - virtual SmallString<32> &getContents() = 0; - virtual const SmallString<32> &getContents() const = 0; + virtual SmallVectorImpl &getContents() = 0; + virtual const SmallVectorImpl &getContents() const = 0; virtual SmallVectorImpl &getFixups() = 0; virtual const SmallVectorImpl &getFixups() const = 0; @@ -132,7 +132,7 @@ public: class MCDataFragment : public MCEncodedFragment { virtual void anchor(); - SmallString<32> Contents; + SmallVector Contents; /// Fixups - The list of fixups in this fragment. SmallVector Fixups; @@ -142,8 +142,8 @@ public: : MCEncodedFragment(FT_Data, SD) { } - SmallString<32> &getContents() { return Contents; } - const SmallString<32> &getContents() const { return Contents; } + virtual SmallVectorImpl &getContents() { return Contents; } + virtual const SmallVectorImpl &getContents() const { return Contents; } SmallVectorImpl &getFixups() { return Fixups; @@ -171,7 +171,7 @@ class MCInstFragment : public MCEncodedFragment { MCInst Inst; /// Contents - Binary data for the currently encoded instruction. - SmallString<32> Contents; + SmallVector Contents; /// Fixups - The list of fixups in this fragment. SmallVector Fixups; @@ -181,8 +181,8 @@ public: : MCEncodedFragment(FT_Inst, SD), Inst(_Inst) { } - SmallString<32> &getContents() { return Contents; } - const SmallString<32> &getContents() const { return Contents; } + virtual SmallVectorImpl &getContents() { return Contents; } + virtual const SmallVectorImpl &getContents() const { return Contents; } unsigned getInstSize() const { return Contents.size(); } const MCInst &getInst() const { return Inst; } diff --git a/include/llvm/MC/MCObjectWriter.h b/include/llvm/MC/MCObjectWriter.h index 22f10ffa271..f77b7d853db 100644 --- a/include/llvm/MC/MCObjectWriter.h +++ b/include/llvm/MC/MCObjectWriter.h @@ -173,7 +173,13 @@ public: OS << StringRef(Zeros, N % 16); } + void WriteBytes(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; diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index b0623d35a9e..bfe17094628 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -203,7 +203,7 @@ class ELFObjectWriter : public MCObjectWriter { void String8(MCDataFragment &F, uint8_t Value) { char buf[1]; buf[0] = Value; - F.getContents() += StringRef(buf, 1); + F.getContents().append(&buf[0], &buf[1]); } void String16(MCDataFragment &F, uint16_t Value) { @@ -212,7 +212,7 @@ class ELFObjectWriter : public MCObjectWriter { StringLE16(buf, Value); else StringBE16(buf, Value); - F.getContents() += StringRef(buf, 2); + F.getContents().append(&buf[0], &buf[2]); } void String32(MCDataFragment &F, uint32_t Value) { @@ -221,7 +221,7 @@ class ELFObjectWriter : public MCObjectWriter { StringLE32(buf, Value); else StringBE32(buf, Value); - F.getContents() += StringRef(buf, 4); + F.getContents().append(&buf[0], &buf[4]); } void String64(MCDataFragment &F, uint64_t Value) { @@ -230,7 +230,7 @@ class ELFObjectWriter : public MCObjectWriter { StringLE64(buf, Value); else StringBE64(buf, Value); - F.getContents() += StringRef(buf, 8); + F.getContents().append(&buf[0], &buf[8]); } void WriteHeader(uint64_t SectionDataSize, @@ -1186,7 +1186,7 @@ void ELFObjectWriter::CreateMetadataSections(MCAssembler &Asm, // The first entry of a string table holds a null character so skip // section 0. uint64_t Index = 1; - F->getContents() += '\x00'; + F->getContents().push_back('\x00'); for (unsigned int I = 0, E = Sections.size(); I != E; ++I) { const MCSectionELF &Section = *Sections[I]; @@ -1204,8 +1204,8 @@ void ELFObjectWriter::CreateMetadataSections(MCAssembler &Asm, SectionStringTableIndex[&Section] = Index; Index += Name.size() + 1; - F->getContents() += Name; - F->getContents() += '\x00'; + F->getContents().append(Name.begin(), Name.end()); + F->getContents().push_back('\x00'); } } @@ -1380,7 +1380,7 @@ void ELFObjectWriter::WriteDataSectionData(MCAssembler &Asm, ++i) { const MCFragment &F = *i; assert(F.getKind() == MCFragment::FT_Data); - WriteBytes(cast(F).getContents().str()); + WriteBytes(cast(F).getContents()); } } else { Asm.writeSectionData(&SD, Layout); diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index b2136e553e2..989d8be0af5 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -391,7 +391,7 @@ void MCAsmLayout::LayoutFragment(MCFragment *F) { /// a MCEncodedFragment. static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { MCEncodedFragment &EF = cast(F); - OW->WriteBytes(EF.getContents().str()); + OW->WriteBytes(EF.getContents()); } /// \brief Write the fragment \p F to the output file.