xref: /llvm-project/llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp (revision 88101dadcc7248133de4add4396ee1e9f2b0e406)
1 //===- DebugCrossExSubsection.cpp -------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
11 
12 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
13 
14 using namespace llvm;
15 using namespace llvm::codeview;
16 
17 Error DebugCrossModuleExportsSubsectionRef::initialize(
18     BinaryStreamReader Reader) {
19   if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
20     return make_error<CodeViewError>(
21         cv_error_code::corrupt_record,
22         "Cross Scope Exports section is an invalid size!");
23 
24   uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
25   return Reader.readArray(References, Size);
26 }
27 
28 Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
29   BinaryStreamReader Reader(Stream);
30   return initialize(Reader);
31 }
32 
33 void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
34                                                    uint32_t Global) {
35   Mappings[Local] = Global;
36 }
37 
38 uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
39   return Mappings.size() * sizeof(CrossModuleExport);
40 }
41 
42 Error DebugCrossModuleExportsSubsection::commit(
43     BinaryStreamWriter &Writer) const {
44   for (const auto &M : Mappings) {
45     if (auto EC = Writer.writeInteger(M.first))
46       return EC;
47     if (auto EC = Writer.writeInteger(M.second))
48       return EC;
49   }
50   return Error::success();
51 }
52