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<StringRef> ExternalFilePrependPath) {
321 auto Parser = std::make_unique<BitstreamRemarkParser>(Buf);
323 if (ExternalFilePrependPath)
324 Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
326 return std::move(Parser);
331 return make_error<EndOfFileError>();
352 if (
Error E = processCommonMeta(MetaHelper))
357 return processStandaloneMeta(MetaHelper);
359 return processSeparateRemarksFileMeta(MetaHelper);
361 return processSeparateRemarksMetaMeta(MetaHelper);
366Error BitstreamRemarkParser::processCommonMeta(
372 std::make_error_code(std::errc::illegal_byte_sequence),
373 "Error while parsing BLOCK_META: missing container version.");
379 std::make_error_code(std::errc::illegal_byte_sequence),
380 "Error while parsing BLOCK_META: invalid container type.");
385 std::make_error_code(std::errc::illegal_byte_sequence),
386 "Error while parsing BLOCK_META: missing container type.");
392 std::optional<StringRef> StrTabBuf) {
395 std::make_error_code(std::errc::illegal_byte_sequence),
396 "Error while parsing BLOCK_META: missing string table.");
398 P.StrTab.emplace(*StrTabBuf);
403 std::optional<uint64_t> RemarkVersion) {
406 std::make_error_code(std::errc::illegal_byte_sequence),
407 "Error while parsing BLOCK_META: missing remark version.");
408 P.RemarkVersion = *RemarkVersion;
412Error BitstreamRemarkParser::processExternalFilePath(
413 std::optional<StringRef> ExternalFilePath) {
414 if (!ExternalFilePath)
416 std::make_error_code(std::errc::illegal_byte_sequence),
417 "Error while parsing BLOCK_META: missing external file path.");
427 if (std::error_code EC = BufferOrErr.
getError())
434 return make_error<EndOfFileError>();
446 if (
Error E = SeparateMetaHelper.parse())
450 if (
Error E = processCommonMeta(SeparateMetaHelper))
455 std::make_error_code(std::errc::illegal_byte_sequence),
456 "Error while parsing external file's BLOCK_META: wrong container "
461 std::make_error_code(std::errc::illegal_byte_sequence),
462 "Error while parsing external file's BLOCK_META: mismatching versions: "
463 "original meta: %lu, external file meta: %lu.",
467 return processSeparateRemarksFileMeta(SeparateMetaHelper);
470Error BitstreamRemarkParser::processStandaloneMeta(
477Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
482Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
494 return processRemark(RemarkHelper);
499 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
502 if (
StrTab == std::nullopt)
504 std::make_error_code(std::errc::invalid_argument),
505 "Error while parsing BLOCK_REMARK: missing string table.");
509 std::make_error_code(std::errc::illegal_byte_sequence),
510 "Error while parsing BLOCK_REMARK: missing remark type.");
515 std::make_error_code(std::errc::illegal_byte_sequence),
516 "Error while parsing BLOCK_REMARK: unknown remark type.");
518 R.RemarkType =
static_cast<Type>(*Helper.
Type);
522 std::make_error_code(std::errc::illegal_byte_sequence),
523 "Error while parsing BLOCK_REMARK: missing remark name.");
526 R.RemarkName = *RemarkName;
528 return RemarkName.takeError();
532 std::make_error_code(std::errc::illegal_byte_sequence),
533 "Error while parsing BLOCK_REMARK: missing remark pass.");
542 std::make_error_code(std::errc::illegal_byte_sequence),
543 "Error while parsing BLOCK_REMARK: missing remark function name.");
545 R.FunctionName = *FunctionName;
547 return FunctionName.takeError();
554 R.Loc->SourceFilePath = *SourceFileName;
563 return std::move(Result);
568 std::make_error_code(std::errc::illegal_byte_sequence),
569 "Error while parsing BLOCK_REMARK: missing key in remark argument.");
572 std::make_error_code(std::errc::illegal_byte_sequence),
573 "Error while parsing BLOCK_REMARK: missing value in remark "
577 R.Args.emplace_back();
580 R.Args.back().Key = *Key;
582 return Key.takeError();
585 R.Args.back().Val = *
Value;
587 return Value.takeError();
592 R.Args.back().Loc.emplace();
593 R.Args.back().Loc->SourceFilePath = *SourceFileName;
594 R.Args.back().Loc->SourceLine = *Arg.
SourceLine;
601 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.
LLVM_ABI Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
LLVM_ABI Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
LLVM_ABI 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.
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...
LLVM_ABI 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.