1 //===-- Target/TargetMachineRegistry.h - Target Registration ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes two classes: the TargetMachineRegistry class, which allows
11 // tools to inspect all of registered targets, and the RegisterTarget class,
12 // which TargetMachine implementations should use to register themselves with
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H
18 #define LLVM_TARGET_TARGETMACHINEREGISTRY_H
20 #include "llvm/Module.h"
21 #include "llvm/Target/TargetRegistry.h"
28 //===--------------------------------------------------------------------===//
29 /// RegisterTarget - This class is used to make targets automatically register
30 /// themselves with the tools they are linked with. Targets should define an
31 /// single global Target instance and register it using the TargetRegistry
32 /// interfaces. Targets must also include a static instance of this class.
34 /// The type 'TargetMachineImpl' should provide a constructor with two
36 /// - const Module& M: the module that is being compiled:
37 /// - const std::string& FS: target-specific string describing target
40 template<class TargetMachineImpl>
41 struct RegisterTarget {
42 RegisterTarget(Target &T, const char *Name, const char *ShortDesc) {
43 TargetRegistry::RegisterTargetMachine(T, &Allocator);
47 static TargetMachine *Allocator(const Target &T, const Module &M,
48 const std::string &FS) {
49 return new TargetMachineImpl(T, M, FS);