A new ErrorCode enumeration is present in PluginInterface which can be used when returning an llvm::Error from offload and PluginInterface functions. This enum must be kept up to sync with liboffload's ol_errc_t enum, so both are automatically generated from liboffload's enum definition. Some error codes have also been shuffled around to allow for future work. Note that this patch only adds the machinery; actual error codes will be added in a future patch. ~~Depends on #137339 , please ignore first commit of this MR.~~ This has been merged.
52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
//===- OffloadError.h - Definition of error class -------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H
|
|
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H
|
|
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
namespace error {
|
|
|
|
enum class ErrorCode {
|
|
#define OFFLOAD_ERRC(Name, _, Value) Name = Value,
|
|
#include "Shared/OffloadErrcodes.inc"
|
|
#undef OFFLOAD_ERRC
|
|
};
|
|
|
|
} // namespace error
|
|
|
|
namespace std {
|
|
template <> struct is_error_code_enum<error::ErrorCode> : std::true_type {};
|
|
} // namespace std
|
|
|
|
namespace error {
|
|
|
|
const std::error_category &OffloadErrCategory();
|
|
|
|
inline std::error_code make_error_code(ErrorCode E) {
|
|
return std::error_code(static_cast<int>(E), OffloadErrCategory());
|
|
}
|
|
|
|
/// Base class for errors originating in DIA SDK, e.g. COM calls
|
|
class OffloadError : public llvm::ErrorInfo<OffloadError, llvm::StringError> {
|
|
public:
|
|
using ErrorInfo<OffloadError, StringError>::ErrorInfo;
|
|
|
|
OffloadError(const llvm::Twine &S) : ErrorInfo(S, ErrorCode::UNKNOWN) {}
|
|
|
|
// The definition for this resides in the plugin static library
|
|
static char ID;
|
|
};
|
|
} // namespace error
|
|
|
|
#endif
|