blob: e4f177beb9ea2ed77141d6d7ac6f7ce7590d5d54 [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
Chris Lattnerd686c8e2010-01-09 22:27:07 +000029enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000030
31typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindola5160d382011-07-25 21:20:54 +000032typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000033typedef struct LLVMStructLayout *LLVMStructLayoutRef;
34
Bob Wilsona96751f2009-06-23 23:59:40 +000035/* Declare all of the target-initialization functions that are available. */
Eric Christopherca3ca132010-07-12 05:13:35 +000036#define LLVM_TARGET(TargetName) \
37 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000038#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000039#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
40
Chris Lattnerff33d832010-04-28 20:24:45 +000041#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilsona96751f2009-06-23 23:59:40 +000042#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000043#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000044
Evan Cheng1abf2cb2011-07-14 23:50:31 +000045#define LLVM_TARGET(TargetName) \
Evan Chenge78085a2011-07-22 21:58:54 +000046 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng43966132011-07-19 06:37:02 +000047#include "llvm/Config/Targets.def"
48#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
49
Daniel Dunbar72736d12011-11-29 00:06:55 +000050/* Declare all of the available assembly printer initialization functions. */
51#define LLVM_ASM_PRINTER(TargetName) \
52 void LLVMInitialize##TargetName##AsmPrinter();
53#include "llvm/Config/AsmPrinters.def"
54
55/* Declare all of the available assembly parser initialization functions. */
56#define LLVM_ASM_PARSER(TargetName) \
57 void LLVMInitialize##TargetName##AsmParser();
58#include "llvm/Config/AsmParsers.def"
59
60/* Declare all of the available disassembler initialization functions. */
61#define LLVM_DISASSEMBLER(TargetName) \
62 void LLVMInitialize##TargetName##Disassembler();
63#include "llvm/Config/Disassemblers.def"
64
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000065/** LLVMInitializeAllTargetInfos - The main program should call this function if
66 it wants access to all available targets that LLVM is configured to
67 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000068static inline void LLVMInitializeAllTargetInfos(void) {
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000069#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
70#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000071#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000072}
73
Bob Wilsona96751f2009-06-23 23:59:40 +000074/** LLVMInitializeAllTargets - The main program should call this function if it
75 wants to link in all available targets that LLVM is configured to
76 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000077static inline void LLVMInitializeAllTargets(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +000078#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
79#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000080#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000081}
Daniel Dunbar72736d12011-11-29 00:06:55 +000082
83/** LLVMInitializeAllTargetMCs - The main program should call this function if
84 it wants access to all available target MC that LLVM is configured to
85 support. */
86static inline void LLVMInitializeAllTargetMCs(void) {
87#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
88#include "llvm/Config/Targets.def"
89#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
90}
91
92/** LLVMInitializeAllAsmPrinters - The main program should call this function if
93 it wants all asm printers that LLVM is configured to support, to make them
94 available via the TargetRegistry. */
95static inline void LLVMInitializeAllAsmPrinters() {
96#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
97#include "llvm/Config/AsmPrinters.def"
98#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
99}
100
101/** LLVMInitializeAllAsmParsers - The main program should call this function if
102 it wants all asm parsers that LLVM is configured to support, to make them
103 available via the TargetRegistry. */
104static inline void LLVMInitializeAllAsmParsers() {
105#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
106#include "llvm/Config/AsmParsers.def"
107#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
108}
109
110/** LLVMInitializeAllDisassemblers - The main program should call this function
111 if it wants all disassemblers that LLVM is configured to support, to make
112 them available via the TargetRegistry. */
113static inline void LLVMInitializeAllDisassemblers() {
114#define LLVM_DISASSEMBLER(TargetName) \
115 LLVMInitialize##TargetName##Disassembler();
116#include "llvm/Config/Disassemblers.def"
117#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
118}
Bob Wilsona96751f2009-06-23 23:59:40 +0000119
120/** LLVMInitializeNativeTarget - The main program should call this function to
121 initialize the native target corresponding to the host. This is useful
122 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattnerc799c552010-04-29 23:27:32 +0000123static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +0000124 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christopher753f3262010-08-30 18:34:48 +0000125#ifdef LLVM_NATIVE_TARGET
126 LLVM_NATIVE_TARGETINFO();
127 LLVM_NATIVE_TARGET();
Evan Chenge78085a2011-07-22 21:58:54 +0000128 LLVM_NATIVE_TARGETMC();
Bob Wilsona96751f2009-06-23 23:59:40 +0000129 return 0;
Bob Wilsona96751f2009-06-23 23:59:40 +0000130#else
131 return 1;
132#endif
133}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000134
135/*===-- Target Data -------------------------------------------------------===*/
136
137/** Creates target data from a target layout string.
138 See the constructor llvm::TargetData::TargetData. */
139LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
140
141/** Adds target data information to a pass manager. This does not take ownership
142 of the target data.
143 See the method llvm::PassManagerBase::add. */
144void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
145
Rafael Espindola5160d382011-07-25 21:20:54 +0000146/** Adds target library information to a pass manager. This does not take
147 ownership of the target library info.
148 See the method llvm::PassManagerBase::add. */
149void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
150
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000151/** Converts target data to a target layout string. The string must be disposed
152 with LLVMDisposeMessage.
153 See the constructor llvm::TargetData::TargetData. */
154char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
155
156/** Returns the byte order of a target, either LLVMBigEndian or
157 LLVMLittleEndian.
158 See the method llvm::TargetData::isLittleEndian. */
Chris Lattner10bc7552010-01-09 23:25:21 +0000159enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000160
161/** Returns the pointer size in bytes for a target.
162 See the method llvm::TargetData::getPointerSize. */
163unsigned LLVMPointerSize(LLVMTargetDataRef);
164
165/** Returns the integer type that is the same size as a pointer on a target.
166 See the method llvm::TargetData::getIntPtrType. */
167LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
168
169/** Computes the size of a type in bytes for a target.
170 See the method llvm::TargetData::getTypeSizeInBits. */
171unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
172
173/** Computes the storage size of a type in bytes for a target.
174 See the method llvm::TargetData::getTypeStoreSize. */
175unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
176
177/** Computes the ABI size of a type in bytes for a target.
Duncan Sands777d2302009-05-09 07:06:46 +0000178 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000179unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
180
181/** Computes the ABI alignment of a type in bytes for a target.
182 See the method llvm::TargetData::getTypeABISize. */
183unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
184
185/** Computes the call frame alignment of a type in bytes for a target.
186 See the method llvm::TargetData::getTypeABISize. */
187unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
188
189/** Computes the preferred alignment of a type in bytes for a target.
190 See the method llvm::TargetData::getTypeABISize. */
191unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
192
193/** Computes the preferred alignment of a global variable in bytes for a target.
194 See the method llvm::TargetData::getPreferredAlignment. */
195unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
196 LLVMValueRef GlobalVar);
197
198/** Computes the structure element that contains the byte offset for a target.
199 See the method llvm::StructLayout::getElementContainingOffset. */
200unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
201 unsigned long long Offset);
202
203/** Computes the byte offset of the indexed struct element for a target.
204 See the method llvm::StructLayout::getElementContainingOffset. */
205unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
206 unsigned Element);
207
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000208/** Deallocates a TargetData.
209 See the destructor llvm::TargetData::~TargetData. */
210void LLVMDisposeTargetData(LLVMTargetDataRef);
211
212
213#ifdef __cplusplus
214}
215
216namespace llvm {
217 class TargetData;
Rafael Espindola5160d382011-07-25 21:20:54 +0000218 class TargetLibraryInfo;
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000219
220 inline TargetData *unwrap(LLVMTargetDataRef P) {
221 return reinterpret_cast<TargetData*>(P);
222 }
223
224 inline LLVMTargetDataRef wrap(const TargetData *P) {
225 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
226 }
Rafael Espindola5160d382011-07-25 21:20:54 +0000227
228 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
229 return reinterpret_cast<TargetLibraryInfo*>(P);
230 }
231
232 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
233 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
234 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
235 }
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000236}
237
238#endif /* defined(__cplusplus) */
239
240#endif