1 //===-- Target.cpp --------------------------------------------------------===//
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 file implements the C bindings for libLLVMTarget.a, which implements
11 // target information.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Target.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/Target/TargetData.h"
21 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
22 return wrap(new TargetData(StringRep));
25 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
26 unwrap(PM)->add(new TargetData(*unwrap(TD)));
29 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
30 std::string StringRep = unwrap(TD)->getStringRepresentation();
31 return strdup(StringRep.c_str());
34 LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
35 return unwrap(TD)->isLittleEndian();
38 unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
39 return unwrap(TD)->getPointerSize();
42 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
43 return wrap(unwrap(TD)->getIntPtrType());
46 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
47 return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
50 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
51 return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
54 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
55 return unwrap(TD)->getABITypeSize(unwrap(Ty));
58 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
59 return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
62 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
63 return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
66 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
67 return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
70 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
71 LLVMValueRef GlobalVar) {
72 return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
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);
81 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
83 const StructType *STy = unwrap<StructType>(StructTy);
84 return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
87 void LLVMInvalidateStructLayout(LLVMTargetDataRef TD, LLVMTypeRef StructTy) {
88 unwrap(TD)->InvalidateStructLayoutInfo(unwrap<StructType>(StructTy));
91 void LLVMDisposeTargetData(LLVMTargetDataRef TD) {