Error.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
  9. #define LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
  10. #include "llvm/ADT/Twine.h"
  11. #include "llvm/Support/Error.h"
  12. namespace llvm {
  13. namespace exegesis {
  14. // A class representing failures that happened within llvm-exegesis, they are
  15. // used to report informations to the user.
  16. class Failure : public StringError {
  17. public:
  18. Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {}
  19. };
  20. // A class representing failures that happened during clustering calculations.
  21. class ClusteringError : public ErrorInfo<ClusteringError> {
  22. public:
  23. static char ID;
  24. ClusteringError(const Twine &S) : Msg(S.str()) {}
  25. void log(raw_ostream &OS) const override;
  26. std::error_code convertToErrorCode() const override;
  27. private:
  28. std::string Msg;
  29. };
  30. // A class representing failures that happened during snippet execution.
  31. // Instead of terminating the program crashes are logged into the output.
  32. class SnippetCrash : public ErrorInfo<SnippetCrash> {
  33. public:
  34. static char ID;
  35. SnippetCrash(const Twine &S) : Msg(S.str()) {}
  36. void log(raw_ostream &OS) const override;
  37. std::error_code convertToErrorCode() const override;
  38. private:
  39. std::string Msg;
  40. };
  41. } // namespace exegesis
  42. } // namespace llvm
  43. #endif