xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- DebugCrossExSubsection.cpp -----------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
10*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11*0b57cec5SDimitry Andric #include "llvm/Support/BinaryStreamWriter.h"
12*0b57cec5SDimitry Andric #include "llvm/Support/Error.h"
13*0b57cec5SDimitry Andric #include <cstdint>
14*0b57cec5SDimitry Andric 
15*0b57cec5SDimitry Andric using namespace llvm;
16*0b57cec5SDimitry Andric using namespace llvm::codeview;
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric Error DebugCrossModuleExportsSubsectionRef::initialize(
19*0b57cec5SDimitry Andric     BinaryStreamReader Reader) {
20*0b57cec5SDimitry Andric   if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
21*0b57cec5SDimitry Andric     return make_error<CodeViewError>(
22*0b57cec5SDimitry Andric         cv_error_code::corrupt_record,
23*0b57cec5SDimitry Andric         "Cross Scope Exports section is an invalid size!");
24*0b57cec5SDimitry Andric 
25*0b57cec5SDimitry Andric   uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
26*0b57cec5SDimitry Andric   return Reader.readArray(References, Size);
27*0b57cec5SDimitry Andric }
28*0b57cec5SDimitry Andric 
29*0b57cec5SDimitry Andric Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
30*0b57cec5SDimitry Andric   BinaryStreamReader Reader(Stream);
31*0b57cec5SDimitry Andric   return initialize(Reader);
32*0b57cec5SDimitry Andric }
33*0b57cec5SDimitry Andric 
34*0b57cec5SDimitry Andric void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
35*0b57cec5SDimitry Andric                                                    uint32_t Global) {
36*0b57cec5SDimitry Andric   Mappings[Local] = Global;
37*0b57cec5SDimitry Andric }
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
40*0b57cec5SDimitry Andric   return Mappings.size() * sizeof(CrossModuleExport);
41*0b57cec5SDimitry Andric }
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric Error DebugCrossModuleExportsSubsection::commit(
44*0b57cec5SDimitry Andric     BinaryStreamWriter &Writer) const {
45*0b57cec5SDimitry Andric   for (const auto &M : Mappings) {
46*0b57cec5SDimitry Andric     if (auto EC = Writer.writeInteger(M.first))
47*0b57cec5SDimitry Andric       return EC;
48*0b57cec5SDimitry Andric     if (auto EC = Writer.writeInteger(M.second))
49*0b57cec5SDimitry Andric       return EC;
50*0b57cec5SDimitry Andric   }
51*0b57cec5SDimitry Andric   return Error::success();
52*0b57cec5SDimitry Andric }
53