27 assert(Ctx &&
"Expected non-null Ctx in diagnostic handler.");
28 std::string &Message = *
static_cast<std::string *
>(Ctx);
29 assert(Message.empty() &&
"Expected an empty string.");
68 "Expecting \\0 after magic number.");
75 "Expecting version number.");
78 support::endian::read<uint64_t, llvm::endianness::little>(Buf.
data());
81 "Mismatching remark version. Got %" PRId64
82 ", expected %" PRId64
".",
91 "Expecting string table size.");
93 support::endian::read<uint64_t, llvm::endianness::little>(Buf.
data());
100 if (Buf.
size() < StrTabSize)
102 "Expecting string table.");
111 StringRef Buf, std::optional<ParsedStringTable> StrTab,
112 std::optional<StringRef> ExternalFilePrependPath) {
118 std::unique_ptr<MemoryBuffer> SeparateBuf;
129 if (*StrTabSize != 0) {
132 "String table already provided.");
136 StrTab = std::move(*MaybeStrTab);
143 if (ExternalFilePrependPath)
144 FullPath = *ExternalFilePrependPath;
150 if (std::error_code EC = BufferOrErr.
getError())
154 SeparateBuf = std::move(*BufferOrErr);
155 Buf = SeparateBuf->getBuffer();
159 std::unique_ptr<YAMLRemarkParser> Result =
161 ? std::make_unique<YAMLStrTabRemarkParser>(Buf, std::move(*StrTab))
162 : std::make_unique<YAMLRemarkParser>(Buf);
164 Result->SeparateBuf = std::move(SeparateBuf);
165 return std::move(Result);
172 std::optional<ParsedStringTable> StrTab)
174 SM(
setupSM(LastErrorMessage)), Stream(Buf, SM), YAMLIt(Stream.begin()) {}
177 return make_error<YAMLParseError>(Message,
SM,
Stream, Node);
196 "not a valid YAML file.");
199 auto *Root = dyn_cast<yaml::MappingNode>(YAMLRoot);
201 return error(
"document root is not of mapping type.", *YAMLRoot);
203 std::unique_ptr<Remark> Result = std::make_unique<Remark>();
204 Remark &TheRemark = *Result;
210 return T.takeError();
221 if (KeyName ==
"Pass") {
225 return MaybeStr.takeError();
226 }
else if (KeyName ==
"Name") {
230 return MaybeStr.takeError();
231 }
else if (KeyName ==
"Function") {
235 return MaybeStr.takeError();
236 }
else if (KeyName ==
"Hotness") {
240 return MaybeU.takeError();
241 }
else if (KeyName ==
"DebugLoc") {
243 TheRemark.
Loc = *MaybeLoc;
245 return MaybeLoc.takeError();
246 }
else if (KeyName ==
"Args") {
247 auto *Args = dyn_cast<yaml::SequenceNode>(RemarkField.getValue());
249 return error(
"wrong value type for key.", RemarkField);
253 TheRemark.
Args.push_back(*MaybeArg);
255 return MaybeArg.takeError();
258 return error(
"unknown key.", RemarkField);
265 return error(
"Type, Pass, Name or Function missing.",
268 return std::move(Result);
281 return error(
"expected a remark tag.", Node);
286 if (
auto *Key = dyn_cast<yaml::ScalarNode>(Node.getKey()))
287 return Key->getRawValue();
289 return error(
"key is not a string.", Node);
293 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
298 ValueBlock = dyn_cast<yaml::BlockScalarNode>(Node.getValue());
300 return error(
"expected a value of scalar type.", Node);
303 Result =
Value->getRawValue();
305 Result.consume_front(
"\'");
306 Result.consume_back(
"\'");
313 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
315 return error(
"expected a value of scalar type.", Node);
316 unsigned UnsignedValue = 0;
317 if (
Value->getValue(Tmp).getAsInteger(10, UnsignedValue))
318 return error(
"expected a value of integer type.", *
Value);
319 return UnsignedValue;
324 auto *
DebugLoc = dyn_cast<yaml::MappingNode>(Node.getValue());
326 return error(
"expected a value of mapping type.", Node);
328 std::optional<StringRef> File;
329 std::optional<unsigned> Line;
330 std::optional<unsigned> Column;
338 if (KeyName ==
"File") {
342 return MaybeStr.takeError();
343 }
else if (KeyName ==
"Column") {
347 return MaybeU.takeError();
348 }
else if (KeyName ==
"Line") {
352 return MaybeU.takeError();
354 return error(
"unknown entry in DebugLoc map.", DLNode);
359 if (!File || !Line || !Column)
360 return error(
"DebugLoc node incomplete.", Node);
366 auto *ArgMap = dyn_cast<yaml::MappingNode>(&Node);
368 return error(
"expected a value of mapping type.", Node);
370 std::optional<StringRef> KeyStr;
371 std::optional<StringRef> ValueStr;
372 std::optional<RemarkLocation> Loc;
381 if (KeyName ==
"DebugLoc") {
384 return error(
"only one DebugLoc entry is allowed per argument.",
391 return MaybeLoc.takeError();
396 return error(
"only one string entry is allowed per argument.", ArgEntry);
400 ValueStr = *MaybeStr;
402 return MaybeStr.takeError();
409 return error(
"argument key is missing.", *ArgMap);
411 return error(
"argument value is missing.", *ArgMap);
413 return Argument{*KeyStr, *ValueStr, Loc};
418 return make_error<EndOfFileError>();
429 return std::move(*MaybeResult);
433 auto *
Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
438 ValueBlock = dyn_cast<yaml::BlockScalarNode>(Node.getValue());
440 return error(
"expected a value of scalar type.", Node);
443 Result =
Value->getRawValue();
449 return MaybeStrID.takeError();
454 return Str.takeError();
456 Result.consume_front(
"\'");
457 Result.consume_back(
"\'");
static Version parseVersion(StringRef Name)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
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, bool ShowLocation=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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
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 block scalar node is an opaque datum that can be presented as a series of zero or more Unicode scal...
StringRef getValue() const
Gets the value of this node as a StringRef.
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.
Implement std::hash so that hash_code can be used in STL containers.