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