xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 //===- DebugCrossExSubsection.cpp -----------------------------------------===//
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 #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
10 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11 #include "llvm/Support/BinaryStreamWriter.h"
12 #include "llvm/Support/Error.h"
13 #include <cstdint>
14 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 
18 Error DebugCrossModuleExportsSubsectionRef::initialize(
19     BinaryStreamReader Reader) {
20   if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
21     return make_error<CodeViewError>(
22         cv_error_code::corrupt_record,
23         "Cross Scope Exports section is an invalid size!");
24 
25   uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
26   return Reader.readArray(References, Size);
27 }
28 
29 Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
30   BinaryStreamReader Reader(Stream);
31   return initialize(Reader);
32 }
33 
34 void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
35                                                    uint32_t Global) {
36   Mappings[Local] = Global;
37 }
38 
39 uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
40   return Mappings.size() * sizeof(CrossModuleExport);
41 }
42 
43 Error DebugCrossModuleExportsSubsection::commit(
44     BinaryStreamWriter &Writer) const {
45   for (const auto &M : Mappings) {
46     if (auto EC = Writer.writeInteger(M.first))
47       return EC;
48     if (auto EC = Writer.writeInteger(M.second))
49       return EC;
50   }
51   return Error::success();
52 }
53