1//===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides utilities to make sure that certain classes of targets are
10// linked into the main application executable, and initialize them as
11// appropriate.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_TARGETSELECT_H
16#define LLVM_SUPPORT_TARGETSELECT_H
17
18#include "llvm/Config/llvm-config.h"
19
20extern "C" {
21  // Declare all of the target-initialization functions that are available.
22#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
23#include "llvm/Config/Targets.def"
24
25#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
26#include "llvm/Config/Targets.def"
27
28  // Declare all of the target-MC-initialization functions that are available.
29#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
30#include "llvm/Config/Targets.def"
31
32  // Declare all of the available assembly printer initialization functions.
33#define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
34#include "llvm/Config/AsmPrinters.def"
35
36  // Declare all of the available assembly parser initialization functions.
37#define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
38#include "llvm/Config/AsmParsers.def"
39
40  // Declare all of the available disassembler initialization functions.
41#define LLVM_DISASSEMBLER(TargetName) \
42  void LLVMInitialize##TargetName##Disassembler();
43#include "llvm/Config/Disassemblers.def"
44}
45
46namespace llvm {
47  /// InitializeAllTargetInfos - The main program should call this function if
48  /// it wants access to all available targets that LLVM is configured to
49  /// support, to make them available via the TargetRegistry.
50  ///
51  /// It is legal for a client to make multiple calls to this function.
52  inline void InitializeAllTargetInfos() {
53#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54#include "llvm/Config/Targets.def"
55  }
56
57  /// InitializeAllTargets - The main program should call this function if it
58  /// wants access to all available target machines that LLVM is configured to
59  /// support, to make them available via the TargetRegistry.
60  ///
61  /// It is legal for a client to make multiple calls to this function.
62  inline void InitializeAllTargets() {
63    // FIXME: Remove this, clients should do it.
64    InitializeAllTargetInfos();
65
66#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
67#include "llvm/Config/Targets.def"
68  }
69
70  /// InitializeAllTargetMCs - The main program should call this function if it
71  /// wants access to all available target MC that LLVM is configured to
72  /// support, to make them available via the TargetRegistry.
73  ///
74  /// It is legal for a client to make multiple calls to this function.
75  inline void InitializeAllTargetMCs() {
76#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
77#include "llvm/Config/Targets.def"
78  }
79
80  /// InitializeAllAsmPrinters - The main program should call this function if
81  /// it wants all asm printers that LLVM is configured to support, to make them
82  /// available via the TargetRegistry.
83  ///
84  /// It is legal for a client to make multiple calls to this function.
85  inline void InitializeAllAsmPrinters() {
86#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
87#include "llvm/Config/AsmPrinters.def"
88  }
89
90  /// InitializeAllAsmParsers - The main program should call this function if it
91  /// wants all asm parsers that LLVM is configured to support, to make them
92  /// available via the TargetRegistry.
93  ///
94  /// It is legal for a client to make multiple calls to this function.
95  inline void InitializeAllAsmParsers() {
96#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
97#include "llvm/Config/AsmParsers.def"
98  }
99
100  /// InitializeAllDisassemblers - The main program should call this function if
101  /// it wants all disassemblers that LLVM is configured to support, to make
102  /// them available via the TargetRegistry.
103  ///
104  /// It is legal for a client to make multiple calls to this function.
105  inline void InitializeAllDisassemblers() {
106#define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
107#include "llvm/Config/Disassemblers.def"
108  }
109
110  /// InitializeNativeTarget - The main program should call this function to
111  /// initialize the native target corresponding to the host.  This is useful
112  /// for JIT applications to ensure that the target gets linked in correctly.
113  ///
114  /// It is legal for a client to make multiple calls to this function.
115  inline bool InitializeNativeTarget() {
116  // If we have a native target, initialize it to ensure it is linked in.
117#ifdef LLVM_NATIVE_TARGET
118    LLVM_NATIVE_TARGETINFO();
119    LLVM_NATIVE_TARGET();
120    LLVM_NATIVE_TARGETMC();
121    return false;
122#else
123    return true;
124#endif
125  }
126
127  /// InitializeNativeTargetAsmPrinter - The main program should call
128  /// this function to initialize the native target asm printer.
129  inline bool InitializeNativeTargetAsmPrinter() {
130  // If we have a native target, initialize the corresponding asm printer.
131#ifdef LLVM_NATIVE_ASMPRINTER
132    LLVM_NATIVE_ASMPRINTER();
133    return false;
134#else
135    return true;
136#endif
137  }
138
139  /// InitializeNativeTargetAsmParser - The main program should call
140  /// this function to initialize the native target asm parser.
141  inline bool InitializeNativeTargetAsmParser() {
142  // If we have a native target, initialize the corresponding asm parser.
143#ifdef LLVM_NATIVE_ASMPARSER
144    LLVM_NATIVE_ASMPARSER();
145    return false;
146#else
147    return true;
148#endif
149  }
150
151  /// InitializeNativeTargetDisassembler - The main program should call
152  /// this function to initialize the native target disassembler.
153  inline bool InitializeNativeTargetDisassembler() {
154  // If we have a native target, initialize the corresponding disassembler.
155#ifdef LLVM_NATIVE_DISASSEMBLER
156    LLVM_NATIVE_DISASSEMBLER();
157    return false;
158#else
159    return true;
160#endif
161  }
162}
163
164#endif
165