blob: 258a2bee95c1aed6ebb2aa4612ce45b2e986f41e [file] [log] [blame]
Eric Christopherf24446d2010-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 Henriksenab4b7d32008-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 Christopherf24446d2010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
Gregory Szorc34c863a2012-03-21 03:54:29 +000029/**
30 * @defgroup LLVMCTarget Target information
31 * @ingroup LLVMC
32 *
33 * @{
34 */
35
Chris Lattner25963c62010-01-09 22:27:07 +000036enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000037
38typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +000039typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000040typedef struct LLVMStructLayout *LLVMStructLayoutRef;
41
Bob Wilson5a495fe2009-06-23 23:59:40 +000042/* Declare all of the target-initialization functions that are available. */
Eric Christopher135de902010-07-12 05:13:35 +000043#define LLVM_TARGET(TargetName) \
44 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000045#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000046#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
47
Chris Lattneree3576e2010-04-28 20:24:45 +000048#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilson5a495fe2009-06-23 23:59:40 +000049#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000050#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000051
Evan Cheng1705ab02011-07-14 23:50:31 +000052#define LLVM_TARGET(TargetName) \
Evan Cheng8c886a42011-07-22 21:58:54 +000053 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng2129f592011-07-19 06:37:02 +000054#include "llvm/Config/Targets.def"
55#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
56
Daniel Dunbar69987ab2011-11-29 00:06:55 +000057/* 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"
61
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"
66
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"
71
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000072/** LLVMInitializeAllTargetInfos - The main program should call this function if
73 it wants access to all available targets that LLVM is configured to
74 support. */
Chris Lattner9d186472010-04-29 23:27:32 +000075static inline void LLVMInitializeAllTargetInfos(void) {
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000076#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
77#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000078#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000079}
80
Bob Wilson5a495fe2009-06-23 23:59:40 +000081/** LLVMInitializeAllTargets - The main program should call this function if it
82 wants to link in all available targets that LLVM is configured to
83 support. */
Chris Lattner9d186472010-04-29 23:27:32 +000084static inline void LLVMInitializeAllTargets(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +000085#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
86#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000087#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000088}
Daniel Dunbar69987ab2011-11-29 00:06:55 +000089
90/** LLVMInitializeAllTargetMCs - The main program should call this function if
91 it wants access to all available target MC that LLVM is configured to
92 support. */
93static 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 */
97}
98
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. */
102static 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 */
106}
107
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. */
111static 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 */
115}
116
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. */
120static 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 */
125}
Bob Wilson5a495fe2009-06-23 23:59:40 +0000126
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. */
Chris Lattner9d186472010-04-29 23:27:32 +0000130static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +0000131 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christophere7a9db12010-08-30 18:34:48 +0000132#ifdef LLVM_NATIVE_TARGET
133 LLVM_NATIVE_TARGETINFO();
134 LLVM_NATIVE_TARGET();
Evan Cheng8c886a42011-07-22 21:58:54 +0000135 LLVM_NATIVE_TARGETMC();
Bob Wilson5a495fe2009-06-23 23:59:40 +0000136 return 0;
Bob Wilson5a495fe2009-06-23 23:59:40 +0000137#else
138 return 1;
139#endif
140}
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000141
142/*===-- Target Data -------------------------------------------------------===*/
143
144/** Creates target data from a target layout string.
145 See the constructor llvm::TargetData::TargetData. */
146LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
147
148/** Adds target data information to a pass manager. This does not take ownership
149 of the target data.
150 See the method llvm::PassManagerBase::add. */
151void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
152
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000153/** 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. */
156void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
157
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000158/** Converts target data to a target layout string. The string must be disposed
159 with LLVMDisposeMessage.
160 See the constructor llvm::TargetData::TargetData. */
161char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
162
163/** Returns the byte order of a target, either LLVMBigEndian or
164 LLVMLittleEndian.
165 See the method llvm::TargetData::isLittleEndian. */
Chris Lattner51c49962010-01-09 23:25:21 +0000166enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000167
168/** Returns the pointer size in bytes for a target.
169 See the method llvm::TargetData::getPointerSize. */
170unsigned LLVMPointerSize(LLVMTargetDataRef);
171
172/** Returns the integer type that is the same size as a pointer on a target.
173 See the method llvm::TargetData::getIntPtrType. */
174LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
175
176/** Computes the size of a type in bytes for a target.
177 See the method llvm::TargetData::getTypeSizeInBits. */
178unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
179
180/** Computes the storage size of a type in bytes for a target.
181 See the method llvm::TargetData::getTypeStoreSize. */
182unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
183
184/** Computes the ABI size of a type in bytes for a target.
Duncan Sandsaf9eaa82009-05-09 07:06:46 +0000185 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000186unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
187
188/** Computes the ABI alignment of a type in bytes for a target.
189 See the method llvm::TargetData::getTypeABISize. */
190unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
191
192/** Computes the call frame alignment of a type in bytes for a target.
193 See the method llvm::TargetData::getTypeABISize. */
194unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
195
196/** Computes the preferred alignment of a type in bytes for a target.
197 See the method llvm::TargetData::getTypeABISize. */
198unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
199
200/** Computes the preferred alignment of a global variable in bytes for a target.
201 See the method llvm::TargetData::getPreferredAlignment. */
202unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
203 LLVMValueRef GlobalVar);
204
205/** Computes the structure element that contains the byte offset for a target.
206 See the method llvm::StructLayout::getElementContainingOffset. */
207unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
208 unsigned long long Offset);
209
210/** Computes the byte offset of the indexed struct element for a target.
211 See the method llvm::StructLayout::getElementContainingOffset. */
212unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
213 unsigned Element);
214
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000215/** Deallocates a TargetData.
216 See the destructor llvm::TargetData::~TargetData. */
217void LLVMDisposeTargetData(LLVMTargetDataRef);
218
Gregory Szorc34c863a2012-03-21 03:54:29 +0000219/**
220 * @}
221 */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000222
223#ifdef __cplusplus
224}
225
226namespace llvm {
227 class TargetData;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000228 class TargetLibraryInfo;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000229
230 inline TargetData *unwrap(LLVMTargetDataRef P) {
231 return reinterpret_cast<TargetData*>(P);
232 }
233
234 inline LLVMTargetDataRef wrap(const TargetData *P) {
235 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
236 }
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000237
238 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
239 return reinterpret_cast<TargetLibraryInfo*>(P);
240 }
241
242 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
243 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
244 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
245 }
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000246}
247
248#endif /* defined(__cplusplus) */
249
250#endif