// SPDX-License-Identifier: GPL-3.0-or-later #ifndef RCC_SUPPORT_ERROR_H #define RCC_SUPPORT_ERROR_H #include #include #include #include #include namespace rcc { enum class ErrorCode : std::uint8_t { InvalidArgument, ParseError, VerificationError, Unsupported, RegisterAllocationFailed, IoError, InternalError, FrameLayoutFailed, SchedulingFailed, BranchRelaxationFailed, PseudoExpansionFailed, FinalEncodabilityFailed, CFGOptimizationFailed, AssemblyLoweringFailed, InstructionEncodingFailed, FixupApplicationFailed, RelocationFailed, ObjectWritingFailed, InvalidInvocation, ManifestError, CacheMiss, ReproducerError, ReductionFailed, FuzzingFailure, }; [[nodiscard]] std::string_view getErrorCodeName(ErrorCode Code) noexcept; class Error final { public: Error(ErrorCode Code, std::string Message); [[nodiscard]] ErrorCode code() const noexcept { return Code; } [[nodiscard]] std::string_view message() const noexcept { return Message; } private: ErrorCode Code; std::string Message; }; [[nodiscard]] Error withErrorContext(const Error &Failure, std::string Context); template using Expected = std::expected; [[nodiscard]] inline std::unexpected makeUnexpected(ErrorCode Code, std::string Message) { return std::unexpected(Error(Code, std::move(Message))); } } // namespace rcc #endif // RCC_SUPPORT_ERROR_H