blob: 89150401ffe62add24c48528a7a5e2a921c1f4ec [file] [log] [blame]
Eric Christophereec50082010-08-08 02:44:17 +00001/*===-- 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/*===----------------------------------------------------------------------===*/
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000018
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
Eric Christophereec50082010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
Gregory Szorc6244b512012-03-21 03:54:29 +000029/**
30 * @defgroup LLVMCTarget Target information
31 * @ingroup LLVMC
32 *
33 * @{
34 */
35
Chris Lattnerd686c8e2010-01-09 22:27:07 +000036enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000037
38typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindola5160d382011-07-25 21:20:54 +000039typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000040typedef struct LLVMStructLayout *LLVMStructLayoutRef;
41
Bob Wilsona96751f2009-06-23 23:59:40 +000042/* Declare all of the target-initialization functions that are available. */
Eric Christopherca3ca132010-07-12 05:13:35 +000043#define LLVM_TARGET(TargetName) \
44 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000045#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000046#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
47
Chris Lattnerff33d832010-04-28 20:24:45 +000048#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilsona96751f2009-06-23 23:59:40 +000049#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000050#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000051
Evan Cheng1abf2cb2011-07-14 23:50:31 +000052#define LLVM_TARGET(TargetName) \
Evan Chenge78085a2011-07-22 21:58:54 +000053 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng43966132011-07-19 06:37:02 +000054#include "llvm/Config/Targets.def"
55#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
56
Daniel Dunbar72736d12011-11-29 00:06:55 +000057/* Declare all of the available assembly printer initialization functions. */
58#define LLVM_ASM_PRINTER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000059 void LLVMInitialize##TargetName##AsmPrinter(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000060#include "llvm/Config/AsmPrinters.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000061#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
Daniel Dunbar72736d12011-11-29 00:06:55 +000062
63/* Declare all of the available assembly parser initialization functions. */
64#define LLVM_ASM_PARSER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000065 void LLVMInitialize##TargetName##AsmParser(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000066#include "llvm/Config/AsmParsers.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000067#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
Daniel Dunbar72736d12011-11-29 00:06:55 +000068
69/* Declare all of the available disassembler initialization functions. */
70#define LLVM_DISASSEMBLER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000071 void LLVMInitialize##TargetName##Disassembler(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000072#include "llvm/Config/Disassemblers.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000073#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
Daniel Dunbar72736d12011-11-29 00:06:55 +000074
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000075/** LLVMInitializeAllTargetInfos - The main program should call this function if
76 it wants access to all available targets that LLVM is configured to
77 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000078static inline void LLVMInitializeAllTargetInfos(void) {
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000079#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
80#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000081#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000082}
83
Bob Wilsona96751f2009-06-23 23:59:40 +000084/** LLVMInitializeAllTargets - The main program should call this function if it
85 wants to link in all available targets that LLVM is configured to
86 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000087static inline void LLVMInitializeAllTargets(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +000088#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
89#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000090#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000091}
Daniel Dunbar72736d12011-11-29 00:06:55 +000092
93/** LLVMInitializeAllTargetMCs - The main program should call this function if
94 it wants access to all available target MC that LLVM is configured to
95 support. */
96static 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 */
100}
101
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. */
Anders Waldenborg8ed99512012-05-02 16:15:32 +0000105static inline void LLVMInitializeAllAsmPrinters(void) {
Daniel Dunbar72736d12011-11-29 00:06:55 +0000106#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 */
109}
110
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. */
Anders Waldenborg8ed99512012-05-02 16:15:32 +0000114static inline void LLVMInitializeAllAsmParsers(void) {
Daniel Dunbar72736d12011-11-29 00:06:55 +0000115#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 */
118}
119
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. */
Anders Waldenborg8ed99512012-05-02 16:15:32 +0000123static inline void LLVMInitializeAllDisassemblers(void) {
Daniel Dunbar72736d12011-11-29 00:06:55 +0000124#define LLVM_DISASSEMBLER(TargetName) \
125 LLVMInitialize##TargetName##Disassembler();
126#include "llvm/Config/Disassemblers.def"
127#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
128}
Bob Wilsona96751f2009-06-23 23:59:40 +0000129
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. */
Chris Lattnerc799c552010-04-29 23:27:32 +0000133static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +0000134 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christopher753f3262010-08-30 18:34:48 +0000135#ifdef LLVM_NATIVE_TARGET
136 LLVM_NATIVE_TARGETINFO();
137 LLVM_NATIVE_TARGET();
Evan Chenge78085a2011-07-22 21:58:54 +0000138 LLVM_NATIVE_TARGETMC();
Bob Wilsona96751f2009-06-23 23:59:40 +0000139 return 0;
Bob Wilsona96751f2009-06-23 23:59:40 +0000140#else
141 return 1;
142#endif
143}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000144
145/*===-- Target Data -------------------------------------------------------===*/
146
147/** Creates target data from a target layout string.
148 See the constructor llvm::TargetData::TargetData. */
149LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
150
151/** Adds target data information to a pass manager. This does not take ownership
152 of the target data.
153 See the method llvm::PassManagerBase::add. */
154void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
155
Rafael Espindola5160d382011-07-25 21:20:54 +0000156/** 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. */
159void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
160
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000161/** Converts target data to a target layout string. The string must be disposed
162 with LLVMDisposeMessage.
163 See the constructor llvm::TargetData::TargetData. */
164char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
165
166/** Returns the byte order of a target, either LLVMBigEndian or
167 LLVMLittleEndian.
168 See the method llvm::TargetData::isLittleEndian. */
Chris Lattner10bc7552010-01-09 23:25:21 +0000169enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000170
171/** Returns the pointer size in bytes for a target.
172 See the method llvm::TargetData::getPointerSize. */
173unsigned LLVMPointerSize(LLVMTargetDataRef);
174
175/** Returns the integer type that is the same size as a pointer on a target.
176 See the method llvm::TargetData::getIntPtrType. */
177LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
178
179/** Computes the size of a type in bytes for a target.
180 See the method llvm::TargetData::getTypeSizeInBits. */
181unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
182
183/** Computes the storage size of a type in bytes for a target.
184 See the method llvm::TargetData::getTypeStoreSize. */
185unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
186
187/** Computes the ABI size of a type in bytes for a target.
Duncan Sands777d2302009-05-09 07:06:46 +0000188 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000189unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
190
191/** Computes the ABI alignment of a type in bytes for a target.
192 See the method llvm::TargetData::getTypeABISize. */
193unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
194
195/** Computes the call frame alignment of a type in bytes for a target.
196 See the method llvm::TargetData::getTypeABISize. */
197unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
198
199/** Computes the preferred alignment of a type in bytes for a target.
200 See the method llvm::TargetData::getTypeABISize. */
201unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
202
203/** Computes the preferred alignment of a global variable in bytes for a target.
204 See the method llvm::TargetData::getPreferredAlignment. */
205unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
206 LLVMValueRef GlobalVar);
207
208/** Computes the structure element that contains the byte offset for a target.
209 See the method llvm::StructLayout::getElementContainingOffset. */
210unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
211 unsigned long long Offset);
212
213/** Computes the byte offset of the indexed struct element for a target.
214 See the method llvm::StructLayout::getElementContainingOffset. */
215unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
216 unsigned Element);
217
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000218/** Deallocates a TargetData.
219 See the destructor llvm::TargetData::~TargetData. */
220void LLVMDisposeTargetData(LLVMTargetDataRef);
221
Gregory Szorc6244b512012-03-21 03:54:29 +0000222/**
223 * @}
224 */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000225
226#ifdef __cplusplus
227}
228
229namespace llvm {
230 class TargetData;
Rafael Espindola5160d382011-07-25 21:20:54 +0000231 class TargetLibraryInfo;
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000232
233 inline TargetData *unwrap(LLVMTargetDataRef P) {
234 return reinterpret_cast<TargetData*>(P);
235 }
236
237 inline LLVMTargetDataRef wrap(const TargetData *P) {
238 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
239 }
Rafael Espindola5160d382011-07-25 21:20:54 +0000240
241 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
242 return reinterpret_cast<TargetLibraryInfo*>(P);
243 }
244
245 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
246 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
247 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
248 }
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000249}
250
251#endif /* defined(__cplusplus) */
252
253#endif