blob: d8edf3e29ee097484e6f360e391287134d5548cf [file] [log] [blame]
Petr Hosek05a04cb2017-08-01 00:33:58 +00001//===- llvm-objcopy.h -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Eugene Zelenko0ad18f82017-11-01 21:16:06 +00009
10#ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H
11#define LLVM_TOOLS_OBJCOPY_OBJCOPY_H
Petr Hosek05a04cb2017-08-01 00:33:58 +000012
13#include "llvm/ADT/Twine.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000014#include "llvm/Support/Compiler.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000015#include "llvm/Support/Error.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000016#include "llvm/Support/raw_ostream.h"
17#include <string>
Petr Hosek05a04cb2017-08-01 00:33:58 +000018
19namespace llvm {
Puyan Lotfi0f5d5fa2018-07-18 00:10:51 +000020namespace objcopy {
Petr Hosek05a04cb2017-08-01 00:33:58 +000021
Zachary Turner41a9ee92017-10-11 23:54:34 +000022LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
Jake Ehrlich76e91102018-01-25 22:46:17 +000023LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
24LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File,
25 std::error_code EC);
Petr Hosek05a04cb2017-08-01 00:33:58 +000026
27// This is taken from llvm-readobj.
28// [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38)
29template <class T> T unwrapOrError(Expected<T> EO) {
30 if (EO)
31 return *EO;
32 std::string Buf;
33 raw_string_ostream OS(Buf);
Jonas Devlieghere45eb84f2018-11-11 01:46:03 +000034 logAllUnhandledErrors(EO.takeError(), OS);
Petr Hosek05a04cb2017-08-01 00:33:58 +000035 OS.flush();
36 error(Buf);
37}
Petr Hosek05a04cb2017-08-01 00:33:58 +000038
Puyan Lotfi0f5d5fa2018-07-18 00:10:51 +000039} // end namespace objcopy
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000040} // end namespace llvm
41
42#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H