Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 1 | /*===-- 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" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | enum { LLVMBigEndian, LLVMLittleEndian }; |
| 29 | typedef int LLVMByteOrdering; |
| 30 | |
| 31 | typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; |
| 32 | typedef struct LLVMStructLayout *LLVMStructLayoutRef; |
| 33 | |
| 34 | |
| 35 | /*===-- Target Data -------------------------------------------------------===*/ |
| 36 | |
| 37 | /** Creates target data from a target layout string. |
| 38 | See the constructor llvm::TargetData::TargetData. */ |
| 39 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); |
| 40 | |
| 41 | /** Adds target data information to a pass manager. This does not take ownership |
| 42 | of the target data. |
| 43 | See the method llvm::PassManagerBase::add. */ |
| 44 | void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); |
| 45 | |
| 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); |
| 50 | |
| 51 | /** Returns the byte order of a target, either LLVMBigEndian or |
| 52 | LLVMLittleEndian. |
| 53 | See the method llvm::TargetData::isLittleEndian. */ |
| 54 | LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); |
| 55 | |
| 56 | /** Returns the pointer size in bytes for a target. |
| 57 | See the method llvm::TargetData::getPointerSize. */ |
| 58 | unsigned LLVMPointerSize(LLVMTargetDataRef); |
| 59 | |
| 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); |
| 63 | |
| 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); |
| 67 | |
| 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); |
| 71 | |
| 72 | /** Computes the ABI size of a type in bytes for a target. |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 73 | See the method llvm::TargetData::getTypeAllocSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 74 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 75 | |
| 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); |
| 79 | |
| 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); |
| 83 | |
| 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); |
| 87 | |
| 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); |
| 92 | |
| 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); |
| 97 | |
| 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, |
| 101 | unsigned Element); |
| 102 | |
| 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); |
| 108 | |
| 109 | /** Deallocates a TargetData. |
| 110 | See the destructor llvm::TargetData::~TargetData. */ |
| 111 | void LLVMDisposeTargetData(LLVMTargetDataRef); |
| 112 | |
| 113 | |
| 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | |
| 117 | namespace llvm { |
| 118 | class TargetData; |
| 119 | |
| 120 | inline TargetData *unwrap(LLVMTargetDataRef P) { |
| 121 | return reinterpret_cast<TargetData*>(P); |
| 122 | } |
| 123 | |
| 124 | inline LLVMTargetDataRef wrap(const TargetData *P) { |
| 125 | return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P)); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | #endif /* defined(__cplusplus) */ |
| 130 | |
| 131 | #endif |