DebugCrossExSubsection.cpp 1.7 KB

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