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();
60 #include "llvm/Config/AsmPrinters.def"
62 /* Declare all of the available assembly parser initialization functions. */
63 #define LLVM_ASM_PARSER(TargetName) \
64 void LLVMInitialize##TargetName##AsmParser();
65 #include "llvm/Config/AsmParsers.def"
67 /* Declare all of the available disassembler initialization functions. */
68 #define LLVM_DISASSEMBLER(TargetName) \
69 void LLVMInitialize##TargetName##Disassembler();
70 #include "llvm/Config/Disassemblers.def"
72 /** LLVMInitializeAllTargetInfos - The main program should call this function if
73 it wants access to all available targets that LLVM is configured to
75 static inline void LLVMInitializeAllTargetInfos(void) {
76 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
77 #include "llvm/Config/Targets.def"
78 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
81 /** LLVMInitializeAllTargets - The main program should call this function if it
82 wants to link in all available targets that LLVM is configured to
84 static inline void LLVMInitializeAllTargets(void) {
85 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
86 #include "llvm/Config/Targets.def"
87 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
90 /** LLVMInitializeAllTargetMCs - The main program should call this function if
91 it wants access to all available target MC that LLVM is configured to
93 static inline void LLVMInitializeAllTargetMCs(void) {
94 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
95 #include "llvm/Config/Targets.def"
96 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
99 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
100 it wants all asm printers that LLVM is configured to support, to make them
101 available via the TargetRegistry. */
102 static inline void LLVMInitializeAllAsmPrinters() {
103 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
104 #include "llvm/Config/AsmPrinters.def"
105 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
108 /** LLVMInitializeAllAsmParsers - The main program should call this function if
109 it wants all asm parsers that LLVM is configured to support, to make them
110 available via the TargetRegistry. */
111 static inline void LLVMInitializeAllAsmParsers() {
112 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
113 #include "llvm/Config/AsmParsers.def"
114 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
117 /** LLVMInitializeAllDisassemblers - The main program should call this function
118 if it wants all disassemblers that LLVM is configured to support, to make
119 them available via the TargetRegistry. */
120 static inline void LLVMInitializeAllDisassemblers() {
121 #define LLVM_DISASSEMBLER(TargetName) \
122 LLVMInitialize##TargetName##Disassembler();
123 #include "llvm/Config/Disassemblers.def"
124 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
127 /** LLVMInitializeNativeTarget - The main program should call this function to
128 initialize the native target corresponding to the host. This is useful
129 for JIT applications to ensure that the target gets linked in correctly. */
130 static inline LLVMBool LLVMInitializeNativeTarget(void) {
131 /* If we have a native target, initialize it to ensure it is linked in. */
132 #ifdef LLVM_NATIVE_TARGET
133 LLVM_NATIVE_TARGETINFO();
134 LLVM_NATIVE_TARGET();
135 LLVM_NATIVE_TARGETMC();
142 /*===-- Target Data -------------------------------------------------------===*/
144 /** Creates target data from a target layout string.
145 See the constructor llvm::TargetData::TargetData. */
146 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
148 /** Adds target data information to a pass manager. This does not take ownership
150 See the method llvm::PassManagerBase::add. */
151 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
153 /** Adds target library information to a pass manager. This does not take
154 ownership of the target library info.
155 See the method llvm::PassManagerBase::add. */
156 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
158 /** Converts target data to a target layout string. The string must be disposed
159 with LLVMDisposeMessage.
160 See the constructor llvm::TargetData::TargetData. */
161 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
163 /** Returns the byte order of a target, either LLVMBigEndian or
165 See the method llvm::TargetData::isLittleEndian. */
166 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
168 /** Returns the pointer size in bytes for a target.
169 See the method llvm::TargetData::getPointerSize. */
170 unsigned LLVMPointerSize(LLVMTargetDataRef);
172 /** Returns the integer type that is the same size as a pointer on a target.
173 See the method llvm::TargetData::getIntPtrType. */
174 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
176 /** Computes the size of a type in bytes for a target.
177 See the method llvm::TargetData::getTypeSizeInBits. */
178 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
180 /** Computes the storage size of a type in bytes for a target.
181 See the method llvm::TargetData::getTypeStoreSize. */
182 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
184 /** Computes the ABI size of a type in bytes for a target.
185 See the method llvm::TargetData::getTypeAllocSize. */
186 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
188 /** Computes the ABI alignment of a type in bytes for a target.
189 See the method llvm::TargetData::getTypeABISize. */
190 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
192 /** Computes the call frame alignment of a type in bytes for a target.
193 See the method llvm::TargetData::getTypeABISize. */
194 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
196 /** Computes the preferred alignment of a type in bytes for a target.
197 See the method llvm::TargetData::getTypeABISize. */
198 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
200 /** Computes the preferred alignment of a global variable in bytes for a target.
201 See the method llvm::TargetData::getPreferredAlignment. */
202 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
203 LLVMValueRef GlobalVar);
205 /** Computes the structure element that contains the byte offset for a target.
206 See the method llvm::StructLayout::getElementContainingOffset. */
207 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
208 unsigned long long Offset);
210 /** Computes the byte offset of the indexed struct element for a target.
211 See the method llvm::StructLayout::getElementContainingOffset. */
212 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
215 /** Deallocates a TargetData.
216 See the destructor llvm::TargetData::~TargetData. */
217 void LLVMDisposeTargetData(LLVMTargetDataRef);
228 class TargetLibraryInfo;
230 inline TargetData *unwrap(LLVMTargetDataRef P) {
231 return reinterpret_cast<TargetData*>(P);
234 inline LLVMTargetDataRef wrap(const TargetData *P) {
235 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
238 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
239 return reinterpret_cast<TargetLibraryInfo*>(P);
242 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
243 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
244 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
248 #endif /* defined(__cplusplus) */