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
15namespace llvm {
16namespace exegesis {
17
18// A class representing failures that happened within llvm-exegesis, they are
19// used to report informations to the user.
20class Failure : public StringError {
21public:
22 Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {}
23};
24
25// A class representing failures that happened during clustering calculations.
26class ClusteringError : public ErrorInfo<ClusteringError> {
27public:
28 static char ID;
29 ClusteringError(const Twine &S) : Msg(S.str()) {}
30
31 void log(raw_ostream &OS) const override;
32
33 std::error_code convertToErrorCode() const override;
34
35private:
36 std::string Msg;
37};
38
39// A class representing a non-descript snippet execution failure. This class
40// is designed to sub-classed into more specific failures that contain
41// additional data about the specific error that they represent. Instead of
42// halting the program, the errors are reported in the output.
43class SnippetExecutionFailure : public ErrorInfo<SnippetExecutionFailure> {
44public:
45 static char ID;
46
47 std::error_code convertToErrorCode() const override;
48};
49
50// A class representing specifically segmentation faults that happen during
51// snippet execution.
52class SnippetSegmentationFault : public SnippetExecutionFailure {
53public:
54 static char ID;
55 SnippetSegmentationFault(intptr_t SegFaultAddress)
56 : Address(SegFaultAddress){};
57
58 intptr_t getAddress() { return Address; }
59
60 void log(raw_ostream &OS) const override;
61
62private:
63 intptr_t Address;
64};
65
66// A class representing all other non-specific failures that happen during
67// snippet execution.
68class SnippetSignal : public SnippetExecutionFailure {
69public:
70 static char ID;
71 SnippetSignal(int Signal) : SignalNumber(Signal){};
72
73 void log(raw_ostream &OS) const override;
74
75private:
76 int SignalNumber;
77};
78
79} // namespace exegesis
80} // namespace llvm
81
82#endif
83