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/Support/Registry.h"
22 #include "llvm/Target/TargetRegistry.h"
29 struct TargetMachineRegistryEntry {
30 const Target &TheTarget;
32 const char *ShortDesc;
35 TargetMachineRegistryEntry(const Target &T, const char *N, const char *SD)
36 : TheTarget(T), Name(N), ShortDesc(SD) {}
40 class RegistryTraits<TargetMachine> {
42 typedef TargetMachineRegistryEntry entry;
44 static const char *nameof(const entry &Entry) { return Entry.Name; }
45 static const char *descof(const entry &Entry) { return Entry.ShortDesc; }
48 struct TargetMachineRegistry : public Registry<TargetMachine> {
52 //===--------------------------------------------------------------------===//
53 /// RegisterTarget - This class is used to make targets automatically register
54 /// themselves with the tools they are linked with. Targets should define an
55 /// single global Target instance and register it using the TargetRegistry
56 /// interfaces. Targets must also include a static instance of this class.
58 /// The type 'TargetMachineImpl' should provide a constructor with two
60 /// - const Module& M: the module that is being compiled:
61 /// - const std::string& FS: target-specific string describing target
64 template<class TargetMachineImpl>
65 struct RegisterTarget {
66 RegisterTarget(Target &T, const char *Name, const char *ShortDesc)
67 : Entry(T, Name, ShortDesc),
69 TargetRegistry::RegisterTargetMachine(T, &Allocator);
73 TargetMachineRegistry::entry Entry;
74 TargetMachineRegistry::node Node;
76 static TargetMachine *Allocator(const Module &M, const std::string &FS) {
77 return new TargetMachineImpl(M, FS);