26 "Error while parsing %s: unknown record entry (%lu).", BlockName,
33 "Error while parsing %s: malformed record entry (%s).", BlockName,
39 : Stream(Stream), BlockInfo(BlockInfo) {}
54 if (Record.
size() != 2)
61 if (Record.
size() != 1)
67 if (Record.
size() != 0)
73 if (Record.
size() != 0)
101 if (Record.
size() != 4)
103 Parser.
Type = Record[0];
110 if (Record.
size() != 3)
118 if (Record.
size() != 1)
124 if (Record.
size() != 5)
125 return malformedRecord(
"BLOCK_REMARK",
"RECORD_REMARK_ARG_WITH_DEBUGLOC");
129 Parser.
TmpArgs.back().KeyIdx = Record[0];
130 Parser.
TmpArgs.back().ValueIdx = Record[1];
131 Parser.
TmpArgs.back().SourceFileNameIdx = Record[2];
132 Parser.
TmpArgs.back().SourceLine = Record[3];
133 Parser.
TmpArgs.back().SourceColumn = Record[4];
139 if (Record.
size() != 2)
141 "RECORD_REMARK_ARG_WITHOUT_DEBUGLOC");
145 Parser.
TmpArgs.back().KeyIdx = Record[0];
146 Parser.
TmpArgs.back().ValueIdx = Record[1];
157 template <
typename T>
159 const char *BlockName) {
167 "Error while parsing %s: expecting [ENTER_SUBBLOCK, %s, ...].",
168 BlockName, BlockName);
172 "Error while entering %s.", BlockName);
180 switch (Next->Kind) {
187 "Error while parsing %s: expecting records.", BlockName);
198 "Error while parsing %s: unterminated block.", BlockName);
213 std::array<char, 4> Result;
214 for (
unsigned i = 0; i < 4; ++i)
218 return R.takeError();
230 "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, " 231 "BLOCKINFO_BLOCK, ...].");
238 if (!*MaybeBlockInfo)
241 "Error while parsing BLOCKINFO_BLOCK.");
255 switch (Next->Kind) {
258 Result = Next->ID == BlockID;
263 "Unexpected error while parsing bitstream.");
284 "Unknown magic number: expecting %s, got %.4s.",
294 StringRef(MagicNumber->data(), MagicNumber->size())))
304 "Expecting META_BLOCK after the BLOCKINFO_BLOCK.");
318 StringRef(MagicNumber->data(), MagicNumber->size())))
322 StrTab ? std::make_unique<BitstreamRemarkParser>(Buf, std::move(*StrTab))
323 : std::make_unique<BitstreamRemarkParser>(Buf);
325 if (ExternalFilePrependPath)
326 Parser->ExternalFilePrependPath = *ExternalFilePrependPath;
328 return std::move(Parser);
332 if (ParserHelper.atEndOfStream())
333 return make_error<EndOfFileError>();
335 if (!ReadyToParseRemarks) {
336 if (
Error E = parseMeta())
338 ReadyToParseRemarks =
true;
341 return parseRemark();
350 ParserHelper.BlockInfo);
354 if (
Error E = processCommonMeta(MetaHelper))
357 switch (ContainerType) {
359 return processStandaloneMeta(MetaHelper);
361 return processSeparateRemarksFileMeta(MetaHelper);
363 return processSeparateRemarksMetaMeta(MetaHelper);
368 Error BitstreamRemarkParser::processCommonMeta(
375 "Error while parsing BLOCK_META: missing container version.");
382 "Error while parsing BLOCK_META: invalid container type.");
388 "Error while parsing BLOCK_META: missing container type.");
398 "Error while parsing BLOCK_META: missing string table.");
400 P.
StrTab.emplace(*StrTabBuf);
409 "Error while parsing BLOCK_META: missing remark version.");
414 Error BitstreamRemarkParser::processExternalFilePath(
416 if (!ExternalFilePath)
419 "Error while parsing BLOCK_META: missing external file path.");
429 if (std::error_code EC = BufferOrErr.
getError())
432 TmpRemarkBuffer = std::move(*BufferOrErr);
435 if (TmpRemarkBuffer->getBufferSize() == 0)
436 return make_error<EndOfFileError>();
447 ParserHelper.BlockInfo);
451 uint64_t PreviousContainerVersion = ContainerVersion;
452 if (
Error E = processCommonMeta(SeparateMetaHelper))
458 "Error while parsing external file's BLOCK_META: wrong container " 461 if (PreviousContainerVersion != ContainerVersion)
464 "Error while parsing external file's BLOCK_META: mismatching versions: " 465 "original meta: %lu, external file meta: %lu.",
466 PreviousContainerVersion, ContainerVersion);
469 return processSeparateRemarksFileMeta(SeparateMetaHelper);
472 Error BitstreamRemarkParser::processStandaloneMeta(
479 Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
484 Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
496 return processRemark(RemarkHelper);
501 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
507 "Error while parsing BLOCK_REMARK: missing string table.");
512 "Error while parsing BLOCK_REMARK: missing remark type.");
518 "Error while parsing BLOCK_REMARK: unknown remark type.");
520 R.RemarkType =
static_cast<Type>(*Helper.
Type);
525 "Error while parsing BLOCK_REMARK: missing remark name.");
528 R.RemarkName = *RemarkName;
530 return RemarkName.takeError();
535 "Error while parsing BLOCK_REMARK: missing remark pass.");
538 R.PassName = *PassName;
540 return PassName.takeError();
545 "Error while parsing BLOCK_REMARK: missing remark function name.");
547 R.FunctionName = *FunctionName;
549 return FunctionName.takeError();
556 R.Loc->SourceFilePath = *SourceFileName;
565 return std::move(Result);
571 "Error while parsing BLOCK_REMARK: missing key in remark argument.");
575 "Error while parsing BLOCK_REMARK: missing value in remark " 579 R.Args.emplace_back();
582 R.Args.back().Key = *
Key;
584 return Key.takeError();
587 R.Args.back().Val = *
Value;
589 return Value.takeError();
594 R.Args.back().Loc.emplace();
595 R.Args.back().Loc->SourceFilePath = *SourceFileName;
596 R.Args.back().Loc->SourceLine = *Arg.
SourceLine;
599 return SourceFileName.takeError();
603 return std::move(Result);
Represents either an error or a value T.
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
This class represents lattice values for constants.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Error takeError()
Take ownership of the stored error.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
std::error_code make_error_code(BitcodeError E)
Tagged union holding either a T or a Error.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
std::error_code getError() const
Expected< Optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
static ErrorSuccess success()
Create a success value.
This class maintains the abbreviations read from a block info block.
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
LLVM Value Representation.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Expected< word_t > Read(unsigned NumBits)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.