DebugCrossImpSubsection.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===- DebugCrossImpSubsection.h --------------------------------*- 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. #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
  9. #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
  10. #include "llvm/ADT/StringMap.h"
  11. #include "llvm/ADT/StringRef.h"
  12. #include "llvm/DebugInfo/CodeView/CodeView.h"
  13. #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
  14. #include "llvm/Support/BinaryStreamArray.h"
  15. #include "llvm/Support/BinaryStreamReader.h"
  16. #include "llvm/Support/BinaryStreamRef.h"
  17. #include "llvm/Support/Endian.h"
  18. #include "llvm/Support/Error.h"
  19. #include <cstdint>
  20. #include <vector>
  21. namespace llvm {
  22. namespace codeview {
  23. struct CrossModuleImportItem {
  24. const CrossModuleImport *Header = nullptr;
  25. FixedStreamArray<support::ulittle32_t> Imports;
  26. };
  27. } // end namespace codeview
  28. template <> struct VarStreamArrayExtractor<codeview::CrossModuleImportItem> {
  29. public:
  30. using ContextType = void;
  31. Error operator()(BinaryStreamRef Stream, uint32_t &Len,
  32. codeview::CrossModuleImportItem &Item);
  33. };
  34. namespace codeview {
  35. class DebugStringTableSubsection;
  36. class DebugCrossModuleImportsSubsectionRef final : public DebugSubsectionRef {
  37. using ReferenceArray = VarStreamArray<CrossModuleImportItem>;
  38. using Iterator = ReferenceArray::Iterator;
  39. public:
  40. DebugCrossModuleImportsSubsectionRef()
  41. : DebugSubsectionRef(DebugSubsectionKind::CrossScopeImports) {}
  42. static bool classof(const DebugSubsectionRef *S) {
  43. return S->kind() == DebugSubsectionKind::CrossScopeImports;
  44. }
  45. Error initialize(BinaryStreamReader Reader);
  46. Error initialize(BinaryStreamRef Stream);
  47. Iterator begin() const { return References.begin(); }
  48. Iterator end() const { return References.end(); }
  49. private:
  50. ReferenceArray References;
  51. };
  52. class DebugCrossModuleImportsSubsection final : public DebugSubsection {
  53. public:
  54. explicit DebugCrossModuleImportsSubsection(
  55. DebugStringTableSubsection &Strings)
  56. : DebugSubsection(DebugSubsectionKind::CrossScopeImports),
  57. Strings(Strings) {}
  58. static bool classof(const DebugSubsection *S) {
  59. return S->kind() == DebugSubsectionKind::CrossScopeImports;
  60. }
  61. void addImport(StringRef Module, uint32_t ImportId);
  62. uint32_t calculateSerializedSize() const override;
  63. Error commit(BinaryStreamWriter &Writer) const override;
  64. private:
  65. DebugStringTableSubsection &Strings;
  66. StringMap<std::vector<support::ulittle32_t>> Mappings;
  67. };
  68. } // end namespace codeview
  69. } // end namespace llvm
  70. #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H