diff options
Diffstat (limited to 'bolt/lib/Core/BinaryContext.cpp')
-rw-r--r-- | bolt/lib/Core/BinaryContext.cpp | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 36745580217e..36092e3a945f 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -33,6 +33,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" #include "llvm/Support/Regex.h" #include <algorithm> #include <functional> @@ -115,7 +116,7 @@ BinaryContext::~BinaryContext() { /// Create BinaryContext for a given architecture \p ArchName and /// triple \p TripleName. -std::unique_ptr<BinaryContext> +Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC, std::unique_ptr<DWARFContext> DwCtx) { StringRef ArchName = ""; @@ -131,8 +132,8 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC, "+fullfp16,+spe,+fuse-aes,+rcpc"; break; default: - errs() << "BOLT-ERROR: Unrecognized machine in ELF file.\n"; - return nullptr; + return createStringError(std::errc::not_supported, + "BOLT-ERROR: Unrecognized machine in ELF file"); } auto TheTriple = std::make_unique<Triple>(File->makeTriple()); @@ -141,39 +142,37 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC, std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(std::string(ArchName), *TheTriple, Error); - if (!TheTarget) { - errs() << "BOLT-ERROR: " << Error; - return nullptr; - } + if (!TheTarget) + return createStringError(make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: ", Error)); std::unique_ptr<const MCRegisterInfo> MRI( TheTarget->createMCRegInfo(TripleName)); - if (!MRI) { - errs() << "BOLT-ERROR: no register info for target " << TripleName << "\n"; - return nullptr; - } + if (!MRI) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no register info for target ", TripleName)); // Set up disassembler. std::unique_ptr<const MCAsmInfo> AsmInfo( TheTarget->createMCAsmInfo(*MRI, TripleName, MCTargetOptions())); - if (!AsmInfo) { - errs() << "BOLT-ERROR: no assembly info for target " << TripleName << "\n"; - return nullptr; - } + if (!AsmInfo) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no assembly info for target ", TripleName)); std::unique_ptr<const MCSubtargetInfo> STI( TheTarget->createMCSubtargetInfo(TripleName, "", FeaturesStr)); - if (!STI) { - errs() << "BOLT-ERROR: no subtarget info for target " << TripleName << "\n"; - return nullptr; - } + if (!STI) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no subtarget info for target ", TripleName)); std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo()); - if (!MII) { - errs() << "BOLT-ERROR: no instruction info for target " << TripleName - << "\n"; - return nullptr; - } + if (!MII) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no instruction info for target ", TripleName)); std::unique_ptr<MCContext> Ctx( new MCContext(*TheTriple, AsmInfo.get(), MRI.get(), STI.get())); @@ -198,28 +197,27 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC, std::unique_ptr<MCDisassembler> DisAsm( TheTarget->createMCDisassembler(*STI, *Ctx)); - if (!DisAsm) { - errs() << "BOLT-ERROR: no disassembler for target " << TripleName << "\n"; - return nullptr; - } + if (!DisAsm) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no disassembler info for target ", TripleName)); std::unique_ptr<const MCInstrAnalysis> MIA( TheTarget->createMCInstrAnalysis(MII.get())); - if (!MIA) { - errs() << "BOLT-ERROR: failed to create instruction analysis for target" - << TripleName << "\n"; - return nullptr; - } + if (!MIA) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: failed to create instruction analysis for target ", + TripleName)); int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); std::unique_ptr<MCInstPrinter> InstructionPrinter( TheTarget->createMCInstPrinter(*TheTriple, AsmPrinterVariant, *AsmInfo, *MII, *MRI)); - if (!InstructionPrinter) { - errs() << "BOLT-ERROR: no instruction printer for target " << TripleName - << '\n'; - return nullptr; - } + if (!InstructionPrinter) + return createStringError( + make_error_code(std::errc::not_supported), + Twine("BOLT-ERROR: no instruction printer for target ", TripleName)); InstructionPrinter->setPrintImmHex(true); std::unique_ptr<MCCodeEmitter> MCE( |