1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
3 /* The LLVM Compiler Infrastructure */
5 /* This file is distributed under the University of Illinois Open Source */
6 /* License. See LICENSE.TXT for details. */
8 /*===----------------------------------------------------------------------===*/
10 /* This header declares the C interface to libLLVMTarget.a, which */
11 /* implements target information. */
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. */
17 /*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_TARGET_H
20 #define LLVM_C_TARGET_H
22 #include "llvm-c/Core.h"
23 #include "llvm/Config/llvm-config.h"
29 enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
31 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
32 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
33 typedef struct LLVMStructLayout *LLVMStructLayoutRef;
35 /* Declare all of the target-initialization functions that are available. */
36 #define LLVM_TARGET(TargetName) \
37 void LLVMInitialize##TargetName##TargetInfo(void);
38 #include "llvm/Config/Targets.def"
39 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
41 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
42 #include "llvm/Config/Targets.def"
43 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
45 #define LLVM_TARGET(TargetName) \
46 void LLVMInitialize##TargetName##TargetMC(void);
47 #include "llvm/Config/Targets.def"
48 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
50 /** LLVMInitializeAllTargetInfos - The main program should call this function if
51 it wants access to all available targets that LLVM is configured to
53 static inline void LLVMInitializeAllTargetInfos(void) {
54 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
55 #include "llvm/Config/Targets.def"
56 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
59 /** LLVMInitializeAllTargets - The main program should call this function if it
60 wants to link in all available targets that LLVM is configured to
62 static inline void LLVMInitializeAllTargets(void) {
63 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
64 #include "llvm/Config/Targets.def"
65 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
68 /** LLVMInitializeNativeTarget - The main program should call this function to
69 initialize the native target corresponding to the host. This is useful
70 for JIT applications to ensure that the target gets linked in correctly. */
71 static inline LLVMBool LLVMInitializeNativeTarget(void) {
72 /* If we have a native target, initialize it to ensure it is linked in. */
73 #ifdef LLVM_NATIVE_TARGET
74 LLVM_NATIVE_TARGETINFO();
76 LLVM_NATIVE_TARGETMC();
83 /*===-- Target Data -------------------------------------------------------===*/
85 /** Creates target data from a target layout string.
86 See the constructor llvm::TargetData::TargetData. */
87 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
89 /** Adds target data information to a pass manager. This does not take ownership
91 See the method llvm::PassManagerBase::add. */
92 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
94 /** Adds target library information to a pass manager. This does not take
95 ownership of the target library info.
96 See the method llvm::PassManagerBase::add. */
97 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
99 /** Converts target data to a target layout string. The string must be disposed
100 with LLVMDisposeMessage.
101 See the constructor llvm::TargetData::TargetData. */
102 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
104 /** Returns the byte order of a target, either LLVMBigEndian or
106 See the method llvm::TargetData::isLittleEndian. */
107 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
109 /** Returns the pointer size in bytes for a target.
110 See the method llvm::TargetData::getPointerSize. */
111 unsigned LLVMPointerSize(LLVMTargetDataRef);
113 /** Returns the integer type that is the same size as a pointer on a target.
114 See the method llvm::TargetData::getIntPtrType. */
115 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
117 /** Computes the size of a type in bytes for a target.
118 See the method llvm::TargetData::getTypeSizeInBits. */
119 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
121 /** Computes the storage size of a type in bytes for a target.
122 See the method llvm::TargetData::getTypeStoreSize. */
123 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
125 /** Computes the ABI size of a type in bytes for a target.
126 See the method llvm::TargetData::getTypeAllocSize. */
127 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
129 /** Computes the ABI alignment of a type in bytes for a target.
130 See the method llvm::TargetData::getTypeABISize. */
131 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
133 /** Computes the call frame alignment of a type in bytes for a target.
134 See the method llvm::TargetData::getTypeABISize. */
135 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
137 /** Computes the preferred alignment of a type in bytes for a target.
138 See the method llvm::TargetData::getTypeABISize. */
139 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
141 /** Computes the preferred alignment of a global variable in bytes for a target.
142 See the method llvm::TargetData::getPreferredAlignment. */
143 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
144 LLVMValueRef GlobalVar);
146 /** Computes the structure element that contains the byte offset for a target.
147 See the method llvm::StructLayout::getElementContainingOffset. */
148 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
149 unsigned long long Offset);
151 /** Computes the byte offset of the indexed struct element for a target.
152 See the method llvm::StructLayout::getElementContainingOffset. */
153 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
156 /** Deallocates a TargetData.
157 See the destructor llvm::TargetData::~TargetData. */
158 void LLVMDisposeTargetData(LLVMTargetDataRef);
166 class TargetLibraryInfo;
168 inline TargetData *unwrap(LLVMTargetDataRef P) {
169 return reinterpret_cast<TargetData*>(P);
172 inline LLVMTargetDataRef wrap(const TargetData *P) {
173 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
176 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
177 return reinterpret_cast<TargetLibraryInfo*>(P);
180 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
181 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
182 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
186 #endif /* defined(__cplusplus) */