blob: 6732e410d8e05fd5c7dcaf05c6d1d78b89513677 [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 {
20
Zachary Turner41a9ee92017-10-11 23:54:34 +000021LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
Petr Hosek05a04cb2017-08-01 00:33:58 +000022
23// This is taken from llvm-readobj.
24// [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38)
25template <class T> T unwrapOrError(Expected<T> EO) {
26 if (EO)
27 return *EO;
28 std::string Buf;
29 raw_string_ostream OS(Buf);
30 logAllUnhandledErrors(EO.takeError(), OS, "");
31 OS.flush();
32 error(Buf);
33}
Petr Hosek05a04cb2017-08-01 00:33:58 +000034
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000035} // end namespace llvm
36
37#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H