Decompressor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- Decompressor.h ------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===/
  13. #ifndef LLVM_OBJECT_DECOMPRESSOR_H
  14. #define LLVM_OBJECT_DECOMPRESSOR_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/Support/Compression.h"
  18. #include "llvm/Support/Error.h"
  19. namespace llvm {
  20. namespace object {
  21. /// Decompressor helps to handle decompression of compressed sections.
  22. class Decompressor {
  23. public:
  24. /// Create decompressor object.
  25. /// @param Name Section name.
  26. /// @param Data Section content.
  27. /// @param IsLE Flag determines if Data is in little endian form.
  28. /// @param Is64Bit Flag determines if object is 64 bit.
  29. static Expected<Decompressor> create(StringRef Name, StringRef Data,
  30. bool IsLE, bool Is64Bit);
  31. /// Resize the buffer and uncompress section data into it.
  32. /// @param Out Destination buffer.
  33. template <class T> Error resizeAndDecompress(T &Out) {
  34. Out.resize(DecompressedSize);
  35. return decompress({(uint8_t *)Out.data(), (size_t)DecompressedSize});
  36. }
  37. /// Uncompress section data to raw buffer provided.
  38. Error decompress(MutableArrayRef<uint8_t> Output);
  39. /// Return memory buffer size required for decompression.
  40. uint64_t getDecompressedSize() { return DecompressedSize; }
  41. private:
  42. Decompressor(StringRef Data);
  43. Error consumeCompressedHeader(bool Is64Bit, bool IsLittleEndian);
  44. StringRef SectionData;
  45. uint64_t DecompressedSize;
  46. DebugCompressionType CompressionType = DebugCompressionType::None;
  47. };
  48. } // end namespace object
  49. } // end namespace llvm
  50. #endif // LLVM_OBJECT_DECOMPRESSOR_H
  51. #ifdef __GNUC__
  52. #pragma GCC diagnostic pop
  53. #endif