xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-dwarfutil/Error.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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_DWARFUTIL_ERROR_H
10 #define LLVM_TOOLS_LLVM_DWARFUTIL_ERROR_H
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Support/Error.h"
18 #include "llvm/Support/Format.h"
19 #include "llvm/Support/WithColor.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 namespace llvm {
23 namespace dwarfutil {
24 
25 inline void error(Error Err, StringRef Prefix = "") {
26   handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) {
27     WithColor::error(errs(), Prefix) << Info.message() << '\n';
28   });
29   std::exit(EXIT_FAILURE);
30 }
31 
32 inline void warning(const Twine &Message, StringRef Prefix = "") {
33   WithColor::warning(errs(), Prefix) << Message << '\n';
34 }
35 
36 inline void verbose(const Twine &Message, bool Verbose) {
37   if (Verbose)
38     outs() << Message << '\n';
39 }
40 
41 } // end of namespace dwarfutil
42 } // end of namespace llvm
43 
44 #endif // LLVM_TOOLS_LLVM_DWARFUTIL_ERROR_H
45