1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- 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 header declares the C interface to libLLVMTarget.a, which */
11 /* implements target information. */
13 /* Many exotic languages can interoperate with C code but have a harder time */
14 /* with C++ due to name mangling. So in addition to C, this interface enables */
15 /* tools written in such languages. */
17 /*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_TARGET_H
20 #define LLVM_C_TARGET_H
22 #include "llvm-c/Core.h"
23 #include "llvm/Config/llvm-config.h"
30 * @defgroup LLVMCTarget Target information
36 enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
38 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
39 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
40 typedef struct LLVMStructLayout *LLVMStructLayoutRef;
42 /* Declare all of the target-initialization functions that are available. */
43 #define LLVM_TARGET(TargetName) \
44 void LLVMInitialize##TargetName##TargetInfo(void);
45 #include "llvm/Config/Targets.def"
46 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
48 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
49 #include "llvm/Config/Targets.def"
50 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
52 #define LLVM_TARGET(TargetName) \
53 void LLVMInitialize##TargetName##TargetMC(void);
54 #include "llvm/Config/Targets.def"
55 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
57 /* Declare all of the available assembly printer initialization functions. */
58 #define LLVM_ASM_PRINTER(TargetName) \
59 void LLVMInitialize##TargetName##AsmPrinter(void);
60 #include "llvm/Config/AsmPrinters.def"
61 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
63 /* Declare all of the available assembly parser initialization functions. */
64 #define LLVM_ASM_PARSER(TargetName) \
65 void LLVMInitialize##TargetName##AsmParser(void);
66 #include "llvm/Config/AsmParsers.def"
67 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
69 /* Declare all of the available disassembler initialization functions. */
70 #define LLVM_DISASSEMBLER(TargetName) \
71 void LLVMInitialize##TargetName##Disassembler(void);
72 #include "llvm/Config/Disassemblers.def"
73 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
75 /** LLVMInitializeAllTargetInfos - The main program should call this function if
76 it wants access to all available targets that LLVM is configured to
78 static inline void LLVMInitializeAllTargetInfos(void) {
79 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
80 #include "llvm/Config/Targets.def"
81 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
84 /** LLVMInitializeAllTargets - The main program should call this function if it
85 wants to link in all available targets that LLVM is configured to
87 static inline void LLVMInitializeAllTargets(void) {
88 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
89 #include "llvm/Config/Targets.def"
90 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
93 /** LLVMInitializeAllTargetMCs - The main program should call this function if
94 it wants access to all available target MC that LLVM is configured to
96 static inline void LLVMInitializeAllTargetMCs(void) {
97 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
98 #include "llvm/Config/Targets.def"
99 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
102 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
103 it wants all asm printers that LLVM is configured to support, to make them
104 available via the TargetRegistry. */
105 static inline void LLVMInitializeAllAsmPrinters(void) {
106 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
107 #include "llvm/Config/AsmPrinters.def"
108 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
111 /** LLVMInitializeAllAsmParsers - The main program should call this function if
112 it wants all asm parsers that LLVM is configured to support, to make them
113 available via the TargetRegistry. */
114 static inline void LLVMInitializeAllAsmParsers(void) {
115 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
116 #include "llvm/Config/AsmParsers.def"
117 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
120 /** LLVMInitializeAllDisassemblers - The main program should call this function
121 if it wants all disassemblers that LLVM is configured to support, to make
122 them available via the TargetRegistry. */
123 static inline void LLVMInitializeAllDisassemblers(void) {
124 #define LLVM_DISASSEMBLER(TargetName) \
125 LLVMInitialize##TargetName##Disassembler();
126 #include "llvm/Config/Disassemblers.def"
127 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
130 /** LLVMInitializeNativeTarget - The main program should call this function to
131 initialize the native target corresponding to the host. This is useful
132 for JIT applications to ensure that the target gets linked in correctly. */
133 static inline LLVMBool LLVMInitializeNativeTarget(void) {
134 /* If we have a native target, initialize it to ensure it is linked in. */
135 #ifdef LLVM_NATIVE_TARGET
136 LLVM_NATIVE_TARGETINFO();
137 LLVM_NATIVE_TARGET();
138 LLVM_NATIVE_TARGETMC();
145 /*===-- Target Data -------------------------------------------------------===*/
147 /** Creates target data from a target layout string.
148 See the constructor llvm::DataLayout::DataLayout. */
149 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
151 /** Adds target data information to a pass manager. This does not take ownership
153 See the method llvm::PassManagerBase::add. */
154 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
156 /** Adds target library information to a pass manager. This does not take
157 ownership of the target library info.
158 See the method llvm::PassManagerBase::add. */
159 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
161 /** Converts target data to a target layout string. The string must be disposed
162 with LLVMDisposeMessage.
163 See the constructor llvm::DataLayout::DataLayout. */
164 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
166 /** Returns the byte order of a target, either LLVMBigEndian or
168 See the method llvm::DataLayout::isLittleEndian. */
169 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
171 /** Returns the pointer size in bytes for a target.
172 See the method llvm::DataLayout::getPointerSize. */
173 unsigned LLVMPointerSize(LLVMTargetDataRef);
175 /** Returns the pointer size in bytes for a target for a specified
177 See the method llvm::DataLayout::getPointerSize. */
178 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS);
180 /** Returns the integer type that is the same size as a pointer on a target.
181 See the method llvm::DataLayout::getIntPtrType. */
182 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
184 /** Returns the integer type that is the same size as a pointer on a target.
185 This version allows the address space to be specified.
186 See the method llvm::DataLayout::getIntPtrType. */
187 LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS);
189 /** Computes the size of a type in bytes for a target.
190 See the method llvm::DataLayout::getTypeSizeInBits. */
191 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
193 /** Computes the storage size of a type in bytes for a target.
194 See the method llvm::DataLayout::getTypeStoreSize. */
195 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
197 /** Computes the ABI size of a type in bytes for a target.
198 See the method llvm::DataLayout::getTypeAllocSize. */
199 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
201 /** Computes the ABI alignment of a type in bytes for a target.
202 See the method llvm::DataLayout::getTypeABISize. */
203 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
205 /** Computes the call frame alignment of a type in bytes for a target.
206 See the method llvm::DataLayout::getTypeABISize. */
207 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
209 /** Computes the preferred alignment of a type in bytes for a target.
210 See the method llvm::DataLayout::getTypeABISize. */
211 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
213 /** Computes the preferred alignment of a global variable in bytes for a target.
214 See the method llvm::DataLayout::getPreferredAlignment. */
215 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
216 LLVMValueRef GlobalVar);
218 /** Computes the structure element that contains the byte offset for a target.
219 See the method llvm::StructLayout::getElementContainingOffset. */
220 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
221 unsigned long long Offset);
223 /** Computes the byte offset of the indexed struct element for a target.
224 See the method llvm::StructLayout::getElementContainingOffset. */
225 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
228 /** Deallocates a TargetData.
229 See the destructor llvm::DataLayout::~DataLayout. */
230 void LLVMDisposeTargetData(LLVMTargetDataRef);
241 class TargetLibraryInfo;
243 inline DataLayout *unwrap(LLVMTargetDataRef P) {
244 return reinterpret_cast<DataLayout*>(P);
247 inline LLVMTargetDataRef wrap(const DataLayout *P) {
248 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
251 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
252 return reinterpret_cast<TargetLibraryInfo*>(P);
255 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
256 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
257 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
261 #endif /* defined(__cplusplus) */