29 std::string ErrorString;
55 ~ParseState() { Args->
clear(); }
61 bool HadAnyErrors =
false;
64 : SM(), Stream(Buf, SM), ErrorString(), ErrorStream(ErrorString),
65 DI(Stream.
begin()), LastRemark(), TmpArgs(), State(TmpArgs) {
88 static void HandleDiagnostic(
const SMDiagnostic &Diag,
void *Ctx) {
89 assert(Ctx &&
"Expected non-null Ctx in diagnostic handler.");
90 auto *Parser =
static_cast<RemarkParser *
>(Ctx);
91 Diag.
print(
nullptr, Parser->ErrorStream,
false,
96 class ParseError :
public ErrorInfo<ParseError> {
101 : Message(Message), Node(Node) {}
104 std::error_code convertToErrorCode()
const override {
108 StringRef getMessage()
const {
return Message; }
125 return make_error<ParseError>(
"key is not a string.", Node);
127 Result =
Key->getRawValue();
134 return make_error<ParseError>(
"expected a value of scalar type.", Node);
135 Result =
Value->getRawValue();
137 if (Result.front() ==
'\'')
138 Result = Result.drop_front();
140 if (Result.back() ==
'\'')
141 Result = Result.drop_back();
151 return make_error<ParseError>(
"expected a value of scalar type.", Node);
152 unsigned UnsignedValue = 0;
153 if (
Value->getValue(Tmp).getAsInteger(10, UnsignedValue))
154 return make_error<ParseError>(
"expected a value of integer type.", *
Value);
155 Result = UnsignedValue;
165 return make_error<ParseError>(
"expected a value of mapping type.", Node);
169 if (
Error E = parseKey(KeyName, DLNode))
171 if (KeyName ==
"File") {
174 if (
Error E = parseValue(*File, DLNode))
176 }
else if (KeyName ==
"Column") {
177 if (
Error E = parseValue(Column, DLNode))
179 }
else if (KeyName ==
"Line") {
180 if (
Error E = parseValue(Line, DLNode))
183 return make_error<ParseError>(
"unknown entry in DebugLoc map.", DLNode);
188 if (!File || !Line || !Column)
189 return make_error<ParseError>(
"DebugLoc node incomplete.", Node);
198 return make_error<ParseError>(
"expected a value of mapping type.", Node);
208 if (
Error E = parseKey(KeyName, ArgEntry))
212 if (KeyName ==
"DebugLoc") {
214 if (File || Line || Column)
215 return make_error<ParseError>(
216 "only one DebugLoc entry is allowed per argument.", ArgEntry);
218 if (
Error E = parseDebugLoc(File, Line, Column, ArgEntry))
224 if (!ValueStr.empty())
225 return make_error<ParseError>(
226 "only one string entry is allowed per argument.", ArgEntry);
229 if (
Error E = parseValue(ValueStr, ArgEntry))
237 return make_error<ParseError>(
"argument key is missing.", *ArgMap);
238 if (ValueStr.empty())
239 return make_error<ParseError>(
"argument value is missing.", *ArgMap);
242 toOptRemarkStr(KeyStr), toOptRemarkStr(ValueStr),
252 State = ParseState(TmpArgs);
256 return make_error<ParseError>(
"document root is not of mapping type.",
259 State.Type = Root->getRawTag();
263 if (
Error E = parseKey(KeyName, RemarkField))
266 if (KeyName ==
"Pass") {
267 if (
Error E = parseValue(State.Pass, RemarkField))
269 }
else if (KeyName ==
"Name") {
270 if (
Error E = parseValue(State.Name, RemarkField))
272 }
else if (KeyName ==
"Function") {
273 if (
Error E = parseValue(State.Function, RemarkField))
275 }
else if (KeyName ==
"Hotness") {
276 if (
Error E = parseValue(State.Hotness, RemarkField))
278 }
else if (KeyName ==
"DebugLoc") {
280 parseDebugLoc(State.File, State.Line, State.Column, RemarkField))
282 }
else if (KeyName ==
"Args") {
285 return make_error<ParseError>(
"wrong value type for key.", RemarkField);
288 if (
Error E = parseArg(*State.Args,
Arg))
291 return make_error<ParseError>(
"unknown key.", RemarkField);
298 return make_error<ParseError>(
"YAML parsing failed.", *Remark.
getRoot());
301 if (State.Type.empty() || State.Pass.empty() || State.Name.empty() ||
302 State.Function.empty())
303 return make_error<ParseError>(
"Type, Pass, Name or Function missing.",
307 toOptRemarkStr(State.Type),
308 toOptRemarkStr(State.Pass),
309 toOptRemarkStr(State.Name),
310 toOptRemarkStr(State.Function),
312 State.Line.getValueOr(0),
313 State.Column.getValueOr(0)},
314 State.Hotness.getValueOr(0),
315 static_cast<uint32_t>(State.Args->size()),
328 new RemarkParser(
StringRef(static_cast<const char *>(Buf), Size)));
333 RemarkParser &TheParser = *
unwrap(Parser);
335 if (TheParser.HadAnyErrors || TheParser.DI == TheParser.Stream.end())
339 if (
Error E = TheParser.parseYAMLElement(*TheParser.DI)) {
341 TheParser.Stream.printError(&PE.getNode(),
343 TheParser.HadAnyErrors =
true;
358 return unwrap(Parser)->HadAnyErrors;
361 extern "C" const char *
363 return unwrap(Parser)->ErrorStream.str().c_str();
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
void push_back(const T &Elt)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Represents a YAML sequence created from either a block sequence for a flow sequence.
Node * getKey()
Parse and return the key.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
amdgpu Simplify well known AMD library false Value Value const Twine & Name
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Attribute unwrap(LLVMAttributeRef Attr)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Node * getRoot()
Parse and return the root level node.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
The instances of the Type class are immutable: once they are created, they are never changed...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
A scalar node is an opaque datum that can be presented as a series of zero or more Unicode scalar val...
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
print lazy value Lazy Value Info Printer Pass
static ErrorSuccess success()
Create a success value.
Node * getValue()
Parse and return the value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This class represents a YAML stream potentially containing multiple documents.
Base class for user error types.
amdgpu Simplify well known AMD library false Value Value * Arg
LLVMAttributeRef wrap(Attribute Attr)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Represents a YAML map created from either a block map for a flow map.
Iterator abstraction for Documents over a Stream.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
A YAML Stream is a sequence of Documents.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Abstract base class for all Nodes.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...