Eugene Zelenko | 8456b16 | 2017-06-29 00:05:44 +0000 | [diff] [blame] | 1 | //===- DebugCrossExSubsection.cpp -----------------------------------------===// |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h" |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
Eugene Zelenko | 8456b16 | 2017-06-29 00:05:44 +0000 | [diff] [blame] | 11 | #include "llvm/Support/BinaryStreamWriter.h" |
| 12 | #include "llvm/Support/Error.h" |
| 13 | #include <cstdint> |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 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) { |
Zachary Turner | 88101da | 2017-06-05 22:12:23 +0000 | [diff] [blame] | 46 | if (auto EC = Writer.writeInteger(M.first)) |
| 47 | return EC; |
| 48 | if (auto EC = Writer.writeInteger(M.second)) |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 49 | return EC; |
| 50 | } |
| 51 | return Error::success(); |
| 52 | } |