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_REMARKPARSER_H |
14 | #define |
15 | |
16 | #include "llvm/ADT/StringRef.h" |
17 | #include "llvm/Remarks/RemarkFormat.h" |
18 | #include "llvm/Support/Error.h" |
19 | #include <memory> |
20 | #include <optional> |
21 | |
22 | namespace llvm { |
23 | namespace remarks { |
24 | |
25 | struct ; |
26 | |
27 | class : public ErrorInfo<EndOfFileError> { |
28 | public: |
29 | static char ; |
30 | |
31 | () = default; |
32 | |
33 | void (raw_ostream &OS) const override { OS << "End of file reached." ; } |
34 | std::error_code () const override { |
35 | return inconvertibleErrorCode(); |
36 | } |
37 | }; |
38 | |
39 | /// Parser used to parse a raw buffer to remarks::Remark objects. |
40 | struct { |
41 | /// The format of the parser. |
42 | Format ; |
43 | /// Path to prepend when opening an external remark file. |
44 | std::string ; |
45 | |
46 | (Format ParserFormat) : ParserFormat(ParserFormat) {} |
47 | |
48 | /// If no error occurs, this returns a valid Remark object. |
49 | /// If an error of type EndOfFileError occurs, it is safe to recover from it |
50 | /// by stopping the parsing. |
51 | /// If any other error occurs, it should be propagated to the user. |
52 | /// The pointer should never be null. |
53 | virtual Expected<std::unique_ptr<Remark>> () = 0; |
54 | |
55 | virtual () = default; |
56 | }; |
57 | |
58 | /// In-memory representation of the string table parsed from a buffer (e.g. the |
59 | /// remarks section). |
60 | struct { |
61 | /// The buffer mapped from the section contents. |
62 | StringRef ; |
63 | /// This object has high changes to be std::move'd around, so don't use a |
64 | /// SmallVector for once. |
65 | std::vector<size_t> ; |
66 | |
67 | (StringRef Buffer); |
68 | /// Disable copy. |
69 | (const ParsedStringTable &) = delete; |
70 | ParsedStringTable &(const ParsedStringTable &) = delete; |
71 | /// Should be movable. |
72 | (ParsedStringTable &&) = default; |
73 | ParsedStringTable &(ParsedStringTable &&) = default; |
74 | |
75 | size_t () const { return Offsets.size(); } |
76 | Expected<StringRef> (size_t Index) const; |
77 | }; |
78 | |
79 | Expected<std::unique_ptr<RemarkParser>> (Format ParserFormat, |
80 | StringRef Buf); |
81 | |
82 | Expected<std::unique_ptr<RemarkParser>> |
83 | (Format ParserFormat, StringRef Buf, |
84 | ParsedStringTable StrTab); |
85 | |
86 | Expected<std::unique_ptr<RemarkParser>> ( |
87 | Format ParserFormat, StringRef Buf, |
88 | std::optional<ParsedStringTable> StrTab = std::nullopt, |
89 | std::optional<StringRef> ExternalFilePrependPath = std::nullopt); |
90 | |
91 | } // end namespace remarks |
92 | } // end namespace llvm |
93 | |
94 | #endif // LLVM_REMARKS_REMARKPARSER_H |
95 | |