Index: include/llvm/Support/Compression.h =================================================================== --- include/llvm/Support/Compression.h +++ include/llvm/Support/Compression.h @@ -52,6 +52,8 @@ uint32_t crc32(StringRef Buffer); +StringRef toString(Status Stat); + } // End of namespace zlib } // End of namespace llvm Index: lib/Support/Compression.cpp =================================================================== --- lib/Support/Compression.cpp +++ lib/Support/Compression.cpp @@ -108,3 +108,21 @@ } #endif +StringRef zlib::toString(zlib::Status Stat) { + switch (Stat) { + case zlib::StatusOK: + return ""; + case zlib::StatusUnsupported: + return "zlib is unavailable"; + case zlib::StatusOutOfMemory: + return "there was not enough memory"; + case zlib::StatusBufferTooShort: + return "there was not enough room in the output buffer"; + case zlib::StatusInvalidArg: + return "invalid input parameter"; + case zlib::StatusInvalidData: + return "data was corrupted or incomplete"; + default: + llvm_unreachable("status unknown"); + } +} Index: unittests/Support/CompressionTest.cpp =================================================================== --- unittests/Support/CompressionTest.cpp +++ unittests/Support/CompressionTest.cpp @@ -67,4 +67,15 @@ #endif +TEST(CompressionTest, ZlibMessages) { + EXPECT_EQ("", zlib::toString(zlib::StatusOK)); + EXPECT_EQ("zlib is unavailable", zlib::toString(zlib::StatusUnsupported)); + EXPECT_EQ("there was not enough memory", + zlib::toString(zlib::StatusOutOfMemory)); + EXPECT_EQ("there was not enough room in the output buffer", + zlib::toString(zlib::StatusBufferTooShort)); + EXPECT_EQ("invalid input parameter", zlib::toString(zlib::StatusInvalidArg)); + EXPECT_EQ("data was corrupted or incomplete", + zlib::toString(zlib::StatusInvalidData)); +} }