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 15using namespace llvm; 16using namespace llvm::codeview; 17 18Error 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 29Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) { 30 BinaryStreamReader Reader(Stream); 31 return initialize(Reader); 32} 33 34void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local, 35 uint32_t Global) { 36 Mappings[Local] = Global; 37} 38 39uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const { 40 return Mappings.size() * sizeof(CrossModuleExport); 41} 42 43Error 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