1*7330f729Sjoerg //===- Error.cpp - system_error extensions for llvm-cxxdump -----*- C++ -*-===// 2*7330f729Sjoerg // 3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information. 5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*7330f729Sjoerg // 7*7330f729Sjoerg //===----------------------------------------------------------------------===// 8*7330f729Sjoerg // 9*7330f729Sjoerg // This defines a new error_category for the llvm-cxxdump tool. 10*7330f729Sjoerg // 11*7330f729Sjoerg //===----------------------------------------------------------------------===// 12*7330f729Sjoerg 13*7330f729Sjoerg #include "Error.h" 14*7330f729Sjoerg #include "llvm/Support/ErrorHandling.h" 15*7330f729Sjoerg 16*7330f729Sjoerg using namespace llvm; 17*7330f729Sjoerg 18*7330f729Sjoerg namespace { 19*7330f729Sjoerg // FIXME: This class is only here to support the transition to llvm::Error. It 20*7330f729Sjoerg // will be removed once this transition is complete. Clients should prefer to 21*7330f729Sjoerg // deal with the Error value directly, rather than converting to error_code. 22*7330f729Sjoerg class cxxdump_error_category : public std::error_category { 23*7330f729Sjoerg public: name() const24*7330f729Sjoerg const char *name() const noexcept override { return "llvm.cxxdump"; } message(int ev) const25*7330f729Sjoerg std::string message(int ev) const override { 26*7330f729Sjoerg switch (static_cast<cxxdump_error>(ev)) { 27*7330f729Sjoerg case cxxdump_error::success: 28*7330f729Sjoerg return "Success"; 29*7330f729Sjoerg case cxxdump_error::file_not_found: 30*7330f729Sjoerg return "No such file."; 31*7330f729Sjoerg case cxxdump_error::unrecognized_file_format: 32*7330f729Sjoerg return "Unrecognized file type."; 33*7330f729Sjoerg } 34*7330f729Sjoerg llvm_unreachable( 35*7330f729Sjoerg "An enumerator of cxxdump_error does not have a message defined."); 36*7330f729Sjoerg } 37*7330f729Sjoerg }; 38*7330f729Sjoerg } // namespace 39*7330f729Sjoerg 40*7330f729Sjoerg namespace llvm { cxxdump_category()41*7330f729Sjoergconst std::error_category &cxxdump_category() { 42*7330f729Sjoerg static cxxdump_error_category o; 43*7330f729Sjoerg return o; 44*7330f729Sjoerg } 45*7330f729Sjoerg } // namespace llvm 46