1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
//===-- Target/TargetMachineRegistry.h - Target Registration ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file exposes two classes: the TargetMachineRegistry class, which allows
// tools to inspect all of registered targets, and the RegisterTarget class,
// which TargetMachine implementations should use to register themselves with
// the system.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H
#define LLVM_TARGET_TARGETMACHINEREGISTRY_H
#include "llvm/Module.h"
#include "llvm/Support/Registry.h"
#include "llvm/Target/TargetRegistry.h"
namespace llvm {
class Module;
class Target;
class TargetMachine;
struct TargetMachineRegistryEntry {
const Target &TheTarget;
const char *Name;
const char *ShortDesc;
public:
TargetMachineRegistryEntry(const Target &T, const char *N, const char *SD)
: TheTarget(T), Name(N), ShortDesc(SD) {}
};
template<>
class RegistryTraits<TargetMachine> {
public:
typedef TargetMachineRegistryEntry entry;
static const char *nameof(const entry &Entry) { return Entry.Name; }
static const char *descof(const entry &Entry) { return Entry.ShortDesc; }
};
struct TargetMachineRegistry : public Registry<TargetMachine> {
};
//===--------------------------------------------------------------------===//
/// RegisterTarget - This class is used to make targets automatically register
/// themselves with the tools they are linked with. Targets should define an
/// single global Target instance and register it using the TargetRegistry
/// interfaces. Targets must also include a static instance of this class.
///
/// The type 'TargetMachineImpl' should provide a constructor with two
/// parameters:
/// - const Module& M: the module that is being compiled:
/// - const std::string& FS: target-specific string describing target
/// flavour.
template<class TargetMachineImpl>
struct RegisterTarget {
RegisterTarget(Target &T, const char *Name, const char *ShortDesc)
: Entry(T, Name, ShortDesc),
Node(Entry) {
TargetRegistry::RegisterTargetMachine(T, &Allocator);
}
private:
TargetMachineRegistry::entry Entry;
TargetMachineRegistry::node Node;
static TargetMachine *Allocator(const Target &T, const Module &M,
const std::string &FS) {
return new TargetMachineImpl(T, M, FS);
}
};
}
#endif
|