LLVM  10.0.0svn
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;
38  uint64_t RemarkVersion;
40  /// Wether the parser is ready to parse remarks.
41  bool ReadyToParseRemarks = false;
42 
43  /// Create a parser that expects to find a string table embedded in the
44  /// stream.
46  : RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
47 
48  /// Create a parser that uses a pre-parsed string table.
50  : RemarkParser(Format::Bitstream), ParserHelper(Buf),
51  StrTab(std::move(StrTab)) {}
52 
54 
55  static bool classof(const RemarkParser *P) {
56  return P->ParserFormat == Format::Bitstream;
57  }
58 
59  /// Parse and process the metadata of the buffer.
60  Error parseMeta();
61 
62  /// Parse a Bitstream remark.
64 
65 private:
66  /// Helper functions.
67  Error processCommonMeta(BitstreamMetaParserHelper &Helper);
68  Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
69  Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
70  Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
72  processRemark(BitstreamRemarkParserHelper &Helper);
73  Error processExternalFilePath(Optional<StringRef> ExternalFilePath);
74 };
75 
79 
80 } // end namespace remarks
81 } // end namespace llvm
82 
83 #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:937
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
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:48
BitstreamRemarkContainerType
Type of the remark container.