blob: 749219fc5155027888a3d92d8e54764a6179b479 [file] [log] [blame]
Francis Visoiu Mistriha85d9ef2019-09-09 17:43:50 +00001//===-- 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"
18#include "llvm/Remarks/BitstreamRemarkParser.h"
19#include "llvm/Remarks/RemarkFormat.h"
20#include "llvm/Remarks/RemarkParser.h"
21#include "llvm/Support/raw_ostream.h"
22#include <memory>
23#include <string>
24
25namespace llvm {
26namespace remarks {
27/// Parses and holds the state of the latest parsed remark.
28struct BitstreamRemarkParser : public RemarkParser {
29 /// The buffer to parse.
30 BitstreamParserHelper ParserHelper;
31 /// The string table used for parsing strings.
32 Optional<ParsedStringTable> StrTab;
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.
Simon Pilgrim56a725a2019-11-09 13:00:36 +000037 uint64_t ContainerVersion = 0;
38 uint64_t RemarkVersion = 0;
39 BitstreamRemarkContainerType ContainerType =
40 BitstreamRemarkContainerType::Standalone;
Francis Visoiu Mistriha85d9ef2019-09-09 17:43:50 +000041 /// 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.
Simon Pilgrim56a725a2019-11-09 13:00:36 +000046 explicit BitstreamRemarkParser(StringRef Buf)
Francis Visoiu Mistriha85d9ef2019-09-09 17:43:50 +000047 : RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
48
49 /// Create a parser that uses a pre-parsed string table.
50 BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
51 : RemarkParser(Format::Bitstream), ParserHelper(Buf),
52 StrTab(std::move(StrTab)) {}
53
54 Expected<std::unique_ptr<Remark>> next() override;
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.
64 Expected<std::unique_ptr<Remark>> parseRemark();
65
66private:
67 /// Helper functions.
68 Error processCommonMeta(BitstreamMetaParserHelper &Helper);
69 Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
70 Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
71 Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
72 Expected<std::unique_ptr<Remark>>
73 processRemark(BitstreamRemarkParserHelper &Helper);
74 Error processExternalFilePath(Optional<StringRef> ExternalFilePath);
75};
76
Francis Visoiu Mistrih684605e2019-10-16 15:40:59 +000077Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
78 StringRef Buf, Optional<ParsedStringTable> StrTab = None,
79 Optional<StringRef> ExternalFilePrependPath = None);
Francis Visoiu Mistriha85d9ef2019-09-09 17:43:50 +000080
81} // end namespace remarks
82} // end namespace llvm
83
84#endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */