LLVM
15.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
21
namespace
llvm
{
22
namespace
remarks
{
23
24
struct
Remark
;
25
26
class
EndOfFileError
:
public
ErrorInfo
<EndOfFileError> {
27
public
:
28
static
char
ID
;
29
30
EndOfFileError
() =
default
;
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.
41
Format
ParserFormat
;
42
/// Path to prepend when opening an external remark file.
43
std::string
ExternalFilePrependPath
;
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).
59
struct
ParsedStringTable
{
60
/// The buffer mapped from the section contents.
61
StringRef
Buffer
;
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
66
ParsedStringTable
(
StringRef
Buffer
);
67
/// Disable copy.
68
ParsedStringTable
(
const
ParsedStringTable
&) =
delete
;
69
ParsedStringTable
&
operator=
(
const
ParsedStringTable
&) =
delete
;
70
/// Should be movable.
71
ParsedStringTable
(
ParsedStringTable
&&) =
default
;
72
ParsedStringTable
&
operator=
(
ParsedStringTable
&&) =
default
;
73
74
size_t
size
()
const
{
return
Offsets
.size(); }
75
Expected<StringRef>
operator[]
(
size_t
Index)
const
;
76
};
77
78
Expected<std::unique_ptr<RemarkParser>
>
createRemarkParser
(
Format
ParserFormat,
79
StringRef
Buf);
80
81
Expected<std::unique_ptr<RemarkParser>
>
82
createRemarkParser
(
Format
ParserFormat,
StringRef
Buf,
83
ParsedStringTable StrTab);
84
85
Expected<std::unique_ptr<RemarkParser>
>
86
createRemarkParserFromMeta
(
Format
ParserFormat,
StringRef
Buf,
87
Optional<ParsedStringTable>
StrTab = None,
88
Optional<StringRef>
ExternalFilePrependPath = None);
89
90
}
// end namespace remarks
91
}
// end namespace llvm
92
93
#endif // LLVM_REMARKS_REMARKPARSER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:17
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:64
StringRef.h
Error.h
llvm::remarks::ParsedStringTable::size
size_t size() const
Definition:
RemarkParser.h:74
llvm::Optional
Definition:
APInt.h:33
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:41
llvm::remarks::ParsedStringTable::Buffer
StringRef Buffer
The buffer mapped from the section contents.
Definition:
RemarkParser.h:61
llvm::remarks::RemarkParser::next
virtual Expected< std::unique_ptr< Remark > > next()=0
If no error occurs, this returns a valid Remark object.
remarks
annotation remarks
Definition:
AnnotationRemarks.cpp:114
llvm::remarks::EndOfFileError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:
RemarkParser.h:33
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:
raw_ostream.h:54
llvm::remarks::createRemarkParser
Expected< std::unique_ptr< RemarkParser > > createRemarkParser(Format ParserFormat, StringRef Buf)
Definition:
RemarkParser.cpp:51
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:25
llvm::remarks::EndOfFileError
Definition:
RemarkParser.h:26
llvm::remarks::EndOfFileError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:
RemarkParser.h:32
llvm::remarks::RemarkParser::RemarkParser
RemarkParser(Format ParserFormat)
Definition:
RemarkParser.h:45
llvm::ErrorInfo
Base class for user error types.
Definition:
Error.h:347
llvm::remarks::ParsedStringTable
In-memory representation of the string table parsed from a buffer (e.g.
Definition:
RemarkParser.h:59
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:
StringRef.h:58
llvm::remarks::RemarkParser
Parser used to parse a raw buffer to remarks::Remark objects.
Definition:
RemarkParser.h:39
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:77
llvm::remarks::RemarkParser::ExternalFilePrependPath
std::string ExternalFilePrependPath
Path to prepend when opening an external remark file.
Definition:
RemarkParser.h:43
llvm::remarks::ParsedStringTable::operator[]
Expected< StringRef > operator[](size_t Index) const
Definition:
RemarkParser.cpp:35
llvm::remarks::EndOfFileError::ID
static char ID
Definition:
RemarkParser.h:28
llvm::remarks::createRemarkParserFromMeta
Expected< std::unique_ptr< RemarkParser > > createRemarkParserFromMeta(Format ParserFormat, StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Definition:
RemarkParser.cpp:88
llvm::remarks::Format
Format
The format used for serializing/deserializing remarks.
Definition:
RemarkFormat.h:25
Generated on Sun May 22 2022 05:55:00 for LLVM by
1.8.17