23#define DEBUG_TYPE "goff-writer"
35 assert(BitIndex < 8 &&
"Bit index out of bounds!");
36 assert(
Length + BitIndex <= 8 &&
"Bit length too long!");
42 return (OldValue & ~Mask) |
Value;
46 constexpr Flags() : Val(0) {}
54 constexpr operator uint8_t()
const {
return Val; }
60constexpr uint8_t RecContinued = Flags(7, 1, 1);
63constexpr uint8_t RecContinuation = Flags(6, 1, 1);
91 bool NewLogicalRecord;
100 size_t bytesToNextPhysicalRecord() {
107 size_t RemainingSize,
108 uint8_t Flags = RecContinuation);
114 void write_impl(
const char *
Ptr,
size_t Size)
override;
122 :
OS(
OS), RemainingSize(0), LogicalRecords(0), NewLogicalRecord(
false) {
134 uint32_t logicalRecords() {
return LogicalRecords; }
137 template <
typename value_type>
void writebe(value_type
Value) {
140 write(
reinterpret_cast<const char *
>(&
Value),
sizeof(value_type));
145 size_t RemainingSize,
uint8_t Flags) {
148 TypeAndFlags |= RecContinued;
150 <<
static_cast<unsigned char>(TypeAndFlags)
151 <<
static_cast<unsigned char>(0);
157 RemainingSize =
Size;
164 RemainingSize += Gap;
166 NewLogicalRecord =
true;
170void GOFFOstream::fillRecord() {
171 assert((GetNumBytesInBuffer() <= RemainingSize) &&
172 "More bytes in buffer than expected");
173 size_t Remains = RemainingSize - GetNumBytesInBuffer();
175 assert(Remains == Gap &&
"Wrong size of fill gap");
177 "Attempt to fill more than one physical record");
181 assert(RemainingSize == 0 &&
"Not fully flushed");
182 assert(GetNumBytesInBuffer() == 0 &&
"Buffer not fully empty");
193void GOFFOstream::write_impl(
const char *
Ptr,
size_t Size) {
194 assert((RemainingSize >=
Size) &&
"Attempt to write too much data");
195 assert(RemainingSize &&
"Logical record overflow");
197 writeRecordPrefix(
OS, CurrentType, RemainingSize,
198 NewLogicalRecord ? 0 : RecContinuation);
199 NewLogicalRecord =
false;
201 assert(!NewLogicalRecord &&
202 "New logical record not on physical record boundary");
206 size_t BytesToWrite = bytesToNextPhysicalRecord();
207 if (BytesToWrite >
Size)
211 Size -= BytesToWrite;
212 RemainingSize -= BytesToWrite;
214 writeRecordPrefix(
OS, CurrentType, RemainingSize);
220 std::unique_ptr<MCGOFFObjectTargetWriter> TargetObjectWriter;
226 GOFFObjectWriter(std::unique_ptr<MCGOFFObjectTargetWriter> MOTW,
228 : TargetObjectWriter(std::move(MOTW)),
OS(
OS) {}
230 ~GOFFObjectWriter()
override {}
244void GOFFObjectWriter::writeHeader() {
258void GOFFObjectWriter::writeEnd() {
283 LLVM_DEBUG(
dbgs() <<
"Wrote " <<
OS.logicalRecords() <<
" logical records.");
285 return OS.
tell() - StartOffset;
288std::unique_ptr<MCObjectWriter>
291 return std::make_unique<GOFFObjectWriter>(std::move(MOTW),
OS);
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Defines the object file and target independent interfaces used by the assembler backend to write nati...
virtual uint64_t writeObject(MCAssembler &Asm)=0
Write the object file and returns the number of bytes written.
virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
This represents an "assembler immediate".
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
raw_ostream & write(unsigned char C)
An abstract base class for streams implementations that also support a pwrite operation.
constexpr uint8_t RecordContentLength
constexpr uint8_t PTVPrefix
Prefix byte on every record. This indicates GOFF format.
constexpr uint8_t RecordLength
Length of the parts of a physical GOFF record.
This is an optimization pass for GlobalISel generic memory operations.
std::unique_ptr< MCObjectWriter > createGOFFObjectWriter(std::unique_ptr< MCGOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
Construct a new GOFF writer instance.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.