1 //===-- BitstreamRemarkParser.h - Parser for Bitstream remarks --*- C++/-*-===//
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
7 //===----------------------------------------------------------------------===//
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/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"
27 /// Parses and holds the state of the latest parsed remark.
28 struct 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.
37 uint64_t ContainerVersion
;
38 uint64_t RemarkVersion
;
39 BitstreamRemarkContainerType ContainerType
;
40 /// Wether the parser is ready to parse remarks.
41 bool ReadyToParseRemarks
= false;
43 /// Create a parser that expects to find a string table embedded in the
45 BitstreamRemarkParser(StringRef Buf
)
46 : RemarkParser(Format::Bitstream
), ParserHelper(Buf
) {}
48 /// Create a parser that uses a pre-parsed string table.
49 BitstreamRemarkParser(StringRef Buf
, ParsedStringTable StrTab
)
50 : RemarkParser(Format::Bitstream
), ParserHelper(Buf
),
51 StrTab(std::move(StrTab
)) {}
53 Expected
<std::unique_ptr
<Remark
>> next() override
;
55 static bool classof(const RemarkParser
*P
) {
56 return P
->ParserFormat
== Format::Bitstream
;
59 /// Parse and process the metadata of the buffer.
62 /// Parse a Bitstream remark.
63 Expected
<std::unique_ptr
<Remark
>> parseRemark();
67 Error
processCommonMeta(BitstreamMetaParserHelper
&Helper
);
68 Error
processStandaloneMeta(BitstreamMetaParserHelper
&Helper
);
69 Error
processSeparateRemarksFileMeta(BitstreamMetaParserHelper
&Helper
);
70 Error
processSeparateRemarksMetaMeta(BitstreamMetaParserHelper
&Helper
);
71 Expected
<std::unique_ptr
<Remark
>>
72 processRemark(BitstreamRemarkParserHelper
&Helper
);
73 Error
processExternalFilePath(Optional
<StringRef
> ExternalFilePath
);
76 Expected
<std::unique_ptr
<BitstreamRemarkParser
>>
77 createBitstreamParserFromMeta(StringRef Buf
,
78 Optional
<ParsedStringTable
> StrTab
= None
);
80 } // end namespace remarks
81 } // end namespace llvm
83 #endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */