LLVM  17.0.0git
Decompressor.h
Go to the documentation of this file.
1 //===-- Decompressor.h ------------------------------------------*- C++ -*-===//
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 #ifndef LLVM_OBJECT_DECOMPRESSOR_H
10 #define LLVM_OBJECT_DECOMPRESSOR_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Error.h"
16 
17 namespace llvm {
18 namespace object {
19 
20 /// Decompressor helps to handle decompression of compressed sections.
21 class Decompressor {
22 public:
23  /// Create decompressor object.
24  /// @param Name Section name.
25  /// @param Data Section content.
26  /// @param IsLE Flag determines if Data is in little endian form.
27  /// @param Is64Bit Flag determines if object is 64 bit.
29  bool IsLE, bool Is64Bit);
30 
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 
38  /// Uncompress section data to raw buffer provided.
40 
41  /// Return memory buffer size required for decompression.
42  uint64_t getDecompressedSize() { return DecompressedSize; }
43 
44 private:
45  Decompressor(StringRef Data);
46 
47  Error consumeCompressedHeader(bool Is64Bit, bool IsLittleEndian);
48 
49  StringRef SectionData;
50  uint64_t DecompressedSize;
52 };
53 
54 } // end namespace object
55 } // end namespace llvm
56 
57 #endif // LLVM_OBJECT_DECOMPRESSOR_H
Compression.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
StringRef.h
Error.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
size_t
llvm::object::Decompressor::resizeAndDecompress
Error resizeAndDecompress(T &Out)
Resize the buffer and uncompress section data into it.
Definition: Decompressor.h:33
llvm::MutableArrayRef< uint8_t >
llvm::DebugCompressionType::None
@ None
No compression.
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
uint64_t
llvm::object::Decompressor::create
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.
Definition: Decompressor.cpp:20
ArrayRef.h
llvm::object::Decompressor::decompress
Error decompress(MutableArrayRef< uint8_t > Output)
Uncompress section data to raw buffer provided.
Definition: Decompressor.cpp:65
llvm::DebugCompressionType
DebugCompressionType
Definition: Compression.h:27
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
llvm::object::Decompressor::getDecompressedSize
uint64_t getDecompressedSize()
Return memory buffer size required for decompression.
Definition: Decompressor.h:42
llvm::object::Decompressor
Decompressor helps to handle decompression of compressed sections.
Definition: Decompressor.h:21