24template <
typename... Ts>
Error error(
char const *Fmt,
const Ts &...Vals) {
30 std::make_error_code(std::errc::illegal_byte_sequence));
36 return error(
"Unknown record entry ({}).", AbbrevID);
40 return error(
"Unexpected record entry ({}).", RecordName);
44 return error(
"Malformed record entry ({}).", RecordName);
48 return error(
"Unexpected subblock ({}).", Code);
54 return Next.takeError();
60 return error(
"Expected subblock, but got unexpected record.");
62 return error(
"Expected subblock, but got unexpected end of bitstream.");
70 return MaybeBlockID.takeError();
72 return error(
"Expected {} block, but got unexpected block ({}).",
BlockName,
101 "Unsupported remark container version (expected: {}, read: {}). "
102 "Please upgrade/downgrade your toolchain to read this container.",
115 "Unsupported remark version in container (expected: {}, read: {}). "
116 "Please upgrade/downgrade your toolchain to read this container.",
209 std::array<char, 4> Result;
210 for (
unsigned I = 0;
I < 4; ++
I)
214 return R.takeError();
218 return error(
"Unknown magic number: expecting {}, got {}.",
226 return Next.takeError();
230 "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
231 "BLOCKINFO_BLOCK, ...].");
234 Stream.ReadBlockInfoBlock();
238 if (!*MaybeBlockInfo)
239 return error(
"Missing BLOCKINFO_BLOCK.");
257 StringRef Buf, std::optional<StringRef> ExternalFilePrependPath) {
258 auto Parser = std::make_unique<BitstreamRemarkParser>(Buf);
260 if (ExternalFilePrependPath)
261 Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
263 return std::move(Parser);
289 if (
Error E = processCommonMeta(MetaHelper))
294 return processStandaloneMeta(MetaHelper);
296 return processSeparateRemarksFileMeta(MetaHelper);
298 return processSeparateRemarksMetaMeta(MetaHelper);
303Error BitstreamRemarkParser::processCommonMeta(
306 return Helper.
error(
"Missing container info.");
311 return Helper.
error(
"Invalid container type.");
318 return Helper.
error(
"Missing string table.");
324Error BitstreamRemarkParser::processRemarkVersion(
327 return Helper.
error(
"Missing remark version.");
332Error BitstreamRemarkParser::processExternalFilePath(
335 return Helper.
error(
"Missing external file path.");
344 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
346 if (std::error_code EC = BufferOrErr.
getError())
363 BitstreamMetaParserHelper SeparateMetaHelper(
ParserHelper.Stream);
364 if (
Error E = SeparateMetaHelper.expectBlock())
366 if (
Error E = SeparateMetaHelper.parseBlock())
369 if (
Error E = processCommonMeta(SeparateMetaHelper))
373 return SeparateMetaHelper.error(
"Wrong container type in external file.");
376 return processSeparateRemarksFileMeta(SeparateMetaHelper);
379Error BitstreamRemarkParser::processStandaloneMeta(
381 if (
Error E = processStrTab(Helper))
383 return processRemarkVersion(Helper);
386Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
388 return processRemarkVersion(Helper);
391Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
393 if (
Error E = processStrTab(Helper))
395 return processExternalFilePath(Helper);
403 return processRemark(RemarkHelper);
408 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
412 return Helper.
error(
"Missing string table.");
415 return Helper.
error(
"Missing remark type.");
419 return Helper.
error(
"Unknown remark type.");
421 R.RemarkType =
static_cast<Type>(*Helper.
Type);
424 return Helper.
error(
"Missing remark name.");
427 R.RemarkName = *RemarkName;
429 return RemarkName.takeError();
432 return Helper.
error(
"Missing remark pass.");
440 return Helper.
error(
"Missing remark function name.");
443 R.FunctionName = *FunctionName;
445 return FunctionName.takeError();
449 (*StrTab)[Helper.
Loc->SourceFileNameIdx];
453 R.Loc->SourceFilePath = *SourceFileName;
454 R.Loc->SourceLine = Helper.
Loc->SourceLine;
455 R.Loc->SourceColumn = Helper.
Loc->SourceColumn;
463 return Helper.
error(
"Missing key in remark argument.");
465 return Helper.
error(
"Missing value in remark argument.");
468 auto &RArg = R.Args.emplace_back();
473 return Key.takeError();
478 return Value.takeError();
484 RArg.Loc->SourceFilePath = *SourceFileName;
485 RArg.Loc->SourceLine = Arg.
Loc->SourceLine;
486 RArg.Loc->SourceColumn = Arg.
Loc->SourceColumn;
492 return std::move(Result);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static const char PassName[]
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
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,...
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.
A raw_ostream that writes to an std::string.
#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.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr Next