@@ -69,48 +69,31 @@ struct ErrPtrHash {
6969using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
7070ErrSetT &errors ();
7171
72- struct ol_impl_result_t {
73- ol_impl_result_t (std::nullptr_t ) : Result(OL_SUCCESS) {}
74- ol_impl_result_t (ol_errc_t Code) {
75- if (Code == OL_ERRC_SUCCESS) {
76- Result = nullptr ;
77- } else {
78- auto Err = std::unique_ptr<ol_error_struct_t >(
79- new ol_error_struct_t {Code, nullptr });
80- Result = errors ().emplace (std::move (Err)).first ->get ();
81- }
82- }
83-
84- ol_impl_result_t (ol_errc_t Code, llvm::StringRef Details) {
85- assert (Code != OL_ERRC_SUCCESS);
86- Result = nullptr ;
87- auto DetailsStr = errorStrs ().insert (Details).first ->getKeyData ();
88- auto Err = std::unique_ptr<ol_error_struct_t >(
89- new ol_error_struct_t {Code, DetailsStr});
90- Result = errors ().emplace (std::move (Err)).first ->get ();
91- }
72+ namespace {
73+ ol_errc_t GetErrorCode (std::error_code Code) {
74+ if (Code.category () ==
75+ error::make_error_code (error::ErrorCode::SUCCESS).category ())
76+ return static_cast <ol_errc_t >(Code.value ());
9277
93- static ol_impl_result_t fromError (llvm::Error &&Error) {
94- ol_errc_t ErrCode;
95- llvm::StringRef Details;
96- llvm::handleAllErrors (std::move (Error), [&](llvm::StringError &Err) {
97- ErrCode = GetErrorCode (Err.convertToErrorCode ());
98- Details = errorStrs ().insert (Err.getMessage ()).first ->getKeyData ();
99- });
78+ return OL_ERRC_UNKNOWN;
79+ }
80+ } // namespace
10081
101- return ol_impl_result_t {ErrCode, Details};
82+ inline ol_result_t llvmErrorToOffloadError (llvm::Error &&Err) {
83+ if (!Err) {
84+ // No error
85+ return nullptr ;
10286 }
10387
104- operator ol_result_t () { return Result; }
88+ ol_errc_t ErrCode;
89+ llvm::StringRef Details;
10590
106- private:
107- static ol_errc_t GetErrorCode (std::error_code Code) {
108- if (Code.category () ==
109- error::make_error_code (error::ErrorCode::SUCCESS).category ()) {
110- return static_cast <ol_errc_t >(Code.value ());
111- }
112- return OL_ERRC_UNKNOWN;
113- }
91+ llvm::handleAllErrors (std::move (Err), [&](llvm::StringError &Err) {
92+ ErrCode = GetErrorCode (Err.convertToErrorCode ());
93+ Details = errorStrs ().insert (Err.getMessage ()).first ->getKeyData ();
94+ });
11495
115- ol_result_t Result;
116- };
96+ auto NewErr = std::unique_ptr<ol_error_struct_t >(
97+ new ol_error_struct_t {ErrCode, Details.data ()});
98+ return errors ().emplace (std::move (NewErr)).first ->get ();
99+ }
0 commit comments