LLVM: lib/Remarks/YAMLRemarkParser.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
19#include
20
21using namespace llvm;
23
25
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.");
31 Diag.print(nullptr, OS, false,
32 true);
33 OS << '\n';
35}
36
39
40
41
42
43
44
45
50
52}
53
59
60
61
64 return false;
65
68 "Expecting \\0 after magic number.");
69 return true;
70}
71
75 "Expecting version number.");
76
81 "Mismatching remark version. Got %" PRId64
82 ", expected %" PRId64 ".",
85 return Version;
86}
87
91 "Expecting string table size.");
95 return StrTabSize;
96}
97
99 StringRef Buf, std::optional ExternalFilePrependPath) {
100
102 if (!isMeta)
104
105 std::unique_ptr SeparateBuf;
106 if (*isMeta) {
109 return Version.takeError();
110
112 if (!StrTabSize)
114
115 if (*StrTabSize != 0) {
117 "String table unsupported for YAML format.");
118 }
119
121
122 StringRef ExternalFilePath = Buf;
124 if (ExternalFilePrependPath)
125 FullPath = *ExternalFilePrependPath;
127
128
131 if (std::error_code EC = BufferOrErr.getError())
133
134
135 SeparateBuf = std::move(*BufferOrErr);
136 Buf = SeparateBuf->getBuffer();
137 }
138 }
139
140 std::unique_ptr Result =
141 std::make_unique(Buf);
142 if (SeparateBuf)
143 Result->SeparateBuf = std::move(SeparateBuf);
144 return std::move(Result);
145}
146
150
154
162
166 return std::move(E);
167
169 if (!YAMLRoot) {
170 return createStringError(std::make_error_code(std::errc::invalid_argument),
171 "not a valid YAML file.");
172 }
173
175 if (!Root)
176 return error("document root is not of mapping type.", *YAMLRoot);
177
178 std::unique_ptr Result = std::make_unique();
179 Remark &TheRemark = *Result;
180
181
182
184 if ()
185 return T.takeError();
186
188
189
192 if (!MaybeKey)
195
196 if (KeyName == "Pass") {
198 TheRemark.PassName = *MaybeStr;
199 else
200 return MaybeStr.takeError();
201 } else if (KeyName == "Name") {
204 else
205 return MaybeStr.takeError();
206 } else if (KeyName == "Function") {
209 else
210 return MaybeStr.takeError();
211 } else if (KeyName == "Hotness") {
213 TheRemark.Hotness = *MaybeU;
214 else
215 return MaybeU.takeError();
216 } else if (KeyName == "DebugLoc") {
218 TheRemark.Loc = *MaybeLoc;
219 else
220 return MaybeLoc.takeError();
221 } else if (KeyName == "Args") {
223 if (!Args)
224 return error("wrong value type for key.", RemarkField);
225
228 TheRemark.Args.push_back(*MaybeArg);
229 else
230 return MaybeArg.takeError();
231 }
232 } else {
233 return error("unknown key.", RemarkField);
234 }
235 }
236
237
240 return error("Type, Pass, Name or Function missing.",
242
243 return std::move(Result);
244}
245
256 return error("expected a remark tag.", Node);
258}
259
262 return Key->getRawValue();
263
264 return error("key is not a string.", Node);
265}
266
272
274 if (!ValueBlock)
275 return error("expected a value of scalar type.", Node);
276 Result = ValueBlock->getValue();
277 } else
278 Result = Value->getRawValue();
279
280 Result.consume_front("\'");
281 Result.consume_back("\'");
282
283 return Result;
284}
285
290 return error("expected a value of scalar type.", Node);
291 unsigned UnsignedValue = 0;
292 if (Value->getValue(Tmp).getAsInteger(10, UnsignedValue))
293 return error("expected a value of integer type.", *Value);
294 return UnsignedValue;
295}
296
301 return error("expected a value of mapping type.", Node);
302
303 std::optional File;
304 std::optional Line;
305 std::optional Column;
306
309 if (!MaybeKey)
312
313 if (KeyName == "File") {
315 File = *MaybeStr;
316 else
317 return MaybeStr.takeError();
318 } else if (KeyName == "Column") {
320 Column = *MaybeU;
321 else
322 return MaybeU.takeError();
323 } else if (KeyName == "Line") {
325 Line = *MaybeU;
326 else
327 return MaybeU.takeError();
328 } else {
329 return error("unknown entry in DebugLoc map.", DLNode);
330 }
331 }
332
333
334 if (!File || !Line || !Column)
335 return error("DebugLoc node incomplete.", Node);
336
338}
339
342 if (!ArgMap)
343 return error("expected a value of mapping type.", Node);
344
345 std::optional KeyStr;
346 std::optional ValueStr;
347 std::optional Loc;
348
351 if (!MaybeKey)
354
355
356 if (KeyName == "DebugLoc") {
357
359 return error("only one DebugLoc entry is allowed per argument.",
360 ArgEntry);
361
363 Loc = *MaybeLoc;
364 continue;
365 } else
366 return MaybeLoc.takeError();
367 }
368
369
370 if (ValueStr)
371 return error("only one string entry is allowed per argument.", ArgEntry);
372
373
375 ValueStr = *MaybeStr;
376 else
377 return MaybeStr.takeError();
378
379
380 KeyStr = KeyName;
381 }
382
383 if (!KeyStr)
384 return error("argument key is missing.", *ArgMap);
385 if (!ValueStr)
386 return error("argument value is missing.", *ArgMap);
387
389 Arg.Key = *KeyStr;
390 Arg.Val = *ValueStr;
392 return Arg;
393}
394
398
400 if (!MaybeResult) {
401
404 }
405
407
408 return std::move(*MaybeResult);
409}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Version parseVersion(StringRef Name)
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...
LLVM_ABI 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.
LLVM_ABI void printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind=SourceMgr::DK_Error)
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
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.