diff options
Diffstat (limited to 'lib/MC/MCDisassembler/Disassembler.cpp')
-rw-r--r-- | lib/MC/MCDisassembler/Disassembler.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/MC/MCDisassembler/Disassembler.cpp b/lib/MC/MCDisassembler/Disassembler.cpp index f156760..572a5a5 100644 --- a/lib/MC/MCDisassembler/Disassembler.cpp +++ b/lib/MC/MCDisassembler/Disassembler.cpp @@ -18,6 +18,8 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/Support/MemoryObject.h" #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ErrorHandling.h" namespace llvm { class Target; @@ -34,6 +36,18 @@ using namespace llvm; LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp) { + // Initialize targets and assembly printers/parsers. + // FIXME: Clients are responsible for initializing the targets. And this + // would be done by calling routines in "llvm-c/Target.h" which are static + // line functions. But the current use of LLVMCreateDisasm() is to dynamically + // load libLTO with dlopen() and then lookup the symbols using dlsym(). + // And since these initialize routines are static that does not work which + // is why the call to them in this 'C' library API was added back. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + // Get the target. std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); @@ -66,7 +80,7 @@ LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo, // Set up the instruction printer. int AsmPrinterVariant = MAI->getAssemblerDialect(); MCInstPrinter *IP = TheTarget->createMCInstPrinter(AsmPrinterVariant, - *MAI, *STI); + *MAI, *MRI, *STI); assert(IP && "Unable to create instruction printer!"); LLVMDisasmContext *DC = new LLVMDisasmContext(TripleName, DisInfo, TagType, @@ -163,5 +177,5 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, return Size; } } - return 0; + llvm_unreachable("Invalid DecodeStatus!"); } |