10b57cec5SDimitry Andric //===- DebugCrossImpSubsection.h --------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
100b57cec5SDimitry Andric #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
130b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
140b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeView.h"
150b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
160b57cec5SDimitry Andric #include "llvm/Support/BinaryStreamArray.h"
170b57cec5SDimitry Andric #include "llvm/Support/BinaryStreamRef.h"
180b57cec5SDimitry Andric #include "llvm/Support/Endian.h"
190b57cec5SDimitry Andric #include "llvm/Support/Error.h"
200b57cec5SDimitry Andric #include <cstdint>
210b57cec5SDimitry Andric #include <vector>
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric namespace llvm {
2481ad6265SDimitry Andric class BinaryStreamReader;
2581ad6265SDimitry Andric class BinaryStreamWriter;
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric namespace codeview {
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric struct CrossModuleImportItem {
300b57cec5SDimitry Andric   const CrossModuleImport *Header = nullptr;
310b57cec5SDimitry Andric   FixedStreamArray<support::ulittle32_t> Imports;
320b57cec5SDimitry Andric };
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric } // end namespace codeview
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric template <> struct VarStreamArrayExtractor<codeview::CrossModuleImportItem> {
370b57cec5SDimitry Andric public:
380b57cec5SDimitry Andric   using ContextType = void;
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric   Error operator()(BinaryStreamRef Stream, uint32_t &Len,
410b57cec5SDimitry Andric                    codeview::CrossModuleImportItem &Item);
420b57cec5SDimitry Andric };
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric namespace codeview {
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric class DebugStringTableSubsection;
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric class DebugCrossModuleImportsSubsectionRef final : public DebugSubsectionRef {
490b57cec5SDimitry Andric   using ReferenceArray = VarStreamArray<CrossModuleImportItem>;
500b57cec5SDimitry Andric   using Iterator = ReferenceArray::Iterator;
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric public:
530b57cec5SDimitry Andric   DebugCrossModuleImportsSubsectionRef()
540b57cec5SDimitry Andric       : DebugSubsectionRef(DebugSubsectionKind::CrossScopeImports) {}
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric   static bool classof(const DebugSubsectionRef *S) {
570b57cec5SDimitry Andric     return S->kind() == DebugSubsectionKind::CrossScopeImports;
580b57cec5SDimitry Andric   }
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric   Error initialize(BinaryStreamReader Reader);
610b57cec5SDimitry Andric   Error initialize(BinaryStreamRef Stream);
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric   Iterator begin() const { return References.begin(); }
640b57cec5SDimitry Andric   Iterator end() const { return References.end(); }
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric private:
670b57cec5SDimitry Andric   ReferenceArray References;
680b57cec5SDimitry Andric };
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric class DebugCrossModuleImportsSubsection final : public DebugSubsection {
710b57cec5SDimitry Andric public:
720b57cec5SDimitry Andric   explicit DebugCrossModuleImportsSubsection(
730b57cec5SDimitry Andric       DebugStringTableSubsection &Strings)
740b57cec5SDimitry Andric       : DebugSubsection(DebugSubsectionKind::CrossScopeImports),
750b57cec5SDimitry Andric         Strings(Strings) {}
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   static bool classof(const DebugSubsection *S) {
780b57cec5SDimitry Andric     return S->kind() == DebugSubsectionKind::CrossScopeImports;
790b57cec5SDimitry Andric   }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   void addImport(StringRef Module, uint32_t ImportId);
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   uint32_t calculateSerializedSize() const override;
840b57cec5SDimitry Andric   Error commit(BinaryStreamWriter &Writer) const override;
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric private:
870b57cec5SDimitry Andric   DebugStringTableSubsection &Strings;
880b57cec5SDimitry Andric   StringMap<std::vector<support::ulittle32_t>> Mappings;
890b57cec5SDimitry Andric };
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric } // end namespace codeview
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric } // end namespace llvm
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
96