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 LLVMStructLayout *LLVMStructLayoutRef;
34 /* Declare all of the target-initialization functions that are available. */
35 #define LLVM_TARGET(TargetName) \
36 void LLVMInitialize##TargetName##TargetInfo(void);
37 #include "llvm/Config/Targets.def"
38 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
40 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
41 #include "llvm/Config/Targets.def"
42 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
44 #define LLVM_TARGET(TargetName) \
45 void LLVMInitialize##TargetName##MCAsmInfo(void);
46 #include "llvm/Config/Targets.def"
47 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
49 /** LLVMInitializeAllTargetInfos - The main program should call this function if
50 it wants access to all available targets that LLVM is configured to
52 static inline void LLVMInitializeAllTargetInfos(void) {
53 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54 #include "llvm/Config/Targets.def"
55 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
58 /** LLVMInitializeAllTargets - The main program should call this function if it
59 wants to link in all available targets that LLVM is configured to
61 static inline void LLVMInitializeAllTargets(void) {
62 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
63 #include "llvm/Config/Targets.def"
64 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
67 /** LLVMInitializeNativeTarget - The main program should call this function to
68 initialize the native target corresponding to the host. This is useful
69 for JIT applications to ensure that the target gets linked in correctly. */
70 static inline LLVMBool LLVMInitializeNativeTarget(void) {
71 /* If we have a native target, initialize it to ensure it is linked in. */
72 #ifdef LLVM_NATIVE_TARGET
73 LLVM_NATIVE_TARGETINFO();
75 LLVM_NATIVE_MCASMINFO();
82 /*===-- Target Data -------------------------------------------------------===*/
84 /** Creates target data from a target layout string.
85 See the constructor llvm::TargetData::TargetData. */
86 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
88 /** Adds target data information to a pass manager. This does not take ownership
90 See the method llvm::PassManagerBase::add. */
91 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
93 /** Converts target data to a target layout string. The string must be disposed
94 with LLVMDisposeMessage.
95 See the constructor llvm::TargetData::TargetData. */
96 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
98 /** Returns the byte order of a target, either LLVMBigEndian or
100 See the method llvm::TargetData::isLittleEndian. */
101 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
103 /** Returns the pointer size in bytes for a target.
104 See the method llvm::TargetData::getPointerSize. */
105 unsigned LLVMPointerSize(LLVMTargetDataRef);
107 /** Returns the integer type that is the same size as a pointer on a target.
108 See the method llvm::TargetData::getIntPtrType. */
109 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
111 /** Computes the size of a type in bytes for a target.
112 See the method llvm::TargetData::getTypeSizeInBits. */
113 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
115 /** Computes the storage size of a type in bytes for a target.
116 See the method llvm::TargetData::getTypeStoreSize. */
117 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
119 /** Computes the ABI size of a type in bytes for a target.
120 See the method llvm::TargetData::getTypeAllocSize. */
121 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
123 /** Computes the ABI alignment of a type in bytes for a target.
124 See the method llvm::TargetData::getTypeABISize. */
125 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
127 /** Computes the call frame alignment of a type in bytes for a target.
128 See the method llvm::TargetData::getTypeABISize. */
129 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
131 /** Computes the preferred alignment of a type in bytes for a target.
132 See the method llvm::TargetData::getTypeABISize. */
133 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
135 /** Computes the preferred alignment of a global variable in bytes for a target.
136 See the method llvm::TargetData::getPreferredAlignment. */
137 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
138 LLVMValueRef GlobalVar);
140 /** Computes the structure element that contains the byte offset for a target.
141 See the method llvm::StructLayout::getElementContainingOffset. */
142 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
143 unsigned long long Offset);
145 /** Computes the byte offset of the indexed struct element for a target.
146 See the method llvm::StructLayout::getElementContainingOffset. */
147 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
150 /** Struct layouts are speculatively cached. If a TargetDataRef is alive when
151 types are being refined and removed, this method must be called whenever a
152 struct type is removed to avoid a dangling pointer in this cache.
153 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
154 void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
156 /** Deallocates a TargetData.
157 See the destructor llvm::TargetData::~TargetData. */
158 void LLVMDisposeTargetData(LLVMTargetDataRef);
167 inline TargetData *unwrap(LLVMTargetDataRef P) {
168 return reinterpret_cast<TargetData*>(P);
171 inline LLVMTargetDataRef wrap(const TargetData *P) {
172 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
176 #endif /* defined(__cplusplus) */