30 Rec_Continuation = 1 << (8 - 6 - 1),
33template <
typename ValueType>
struct BinaryBeImpl {
38template <
typename ValueType>
40 char Buffer[
sizeof(BBE.Value)];
43 OS.
write(Buffer,
sizeof(BBE.Value));
47template <
typename ValueType> BinaryBeImpl<ValueType> binaryBe(
ValueType V) {
48 return BinaryBeImpl<ValueType>(V);
60ZerosImpl
zeros(
const size_t NumBytes) {
return ZerosImpl{NumBytes}; }
69 explicit GOFFOstream(raw_ostream &OS)
70 : OS(OS), LogicalRecords(0), RemainingSize(0), NewLogicalRecord(
false) {
82 NewLogicalRecord =
true;
88 uint32_t logicalRecords() {
return LogicalRecords; }
95 uint32_t LogicalRecords;
104 bool NewLogicalRecord;
109 size_t bytesToNextPhysicalRecord() {
117 size_t RemainingSize,
118 uint8_t Flags = Rec_Continuation) {
119 uint8_t TypeAndFlags =
Flags | (
Type << 4);
121 TypeAndFlags |= Rec_Continued;
123 << binaryBe(
static_cast<unsigned char>(TypeAndFlags))
124 << binaryBe(
static_cast<unsigned char>(0));
129 assert((GetNumBytesInBuffer() <= RemainingSize) &&
130 "More bytes in buffer than expected");
131 size_t Remains = RemainingSize - GetNumBytesInBuffer();
134 "Attempting to fill more than one physical record");
138 assert(RemainingSize == 0 &&
"Not fully flushed");
139 assert(GetNumBytesInBuffer() == 0 &&
"Buffer not fully empty");
143 void write_impl(
const char *
Ptr,
size_t Size)
override {
144 assert((RemainingSize >=
Size) &&
"Attempt to write too much data");
145 assert(RemainingSize &&
"Logical record overflow");
147 writeRecordPrefix(OS, CurrentType, RemainingSize,
148 NewLogicalRecord ? 0 : Rec_Continuation);
149 NewLogicalRecord =
false;
151 assert(!NewLogicalRecord &&
152 "New logical record not on physical record boundary");
156 size_t BytesToWrite = bytesToNextPhysicalRecord();
157 if (BytesToWrite >
Size)
159 OS.write(
Ptr + Idx, BytesToWrite);
161 Size -= BytesToWrite;
162 RemainingSize -= BytesToWrite;
164 writeRecordPrefix(OS, CurrentType, RemainingSize);
171 uint64_t current_pos()
const override {
return OS.tell(); }
175 void writeHeader(GOFFYAML::FileHeader &FileHdr);
183 GOFFState(raw_ostream &OS, GOFFYAML::Object &Doc,
185 : GW(OS), Doc(Doc), ErrHandler(ErrHandler), HasError(
false) {}
187 ~GOFFState() { GW.finalize(); }
192 static bool writeGOFF(raw_ostream &OS, GOFFYAML::Object &Doc,
197 GOFFYAML::Object &Doc;
203 SmallString<16> CCSIDName;
204 if (std::error_code EC =
207 if (CCSIDName.
size() > 16) {
211 SmallString<16> LangProd;
215 if (LangProd.
size() > 16) {
224 << binaryBe(FileHdr.
CCSID)
231 uint16_t ModPropLen = 0;
237 GW << binaryBe(ModPropLen) <<
zeros(6);
245void GOFFState::writeEnd() {
247 GW << binaryBe(uint8_t(0))
248 << binaryBe(uint8_t(0))
250 << binaryBe(GW.logicalRecords());
255bool GOFFState::writeObject() {
263bool GOFFState::writeGOFF(raw_ostream &OS, GOFFYAML::Object &Doc,
265 GOFFState State(OS, Doc, ErrHandler);
266 return State.writeObject();
275 return GOFFState::writeGOFF(Out, Doc, ErrHandler);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis false
static Error reportError(StringRef Message)
zeros_impl< sizeof(T)> zeros(const T &)
This file provides utility functions for converting between EBCDIC-1047 and UTF-8.
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.
raw_ostream & write(unsigned char C)
LLVM_ABI std::error_code convertToEBCDIC(StringRef Source, SmallVectorImpl< char > &Result)
constexpr uint8_t PayloadLength
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.
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
LLVM_ABI bool yaml2goff(GOFFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH)
llvm::function_ref< void(const Twine &Msg)> ErrorHandler
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
Common declarations for yaml2obj.