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