1b915e9e0SDimitry Andric //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===// 2b915e9e0SDimitry Andric // 3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b915e9e0SDimitry Andric // 7b915e9e0SDimitry Andric //===----------------------------------------------------------------------===// 8b915e9e0SDimitry Andric 9b915e9e0SDimitry Andric #include "llvm/DebugInfo/MSF/MSFError.h" 10b915e9e0SDimitry Andric #include "llvm/Support/ErrorHandling.h" 11344a3780SDimitry Andric #include <string> 12b915e9e0SDimitry Andric 13b915e9e0SDimitry Andric using namespace llvm; 14b915e9e0SDimitry Andric using namespace llvm::msf; 15b915e9e0SDimitry Andric 16e6d15924SDimitry Andric namespace { 17b915e9e0SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 18b915e9e0SDimitry Andric // will be removed once this transition is complete. Clients should prefer to 19b915e9e0SDimitry Andric // deal with the Error value directly, rather than converting to error_code. 20b915e9e0SDimitry Andric class MSFErrorCategory : public std::error_category { 21b915e9e0SDimitry Andric public: name() const22b915e9e0SDimitry Andric const char *name() const noexcept override { return "llvm.msf"; } message(int Condition) const23b915e9e0SDimitry Andric std::string message(int Condition) const override { 24b915e9e0SDimitry Andric switch (static_cast<msf_error_code>(Condition)) { 25b915e9e0SDimitry Andric case msf_error_code::unspecified: 26b915e9e0SDimitry Andric return "An unknown error has occurred."; 27b915e9e0SDimitry Andric case msf_error_code::insufficient_buffer: 28b915e9e0SDimitry Andric return "The buffer is not large enough to read the requested number of " 29b915e9e0SDimitry Andric "bytes."; 3077fc4c14SDimitry Andric case msf_error_code::size_overflow_4096: 31344a3780SDimitry Andric return "Output data is larger than 4 GiB."; 3277fc4c14SDimitry Andric case msf_error_code::size_overflow_8192: 3377fc4c14SDimitry Andric return "Output data is larger than 8 GiB."; 3477fc4c14SDimitry Andric case msf_error_code::size_overflow_16384: 3577fc4c14SDimitry Andric return "Output data is larger than 16 GiB."; 3677fc4c14SDimitry Andric case msf_error_code::size_overflow_32768: 3777fc4c14SDimitry Andric return "Output data is larger than 32 GiB."; 38b915e9e0SDimitry Andric case msf_error_code::not_writable: 39b915e9e0SDimitry Andric return "The specified stream is not writable."; 40b915e9e0SDimitry Andric case msf_error_code::no_stream: 41b915e9e0SDimitry Andric return "The specified stream does not exist."; 42b915e9e0SDimitry Andric case msf_error_code::invalid_format: 43b915e9e0SDimitry Andric return "The data is in an unexpected format."; 44b915e9e0SDimitry Andric case msf_error_code::block_in_use: 45b915e9e0SDimitry Andric return "The block is already in use."; 467fa27ce4SDimitry Andric case msf_error_code::stream_directory_overflow: 477fa27ce4SDimitry Andric return "PDB stream directory too large."; 48b915e9e0SDimitry Andric } 49b915e9e0SDimitry Andric llvm_unreachable("Unrecognized msf_error_code"); 50b915e9e0SDimitry Andric } 51b915e9e0SDimitry Andric }; 52e6d15924SDimitry Andric } // namespace 53b915e9e0SDimitry Andric MSFErrCategory()541f917f69SDimitry Andricconst std::error_category &llvm::msf::MSFErrCategory() { 551f917f69SDimitry Andric static MSFErrorCategory MSFCategory; 561f917f69SDimitry Andric return MSFCategory; 571f917f69SDimitry Andric } 58b915e9e0SDimitry Andric 59d8e91e46SDimitry Andric char MSFError::ID; 60