blob: 18a789ca1f83bbe030fd05953366d43f79ab1dae [file] [log] [blame]
Petr Hosek05a04cb2017-08-01 00:33:58 +00001//===- llvm-objcopy.h -------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Petr Hosek05a04cb2017-08-01 00:33:58 +00006//
7//===----------------------------------------------------------------------===//
Eugene Zelenko0ad18f82017-11-01 21:16:06 +00008
9#ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H
10#define LLVM_TOOLS_OBJCOPY_OBJCOPY_H
Petr Hosek05a04cb2017-08-01 00:33:58 +000011
12#include "llvm/ADT/Twine.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000013#include "llvm/Support/Compiler.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000014#include "llvm/Support/Error.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000015#include "llvm/Support/raw_ostream.h"
16#include <string>
Petr Hosek05a04cb2017-08-01 00:33:58 +000017
18namespace llvm {
Puyan Lotfi0f5d5fa2018-07-18 00:10:51 +000019namespace objcopy {
Petr Hosek05a04cb2017-08-01 00:33:58 +000020
Zachary Turner41a9ee92017-10-11 23:54:34 +000021LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
Jordan Rupprecht881cae72019-01-22 23:49:16 +000022LLVM_ATTRIBUTE_NORETURN extern void error(Error E);
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