summaryrefslogtreecommitdiffstats
path: root/lld/lib/Core/Error.cpp
blob: 32496b91f474306eaa30e78688b0541d8af52aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//===- Error.cpp - system_error extensions for lld --------------*- C++ -*-===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lld/Core/Error.h"

#include "llvm/Support/ErrorHandling.h"

using namespace lld;

class _NativeReaderErrorCategory : public llvm::_do_message {
public:
  const char* name() const override {
    return "lld.native.reader";
  }

  std::string message(int ev) const override {
    if (NativeReaderError(ev) == NativeReaderError::success)
      return "Success";
    if (NativeReaderError(ev) == NativeReaderError::unknown_file_format)
      return "Unknown file format";
    if (NativeReaderError(ev) == NativeReaderError::file_too_short)
      return "file truncated";
    if (NativeReaderError(ev) == NativeReaderError::file_malformed)
      return "file malformed";
    if (NativeReaderError(ev) == NativeReaderError::memory_error)
      return "out of memory";
    if (NativeReaderError(ev) == NativeReaderError::unknown_chunk_type)
      return "unknown chunk type";
    llvm_unreachable("An enumerator of NativeReaderError does not have a "
                     "message defined.");
  }

  llvm::error_condition default_error_condition(int ev) const override {
    if (NativeReaderError(ev) == NativeReaderError::success)
      return llvm::errc::success;
    return llvm::errc::invalid_argument;
  }
};

const llvm::error_category &lld::native_reader_category() {
  static _NativeReaderErrorCategory o;
  return o;
}

class _YamlReaderErrorCategory : public llvm::_do_message {
public:
  const char* name() const override {
    return "lld.yaml.reader";
  }

  std::string message(int ev) const override {
    if (YamlReaderError(ev) == YamlReaderError::success)
      return "Success";
    if (YamlReaderError(ev) == YamlReaderError::unknown_keyword)
      return "Unknown keyword found in yaml file";
    if (YamlReaderError(ev) == YamlReaderError::illegal_value)
      return "Bad value found in yaml file";
    llvm_unreachable("An enumerator of YamlReaderError does not have a "
                     "message defined.");
  }

  llvm::error_condition default_error_condition(int ev) const override {
    if (YamlReaderError(ev) == YamlReaderError::success)
      return llvm::errc::success;
    return llvm::errc::invalid_argument;
  }
};

const llvm::error_category &lld::YamlReaderCategory() {
  static _YamlReaderErrorCategory o;
  return o;
}

class _LinkerScriptReaderErrorCategory : public llvm::_do_message {
public:
  const char *name() const override { return "lld.linker-script.reader"; }

  std::string message(int ev) const override {
    LinkerScriptReaderError e = LinkerScriptReaderError(ev);
    if (e == LinkerScriptReaderError::success)
      return "Success";
    if (e == LinkerScriptReaderError::parse_error)
      return "Error parsing linker script";
    llvm_unreachable(
        "An enumerator of LinkerScriptReaderError does not have a "
        "message defined.");
  }

  llvm::error_condition default_error_condition(int ev) const override {
    LinkerScriptReaderError e = LinkerScriptReaderError(ev);
    if (e == LinkerScriptReaderError::success)
      return llvm::errc::success;
    return llvm::errc::invalid_argument;
  }
};

const llvm::error_category &lld::LinkerScriptReaderCategory() {
  static _LinkerScriptReaderErrorCategory o;
  return o;
}

class _InputGraphErrorCategory : public llvm::_do_message {
public:
  const char *name() const override { return "lld.inputGraph.parse"; }

  std::string message(int ev) const override {
    if (InputGraphError(ev) == InputGraphError::success)
      return "Success";
    llvm_unreachable("An enumerator of InputGraphError does not have a "
                     "message defined.");
  }

  llvm::error_condition default_error_condition(int ev) const override {
    if (InputGraphError(ev) == InputGraphError::success)
      return llvm::errc::success;
    return llvm::errc::invalid_argument;
  }
};

const llvm::error_category &lld::InputGraphErrorCategory() {
  static _InputGraphErrorCategory i;
  return i;
}

class _ReaderErrorCategory : public llvm::_do_message {
public:
  const char *name() const override { return "lld.inputGraph.parse"; }

  std::string message(int ev) const override {
    if (ReaderError(ev) == ReaderError::success)
      return "Success";
    else if (ReaderError(ev) == ReaderError::unknown_file_format)
      return "File format for the input file is not recognized by this flavor";

    llvm_unreachable("An enumerator of ReaderError does not have a "
                     "message defined.");
  }

  llvm::error_condition default_error_condition(int ev) const override {
    if (ReaderError(ev) == ReaderError::success)
      return llvm::errc::success;
    return llvm::errc::invalid_argument;
  }
};

const llvm::error_category &lld::ReaderErrorCategory() {
  static _ReaderErrorCategory i;
  return i;
}
OpenPOWER on IntegriCloud