1 //===-- llvm/Remarks/Remark.h - The remark type -----------------*- C++/-*-===//
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
7 //===----------------------------------------------------------------------===//
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"
26 class EndOfFileError
: public ErrorInfo
<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.
40 /// The format of the parser.
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
57 struct ParsedStringTable
{
58 /// The buffer mapped from the section contents.
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
);
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
,
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 */