DebugCrossExSubsection.cpp 1.8 KB

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