xref: /src/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
19df3605dSDimitry Andric //===- DebugCrossExSubsection.cpp -----------------------------------------===//
27ab83427SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67ab83427SDimitry Andric //
77ab83427SDimitry Andric //===----------------------------------------------------------------------===//
87ab83427SDimitry Andric 
97ab83427SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
107ab83427SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11145449b1SDimitry Andric #include "llvm/Support/BinaryStreamReader.h"
129df3605dSDimitry Andric #include "llvm/Support/BinaryStreamWriter.h"
139df3605dSDimitry Andric #include "llvm/Support/Error.h"
149df3605dSDimitry Andric #include <cstdint>
157ab83427SDimitry Andric 
167ab83427SDimitry Andric using namespace llvm;
177ab83427SDimitry Andric using namespace llvm::codeview;
187ab83427SDimitry Andric 
initialize(BinaryStreamReader Reader)197ab83427SDimitry Andric Error DebugCrossModuleExportsSubsectionRef::initialize(
207ab83427SDimitry Andric     BinaryStreamReader Reader) {
217ab83427SDimitry Andric   if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
227ab83427SDimitry Andric     return make_error<CodeViewError>(
237ab83427SDimitry Andric         cv_error_code::corrupt_record,
247ab83427SDimitry Andric         "Cross Scope Exports section is an invalid size!");
257ab83427SDimitry Andric 
267ab83427SDimitry Andric   uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
277ab83427SDimitry Andric   return Reader.readArray(References, Size);
287ab83427SDimitry Andric }
297ab83427SDimitry Andric 
initialize(BinaryStreamRef Stream)307ab83427SDimitry Andric Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
317ab83427SDimitry Andric   BinaryStreamReader Reader(Stream);
327ab83427SDimitry Andric   return initialize(Reader);
337ab83427SDimitry Andric }
347ab83427SDimitry Andric 
addMapping(uint32_t Local,uint32_t Global)357ab83427SDimitry Andric void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
367ab83427SDimitry Andric                                                    uint32_t Global) {
377ab83427SDimitry Andric   Mappings[Local] = Global;
387ab83427SDimitry Andric }
397ab83427SDimitry Andric 
calculateSerializedSize() const407ab83427SDimitry Andric uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
417ab83427SDimitry Andric   return Mappings.size() * sizeof(CrossModuleExport);
427ab83427SDimitry Andric }
437ab83427SDimitry Andric 
commit(BinaryStreamWriter & Writer) const447ab83427SDimitry Andric Error DebugCrossModuleExportsSubsection::commit(
457ab83427SDimitry Andric     BinaryStreamWriter &Writer) const {
467ab83427SDimitry Andric   for (const auto &M : Mappings) {
477ab83427SDimitry Andric     if (auto EC = Writer.writeInteger(M.first))
487ab83427SDimitry Andric       return EC;
497ab83427SDimitry Andric     if (auto EC = Writer.writeInteger(M.second))
507ab83427SDimitry Andric       return EC;
517ab83427SDimitry Andric   }
527ab83427SDimitry Andric   return Error::success();
537ab83427SDimitry Andric }
54