[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / Remarks / BitstreamRemarkParser.h
blobfc786fc57622d27f92cbdc0fbc5b35e31f0ba36c
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
14 #define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
16 #include "llvm/Remarks/BitstreamRemarkContainer.h"
17 #include "llvm/Remarks/BitstreamRemarkParser.h"
18 #include "llvm/Remarks/RemarkFormat.h"
19 #include "llvm/Remarks/RemarkParser.h"
20 #include <cstdint>
21 #include <memory>
22 #include <optional>
24 namespace llvm {
25 namespace remarks {
27 struct Remark;
29 /// Parses and holds the state of the latest parsed remark.
30 struct BitstreamRemarkParser : public RemarkParser {
31 /// The buffer to parse.
32 BitstreamParserHelper ParserHelper;
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.
39 uint64_t ContainerVersion = 0;
40 uint64_t RemarkVersion = 0;
41 BitstreamRemarkContainerType ContainerType =
42 BitstreamRemarkContainerType::Standalone;
43 /// Wether the parser is ready to parse remarks.
44 bool ReadyToParseRemarks = false;
46 /// Create a parser that expects to find a string table embedded in the
47 /// stream.
48 explicit BitstreamRemarkParser(StringRef Buf)
49 : RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
51 /// Create a parser that uses a pre-parsed string table.
52 BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
53 : RemarkParser(Format::Bitstream), ParserHelper(Buf),
54 StrTab(std::move(StrTab)) {}
56 Expected<std::unique_ptr<Remark>> next() override;
58 static bool classof(const RemarkParser *P) {
59 return P->ParserFormat == Format::Bitstream;
62 /// Parse and process the metadata of the buffer.
63 Error parseMeta();
65 /// Parse a Bitstream remark.
66 Expected<std::unique_ptr<Remark>> parseRemark();
68 private:
69 /// Helper functions.
70 Error processCommonMeta(BitstreamMetaParserHelper &Helper);
71 Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
72 Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
73 Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
74 Expected<std::unique_ptr<Remark>>
75 processRemark(BitstreamRemarkParserHelper &Helper);
76 Error processExternalFilePath(std::optional<StringRef> ExternalFilePath);
79 Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
80 StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
81 std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
83 } // end namespace remarks
84 } // end namespace llvm
86 #endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */