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 common infrastructure (including C bindings) for
11 // libLLVMTarget.a, which implements target information.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Target.h"
16 #include "llvm-c/Initialization.h"
17 #include "llvm/InitializePasses.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetData.h"
20 #include "llvm/LLVMContext.h"
25 void llvm::initializeTarget(PassRegistry
&Registry
) {
26 initializeTargetDataPass(Registry
);
27 initializeTargetLibraryInfoPass(Registry
);
30 void LLVMInitializeTarget(LLVMPassRegistryRef R
) {
31 initializeTarget(*unwrap(R
));
34 LLVMTargetDataRef
LLVMCreateTargetData(const char *StringRep
) {
35 return wrap(new TargetData(StringRep
));
38 void LLVMAddTargetData(LLVMTargetDataRef TD
, LLVMPassManagerRef PM
) {
39 unwrap(PM
)->add(new TargetData(*unwrap(TD
)));
42 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD
) {
43 std::string StringRep
= unwrap(TD
)->getStringRepresentation();
44 return strdup(StringRep
.c_str());
47 LLVMByteOrdering
LLVMByteOrder(LLVMTargetDataRef TD
) {
48 return unwrap(TD
)->isLittleEndian() ? LLVMLittleEndian
: LLVMBigEndian
;
51 unsigned LLVMPointerSize(LLVMTargetDataRef TD
) {
52 return unwrap(TD
)->getPointerSize();
55 LLVMTypeRef
LLVMIntPtrType(LLVMTargetDataRef TD
) {
56 return wrap(unwrap(TD
)->getIntPtrType(getGlobalContext()));
59 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
60 return unwrap(TD
)->getTypeSizeInBits(unwrap(Ty
));
63 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
64 return unwrap(TD
)->getTypeStoreSize(unwrap(Ty
));
67 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
68 return unwrap(TD
)->getTypeAllocSize(unwrap(Ty
));
71 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
72 return unwrap(TD
)->getABITypeAlignment(unwrap(Ty
));
75 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
76 return unwrap(TD
)->getCallFrameTypeAlignment(unwrap(Ty
));
79 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
) {
80 return unwrap(TD
)->getPrefTypeAlignment(unwrap(Ty
));
83 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD
,
84 LLVMValueRef GlobalVar
) {
85 return unwrap(TD
)->getPreferredAlignment(unwrap
<GlobalVariable
>(GlobalVar
));
88 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD
, LLVMTypeRef StructTy
,
89 unsigned long long Offset
) {
90 const StructType
*STy
= unwrap
<StructType
>(StructTy
);
91 return unwrap(TD
)->getStructLayout(STy
)->getElementContainingOffset(Offset
);
94 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD
, LLVMTypeRef StructTy
,
96 const StructType
*STy
= unwrap
<StructType
>(StructTy
);
97 return unwrap(TD
)->getStructLayout(STy
)->getElementOffset(Element
);
100 void LLVMInvalidateStructLayout(LLVMTargetDataRef TD
, LLVMTypeRef StructTy
) {
101 unwrap(TD
)->InvalidateStructLayoutInfo(unwrap
<StructType
>(StructTy
));
104 void LLVMDisposeTargetData(LLVMTargetDataRef TD
) {