1a3225b04SZachary Turner //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===// 2a3225b04SZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a3225b04SZachary Turner // 7a3225b04SZachary Turner //===----------------------------------------------------------------------===// 8a3225b04SZachary Turner 9a3225b04SZachary Turner #include "llvm/DebugInfo/MSF/MSFError.h" 10a3225b04SZachary Turner #include "llvm/Support/ErrorHandling.h" 119277ce79SSimon Pilgrim #include <string> 12a3225b04SZachary Turner 13a3225b04SZachary Turner using namespace llvm; 14a3225b04SZachary Turner using namespace llvm::msf; 15a3225b04SZachary Turner 16711950c1SBenjamin Kramer namespace { 17a3225b04SZachary Turner // FIXME: This class is only here to support the transition to llvm::Error. It 18a3225b04SZachary Turner // will be removed once this transition is complete. Clients should prefer to 19a3225b04SZachary Turner // deal with the Error value directly, rather than converting to error_code. 20a3225b04SZachary Turner class MSFErrorCategory : public std::error_category { 21a3225b04SZachary Turner public: name() const22990504e6SReid Kleckner const char *name() const noexcept override { return "llvm.msf"; } message(int Condition) const23a3225b04SZachary Turner std::string message(int Condition) const override { 24a3225b04SZachary Turner switch (static_cast<msf_error_code>(Condition)) { 25a3225b04SZachary Turner case msf_error_code::unspecified: 26a3225b04SZachary Turner return "An unknown error has occurred."; 27a3225b04SZachary Turner case msf_error_code::insufficient_buffer: 28a3225b04SZachary Turner return "The buffer is not large enough to read the requested number of " 29a3225b04SZachary Turner "bytes."; 30e4eb6216SChris Davis case msf_error_code::size_overflow_4096: 31ac2226b0SReid Kleckner return "Output data is larger than 4 GiB."; 32e4eb6216SChris Davis case msf_error_code::size_overflow_8192: 33e4eb6216SChris Davis return "Output data is larger than 8 GiB."; 34e4eb6216SChris Davis case msf_error_code::size_overflow_16384: 35e4eb6216SChris Davis return "Output data is larger than 16 GiB."; 36e4eb6216SChris Davis case msf_error_code::size_overflow_32768: 37e4eb6216SChris Davis return "Output data is larger than 32 GiB."; 38a3225b04SZachary Turner case msf_error_code::not_writable: 39a3225b04SZachary Turner return "The specified stream is not writable."; 40a3225b04SZachary Turner case msf_error_code::no_stream: 41a3225b04SZachary Turner return "The specified stream does not exist."; 42a3225b04SZachary Turner case msf_error_code::invalid_format: 43a3225b04SZachary Turner return "The data is in an unexpected format."; 44a3225b04SZachary Turner case msf_error_code::block_in_use: 45a3225b04SZachary Turner return "The block is already in use."; 46a3225b04SZachary Turner } 47a3225b04SZachary Turner llvm_unreachable("Unrecognized msf_error_code"); 48a3225b04SZachary Turner } 49a3225b04SZachary Turner }; 50711950c1SBenjamin Kramer } // namespace 51a3225b04SZachary Turner MSFErrCategory()52*ede60037SNicolai Hähnleconst std::error_category &llvm::msf::MSFErrCategory() { 53*ede60037SNicolai Hähnle static MSFErrorCategory MSFCategory; 54*ede60037SNicolai Hähnle return MSFCategory; 55*ede60037SNicolai Hähnle } 56a3225b04SZachary Turner 576a7efef4SAlexandre Ganea char MSFError::ID; 58