1//===- llvm-objcopy.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_OBJCOPY_OBJCOPY_H 10#define LLVM_TOOLS_OBJCOPY_OBJCOPY_H 11 12#include "llvm/ADT/Twine.h" 13#include "llvm/Support/Compiler.h" 14#include "llvm/Support/Error.h" 15#include "llvm/Support/raw_ostream.h" 16#include <string> 17 18namespace llvm { 19namespace objcopy { 20 21LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message); 22LLVM_ATTRIBUTE_NORETURN extern void error(Error E); 23LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E); 24LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, 25 std::error_code EC); 26 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); 34 logAllUnhandledErrors(EO.takeError(), OS); 35 OS.flush(); 36 error(Buf); 37} 38 39} // end namespace objcopy 40} // end namespace llvm 41 42#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H 43