BitstreamRemarkParser.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
  13. #define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
  14. #include "llvm/ADT/Optional.h"
  15. #include "llvm/Remarks/BitstreamRemarkContainer.h"
  16. #include "llvm/Remarks/BitstreamRemarkParser.h"
  17. #include "llvm/Remarks/RemarkFormat.h"
  18. #include "llvm/Remarks/RemarkParser.h"
  19. #include <cstdint>
  20. #include <memory>
  21. namespace llvm {
  22. namespace remarks {
  23. struct Remark;
  24. /// Parses and holds the state of the latest parsed remark.
  25. struct BitstreamRemarkParser : public RemarkParser {
  26. /// The buffer to parse.
  27. BitstreamParserHelper ParserHelper;
  28. /// The string table used for parsing strings.
  29. Optional<ParsedStringTable> StrTab;
  30. /// Temporary remark buffer used when the remarks are stored separately.
  31. std::unique_ptr<MemoryBuffer> TmpRemarkBuffer;
  32. /// The common metadata used to decide how to parse the buffer.
  33. /// This is filled when parsing the metadata block.
  34. uint64_t ContainerVersion = 0;
  35. uint64_t RemarkVersion = 0;
  36. BitstreamRemarkContainerType ContainerType =
  37. BitstreamRemarkContainerType::Standalone;
  38. /// Wether the parser is ready to parse remarks.
  39. bool ReadyToParseRemarks = false;
  40. /// Create a parser that expects to find a string table embedded in the
  41. /// stream.
  42. explicit BitstreamRemarkParser(StringRef Buf)
  43. : RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
  44. /// Create a parser that uses a pre-parsed string table.
  45. BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
  46. : RemarkParser(Format::Bitstream), ParserHelper(Buf),
  47. StrTab(std::move(StrTab)) {}
  48. Expected<std::unique_ptr<Remark>> next() override;
  49. static bool classof(const RemarkParser *P) {
  50. return P->ParserFormat == Format::Bitstream;
  51. }
  52. /// Parse and process the metadata of the buffer.
  53. Error parseMeta();
  54. /// Parse a Bitstream remark.
  55. Expected<std::unique_ptr<Remark>> parseRemark();
  56. private:
  57. /// Helper functions.
  58. Error processCommonMeta(BitstreamMetaParserHelper &Helper);
  59. Error processStandaloneMeta(BitstreamMetaParserHelper &Helper);
  60. Error processSeparateRemarksFileMeta(BitstreamMetaParserHelper &Helper);
  61. Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
  62. Expected<std::unique_ptr<Remark>>
  63. processRemark(BitstreamRemarkParserHelper &Helper);
  64. Error processExternalFilePath(Optional<StringRef> ExternalFilePath);
  65. };
  66. Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
  67. StringRef Buf, Optional<ParsedStringTable> StrTab = None,
  68. Optional<StringRef> ExternalFilePrependPath = None);
  69. } // end namespace remarks
  70. } // end namespace llvm
  71. #endif /* LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H */