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