//===- lib/MC/GOFFObjectWriter.cpp - GOFF File Writer ---------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements GOFF object file writer information. // //===----------------------------------------------------------------------===// #include "llvm/BinaryFormat/GOFF.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCGOFFObjectWriter.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" usingnamespacellvm; #define DEBUG_TYPE … namespace { // The standard System/390 convention is to name the high-order (leftmost) bit // in a byte as bit zero. The Flags type helps to set bits in a byte according // to this numeration order. class Flags { … }; // Common flag values on records. // Flag: This record is continued. constexpr uint8_t RecContinued = …; // Flag: This record is a continuation. constexpr uint8_t RecContinuation = …; // The GOFFOstream is responsible to write the data into the fixed physical // records of the format. A user of this class announces the start of a new // logical record and the size of its content. While writing the content, the // physical records are created for the data. Possible fill bytes at the end of // a physical record are written automatically. In principle, the GOFFOstream // is agnostic of the endianness of the content. However, it also supports // writing data in big endian byte order. class GOFFOstream : public raw_ostream { … }; void GOFFOstream::writeRecordPrefix(raw_ostream &OS, GOFF::RecordType Type, size_t RemainingSize, uint8_t Flags) { … } void GOFFOstream::newRecord(GOFF::RecordType Type, size_t Size) { … } void GOFFOstream::fillRecord() { … } // This function is called from the raw_ostream implementation if: // - The internal buffer is full. Size is excactly the size of the buffer. // - Data larger than the internal buffer is written. Size is a multiple of the // buffer size. // - flush() has been called. Size is at most the buffer size. // The GOFFOstream implementation ensures that flush() is called before a new // logical record begins. Therefore it is sufficient to check for a new block // only once. void GOFFOstream::write_impl(const char *Ptr, size_t Size) { … } class GOFFObjectWriter : public MCObjectWriter { … }; } // end anonymous namespace void GOFFObjectWriter::writeHeader() { … } void GOFFObjectWriter::writeEnd() { … } uint64_t GOFFObjectWriter::writeObject(MCAssembler &Asm) { … } std::unique_ptr<MCObjectWriter> llvm::createGOFFObjectWriter(std::unique_ptr<MCGOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS) { … }