26 std::make_error_code(std::errc::illegal_byte_sequence),
27 "Error while parsing %s: unknown record entry (%lu).", BlockName,
33 std::make_error_code(std::errc::illegal_byte_sequence),
34 "Error while parsing %s: malformed record entry (%s).", BlockName,
40 : Stream(Stream), BlockInfo(BlockInfo) {}
126 return malformedRecord(
"BLOCK_REMARK",
"RECORD_REMARK_ARG_WITH_DEBUGLOC");
142 "RECORD_REMARK_ARG_WITHOUT_DEBUGLOC");
160 const char *BlockName) {
167 std::make_error_code(std::errc::illegal_byte_sequence),
168 "Error while parsing %s: expecting [ENTER_SUBBLOCK, %s, ...].",
169 BlockName, BlockName);
172 std::make_error_code(std::errc::illegal_byte_sequence),
173 "Error while entering %s.", BlockName);
181 switch (Next->Kind) {
187 std::make_error_code(std::errc::illegal_byte_sequence),
188 "Error while parsing %s: expecting records.", BlockName);
198 std::make_error_code(std::errc::illegal_byte_sequence),
199 "Error while parsing %s: unterminated block.", BlockName);
214 std::array<char, 4> Result;
215 for (
unsigned i = 0; i < 4; ++i)
219 return R.takeError();
230 std::make_error_code(std::errc::illegal_byte_sequence),
231 "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
232 "BLOCKINFO_BLOCK, ...].");
239 if (!*MaybeBlockInfo)
241 std::make_error_code(std::errc::illegal_byte_sequence),
242 "Error while parsing BLOCKINFO_BLOCK.");
256 switch (Next->Kind) {
259 Result = Next->ID == BlockID;
263 std::make_error_code(std::errc::illegal_byte_sequence),
264 "Unexpected error while parsing bitstream.");
285 "Unknown magic number: expecting %s, got %.4s.",
304 std::make_error_code(std::errc::illegal_byte_sequence),
305 "Expecting META_BLOCK after the BLOCKINFO_BLOCK.");
311 StringRef Buf, std::optional<ParsedStringTable> StrTab,
312 std::optional<StringRef> ExternalFilePrependPath) {
323 StrTab ? std::make_unique<BitstreamRemarkParser>(Buf, std::move(*StrTab))
324 : std::make_unique<BitstreamRemarkParser>(Buf);
326 if (ExternalFilePrependPath)
327 Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
329 return std::move(Parser);
334 return make_error<EndOfFileError>();
355 if (
Error E = processCommonMeta(MetaHelper))
360 return processStandaloneMeta(MetaHelper);
362 return processSeparateRemarksFileMeta(MetaHelper);
364 return processSeparateRemarksMetaMeta(MetaHelper);
369Error BitstreamRemarkParser::processCommonMeta(
375 std::make_error_code(std::errc::illegal_byte_sequence),
376 "Error while parsing BLOCK_META: missing container version.");
382 std::make_error_code(std::errc::illegal_byte_sequence),
383 "Error while parsing BLOCK_META: invalid container type.");
388 std::make_error_code(std::errc::illegal_byte_sequence),
389 "Error while parsing BLOCK_META: missing container type.");
395 std::optional<StringRef> StrTabBuf) {
398 std::make_error_code(std::errc::illegal_byte_sequence),
399 "Error while parsing BLOCK_META: missing string table.");
401 P.StrTab.emplace(*StrTabBuf);
406 std::optional<uint64_t> RemarkVersion) {
409 std::make_error_code(std::errc::illegal_byte_sequence),
410 "Error while parsing BLOCK_META: missing remark version.");
411 P.RemarkVersion = *RemarkVersion;
415Error BitstreamRemarkParser::processExternalFilePath(
416 std::optional<StringRef> ExternalFilePath) {
417 if (!ExternalFilePath)
419 std::make_error_code(std::errc::illegal_byte_sequence),
420 "Error while parsing BLOCK_META: missing external file path.");
430 if (std::error_code EC = BufferOrErr.
getError())
437 return make_error<EndOfFileError>();
449 if (
Error E = SeparateMetaHelper.parse())
453 if (
Error E = processCommonMeta(SeparateMetaHelper))
458 std::make_error_code(std::errc::illegal_byte_sequence),
459 "Error while parsing external file's BLOCK_META: wrong container "
464 std::make_error_code(std::errc::illegal_byte_sequence),
465 "Error while parsing external file's BLOCK_META: mismatching versions: "
466 "original meta: %lu, external file meta: %lu.",
470 return processSeparateRemarksFileMeta(SeparateMetaHelper);
473Error BitstreamRemarkParser::processStandaloneMeta(
480Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
485Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
497 return processRemark(RemarkHelper);
502 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
505 if (
StrTab == std::nullopt)
507 std::make_error_code(std::errc::invalid_argument),
508 "Error while parsing BLOCK_REMARK: missing string table.");
512 std::make_error_code(std::errc::illegal_byte_sequence),
513 "Error while parsing BLOCK_REMARK: missing remark type.");
518 std::make_error_code(std::errc::illegal_byte_sequence),
519 "Error while parsing BLOCK_REMARK: unknown remark type.");
521 R.RemarkType =
static_cast<Type>(*Helper.
Type);
525 std::make_error_code(std::errc::illegal_byte_sequence),
526 "Error while parsing BLOCK_REMARK: missing remark name.");
529 R.RemarkName = *RemarkName;
531 return RemarkName.takeError();
535 std::make_error_code(std::errc::illegal_byte_sequence),
536 "Error while parsing BLOCK_REMARK: missing remark pass.");
545 std::make_error_code(std::errc::illegal_byte_sequence),
546 "Error while parsing BLOCK_REMARK: missing remark function name.");
548 R.FunctionName = *FunctionName;
550 return FunctionName.takeError();
557 R.Loc->SourceFilePath = *SourceFileName;
566 return std::move(Result);
571 std::make_error_code(std::errc::illegal_byte_sequence),
572 "Error while parsing BLOCK_REMARK: missing key in remark argument.");
575 std::make_error_code(std::errc::illegal_byte_sequence),
576 "Error while parsing BLOCK_REMARK: missing value in remark "
580 R.Args.emplace_back();
583 R.Args.back().Key = *Key;
585 return Key.takeError();
588 R.Args.back().Val = *
Value;
590 return Value.takeError();
595 R.Args.back().Loc.emplace();
596 R.Args.back().Loc->SourceFilePath = *SourceFileName;
597 R.Args.back().Loc->SourceLine = *Arg.
SourceLine;
604 return std::move(Result);
static const char PassName[]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class maintains the abbreviations read from a block info block.
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Expected< word_t > Read(unsigned NumBits)
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Expected< std::optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.