1226584Sdim//===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
2226584Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6226584Sdim//
7226584Sdim//===----------------------------------------------------------------------===//
8226584Sdim//
9226584Sdim// This file provides utilities to make sure that certain classes of targets are
10226584Sdim// linked into the main application executable, and initialize them as
11226584Sdim// appropriate.
12226584Sdim//
13226584Sdim//===----------------------------------------------------------------------===//
14226584Sdim
15226584Sdim#ifndef LLVM_SUPPORT_TARGETSELECT_H
16226584Sdim#define LLVM_SUPPORT_TARGETSELECT_H
17226584Sdim
18226584Sdim#include "llvm/Config/llvm-config.h"
19226584Sdim
20226584Sdimextern "C" {
21226584Sdim  // Declare all of the target-initialization functions that are available.
22226584Sdim#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
23226584Sdim#include "llvm/Config/Targets.def"
24226584Sdim
25226584Sdim#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
26226584Sdim#include "llvm/Config/Targets.def"
27296417Sdim
28226584Sdim  // Declare all of the target-MC-initialization functions that are available.
29226584Sdim#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
30226584Sdim#include "llvm/Config/Targets.def"
31296417Sdim
32226584Sdim  // Declare all of the available assembly printer initialization functions.
33226584Sdim#define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
34226584Sdim#include "llvm/Config/AsmPrinters.def"
35226584Sdim
36226584Sdim  // Declare all of the available assembly parser initialization functions.
37226584Sdim#define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
38226584Sdim#include "llvm/Config/AsmParsers.def"
39226584Sdim
40226584Sdim  // Declare all of the available disassembler initialization functions.
41226584Sdim#define LLVM_DISASSEMBLER(TargetName) \
42226584Sdim  void LLVMInitialize##TargetName##Disassembler();
43226584Sdim#include "llvm/Config/Disassemblers.def"
44226584Sdim}
45226584Sdim
46226584Sdimnamespace llvm {
47226584Sdim  /// InitializeAllTargetInfos - The main program should call this function if
48226584Sdim  /// it wants access to all available targets that LLVM is configured to
49226584Sdim  /// support, to make them available via the TargetRegistry.
50226584Sdim  ///
51226584Sdim  /// It is legal for a client to make multiple calls to this function.
52226584Sdim  inline void InitializeAllTargetInfos() {
53226584Sdim#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54226584Sdim#include "llvm/Config/Targets.def"
55226584Sdim  }
56296417Sdim
57226584Sdim  /// InitializeAllTargets - The main program should call this function if it
58226584Sdim  /// wants access to all available target machines that LLVM is configured to
59226584Sdim  /// support, to make them available via the TargetRegistry.
60226584Sdim  ///
61226584Sdim  /// It is legal for a client to make multiple calls to this function.
62226584Sdim  inline void InitializeAllTargets() {
63226584Sdim    // FIXME: Remove this, clients should do it.
64226584Sdim    InitializeAllTargetInfos();
65226584Sdim
66226584Sdim#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
67226584Sdim#include "llvm/Config/Targets.def"
68226584Sdim  }
69296417Sdim
70226584Sdim  /// InitializeAllTargetMCs - The main program should call this function if it
71226584Sdim  /// wants access to all available target MC that LLVM is configured to
72226584Sdim  /// support, to make them available via the TargetRegistry.
73226584Sdim  ///
74226584Sdim  /// It is legal for a client to make multiple calls to this function.
75226584Sdim  inline void InitializeAllTargetMCs() {
76226584Sdim#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
77226584Sdim#include "llvm/Config/Targets.def"
78226584Sdim  }
79296417Sdim
80226584Sdim  /// InitializeAllAsmPrinters - The main program should call this function if
81226584Sdim  /// it wants all asm printers that LLVM is configured to support, to make them
82226584Sdim  /// available via the TargetRegistry.
83226584Sdim  ///
84226584Sdim  /// It is legal for a client to make multiple calls to this function.
85226584Sdim  inline void InitializeAllAsmPrinters() {
86226584Sdim#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
87226584Sdim#include "llvm/Config/AsmPrinters.def"
88226584Sdim  }
89296417Sdim
90226584Sdim  /// InitializeAllAsmParsers - The main program should call this function if it
91226584Sdim  /// wants all asm parsers that LLVM is configured to support, to make them
92226584Sdim  /// available via the TargetRegistry.
93226584Sdim  ///
94226584Sdim  /// It is legal for a client to make multiple calls to this function.
95226584Sdim  inline void InitializeAllAsmParsers() {
96226584Sdim#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
97226584Sdim#include "llvm/Config/AsmParsers.def"
98226584Sdim  }
99296417Sdim
100226584Sdim  /// InitializeAllDisassemblers - The main program should call this function if
101226584Sdim  /// it wants all disassemblers that LLVM is configured to support, to make
102226584Sdim  /// them available via the TargetRegistry.
103226584Sdim  ///
104226584Sdim  /// It is legal for a client to make multiple calls to this function.
105226584Sdim  inline void InitializeAllDisassemblers() {
106226584Sdim#define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
107226584Sdim#include "llvm/Config/Disassemblers.def"
108226584Sdim  }
109296417Sdim
110226584Sdim  /// InitializeNativeTarget - The main program should call this function to
111296417Sdim  /// initialize the native target corresponding to the host.  This is useful
112226584Sdim  /// for JIT applications to ensure that the target gets linked in correctly.
113226584Sdim  ///
114226584Sdim  /// It is legal for a client to make multiple calls to this function.
115226584Sdim  inline bool InitializeNativeTarget() {
116226584Sdim  // If we have a native target, initialize it to ensure it is linked in.
117226584Sdim#ifdef LLVM_NATIVE_TARGET
118226584Sdim    LLVM_NATIVE_TARGETINFO();
119226584Sdim    LLVM_NATIVE_TARGET();
120226584Sdim    LLVM_NATIVE_TARGETMC();
121226584Sdim    return false;
122226584Sdim#else
123226584Sdim    return true;
124226584Sdim#endif
125296417Sdim  }
126226584Sdim
127226584Sdim  /// InitializeNativeTargetAsmPrinter - The main program should call
128226584Sdim  /// this function to initialize the native target asm printer.
129226584Sdim  inline bool InitializeNativeTargetAsmPrinter() {
130226584Sdim  // If we have a native target, initialize the corresponding asm printer.
131226584Sdim#ifdef LLVM_NATIVE_ASMPRINTER
132226584Sdim    LLVM_NATIVE_ASMPRINTER();
133226584Sdim    return false;
134226584Sdim#else
135226584Sdim    return true;
136226584Sdim#endif
137296417Sdim  }
138226584Sdim
139226584Sdim  /// InitializeNativeTargetAsmParser - The main program should call
140226584Sdim  /// this function to initialize the native target asm parser.
141226584Sdim  inline bool InitializeNativeTargetAsmParser() {
142226584Sdim  // If we have a native target, initialize the corresponding asm parser.
143226584Sdim#ifdef LLVM_NATIVE_ASMPARSER
144226584Sdim    LLVM_NATIVE_ASMPARSER();
145226584Sdim    return false;
146226584Sdim#else
147226584Sdim    return true;
148226584Sdim#endif
149296417Sdim  }
150226584Sdim
151234353Sdim  /// InitializeNativeTargetDisassembler - The main program should call
152234353Sdim  /// this function to initialize the native target disassembler.
153234353Sdim  inline bool InitializeNativeTargetDisassembler() {
154234353Sdim  // If we have a native target, initialize the corresponding disassembler.
155234353Sdim#ifdef LLVM_NATIVE_DISASSEMBLER
156234353Sdim    LLVM_NATIVE_DISASSEMBLER();
157234353Sdim    return false;
158234353Sdim#else
159234353Sdim    return true;
160234353Sdim#endif
161296417Sdim  }
162226584Sdim}
163226584Sdim
164226584Sdim#endif
165