Clement Courbet | 03a3d29 | 2019-09-30 13:53:50 +0000 | [diff] [blame] | 1 | //===-- Error.h -------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H |
| 10 | #define LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H |
| 11 | |
| 12 | #include "llvm/ADT/Twine.h" |
| 13 | #include "llvm/Support/Error.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | namespace exegesis { |
| 17 | |
| 18 | // A class representing failures that happened within llvm-exegesis, they are |
| 19 | // used to report informations to the user. |
| 20 | class Failure : public StringError { |
| 21 | public: |
| 22 | Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {} |
| 23 | }; |
| 24 | |
Miloš Stojanović | 446268a | 2020-02-06 17:08:05 +0100 | [diff] [blame] | 25 | // A class representing failures that happened during clustering calculations. |
| 26 | class ClusteringError : public ErrorInfo<ClusteringError> { |
| 27 | public: |
| 28 | static char ID; |
Miloš Stojanović | 2052927 | 2020-02-07 13:45:10 +0100 | [diff] [blame] | 29 | ClusteringError(const Twine &S) : Msg(S.str()) {} |
Miloš Stojanović | 446268a | 2020-02-06 17:08:05 +0100 | [diff] [blame] | 30 | |
| 31 | void log(raw_ostream &OS) const override; |
| 32 | |
| 33 | std::error_code convertToErrorCode() const override; |
Miloš Stojanović | 2052927 | 2020-02-07 13:45:10 +0100 | [diff] [blame] | 34 | |
Miloš Stojanović | 446268a | 2020-02-06 17:08:05 +0100 | [diff] [blame] | 35 | private: |
Miloš Stojanović | 2052927 | 2020-02-07 13:45:10 +0100 | [diff] [blame] | 36 | std::string Msg; |
| 37 | }; |
| 38 | |
| 39 | // A class representing failures that happened during snippet execution. |
| 40 | // Instead of terminating the program crashes are logged into the output. |
| 41 | class SnippetCrash : public ErrorInfo<SnippetCrash> { |
| 42 | public: |
| 43 | static char ID; |
| 44 | SnippetCrash(const Twine &S) : Msg(S.str()) {} |
| 45 | |
| 46 | void log(raw_ostream &OS) const override; |
| 47 | |
| 48 | std::error_code convertToErrorCode() const override; |
| 49 | |
| 50 | private: |
| 51 | std::string Msg; |
Miloš Stojanović | 446268a | 2020-02-06 17:08:05 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
Clement Courbet | 03a3d29 | 2019-09-30 13:53:50 +0000 | [diff] [blame] | 54 | } // namespace exegesis |
| 55 | } // namespace llvm |
| 56 | |
| 57 | #endif |