LLVM  12.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 
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/SmallVector.h"
22 #include <memory>
23 #include <string>
24 
25 namespace llvm {
26 namespace remarks {
27 /// Parses and holds the state of the latest parsed remark.
29  /// The buffer to parse.
31  /// The string table used for parsing strings.
33  /// Temporary remark buffer used when the remarks are stored separately.
34  std::unique_ptr<MemoryBuffer> TmpRemarkBuffer;
35  /// The common metadata used to decide how to parse the buffer.
36  /// This is filled when parsing the metadata block.
37  uint64_t ContainerVersion = 0;
38  uint64_t RemarkVersion = 0;
41  /// Wether the parser is ready to parse remarks.
42  bool ReadyToParseRemarks = false;
43 
44  /// Create a parser that expects to find a string table embedded in the
45  /// stream.
47  : RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
48 
49  /// Create a parser that uses a pre-parsed string table.
51  : RemarkParser(Format::Bitstream), ParserHelper(Buf),
52  StrTab(std::move(StrTab)) {}
53 
55 
56  static bool classof(const RemarkParser *P) {
57  return P->ParserFormat == Format::Bitstream;
58  }
59 
60  /// Parse and process the metadata of the buffer.
61  Error parseMeta();
62 
63  /// Parse a Bitstream remark.
65 
66 private:
67  /// Helper functions.
68  Error processCommonMeta(BitstreamMetaParserHelper &Helper);
69  Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
70  Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
71  Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
73  processRemark(BitstreamRemarkParserHelper &Helper);
74  Error processExternalFilePath(Optional<StringRef> ExternalFilePath);
75 };
76 
80 
81 } // end namespace remarks
82 } // end namespace llvm
83 
84 #endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */
const NoneType None
Definition: None.h:23
Helper to parse any bitstream remark container.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Error parseMeta()
Parse and process the metadata of the buffer.
Helper to parse a META_BLOCK for a bitstream remark container.
std::string ExternalFilePrependPath
Path to prepend when opening an external remark file.
Definition: RemarkParser.h:43
static bool classof(const RemarkParser *P)
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25
Helper to parse a REMARK_BLOCK for a bitstream remark container.
Definition: BitVector.h:959
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
In-memory representation of the string table parsed from a buffer (e.g.
Definition: RemarkParser.h:59
bool ReadyToParseRemarks
Wether the parser is ready to parse remarks.
#define P(N)
uint64_t ContainerVersion
The common metadata used to decide how to parse the buffer.
Expected< std::unique_ptr< BitstreamRemarkParser > > createBitstreamParserFromMeta(StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
Expected< std::unique_ptr< Remark > > parseRemark()
Parse a Bitstream remark.
BitstreamParserHelper ParserHelper
The buffer to parse.
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.
Format ParserFormat
The format of the parser.
Definition: RemarkParser.h:41
BitstreamRemarkContainerType ContainerType
Optional< ParsedStringTable > StrTab
The string table used for parsing strings.
Parses and holds the state of the latest parsed remark.
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:39
std::unique_ptr< MemoryBuffer > TmpRemarkBuffer
Temporary remark buffer used when the remarks are stored separately.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
BitstreamRemarkContainerType
Type of the remark container.