LLVM 20.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.
50
51 /// Create a parser that uses a pre-parsed string table.
54 StrTab(std::move(StrTab)) {}
55
57
58 static bool classof(const RemarkParser *P) {
59 return P->ParserFormat == Format::Bitstream;
60 }
61
62 /// Parse and process the metadata of the buffer.
64
65 /// Parse a Bitstream remark.
67
68private:
69 /// Helper functions.
70 Error processCommonMeta(BitstreamMetaParserHelper &Helper);
71 Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
72 Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
73 Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
75 processRemark(BitstreamRemarkParserHelper &Helper);
76 Error processExternalFilePath(std::optional<StringRef> ExternalFilePath);
77};
78
80 StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
81 std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
82
83} // end namespace remarks
84} // end namespace llvm
85
86#endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */
#define P(N)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
BitstreamRemarkContainerType
Type of the remark container.
@ Standalone
Everything is emitted together.
Expected< std::unique_ptr< BitstreamRemarkParser > > createBitstreamParserFromMeta(StringRef Buf, std::optional< ParsedStringTable > StrTab=std::nullopt, std::optional< StringRef > ExternalFilePrependPath=std::nullopt)
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
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)
BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
Create a parser that uses a pre-parsed string table.
BitstreamRemarkParser(StringRef Buf)
Create a parser that expects to find a string table embedded in the stream.
BitstreamRemarkContainerType ContainerType
bool ReadyToParseRemarks
Wether the parser is ready to parse remarks.
In-memory representation of the string table parsed from a buffer (e.g.
Definition: RemarkParser.h:60
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:40