Add AllTargetsBindings sublibrary instead of having static inlines in the llvm-c...
[oota-llvm.git] / include / llvm-c / Target.h
1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
2 /*                                                                            */
3 /*                     The LLVM Compiler Infrastructure                       */
4 /*                                                                            */
5 /* This file is distributed under the University of Illinois Open Source      */
6 /* License. See LICENSE.TXT for details.                                      */
7 /*                                                                            */
8 /*===----------------------------------------------------------------------===*/
9 /*                                                                            */
10 /* This header declares the C interface to libLLVMTarget.a, which             */
11 /* implements target information.                                             */
12 /*                                                                            */
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.                                           */
16 /*                                                                            */
17 /*===----------------------------------------------------------------------===*/
18
19 #ifndef LLVM_C_TARGET_H
20 #define LLVM_C_TARGET_H
21
22 #include "llvm-c/Core.h"
23 #include "llvm/Config/llvm-config.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /**
30  * @defgroup LLVMCTarget Target information
31  * @ingroup LLVMC
32  *
33  * @{
34  */
35
36 enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
37
38 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
39 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
40 typedef struct LLVMStructLayout *LLVMStructLayoutRef;
41
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 */
47   
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 */
51
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 */
56   
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 */
62
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 */
68
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 */
74
75 /** LLVMInitializeAllTargetInfos - The main program should call this function if
76     it wants access to all available targets that LLVM is configured to
77     support. */
78 void LLVMInitializeAllTargetInfos(void);
79
80 /** LLVMInitializeAllTargets - The main program should call this function if it
81     wants to link in all available targets that LLVM is configured to
82     support. */
83 void LLVMInitializeAllTargets(void);
84
85 /** LLVMInitializeAllTargetMCs - The main program should call this function if
86     it wants access to all available target MC that LLVM is configured to
87     support. */
88 void LLVMInitializeAllTargetMCs(void);
89
90 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
91     it wants all asm printers that LLVM is configured to support, to make them
92     available via the TargetRegistry. */
93 void LLVMInitializeAllAsmPrinters(void);
94
95 /** LLVMInitializeAllAsmParsers - The main program should call this function if
96     it wants all asm parsers that LLVM is configured to support, to make them
97     available via the TargetRegistry. */
98 void LLVMInitializeAllAsmParsers(void);
99
100 /** LLVMInitializeAllDisassemblers - The main program should call this function
101     if it wants all disassemblers that LLVM is configured to support, to make
102     them available via the TargetRegistry. */
103 void LLVMInitializeAllDisassemblers(void);
104
105 /** LLVMInitializeNativeTarget - The main program should call this function to
106     initialize the native target corresponding to the host.  This is useful 
107     for JIT applications to ensure that the target gets linked in correctly. */
108 static inline LLVMBool LLVMInitializeNativeTarget(void) {
109   /* If we have a native target, initialize it to ensure it is linked in. */
110 #ifdef LLVM_NATIVE_TARGET
111   LLVM_NATIVE_TARGETINFO();
112   LLVM_NATIVE_TARGET();
113   LLVM_NATIVE_TARGETMC();
114   return 0;
115 #else
116   return 1;
117 #endif
118 }  
119
120 /*===-- Target Data -------------------------------------------------------===*/
121
122 /** Creates target data from a target layout string.
123     See the constructor llvm::DataLayout::DataLayout. */
124 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
125
126 /** Adds target data information to a pass manager. This does not take ownership
127     of the target data.
128     See the method llvm::PassManagerBase::add. */
129 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
130
131 /** Adds target library information to a pass manager. This does not take
132     ownership of the target library info.
133     See the method llvm::PassManagerBase::add. */
134 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
135
136 /** Converts target data to a target layout string. The string must be disposed
137     with LLVMDisposeMessage.
138     See the constructor llvm::DataLayout::DataLayout. */
139 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
140
141 /** Returns the byte order of a target, either LLVMBigEndian or
142     LLVMLittleEndian.
143     See the method llvm::DataLayout::isLittleEndian. */
144 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
145
146 /** Returns the pointer size in bytes for a target.
147     See the method llvm::DataLayout::getPointerSize. */
148 unsigned LLVMPointerSize(LLVMTargetDataRef);
149
150 /** Returns the pointer size in bytes for a target for a specified
151     address space.
152     See the method llvm::DataLayout::getPointerSize. */
153 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS);
154
155 /** Returns the integer type that is the same size as a pointer on a target.
156     See the method llvm::DataLayout::getIntPtrType. */
157 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
158
159 /** Returns the integer type that is the same size as a pointer on a target.
160     This version allows the address space to be specified.
161     See the method llvm::DataLayout::getIntPtrType. */
162 LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS);
163
164 /** Computes the size of a type in bytes for a target.
165     See the method llvm::DataLayout::getTypeSizeInBits. */
166 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
167
168 /** Computes the storage size of a type in bytes for a target.
169     See the method llvm::DataLayout::getTypeStoreSize. */
170 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
171
172 /** Computes the ABI size of a type in bytes for a target.
173     See the method llvm::DataLayout::getTypeAllocSize. */
174 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
175
176 /** Computes the ABI alignment of a type in bytes for a target.
177     See the method llvm::DataLayout::getTypeABISize. */
178 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
179
180 /** Computes the call frame alignment of a type in bytes for a target.
181     See the method llvm::DataLayout::getTypeABISize. */
182 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
183
184 /** Computes the preferred alignment of a type in bytes for a target.
185     See the method llvm::DataLayout::getTypeABISize. */
186 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
187
188 /** Computes the preferred alignment of a global variable in bytes for a target.
189     See the method llvm::DataLayout::getPreferredAlignment. */
190 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
191                                         LLVMValueRef GlobalVar);
192
193 /** Computes the structure element that contains the byte offset for a target.
194     See the method llvm::StructLayout::getElementContainingOffset. */
195 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
196                              unsigned long long Offset);
197
198 /** Computes the byte offset of the indexed struct element for a target.
199     See the method llvm::StructLayout::getElementContainingOffset. */
200 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
201                                        unsigned Element);
202
203 /** Deallocates a TargetData.
204     See the destructor llvm::DataLayout::~DataLayout. */
205 void LLVMDisposeTargetData(LLVMTargetDataRef);
206
207 /**
208  * @}
209  */
210
211 #ifdef __cplusplus
212 }
213 #endif /* defined(__cplusplus) */
214
215 #endif