xref: /openbsd-src/gnu/llvm/llvm/tools/llvm-exegesis/lib/Error.h (revision 097a140d792de8b2bbe59ad827d39eabf9b4280a)
109467b48Spatrick //===-- Error.h -------------------------------------------------*- C++ -*-===//
209467b48Spatrick //
309467b48Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
409467b48Spatrick // See https://llvm.org/LICENSE.txt for license information.
509467b48Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
609467b48Spatrick //
709467b48Spatrick //===----------------------------------------------------------------------===//
809467b48Spatrick 
909467b48Spatrick #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
1009467b48Spatrick #define LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
1109467b48Spatrick 
1209467b48Spatrick #include "llvm/ADT/Twine.h"
1309467b48Spatrick #include "llvm/Support/Error.h"
1409467b48Spatrick 
1509467b48Spatrick namespace llvm {
1609467b48Spatrick namespace exegesis {
1709467b48Spatrick 
1809467b48Spatrick // A class representing failures that happened within llvm-exegesis, they are
1909467b48Spatrick // used to report informations to the user.
2009467b48Spatrick class Failure : public StringError {
2109467b48Spatrick public:
Failure(const Twine & S)2209467b48Spatrick   Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {}
2309467b48Spatrick };
2409467b48Spatrick 
25*097a140dSpatrick // A class representing failures that happened during clustering calculations.
26*097a140dSpatrick class ClusteringError : public ErrorInfo<ClusteringError> {
27*097a140dSpatrick public:
28*097a140dSpatrick   static char ID;
ClusteringError(const Twine & S)29*097a140dSpatrick   ClusteringError(const Twine &S) : Msg(S.str()) {}
30*097a140dSpatrick 
31*097a140dSpatrick   void log(raw_ostream &OS) const override;
32*097a140dSpatrick 
33*097a140dSpatrick   std::error_code convertToErrorCode() const override;
34*097a140dSpatrick 
35*097a140dSpatrick private:
36*097a140dSpatrick   std::string Msg;
37*097a140dSpatrick };
38*097a140dSpatrick 
39*097a140dSpatrick // A class representing failures that happened during snippet execution.
40*097a140dSpatrick // Instead of terminating the program crashes are logged into the output.
41*097a140dSpatrick class SnippetCrash : public ErrorInfo<SnippetCrash> {
42*097a140dSpatrick public:
43*097a140dSpatrick   static char ID;
SnippetCrash(const Twine & S)44*097a140dSpatrick   SnippetCrash(const Twine &S) : Msg(S.str()) {}
45*097a140dSpatrick 
46*097a140dSpatrick   void log(raw_ostream &OS) const override;
47*097a140dSpatrick 
48*097a140dSpatrick   std::error_code convertToErrorCode() const override;
49*097a140dSpatrick 
50*097a140dSpatrick private:
51*097a140dSpatrick   std::string Msg;
52*097a140dSpatrick };
53*097a140dSpatrick 
5409467b48Spatrick } // namespace exegesis
5509467b48Spatrick } // namespace llvm
5609467b48Spatrick 
5709467b48Spatrick #endif
58