blob: 00571826487cc59e31cec1a6c63edecafe6578c8 [file] [log] [blame]
Gordon Henriksen3e0c8352008-03-16 20:08:03 +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\*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
Bob Wilsona96751f2009-06-23 23:59:40 +000023#include "llvm/Config/config.h"
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29enum { LLVMBigEndian, LLVMLittleEndian };
30typedef int LLVMByteOrdering;
31
32typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
33typedef struct LLVMStructLayout *LLVMStructLayoutRef;
34
Bob Wilsona96751f2009-06-23 23:59:40 +000035/* Declare all of the target-initialization functions that are available. */
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000036#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
37#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000038#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
39
Bob Wilsona96751f2009-06-23 23:59:40 +000040#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
41#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000042#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000043
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000044/** LLVMInitializeAllTargetInfos - The main program should call this function if
45 it wants access to all available targets that LLVM is configured to
46 support. */
47static inline void LLVMInitializeAllTargetInfos() {
48#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
49#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000050#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000051}
52
Bob Wilsona96751f2009-06-23 23:59:40 +000053/** LLVMInitializeAllTargets - The main program should call this function if it
54 wants to link in all available targets that LLVM is configured to
55 support. */
56static inline void LLVMInitializeAllTargets() {
57#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
58#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000059#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000060}
61
62/** LLVMInitializeNativeTarget - The main program should call this function to
63 initialize the native target corresponding to the host. This is useful
64 for JIT applications to ensure that the target gets linked in correctly. */
65static inline int LLVMInitializeNativeTarget() {
66 /* If we have a native target, initialize it to ensure it is linked in. */
67#ifdef LLVM_NATIVE_ARCH
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000068#define DoInit2(TARG) \
69 LLVMInitialize ## TARG ## Info (); \
70 LLVMInitialize ## TARG ()
Bob Wilsona96751f2009-06-23 23:59:40 +000071#define DoInit(T) DoInit2(T)
72 DoInit(LLVM_NATIVE_ARCH);
73 return 0;
74#undef DoInit
75#undef DoInit2
76#else
77 return 1;
78#endif
79}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000080
81/*===-- Target Data -------------------------------------------------------===*/
82
83/** Creates target data from a target layout string.
84 See the constructor llvm::TargetData::TargetData. */
85LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
86
87/** Adds target data information to a pass manager. This does not take ownership
88 of the target data.
89 See the method llvm::PassManagerBase::add. */
90void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
91
92/** Converts target data to a target layout string. The string must be disposed
93 with LLVMDisposeMessage.
94 See the constructor llvm::TargetData::TargetData. */
95char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
96
97/** Returns the byte order of a target, either LLVMBigEndian or
98 LLVMLittleEndian.
99 See the method llvm::TargetData::isLittleEndian. */
100LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
101
102/** Returns the pointer size in bytes for a target.
103 See the method llvm::TargetData::getPointerSize. */
104unsigned LLVMPointerSize(LLVMTargetDataRef);
105
106/** Returns the integer type that is the same size as a pointer on a target.
107 See the method llvm::TargetData::getIntPtrType. */
108LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
109
110/** Computes the size of a type in bytes for a target.
111 See the method llvm::TargetData::getTypeSizeInBits. */
112unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
113
114/** Computes the storage size of a type in bytes for a target.
115 See the method llvm::TargetData::getTypeStoreSize. */
116unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
117
118/** Computes the ABI size of a type in bytes for a target.
Duncan Sands777d2302009-05-09 07:06:46 +0000119 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000120unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
121
122/** Computes the ABI alignment of a type in bytes for a target.
123 See the method llvm::TargetData::getTypeABISize. */
124unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
125
126/** Computes the call frame alignment of a type in bytes for a target.
127 See the method llvm::TargetData::getTypeABISize. */
128unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
129
130/** Computes the preferred alignment of a type in bytes for a target.
131 See the method llvm::TargetData::getTypeABISize. */
132unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
133
134/** Computes the preferred alignment of a global variable in bytes for a target.
135 See the method llvm::TargetData::getPreferredAlignment. */
136unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
137 LLVMValueRef GlobalVar);
138
139/** Computes the structure element that contains the byte offset for a target.
140 See the method llvm::StructLayout::getElementContainingOffset. */
141unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
142 unsigned long long Offset);
143
144/** Computes the byte offset of the indexed struct element for a target.
145 See the method llvm::StructLayout::getElementContainingOffset. */
146unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
147 unsigned Element);
148
149/** Struct layouts are speculatively cached. If a TargetDataRef is alive when
150 types are being refined and removed, this method must be called whenever a
151 struct type is removed to avoid a dangling pointer in this cache.
152 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
153void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
154
155/** Deallocates a TargetData.
156 See the destructor llvm::TargetData::~TargetData. */
157void LLVMDisposeTargetData(LLVMTargetDataRef);
158
159
160#ifdef __cplusplus
161}
162
163namespace llvm {
164 class TargetData;
165
166 inline TargetData *unwrap(LLVMTargetDataRef P) {
167 return reinterpret_cast<TargetData*>(P);
168 }
169
170 inline LLVMTargetDataRef wrap(const TargetData *P) {
171 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
172 }
173}
174
175#endif /* defined(__cplusplus) */
176
177#endif