LLVM  10.0.0svn
RemarkParser.h
Go to the documentation of this file.
1 //===-- llvm/Remarks/Remark.h - The remark type -----------------*- 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 an interface for parsing remarks in LLVM.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_REMARKS_REMARK_PARSER_H
14 #define LLVM_REMARKS_REMARK_PARSER_H
15 
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Remarks/Remark.h"
20 #include "llvm/Support/Error.h"
21 #include <memory>
22 
23 namespace llvm {
24 namespace remarks {
25 
26 class EndOfFileError : public ErrorInfo<EndOfFileError> {
27 public:
28  static char ID;
29 
31 
32  void log(raw_ostream &OS) const override { OS << "End of file reached."; }
33  std::error_code convertToErrorCode() const override {
34  return inconvertibleErrorCode();
35  }
36 };
37 
38 /// Parser used to parse a raw buffer to remarks::Remark objects.
39 struct RemarkParser {
40  /// The format of the parser.
42  /// Path to prepend when opening an external remark file.
44 
45  RemarkParser(Format ParserFormat) : ParserFormat(ParserFormat) {}
46 
47  /// If no error occurs, this returns a valid Remark object.
48  /// If an error of type EndOfFileError occurs, it is safe to recover from it
49  /// by stopping the parsing.
50  /// If any other error occurs, it should be propagated to the user.
51  /// The pointer should never be null.
52  virtual Expected<std::unique_ptr<Remark>> next() = 0;
53 
54  virtual ~RemarkParser() = default;
55 };
56 
57 /// In-memory representation of the string table parsed from a buffer (e.g. the
58 /// remarks section).
60  /// The buffer mapped from the section contents.
62  /// This object has high changes to be std::move'd around, so don't use a
63  /// SmallVector for once.
64  std::vector<size_t> Offsets;
65 
67  /// Disable copy.
68  ParsedStringTable(const ParsedStringTable &) = delete;
69  ParsedStringTable &operator=(const ParsedStringTable &) = delete;
70  /// Should be movable.
72  ParsedStringTable &operator=(ParsedStringTable &&) = default;
73 
74  size_t size() const { return Offsets.size(); }
75  Expected<StringRef> operator[](size_t Index) const;
76 };
77 
79  StringRef Buf);
80 
82 createRemarkParser(Format ParserFormat, StringRef Buf,
83  ParsedStringTable StrTab);
84 
88  Optional<StringRef> ExternalFilePrependPath = None);
89 
90 } // end namespace remarks
91 } // end namespace llvm
92 
93 #endif /* LLVM_REMARKS_REMARK_PARSER_H */
std::vector< size_t > Offsets
This object has high changes to be std::move&#39;d around, so don&#39;t use a SmallVector for once...
Definition: RemarkParser.h:64
const NoneType None
Definition: None.h:23
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Expected< std::unique_ptr< RemarkParser > > createRemarkParser(Format ParserFormat, StringRef Buf)
std::string ExternalFilePrependPath
Path to prepend when opening an external remark file.
Definition: RemarkParser.h:43
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: RemarkParser.h:33
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
In-memory representation of the string table parsed from a buffer (e.g.
Definition: RemarkParser.h:59
StringRef Buffer
The buffer mapped from the section contents.
Definition: RemarkParser.h:61
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: RemarkParser.h:32
Expected< std::unique_ptr< RemarkParser > > createRemarkParserFromMeta(Format ParserFormat, StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Base class for user error types.
Definition: Error.h:344
Format ParserFormat
The format of the parser.
Definition: RemarkParser.h:41
RemarkParser(Format ParserFormat)
Definition: RemarkParser.h:45
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:39
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77