10b57cec5SDimitry Andric //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "llvm/DebugInfo/MSF/MSFError.h" 100b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h" 11fe6060f1SDimitry Andric #include <string> 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric using namespace llvm; 140b57cec5SDimitry Andric using namespace llvm::msf; 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric namespace { 170b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 180b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to 190b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code. 200b57cec5SDimitry Andric class MSFErrorCategory : public std::error_category { 210b57cec5SDimitry Andric public: name() const220b57cec5SDimitry Andric const char *name() const noexcept override { return "llvm.msf"; } message(int Condition) const230b57cec5SDimitry Andric std::string message(int Condition) const override { 240b57cec5SDimitry Andric switch (static_cast<msf_error_code>(Condition)) { 250b57cec5SDimitry Andric case msf_error_code::unspecified: 260b57cec5SDimitry Andric return "An unknown error has occurred."; 270b57cec5SDimitry Andric case msf_error_code::insufficient_buffer: 280b57cec5SDimitry Andric return "The buffer is not large enough to read the requested number of " 290b57cec5SDimitry Andric "bytes."; 300eae32dcSDimitry Andric case msf_error_code::size_overflow_4096: 31fe6060f1SDimitry Andric return "Output data is larger than 4 GiB."; 320eae32dcSDimitry Andric case msf_error_code::size_overflow_8192: 330eae32dcSDimitry Andric return "Output data is larger than 8 GiB."; 340eae32dcSDimitry Andric case msf_error_code::size_overflow_16384: 350eae32dcSDimitry Andric return "Output data is larger than 16 GiB."; 360eae32dcSDimitry Andric case msf_error_code::size_overflow_32768: 370eae32dcSDimitry Andric return "Output data is larger than 32 GiB."; 380b57cec5SDimitry Andric case msf_error_code::not_writable: 390b57cec5SDimitry Andric return "The specified stream is not writable."; 400b57cec5SDimitry Andric case msf_error_code::no_stream: 410b57cec5SDimitry Andric return "The specified stream does not exist."; 420b57cec5SDimitry Andric case msf_error_code::invalid_format: 430b57cec5SDimitry Andric return "The data is in an unexpected format."; 440b57cec5SDimitry Andric case msf_error_code::block_in_use: 450b57cec5SDimitry Andric return "The block is already in use."; 46*06c3fb27SDimitry Andric case msf_error_code::stream_directory_overflow: 47*06c3fb27SDimitry Andric return "PDB stream directory too large."; 480b57cec5SDimitry Andric } 490b57cec5SDimitry Andric llvm_unreachable("Unrecognized msf_error_code"); 500b57cec5SDimitry Andric } 510b57cec5SDimitry Andric }; 520b57cec5SDimitry Andric } // namespace 530b57cec5SDimitry Andric MSFErrCategory()54753f127fSDimitry Andricconst std::error_category &llvm::msf::MSFErrCategory() { 55753f127fSDimitry Andric static MSFErrorCategory MSFCategory; 56753f127fSDimitry Andric return MSFCategory; 57753f127fSDimitry Andric } 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric char MSFError::ID; 60