diff --git a/llvm/tools/llvm-objcopy/wasm/Writer.cpp b/llvm/tools/llvm-objcopy/wasm/Writer.cpp --- a/llvm/tools/llvm-objcopy/wasm/Writer.cpp +++ b/llvm/tools/llvm-objcopy/wasm/Writer.cpp @@ -55,28 +55,21 @@ } Error Writer::write() { - size_t TotalSize = finalize(); - std::unique_ptr Buf = - WritableMemoryBuffer::getNewMemBuffer(TotalSize); - if (!Buf) - return createStringError(llvm::errc::not_enough_memory, Twine(TotalSize)); + finalize(); // Write the header. - uint8_t *Ptr = reinterpret_cast(Buf->getBufferStart()); - Ptr = std::copy(Obj.Header.Magic.begin(), Obj.Header.Magic.end(), Ptr); - support::endian::write32le(Ptr, Obj.Header.Version); - Ptr += sizeof(Obj.Header.Version); + Out.write(Obj.Header.Magic.data(), Obj.Header.Magic.size()); + uint32_t Version; + support::endian::write32le(&Version, Obj.Header.Version); + Out.write((const char *)&Version, sizeof(Version)); // Write each section. for (size_t I = 0, S = SectionHeaders.size(); I < S; ++I) { - Ptr = std::copy(SectionHeaders[I].begin(), SectionHeaders[I].end(), Ptr); - ArrayRef Contents = Obj.Sections[I].Contents; - Ptr = std::copy(Contents.begin(), Contents.end(), Ptr); + Out.write(SectionHeaders[I].data(), SectionHeaders[I].size()); + Out.write((const char *)Obj.Sections[I].Contents.data(), + Obj.Sections[I].Contents.size()); } - // TODO: Implement direct writing to the output stream - // TODO: (without intermediate memory buffer Buf). - Out.write(Buf->getBufferStart(), Buf->getBufferSize()); Out.flush(); return Error::success(); }