From 178051fbae2b224ecc5aa20e39b7cee3ab38e760 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 11 Nov 2011 13:20:40 +0000 Subject: [PATCH] Clients are responsible for initializing the targets, remove it from the disassembler API. This will break users of the LLVMCreateDisasm API (not that I know of any). They have to call the LLVMInitializeAll* functions from llvm-c/Target.h themselves now. edis' C API in all its horribleness should be unaffected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144385 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCDisassembler/Disassembler.cpp | 7 ------- lib/MC/MCDisassembler/EDDisassembler.cpp | 16 ---------------- lib/MC/MCDisassembler/EDDisassembler.h | 5 ----- lib/MC/MCDisassembler/LLVMBuild.txt | 5 +---- tools/edis/EDMain.cpp | 13 +++++++++++-- tools/llvm-mc/Disassembler.cpp | 1 - 6 files changed, 12 insertions(+), 35 deletions(-) diff --git a/lib/MC/MCDisassembler/Disassembler.cpp b/lib/MC/MCDisassembler/Disassembler.cpp index 16e66dc98e7..f156760875c 100644 --- a/lib/MC/MCDisassembler/Disassembler.cpp +++ b/lib/MC/MCDisassembler/Disassembler.cpp @@ -18,7 +18,6 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/Support/MemoryObject.h" #include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" namespace llvm { class Target; @@ -35,12 +34,6 @@ using namespace llvm; LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp) { - // Initialize targets and assembly printers/parsers. - llvm::InitializeAllTargetInfos(); - llvm::InitializeAllTargetMCs(); - llvm::InitializeAllAsmParsers(); - llvm::InitializeAllDisassemblers(); - // Get the target. std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); diff --git a/lib/MC/MCDisassembler/EDDisassembler.cpp b/lib/MC/MCDisassembler/EDDisassembler.cpp index 5633cb11e79..3540334344f 100644 --- a/lib/MC/MCDisassembler/EDDisassembler.cpp +++ b/lib/MC/MCDisassembler/EDDisassembler.cpp @@ -34,10 +34,8 @@ #include "llvm/Support/MemoryObject.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" using namespace llvm; -bool EDDisassembler::sInitialized = false; EDDisassembler::DisassemblerMap_t EDDisassembler::sDisassemblers; struct TripleMap { @@ -98,20 +96,6 @@ static int getLLVMSyntaxVariant(Triple::ArchType arch, } } -void EDDisassembler::initialize() { - if (sInitialized) - return; - - sInitialized = true; - - InitializeAllTargetInfos(); - InitializeAllTargetMCs(); - InitializeAllAsmParsers(); - InitializeAllDisassemblers(); -} - -#undef BRINGUP_TARGET - EDDisassembler *EDDisassembler::getDisassembler(Triple::ArchType arch, AssemblySyntax syntax) { CPUKey key; diff --git a/lib/MC/MCDisassembler/EDDisassembler.h b/lib/MC/MCDisassembler/EDDisassembler.h index 38c22038c51..97c2d1fd99b 100644 --- a/lib/MC/MCDisassembler/EDDisassembler.h +++ b/lib/MC/MCDisassembler/EDDisassembler.h @@ -94,8 +94,6 @@ struct EDDisassembler { typedef std::map DisassemblerMap_t; - /// True if the disassembler registry has been initialized; false if not - static bool sInitialized; /// A map from disassembler specifications to disassemblers. Populated /// lazily. static DisassemblerMap_t sDisassemblers; @@ -116,9 +114,6 @@ struct EDDisassembler { static EDDisassembler *getDisassembler(llvm::StringRef str, AssemblySyntax syntax); - /// initialize - Initializes the disassembler registry and the LLVM backend - static void initialize(); - //////////////////////// // Per-object members // //////////////////////// diff --git a/lib/MC/MCDisassembler/LLVMBuild.txt b/lib/MC/MCDisassembler/LLVMBuild.txt index 7b8c7ffc28c..d73c6adcbb4 100644 --- a/lib/MC/MCDisassembler/LLVMBuild.txt +++ b/lib/MC/MCDisassembler/LLVMBuild.txt @@ -19,7 +19,4 @@ type = Library name = MCDisassembler parent = MC -; FIXME: This is really horrible, MCDisassembler should not in and of its own -; accord depending on every target. -required_libraries = all-targets MC MCParser Support - +required_libraries = MC MCParser Support diff --git a/tools/edis/EDMain.cpp b/tools/edis/EDMain.cpp index 16855b3f45d..14a17d66e63 100644 --- a/tools/edis/EDMain.cpp +++ b/tools/edis/EDMain.cpp @@ -17,14 +17,23 @@ #include "../../lib/MC/MCDisassembler/EDInst.h" #include "../../lib/MC/MCDisassembler/EDOperand.h" #include "../../lib/MC/MCDisassembler/EDToken.h" +#include "llvm/Support/TargetSelect.h" #include "llvm-c/EnhancedDisassembly.h" using namespace llvm; int EDGetDisassembler(EDDisassemblerRef *disassembler, const char *triple, EDAssemblySyntax_t syntax) { - EDDisassembler::initialize(); - + static bool initialized; + if (!initialized) { + // Initialize targets and assembly printers/parsers. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + initialized = true; + } + EDDisassembler::AssemblySyntax Syntax; switch (syntax) { default: assert(0 && "Unknown assembly syntax!"); diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index e0064888ded..1b5aa5775ce 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -249,7 +249,6 @@ int Disassembler::disassembleEnhanced(const std::string &TS, break; } - EDDisassembler::initialize(); OwningPtr disassembler(EDDisassembler::getDisassembler(TS.c_str(), AS));