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"
28 enum { LLVMBigEndian
, LLVMLittleEndian
};
29 typedef int LLVMByteOrdering
;
31 typedef struct LLVMOpaqueTargetData
*LLVMTargetDataRef
;
32 typedef struct LLVMStructLayout
*LLVMStructLayoutRef
;
35 /*===-- Target Data -------------------------------------------------------===*/
37 /** Creates target data from a target layout string.
38 See the constructor llvm::TargetData::TargetData. */
39 LLVMTargetDataRef
LLVMCreateTargetData(const char *StringRep
);
41 /** Adds target data information to a pass manager. This does not take ownership
43 See the method llvm::PassManagerBase::add. */
44 void LLVMAddTargetData(LLVMTargetDataRef
, LLVMPassManagerRef
);
46 /** Converts target data to a target layout string. The string must be disposed
47 with LLVMDisposeMessage.
48 See the constructor llvm::TargetData::TargetData. */
49 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef
);
51 /** Returns the byte order of a target, either LLVMBigEndian or
53 See the method llvm::TargetData::isLittleEndian. */
54 LLVMByteOrdering
LLVMByteOrder(LLVMTargetDataRef
);
56 /** Returns the pointer size in bytes for a target.
57 See the method llvm::TargetData::getPointerSize. */
58 unsigned LLVMPointerSize(LLVMTargetDataRef
);
60 /** Returns the integer type that is the same size as a pointer on a target.
61 See the method llvm::TargetData::getIntPtrType. */
62 LLVMTypeRef
LLVMIntPtrType(LLVMTargetDataRef
);
64 /** Computes the size of a type in bytes for a target.
65 See the method llvm::TargetData::getTypeSizeInBits. */
66 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef
, LLVMTypeRef
);
68 /** Computes the storage size of a type in bytes for a target.
69 See the method llvm::TargetData::getTypeStoreSize. */
70 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef
, LLVMTypeRef
);
72 /** Computes the ABI size of a type in bytes for a target.
73 See the method llvm::TargetData::getTypePaddedSize. */
74 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef
, LLVMTypeRef
);
76 /** Computes the ABI alignment of a type in bytes for a target.
77 See the method llvm::TargetData::getTypeABISize. */
78 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
80 /** Computes the call frame alignment of a type in bytes for a target.
81 See the method llvm::TargetData::getTypeABISize. */
82 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
84 /** Computes the preferred alignment of a type in bytes for a target.
85 See the method llvm::TargetData::getTypeABISize. */
86 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
88 /** Computes the preferred alignment of a global variable in bytes for a target.
89 See the method llvm::TargetData::getPreferredAlignment. */
90 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef
,
91 LLVMValueRef GlobalVar
);
93 /** Computes the structure element that contains the byte offset for a target.
94 See the method llvm::StructLayout::getElementContainingOffset. */
95 unsigned LLVMElementAtOffset(LLVMTargetDataRef
, LLVMTypeRef StructTy
,
96 unsigned long long Offset
);
98 /** Computes the byte offset of the indexed struct element for a target.
99 See the method llvm::StructLayout::getElementContainingOffset. */
100 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef
, LLVMTypeRef StructTy
,
103 /** Struct layouts are speculatively cached. If a TargetDataRef is alive when
104 types are being refined and removed, this method must be called whenever a
105 struct type is removed to avoid a dangling pointer in this cache.
106 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
107 void LLVMInvalidateStructLayout(LLVMTargetDataRef
, LLVMTypeRef StructTy
);
109 /** Deallocates a TargetData.
110 See the destructor llvm::TargetData::~TargetData. */
111 void LLVMDisposeTargetData(LLVMTargetDataRef
);
120 inline TargetData
*unwrap(LLVMTargetDataRef P
) {
121 return reinterpret_cast<TargetData
*>(P
);
124 inline LLVMTargetDataRef
wrap(const TargetData
*P
) {
125 return reinterpret_cast<LLVMTargetDataRef
>(const_cast<TargetData
*>(P
));
129 #endif /* defined(__cplusplus) */