[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / Remarks / RemarkParser.h
blob551d20a8a0a9f6a03ae397937941836f9c0807d5
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_REMARKS_REMARK_PARSER_H
14 #define LLVM_REMARKS_REMARK_PARSER_H
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Remarks/Remark.h"
19 #include "llvm/Remarks/RemarkFormat.h"
20 #include "llvm/Support/Error.h"
21 #include <memory>
23 namespace llvm {
24 namespace remarks {
26 class EndOfFileError : public ErrorInfo<EndOfFileError> {
27 public:
28 static char ID;
30 EndOfFileError() {}
32 void log(raw_ostream &OS) const override { OS << "End of file reached."; }
33 std::error_code convertToErrorCode() const override {
34 return inconvertibleErrorCode();
38 /// Parser used to parse a raw buffer to remarks::Remark objects.
39 struct RemarkParser {
40 /// The format of the parser.
41 Format ParserFormat;
43 RemarkParser(Format ParserFormat) : ParserFormat(ParserFormat) {}
45 /// If no error occurs, this returns a valid Remark object.
46 /// If an error of type EndOfFileError occurs, it is safe to recover from it
47 /// by stopping the parsing.
48 /// If any other error occurs, it should be propagated to the user.
49 /// The pointer should never be null.
50 virtual Expected<std::unique_ptr<Remark>> next() = 0;
52 virtual ~RemarkParser() = default;
55 /// In-memory representation of the string table parsed from a buffer (e.g. the
56 /// remarks section).
57 struct ParsedStringTable {
58 /// The buffer mapped from the section contents.
59 StringRef Buffer;
60 /// This object has high changes to be std::move'd around, so don't use a
61 /// SmallVector for once.
62 std::vector<size_t> Offsets;
64 ParsedStringTable(StringRef Buffer);
65 /// Disable copy.
66 ParsedStringTable(const ParsedStringTable &) = delete;
67 ParsedStringTable &operator=(const ParsedStringTable &) = delete;
68 /// Should be movable.
69 ParsedStringTable(ParsedStringTable &&) = default;
70 ParsedStringTable &operator=(ParsedStringTable &&) = default;
72 size_t size() const { return Offsets.size(); }
73 Expected<StringRef> operator[](size_t Index) const;
76 Expected<std::unique_ptr<RemarkParser>> createRemarkParser(Format ParserFormat,
77 StringRef Buf);
79 Expected<std::unique_ptr<RemarkParser>>
80 createRemarkParser(Format ParserFormat, StringRef Buf,
81 ParsedStringTable StrTab);
83 Expected<std::unique_ptr<RemarkParser>>
84 createRemarkParserFromMeta(Format ParserFormat, StringRef Buf,
85 Optional<ParsedStringTable> StrTab = None);
87 } // end namespace remarks
88 } // end namespace llvm
90 #endif /* LLVM_REMARKS_REMARK_PARSER_H */