diff options
author | Evan Cheng <evan.cheng@apple.com> | 2011-08-23 20:15:21 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2011-08-23 20:15:21 +0000 |
commit | 7801136b95d1fbe515b9655b73ada39b05a33559 (patch) | |
tree | ff75c7f27a25aeea99b1e06eb3dc96d955978bf9 /include/llvm/Target | |
parent | acc8f2d938dbf00c79c34f4541a5a05662964797 (diff) | |
download | llvm-7801136b95d1fbe515b9655b73ada39b05a33559.tar.gz llvm-7801136b95d1fbe515b9655b73ada39b05a33559.tar.bz2 llvm-7801136b95d1fbe515b9655b73ada39b05a33559.tar.xz |
Some refactoring so TargetRegistry.h no longer has to include any files
from MC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Target')
-rw-r--r-- | include/llvm/Target/TargetRegistry.h | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h index 6e55c1fbf6..19a5fc34e3 100644 --- a/include/llvm/Target/TargetRegistry.h +++ b/include/llvm/Target/TargetRegistry.h @@ -19,8 +19,7 @@ #ifndef LLVM_TARGET_TARGETREGISTRY_H #define LLVM_TARGET_TARGETREGISTRY_H -#include "llvm/MC/MCCodeGenInfo.h" -#include "llvm/MC/MCInstrAnalysis.h" +#include "llvm/Support/CodeGen.h" #include "llvm/ADT/Triple.h" #include <string> #include <cassert> @@ -36,6 +35,7 @@ namespace llvm { class MCCodeGenInfo; class MCContext; class MCDisassembler; + class MCInstrAnalysis; class MCInstPrinter; class MCInstrInfo; class MCRegisterInfo; @@ -291,7 +291,7 @@ namespace llvm { /// MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const { if (!MCInstrAnalysisCtorFn) - return new MCInstrAnalysis(Info); + return 0; return MCInstrAnalysisCtorFn(Info); } @@ -890,6 +890,39 @@ namespace llvm { } }; + /// RegisterMCInstrAnalysis - Helper template for registering a target + /// instruction analyzer implementation. This invokes the static "Create" + /// method on the class to actually do the construction. Usage: + /// + /// extern "C" void LLVMInitializeFooTarget() { + /// extern Target TheFooTarget; + /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget); + /// } + template<class MCInstrAnalysisImpl> + struct RegisterMCInstrAnalysis { + RegisterMCInstrAnalysis(Target &T) { + TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator); + } + private: + static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) { + return new MCInstrAnalysisImpl(Info); + } + }; + + /// RegisterMCInstrAnalysisFn - Helper template for registering a target + /// instruction analyzer implementation. This invokes the specified function + /// to do the construction. Usage: + /// + /// extern "C" void LLVMInitializeFooTarget() { + /// extern Target TheFooTarget; + /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction); + /// } + struct RegisterMCInstrAnalysisFn { + RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) { + TargetRegistry::RegisterMCInstrAnalysis(T, Fn); + } + }; + /// RegisterMCRegInfo - Helper template for registering a target register info /// implementation. This invokes the static "Create" method on the class to /// actually do the construction. Usage: |