LLVM
17.0.0git
include
llvm
Remarks
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_REMARKPARSER_H
14
#define LLVM_REMARKS_REMARKPARSER_H
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
Remark
;
26
27
class
EndOfFileError
:
public
ErrorInfo
<EndOfFileError> {
28
public
:
29
static
char
ID
;
30
31
EndOfFileError
() =
default
;
32
33
void
log
(
raw_ostream
&OS)
const override
{ OS <<
"End of file reached."
; }
34
std::error_code
convertToErrorCode
()
const override
{
35
return
inconvertibleErrorCode
();
36
}
37
};
38
39
/// Parser used to parse a raw buffer to remarks::Remark objects.
40
struct
RemarkParser
{
41
/// The format of the parser.
42
Format
ParserFormat
;
43
/// Path to prepend when opening an external remark file.
44
std::string
ExternalFilePrependPath
;
45
46
RemarkParser
(
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>
>
next
() = 0;
54
55
virtual
~RemarkParser
() =
default
;
56
};
57
58
/// In-memory representation of the string table parsed from a buffer (e.g. the
59
/// remarks section).
60
struct
ParsedStringTable
{
61
/// The buffer mapped from the section contents.
62
StringRef
Buffer
;
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>
Offsets
;
66
67
ParsedStringTable
(
StringRef
Buffer
);
68
/// Disable copy.
69
ParsedStringTable
(
const
ParsedStringTable
&) =
delete
;
70
ParsedStringTable
&
operator=
(
const
ParsedStringTable
&) =
delete
;
71
/// Should be movable.
72
ParsedStringTable
(
ParsedStringTable
&&) =
default
;
73
ParsedStringTable
&
operator=
(
ParsedStringTable
&&) =
default
;
74
75
size_t
size
()
const
{
return
Offsets
.size(); }
76
Expected<StringRef>
operator[]
(
size_t
Index
)
const
;
77
};
78
79
Expected<std::unique_ptr<RemarkParser>
>
createRemarkParser
(
Format
ParserFormat,
80
StringRef
Buf);
81
82
Expected<std::unique_ptr<RemarkParser>
>
83
createRemarkParser
(
Format
ParserFormat,
StringRef
Buf,
84
ParsedStringTable StrTab);
85
86
Expected<std::unique_ptr<RemarkParser>
>
createRemarkParserFromMeta
(
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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:18
llvm::remarks::ParsedStringTable::Offsets
std::vector< size_t > Offsets
This object has high changes to be std::move'd around, so don't use a SmallVector for once.
Definition:
RemarkParser.h:65
StringRef.h
Error.h
llvm::remarks::ParsedStringTable::size
size_t size() const
Definition:
RemarkParser.h:75
llvm::remarks::RemarkParser::~RemarkParser
virtual ~RemarkParser()=default
llvm::Expected
Tagged union holding either a T or a Error.
Definition:
APFloat.h:41
llvm::remarks::RemarkParser::ParserFormat
Format ParserFormat
The format of the parser.
Definition:
RemarkParser.h:42
llvm::remarks::ParsedStringTable::Buffer
StringRef Buffer
The buffer mapped from the section contents.
Definition:
RemarkParser.h:62
llvm::remarks::RemarkParser::next
virtual Expected< std::unique_ptr< Remark > > next()=0
If no error occurs, this returns a valid Remark object.
llvm::dwarf::Index
Index
Definition:
Dwarf.h:550
llvm::remarks::EndOfFileError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:
RemarkParser.h:34
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:
raw_ostream.h:52
llvm::remarks::createRemarkParser
Expected< std::unique_ptr< RemarkParser > > createRemarkParser(Format ParserFormat, StringRef Buf)
Definition:
RemarkParser.cpp:52
llvm::remarks::EndOfFileError::EndOfFileError
EndOfFileError()=default
RemarkFormat.h
llvm::remarks::ParsedStringTable::operator=
ParsedStringTable & operator=(const ParsedStringTable &)=delete
llvm::HighlightColor::Remark
@ Remark
llvm::remarks::ParsedStringTable::ParsedStringTable
ParsedStringTable(StringRef Buffer)
Definition:
RemarkParser.cpp:26
llvm::remarks::EndOfFileError
Definition:
RemarkParser.h:27
llvm::remarks::createRemarkParserFromMeta
Expected< std::unique_ptr< RemarkParser > > createRemarkParserFromMeta(Format ParserFormat, StringRef Buf, std::optional< ParsedStringTable > StrTab=std::nullopt, std::optional< StringRef > ExternalFilePrependPath=std::nullopt)
Definition:
RemarkParser.cpp:89
llvm::remarks::EndOfFileError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:
RemarkParser.h:33
llvm::remarks::RemarkParser::RemarkParser
RemarkParser(Format ParserFormat)
Definition:
RemarkParser.h:46
llvm::ErrorInfo
Base class for user error types.
Definition:
Error.h:348
llvm::remarks::ParsedStringTable
In-memory representation of the string table parsed from a buffer (e.g.
Definition:
RemarkParser.h:60
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:
StringRef.h:50
llvm::remarks::RemarkParser
Parser used to parse a raw buffer to remarks::Remark objects.
Definition:
RemarkParser.h:40
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:79
llvm::remarks::RemarkParser::ExternalFilePrependPath
std::string ExternalFilePrependPath
Path to prepend when opening an external remark file.
Definition:
RemarkParser.h:44
llvm::remarks::ParsedStringTable::operator[]
Expected< StringRef > operator[](size_t Index) const
Definition:
RemarkParser.cpp:36
llvm::remarks::EndOfFileError::ID
static char ID
Definition:
RemarkParser.h:29
llvm::remarks::Format
Format
The format used for serializing/deserializing remarks.
Definition:
RemarkFormat.h:25
Generated on Sat Jan 28 2023 08:50:04 for LLVM by
1.8.17