| Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame^] | 1 | //===-- Target.cpp --------------------------------------------------------===// | 
 | 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 file implements the C bindings for libLLVMTarget.a, which implements | 
 | 11 | // target information. | 
 | 12 | // | 
 | 13 | //===----------------------------------------------------------------------===// | 
 | 14 |  | 
 | 15 | #include "llvm-c/Target.h" | 
 | 16 | #include "llvm/PassManager.h" | 
 | 17 | #include "llvm/Target/TargetData.h" | 
 | 18 |  | 
 | 19 | using namespace llvm; | 
 | 20 |  | 
 | 21 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) { | 
 | 22 |   return wrap(new TargetData(StringRep)); | 
 | 23 | } | 
 | 24 |  | 
 | 25 | void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) { | 
 | 26 |   unwrap(PM)->add(new TargetData(*unwrap(TD))); | 
 | 27 | } | 
 | 28 |  | 
 | 29 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) { | 
 | 30 |   std::string StringRep = unwrap(TD)->getStringRepresentation(); | 
 | 31 |   return strdup(StringRep.c_str()); | 
 | 32 | } | 
 | 33 |  | 
 | 34 | LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) { | 
 | 35 |   return unwrap(TD)->isLittleEndian(); | 
 | 36 | } | 
 | 37 |  | 
 | 38 | unsigned LLVMPointerSize(LLVMTargetDataRef TD) { | 
 | 39 |   return unwrap(TD)->getPointerSize(); | 
 | 40 | } | 
 | 41 |  | 
 | 42 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) { | 
 | 43 |   return wrap(unwrap(TD)->getIntPtrType()); | 
 | 44 | } | 
 | 45 |  | 
 | 46 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 47 |   return unwrap(TD)->getTypeSizeInBits(unwrap(Ty)); | 
 | 48 | } | 
 | 49 |  | 
 | 50 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 51 |   return unwrap(TD)->getTypeStoreSize(unwrap(Ty)); | 
 | 52 | } | 
 | 53 |  | 
 | 54 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 55 |   return unwrap(TD)->getABITypeSize(unwrap(Ty)); | 
 | 56 | } | 
 | 57 |  | 
 | 58 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 59 |   return unwrap(TD)->getABITypeAlignment(unwrap(Ty)); | 
 | 60 | } | 
 | 61 |  | 
 | 62 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 63 |   return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty)); | 
 | 64 | } | 
 | 65 |  | 
 | 66 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { | 
 | 67 |   return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty)); | 
 | 68 | } | 
 | 69 |  | 
 | 70 | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, | 
 | 71 |                                         LLVMValueRef GlobalVar) { | 
 | 72 |   return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar)); | 
 | 73 | } | 
 | 74 |  | 
 | 75 | unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy, | 
 | 76 |                              unsigned long long Offset) { | 
 | 77 |   const StructType *STy = unwrap<StructType>(StructTy); | 
 | 78 |   return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset); | 
 | 79 | } | 
 | 80 |  | 
 | 81 | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy, | 
 | 82 |                                        unsigned Element) { | 
 | 83 |   const StructType *STy = unwrap<StructType>(StructTy); | 
 | 84 |   return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element); | 
 | 85 | } | 
 | 86 |  | 
 | 87 | void LLVMInvalidateStructLayout(LLVMTargetDataRef TD, LLVMTypeRef StructTy) { | 
 | 88 |   unwrap(TD)->InvalidateStructLayoutInfo(unwrap<StructType>(StructTy)); | 
 | 89 | } | 
 | 90 |  | 
 | 91 | void LLVMDisposeTargetData(LLVMTargetDataRef TD) { | 
 | 92 |   delete unwrap(TD); | 
 | 93 | } |