MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / parseSectionHeader

Function parseSectionHeader

lib/Bytecode/Reader/BytecodeReader.cpp:331–372  ·  view source on GitHub ↗

Parses the section header from the bytecode.

Source from the content-addressed store, hash-verified

329
330/// Parses the section header from the bytecode.
331static LogicalResult parseSectionHeader(EncodingReader &reader,
332 SectionHeader &header,
333 MLIRContext &context) {
334 if (reader.remaining() < 1)
335 return reader.emitError()
336 << "unexpected end of data while reading section header";
337 uint8_t idAndIsAligned;
338 if (failed(reader.readLE(idAndIsAligned)))
339 return reader.emitError() << "failed to read section ID and alignment flag";
340 header.sectionID = idAndIsAligned & 0x7F;
341 header.hasAlignment = (idAndIsAligned & 0x80) != 0;
342
343 // If this is the end section marker, return success.
344 if (header.sectionID == Section::EndOfBytecode) {
345 if (header.hasAlignment)
346 return reader.emitError()
347 << "end section should not have alignment flag set";
348 return success();
349 }
350 if (header.sectionID >= Section::NumSections)
351 return reader.emitError() << "unknown section ID: " << header.sectionID;
352
353 // Read the section length.
354 if (failed(reader.readVarInt(header.length)))
355 return reader.emitError() << "failed to read section length";
356 if (header.length > reader.remaining())
357 return reader.emitError()
358 << "section length " << header.length
359 << " exceeds remaining data size " << reader.remaining();
360
361 // If the section is aligned, read the alignment value and adjust the buffer.
362 if (header.hasAlignment) {
363 if (failed(reader.readVarInt(header.alignment)))
364 return failure();
365 if (header.alignment == 0 || !llvm::isPowerOf2_64(header.alignment))
366 return reader.emitError()
367 << "invalid alignment value: " << header.alignment;
368 if (failed(reader.skipPadding(header.alignment)))
369 return failure();
370 }
371 return success();
372}
373
374//===----------------------------------------------------------------------===//
375// String Section

Callers 2

getBytecodeSizeMethod · 0.85
readBytecodeMethod · 0.85

Calls 5

remainingMethod · 0.80
emitErrorMethod · 0.80
readLEMethod · 0.80
readVarIntMethod · 0.80
skipPaddingMethod · 0.80

Tested by

no test coverage detected