LLVM  14.0.0git
YAMLRemarkParser.h
Go to the documentation of this file.
1 //===-- YAMLRemarkParser.h - Parser for YAML remarks ------------*- C++/-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the impementation of the YAML remark parser.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
14 #define LLVM_REMARKS_YAML_REMARK_PARSER_H
15 
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Remarks/Remark.h"
20 #include "llvm/Support/Error.h"
22 #include "llvm/Support/SourceMgr.h"
26 #include <string>
27 
28 namespace llvm {
29 namespace remarks {
30 
31 class YAMLParseError : public ErrorInfo<YAMLParseError> {
32 public:
33  static char ID;
34 
35  YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream,
36  yaml::Node &Node);
37 
38  YAMLParseError(StringRef Message) : Message(std::string(Message)) {}
39 
40  void log(raw_ostream &OS) const override { OS << Message; }
41  std::error_code convertToErrorCode() const override {
42  return inconvertibleErrorCode();
43  }
44 
45 private:
46  std::string Message;
47 };
48 
49 /// Regular YAML to Remark parser.
50 struct YAMLRemarkParser : public RemarkParser {
51  /// The string table used for parsing strings.
53  /// Last error message that can come from the YAML parser diagnostics.
54  /// We need this for catching errors in the constructor.
55  std::string LastErrorMessage;
56  /// Source manager for better error messages.
58  /// Stream for yaml parsing.
60  /// Iterator in the YAML stream.
62  /// If we parse remark metadata in separate mode, we need to open a new file
63  /// and parse that.
64  std::unique_ptr<MemoryBuffer> SeparateBuf;
65 
67 
69 
70  static bool classof(const RemarkParser *P) {
71  return P->ParserFormat == Format::YAML;
72  }
73 
74 protected:
76  /// Create a YAMLParseError error from an existing error generated by the YAML
77  /// parser.
78  /// If there is no error, this returns Success.
79  Error error();
80  /// Create a YAMLParseError error referencing a specific node.
81  Error error(StringRef Message, yaml::Node &Node);
82  /// Parse a YAML remark to a remarks::Remark object.
84  /// Parse the type of a remark to an enum type.
86  /// Parse one key to a string.
88  /// Parse one value to a string.
90  /// Parse one value to an unsigned.
92  /// Parse a debug location.
94  /// Parse an argument.
96 };
97 
98 /// YAML with a string table to Remark parser.
101  : YAMLRemarkParser(Buf, std::move(StrTab)) {}
102 
103  static bool classof(const RemarkParser *P) {
104  return P->ParserFormat == Format::YAMLStrTab;
105  }
106 
107 protected:
108  /// Parse one value to a string.
110 };
111 
114  Optional<ParsedStringTable> StrTab = None,
115  Optional<StringRef> ExternalFilePrependPath = None);
116 
117 } // end namespace remarks
118 } // end namespace llvm
119 
120 #endif /* LLVM_REMARKS_YAML_REMARK_PARSER_H */
MemoryBuffer.h
llvm::yaml::Document
A YAML Stream is a sequence of Documents.
Definition: YAMLParser.h:531
llvm::remarks::YAMLRemarkParser::classof
static bool classof(const RemarkParser *P)
Definition: YAMLRemarkParser.h:70
llvm::remarks::YAMLRemarkParser::parseDebugLoc
Expected< RemarkLocation > parseDebugLoc(yaml::KeyValueNode &Node)
Parse a debug location.
Definition: YAMLRemarkParser.cpp:320
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::remarks::YAMLRemarkParser
Regular YAML to Remark parser.
Definition: YAMLRemarkParser.h:50
Optional.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::remarks::YAMLStrTabRemarkParser
YAML with a string table to Remark parser.
Definition: YAMLRemarkParser.h:99
llvm::yaml::Node
Abstract base class for all Nodes.
Definition: YAMLParser.h:119
YAMLParser.h
llvm::remarks::YAMLRemarkParser::parseRemark
Expected< std::unique_ptr< Remark > > parseRemark(yaml::Document &Remark)
Parse a YAML remark to a remarks::Remark object.
Definition: YAMLRemarkParser.cpp:190
RemarkParser.h
Error.h
llvm::remarks::YAMLRemarkParser::parseUnsigned
Expected< unsigned > parseUnsigned(yaml::KeyValueNode &Node)
Parse one value to an unsigned.
Definition: YAMLRemarkParser.cpp:308
llvm::Optional
Definition: APInt.h:33
llvm::yaml::MappingNode
Represents a YAML map created from either a block map for a flow map.
Definition: YAMLParser.h:414
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::remarks::YAMLRemarkParser::parseType
Expected< Type > parseType(yaml::MappingNode &Node)
Parse the type of a remark to an enum type.
Definition: YAMLRemarkParser.cpp:272
llvm::remarks::YAMLRemarkParser::YAMLIt
yaml::document_iterator YAMLIt
Iterator in the YAML stream.
Definition: YAMLRemarkParser.h:61
llvm::remarks::YAMLParseError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: YAMLRemarkParser.h:40
llvm::remarks::YAMLParseError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: YAMLRemarkParser.h:41
llvm::remarks::YAMLRemarkParser::StrTab
Optional< ParsedStringTable > StrTab
The string table used for parsing strings.
Definition: YAMLRemarkParser.h:52
llvm::remarks::YAMLParseError::YAMLParseError
YAMLParseError(StringRef Message)
Definition: YAMLRemarkParser.h:38
Remark.h
remarks
annotation remarks
Definition: AnnotationRemarks.cpp:117
llvm::remarks::YAMLRemarkParser::parseArg
Expected< Argument > parseArg(yaml::Node &Node)
Parse an argument.
Definition: YAMLRemarkParser.cpp:362
llvm::remarks::YAMLRemarkParser::error
Error error()
Create a YAMLParseError error from an existing error generated by the YAML parser.
Definition: YAMLRemarkParser.cpp:181
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::remarks::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::remarks::YAMLRemarkParser::SeparateBuf
std::unique_ptr< MemoryBuffer > SeparateBuf
If we parse remark metadata in separate mode, we need to open a new file and parse that.
Definition: YAMLRemarkParser.h:64
SourceMgr.h
llvm::remarks::YAMLRemarkParser::parseKey
Expected< StringRef > parseKey(yaml::KeyValueNode &Node)
Parse one key to a string.
Definition: YAMLRemarkParser.cpp:286
llvm::remarks::YAMLRemarkParser::LastErrorMessage
std::string LastErrorMessage
Last error message that can come from the YAML parser diagnostics.
Definition: YAMLRemarkParser.h:55
llvm::remarks::YAMLRemarkParser::next
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
Definition: YAMLRemarkParser.cpp:413
llvm::remarks::Format::YAML
@ YAML
llvm::remarks::Format::YAMLStrTab
@ YAMLStrTab
llvm::remarks::YAMLRemarkParser::YAMLRemarkParser
YAMLRemarkParser(StringRef Buf)
Definition: YAMLRemarkParser.cpp:169
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::remarks::createYAMLParserFromMeta
Expected< std::unique_ptr< YAMLRemarkParser > > createYAMLParserFromMeta(StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Definition: YAMLRemarkParser.cpp:111
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:349
YAMLTraits.h
llvm::remarks::ParsedStringTable
In-memory representation of the string table parsed from a buffer (e.g.
Definition: RemarkParser.h:59
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
llvm::yaml::KeyValueNode
A key and value pair.
Definition: YAMLParser.h:285
llvm::yaml::Stream
This class represents a YAML stream potentially containing multiple documents.
Definition: YAMLParser.h:86
llvm::remarks::YAMLRemarkParser::Stream
yaml::Stream Stream
Stream for yaml parsing.
Definition: YAMLRemarkParser.h:59
Node
Definition: ItaniumDemangle.h:235
llvm::remarks::YAMLParseError::ID
static char ID
Definition: YAMLRemarkParser.h:33
llvm::remarks::RemarkParser
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:39
llvm::remarks::YAMLStrTabRemarkParser::classof
static bool classof(const RemarkParser *P)
Definition: YAMLRemarkParser.h:103
llvm::remarks::YAMLStrTabRemarkParser::parseStr
Expected< StringRef > parseStr(yaml::KeyValueNode &Node) override
Parse one value to a string.
Definition: YAMLRemarkParser.cpp:429
std
Definition: BitVector.h:838
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::remarks::YAMLStrTabRemarkParser::YAMLStrTabRemarkParser
YAMLStrTabRemarkParser(StringRef Buf, ParsedStringTable StrTab)
Definition: YAMLRemarkParser.h:100
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::remarks::YAMLRemarkParser::SM
SourceMgr SM
Source manager for better error messages.
Definition: YAMLRemarkParser.h:57
SmallVector.h
llvm::yaml::document_iterator
Iterator abstraction for Documents over a Stream.
Definition: YAMLParser.h:588
llvm::remarks::YAMLParseError::YAMLParseError
YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream, yaml::Node &Node)
Definition: YAMLRemarkParser.cpp:35
raw_ostream.h
llvm::remarks::YAMLRemarkParser::parseStr
virtual Expected< StringRef > parseStr(yaml::KeyValueNode &Node)
Parse one value to a string.
Definition: YAMLRemarkParser.cpp:293
llvm::remarks::YAMLParseError
Definition: YAMLRemarkParser.h:31
SpecialSubKind::string
@ string