LLVM 22.0.0git
BitstreamRemarkParser.h
Go to the documentation of this file.
1//===-- BitstreamRemarkParser.h - Parser for Bitstream remarks --*- 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 the impementation of the Bitstream remark parser.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
14#define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
15
20#include <cstdint>
21#include <memory>
22#include <optional>
23
24namespace llvm {
25namespace remarks {
26
27struct Remark;
28
29/// Parses and holds the state of the latest parsed remark.
31 /// The buffer to parse.
33 /// The string table used for parsing strings.
34 std::optional<ParsedStringTable> StrTab;
35 /// Temporary remark buffer used when the remarks are stored separately.
36 std::unique_ptr<MemoryBuffer> TmpRemarkBuffer;
37 /// The common metadata used to decide how to parse the buffer.
38 /// This is filled when parsing the metadata block.
43 /// Wether the parser is ready to parse remarks.
44 bool ReadyToParseRemarks = false;
45
46 /// Create a parser that expects to find a string table embedded in the
47 /// stream.
48 explicit BitstreamRemarkParser(StringRef Buf);
49
51
52 static bool classof(const RemarkParser *P) {
53 return P->ParserFormat == Format::Bitstream;
54 }
55
56 /// Parse and process the metadata of the buffer.
58
59 /// Parse a Bitstream remark.
61
62private:
63 /// Helper functions.
64 Error processCommonMeta(BitstreamMetaParserHelper &Helper);
65 Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
66 Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
67 Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
69 processRemark(BitstreamRemarkParserHelper &Helper);
70 Error processExternalFilePath(std::optional<StringRef> ExternalFilePath);
71};
72
74 StringRef Buf,
75 std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
76
77} // end namespace remarks
78} // end namespace llvm
79
80#endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */
#define P(N)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
BitstreamRemarkContainerType
Type of the remark container.
@ Standalone
Everything is emitted together.
Expected< std::unique_ptr< BitstreamRemarkParser > > createBitstreamParserFromMeta(StringRef Buf, std::optional< StringRef > ExternalFilePrependPath=std::nullopt)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Helper to parse a META_BLOCK for a bitstream remark container.
Helper to parse any bitstream remark container.
Helper to parse a REMARK_BLOCK for a bitstream remark container.
Parses and holds the state of the latest parsed remark.
Error parseMeta()
Parse and process the metadata of the buffer.
std::optional< ParsedStringTable > StrTab
The string table used for parsing strings.
Expected< std::unique_ptr< Remark > > parseRemark()
Parse a Bitstream remark.
std::unique_ptr< MemoryBuffer > TmpRemarkBuffer
Temporary remark buffer used when the remarks are stored separately.
uint64_t ContainerVersion
The common metadata used to decide how to parse the buffer.
BitstreamParserHelper ParserHelper
The buffer to parse.
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
static bool classof(const RemarkParser *P)
BitstreamRemarkContainerType ContainerType
bool ReadyToParseRemarks
Wether the parser is ready to parse remarks.
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:41