blob: 46d8339576c95c03f1c5e5ed3322071b4b573f35 [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);
Jake Ehrlich76e91102018-01-25 22:46:17 +000022LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
23LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File,
24 std::error_code EC);
Petr Hosek05a04cb2017-08-01 00:33:58 +000025
26// This is taken from llvm-readobj.
27// [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38)
28template <class T> T unwrapOrError(Expected<T> EO) {
29 if (EO)
30 return *EO;
31 std::string Buf;
32 raw_string_ostream OS(Buf);
Jonas Devlieghere45eb84f2018-11-11 01:46:03 +000033 logAllUnhandledErrors(EO.takeError(), OS);
Petr Hosek05a04cb2017-08-01 00:33:58 +000034 OS.flush();
35 error(Buf);
36}
Petr Hosek05a04cb2017-08-01 00:33:58 +000037
Puyan Lotfi0f5d5fa2018-07-18 00:10:51 +000038} // end namespace objcopy
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000039} // end namespace llvm
40
41#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H