26 assert(Ctx &&
"Expected non-null Ctx in diagnostic handler.");
27 std::string &Message = *
static_cast<std::string *
>(Ctx);
28 assert(Message.empty() &&
"Expected an empty string.");
67 "Expecting \\0 after magic number.");
74 "Expecting version number.");
77 support::endian::read<uint64_t, support::little, support::unaligned>(
81 "Mismatching remark version. Got %" PRId64
82 ", expected %" PRId64
".",
91 "Expecting string table size.");
93 support::endian::read<uint64_t, support::little, support::unaligned>(
101 if (Buf.
size() < StrTabSize)
103 "Expecting string table.");
112 StringRef Buf, std::optional<ParsedStringTable> StrTab,
113 std::optional<StringRef> ExternalFilePrependPath) {
119 std::unique_ptr<MemoryBuffer> SeparateBuf;
123 return Version.takeError();
130 if (*StrTabSize != 0) {
133 "String table already provided.");
137 StrTab = std::move(*MaybeStrTab);
144 if (ExternalFilePrependPath)
145 FullPath = *ExternalFilePrependPath;
151 if (std::error_code EC = BufferOrErr.
getError())
155 SeparateBuf = std::move(*BufferOrErr);
156 Buf = SeparateBuf->getBuffer();
160 std::unique_ptr<YAMLRemarkParser> Result =
162 ? std::make_unique<YAMLStrTabRemarkParser>(Buf, std::move(*StrTab))
163 : std::make_unique<YAMLRemarkParser>(Buf);
165 Result->SeparateBuf = std::move(SeparateBuf);
166 return std::move(Result);
173 std::optional<ParsedStringTable> StrTab)
175 SM(
setupSM(LastErrorMessage)), Stream(Buf, SM), YAMLIt(Stream.begin()) {}
178 return make_error<YAMLParseError>(Message,
SM,
Stream, Node);
197 "not a valid YAML file.");
200 auto *Root = dyn_cast<yaml::MappingNode>(YAMLRoot);
202 return error(
"document root is not of mapping type.", *YAMLRoot);
204 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
205 Remark &TheRemark = *Result;
211 return T.takeError();
222 if (KeyName ==
"Pass") {
226 return MaybeStr.takeError();
227 }
else if (KeyName ==
"Name") {
231 return MaybeStr.takeError();
232 }
else if (KeyName ==
"Function") {
236 return MaybeStr.takeError();
237 }
else if (KeyName ==
"Hotness") {
241 return MaybeU.takeError();
242 }
else if (KeyName ==
"DebugLoc") {
244 TheRemark.
Loc = *MaybeLoc;
246 return MaybeLoc.takeError();
247 }
else if (KeyName ==
"Args") {
248 auto *Args = dyn_cast<yaml::SequenceNode>(RemarkField.getValue());
250 return error(
"wrong value type for key.", RemarkField);
254 TheRemark.
Args.push_back(*MaybeArg);
256 return MaybeArg.takeError();
259 return error(
"unknown key.", RemarkField);
266 return error(
"Type, Pass, Name or Function missing.",
269 return std::move(Result);
282 return error(
"expected a remark tag.", Node);
287 if (
auto *Key = dyn_cast<yaml::ScalarNode>(Node.getKey()))
288 return Key->getRawValue();
290 return error(
"key is not a string.", Node);
294 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
296 return error(
"expected a value of scalar type.", Node);
299 if (Result.front() ==
'\'')
300 Result = Result.drop_front();
302 if (Result.back() ==
'\'')
303 Result = Result.drop_back();
310 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
312 return error(
"expected a value of scalar type.", Node);
313 unsigned UnsignedValue = 0;
314 if (
Value->getValue(Tmp).getAsInteger(10, UnsignedValue))
315 return error(
"expected a value of integer type.", *
Value);
316 return UnsignedValue;
321 auto *
DebugLoc = dyn_cast<yaml::MappingNode>(Node.getValue());
323 return error(
"expected a value of mapping type.", Node);
325 std::optional<StringRef> File;
326 std::optional<unsigned> Line;
327 std::optional<unsigned> Column;
335 if (KeyName ==
"File") {
339 return MaybeStr.takeError();
340 }
else if (KeyName ==
"Column") {
344 return MaybeU.takeError();
345 }
else if (KeyName ==
"Line") {
349 return MaybeU.takeError();
351 return error(
"unknown entry in DebugLoc map.", DLNode);
356 if (!File || !Line || !Column)
357 return error(
"DebugLoc node incomplete.", Node);
363 auto *ArgMap = dyn_cast<yaml::MappingNode>(&Node);
365 return error(
"expected a value of mapping type.", Node);
367 std::optional<StringRef> KeyStr;
368 std::optional<StringRef> ValueStr;
369 std::optional<RemarkLocation> Loc;
378 if (KeyName ==
"DebugLoc") {
381 return error(
"only one DebugLoc entry is allowed per argument.",
388 return MaybeLoc.takeError();
393 return error(
"only one string entry is allowed per argument.", ArgEntry);
397 ValueStr = *MaybeStr;
399 return MaybeStr.takeError();
406 return error(
"argument key is missing.", *ArgMap);
408 return error(
"argument value is missing.", *ArgMap);
410 return Argument{*KeyStr, *ValueStr, Loc};
415 return make_error<EndOfFileError>();
426 return std::move(*MaybeResult);
430 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
432 return error(
"expected a value of scalar type.", Node);
439 return MaybeStrID.takeError();
444 return Str.takeError();
446 if (Result.front() ==
'\'')
447 Result = Result.drop_front();
449 if (Result.back() ==
'\'')
450 Result = Result.drop_back();
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Version parseVersion(StringRef Name)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
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,...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
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.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
void * getDiagContext() const
DiagHandlerTy getDiagHandler() const
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
bool startswith(StringRef Prefix) const
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
A raw_ostream that writes to an std::string.
A YAML Stream is a sequence of Documents.
Node * getRoot()
Parse and return the root level node.
Represents a YAML map created from either a block map for a flow map.
Abstract base class for all Nodes.
This class represents a YAML stream potentially containing multiple documents.
void printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind=SourceMgr::DK_Error)
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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.