@@ -61,82 +61,20 @@ constexpr uint8_t RecContinued = Flags(7, 1, 1);
6161
6262// Flag: This record is a continuation.
6363constexpr uint8_t RecContinuation = Flags(6 , 1 , 1 );
64-
65- // The GOFFOstream is responsible to write the data into the fixed physical
66- // records of the format. A user of this class announces the begin of a new
67- // logical record. While writing the payload, the physical records are created
68- // for the data. Possible fill bytes at the end of a physical record are written
69- // automatically. In principle, the GOFFOstream is agnostic of the endianness of
70- // the payload. However, it also supports writing data in big endian byte order.
71- //
72- // The physical records use the flag field to indicate if the there is a
73- // successor and predecessor record. To be able to set these flags while
74- // writing, the basic implementation idea is to always buffer the last seen
75- // physical record.
76- class GOFFOstream {
77- // / The underlying raw_pwrite_stream.
78- raw_pwrite_stream &OS;
79-
80- // / The number of logical records emitted so far.
81- uint32_t LogicalRecords = 0 ;
82-
83- // / The number of physical records emitted so far.
84- uint32_t PhysicalRecords = 0 ;
85-
86- // / The size of the buffer. Same as the payload size of a physical record.
87- static constexpr uint8_t BufferSize = GOFF::PayloadLength;
88-
89- // / Current position in buffer.
90- char *BufferPtr = Buffer;
91-
92- // / Static allocated buffer for the stream.
93- char Buffer[BufferSize];
94-
95- // / The type of the current logical record, and the flags (aka continued and
96- // / continuation indicators) for the previous (physical) record.
97- uint8_t TypeAndFlags = 0 ;
98-
99- public:
100- GOFFOstream (raw_pwrite_stream &OS);
101- ~GOFFOstream ();
102-
103- raw_pwrite_stream &getOS () { return OS; }
104- size_t getWrittenSize () const { return PhysicalRecords * GOFF::RecordLength; }
105- uint32_t getNumLogicalRecords () { return LogicalRecords; }
106-
107- // / Write the specified bytes.
108- void write (const char *Ptr, size_t Size);
109-
110- // / Write zeroes, up to a maximum of 16 bytes.
111- void write_zeros (unsigned NumZeros);
112-
113- // / Support for endian-specific data.
114- template <typename value_type> void writebe (value_type Value) {
115- Value =
116- support::endian::byte_swap<value_type>(Value, llvm::endianness::big);
117- write ((const char *)&Value, sizeof (value_type));
118- }
119-
120- // / Begin a new logical record. Implies finalizing the previous record.
121- void newRecord (GOFF::RecordType Type);
122-
123- // / Ends a logical record.
124- void finalizeRecord ();
125-
126- private:
127- // / Updates the continued/continuation flags, and writes the record prefix of
128- // / a physical record.
129- void updateFlagsAndWritePrefix (bool IsContinued);
130-
131- // / Returns the remaining size in the buffer.
132- size_t getRemainingSize ();
133- };
13464} // namespace
13565
13666GOFFOstream::GOFFOstream (raw_pwrite_stream &OS) : OS(OS) {}
13767
13868GOFFOstream::~GOFFOstream () { finalizeRecord (); }
13969
70+ raw_pwrite_stream &GOFFOstream::getOS () { return OS; }
71+
72+ size_t GOFFOstream::getWrittenSize () const {
73+ return PhysicalRecords * GOFF::RecordLength;
74+ }
75+
76+ uint32_t GOFFOstream::getNumLogicalRecords () { return LogicalRecords; }
77+
14078void GOFFOstream::updateFlagsAndWritePrefix (bool IsContinued) {
14179 // Update the flags based on the previous state and the flag IsContinued.
14280 if (TypeAndFlags & RecContinued)
@@ -222,20 +160,6 @@ void GOFFOstream::finalizeRecord() {
222160 BufferPtr = Buffer;
223161}
224162
225- namespace {
226- class GOFFWriter {
227- GOFFOstream OS;
228- [[maybe_unused]] MCAssembler &Asm;
229-
230- void writeHeader ();
231- void writeEnd ();
232-
233- public:
234- GOFFWriter (raw_pwrite_stream &OS, MCAssembler &Asm);
235- uint64_t writeObject ();
236- };
237- } // namespace
238-
239163GOFFWriter::GOFFWriter (raw_pwrite_stream &OS, MCAssembler &Asm)
240164 : OS(OS), Asm(Asm) {}
241165
0 commit comments