17#include "llvm/Config/config.h"
40 return "LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at "
45 return "LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at "
64 uint8_t *Output,
size_t UncompressedSize) {
76 size_t UncompressedSize) {
88 size_t UncompressedSize) {
94static StringRef convertZlibCodeToString(
int Code) {
97 return "zlib error: Z_MEM_ERROR";
99 return "zlib error: Z_BUF_ERROR";
101 return "zlib error: Z_STREAM_ERROR";
103 return "zlib error: Z_DATA_ERROR";
114 unsigned long CompressedSize = ::compressBound(
Input.size());
116 int Res = ::compress2((Bytef *)CompressedBuffer.
data(), &CompressedSize,
117 (
const Bytef *)
Input.data(),
Input.size(), Level);
118 if (Res == Z_MEM_ERROR)
124 if (CompressedSize < CompressedBuffer.
size())
125 CompressedBuffer.
truncate(CompressedSize);
129 size_t &UncompressedSize) {
130 int Res = ::uncompress((Bytef *)Output, (uLongf *)&UncompressedSize,
142 size_t UncompressedSize) {
145 if (UncompressedSize < Output.
size())
157 size_t &UncompressedSize) {
162 size_t UncompressedSize) {
176 ZSTD_CCtx *Cctx = ZSTD_createCCtx();
180 if (ZSTD_isError(ZSTD_CCtx_setParameter(
181 Cctx, ZSTD_c_enableLongDistanceMatching, EnableLdm ? 1 : 0))) {
187 ZSTD_CCtx_setParameter(Cctx, ZSTD_c_compressionLevel, Level))) {
192 unsigned long CompressedBufferSize = ZSTD_compressBound(
Input.size());
195 size_t const CompressedSize =
196 ZSTD_compress2(Cctx, CompressedBuffer.
data(), CompressedBufferSize,
201 if (ZSTD_isError(CompressedSize))
205 if (CompressedSize < CompressedBuffer.
size())
206 CompressedBuffer.
truncate(CompressedSize);
210 size_t &UncompressedSize) {
211 const size_t Res = ::ZSTD_decompress(
213 UncompressedSize = Res;
214 if (ZSTD_isError(Res))
225 size_t UncompressedSize) {
228 if (UncompressedSize < Output.
size())
241 size_t &UncompressedSize) {
246 size_t UncompressedSize) {
257static const char *convertLZMACodeToString(lzma_ret Code) {
259 case LZMA_STREAM_END:
260 return "lzma error: LZMA_STREAM_END";
262 return "lzma error: LZMA_NO_CHECK";
263 case LZMA_UNSUPPORTED_CHECK:
264 return "lzma error: LZMA_UNSUPPORTED_CHECK";
266 return "lzma error: LZMA_GET_CHECK";
268 return "lzma error: LZMA_MEM_ERROR";
269 case LZMA_MEMLIMIT_ERROR:
270 return "lzma error: LZMA_MEMLIMIT_ERROR";
271 case LZMA_FORMAT_ERROR:
272 return "lzma error: LZMA_FORMAT_ERROR";
273 case LZMA_OPTIONS_ERROR:
274 return "lzma error: LZMA_OPTIONS_ERROR";
275 case LZMA_DATA_ERROR:
276 return "lzma error: LZMA_DATA_ERROR";
278 return "lzma error: LZMA_BUF_ERROR";
279 case LZMA_PROG_ERROR:
280 return "lzma error: LZMA_PROG_ERROR";
288 if (
Input.size() < LZMA_STREAM_HEADER_SIZE)
290 "size of xz-compressed blob (%zu bytes) is smaller than the "
291 "LZMA_STREAM_HEADER_SIZE (%zu bytes)",
292 Input.size(),
size_t(LZMA_STREAM_HEADER_SIZE));
295 lzma_stream_flags FooterFlags{};
296 lzma_ret Ret = lzma_stream_footer_decode(
297 &FooterFlags,
Input.take_back(LZMA_STREAM_HEADER_SIZE).data());
300 convertLZMACodeToString(Ret));
303 uint64_t MinSize = FooterFlags.backward_size + 2 * LZMA_STREAM_HEADER_SIZE;
304 if (
Input.size() < MinSize)
306 "xz-compressed buffer size (%zu bytes) too small (required at "
307 "least %" PRIu64
" bytes)",
308 Input.size(), MinSize);
312 lzma_index *Index =
nullptr;
316 Ret = lzma_index_buffer_decode(
317 &Index, &MemLimit,
nullptr,
318 Input.take_back(LZMA_STREAM_HEADER_SIZE + FooterFlags.backward_size)
320 &InPos,
Input.size());
323 convertLZMACodeToString(Ret));
325 return lzma_index_uncompressed_size(Index);
334 if (!UncompressedSize)
337 if (*UncompressedSize > std::numeric_limits<size_t>::max())
339 " bytes) exceeds addressable memory",
344 Output.
resize(
static_cast<size_t>(*UncompressedSize));
348 lzma_ret Ret = lzma_stream_buffer_decode(
349 &MemLimit, 0,
nullptr,
Input.data(), &InPos,
Input.size(),
350 Output.
data(), &OutPos, Output.
size());
351 if (Ret != LZMA_OK) {
354 convertLZMACodeToString(Ret));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define __msan_unpoison(p, size)
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
void truncate(size_type N)
Like resize, but requires that N is less than size().
pointer data()
Return a pointer to the vector's buffer, even if empty().
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI bool isAvailable()
Return true if LLVM was built with LZMA support (LLVM_ENABLE_LZMA).
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
Decompress an xz stream.
LLVM_ABI void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
LLVM_ABI bool isAvailable()
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
LLVM_ABI bool isAvailable()
LLVM_ABI void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression, bool EnableLdm=false)
LLVM_ABI const char * getReasonIfUnsupported(Format F)
LLVM_ABI Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
Format formatFor(DebugCompressionType Type)
LLVM_ABI void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
LogicalResult success(bool IsSuccess=true)
Utility function to generate a LogicalResult.
LLVM_ABI void report_bad_alloc_error(const char *Reason, bool GenCrashDiag=true)
Reports a bad alloc error, calling any user defined bad alloc error handler.