Target.cpp revision 193323
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#include <cstring>
19
20using namespace llvm;
21
22LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
23  return wrap(new TargetData(StringRep));
24}
25
26void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
27  unwrap(PM)->add(new TargetData(*unwrap(TD)));
28}
29
30char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
31  std::string StringRep = unwrap(TD)->getStringRepresentation();
32  return strdup(StringRep.c_str());
33}
34
35LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
36  return unwrap(TD)->isLittleEndian();
37}
38
39unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
40  return unwrap(TD)->getPointerSize();
41}
42
43LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
44  return wrap(unwrap(TD)->getIntPtrType());
45}
46
47unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
48  return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
49}
50
51unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
52  return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
53}
54
55unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
56  return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
57}
58
59unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
60  return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
61}
62
63unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
64  return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
65}
66
67unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
68  return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
69}
70
71unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
72                                        LLVMValueRef GlobalVar) {
73  return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
74}
75
76unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
77                             unsigned long long Offset) {
78  const StructType *STy = unwrap<StructType>(StructTy);
79  return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
80}
81
82unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
83                                       unsigned Element) {
84  const StructType *STy = unwrap<StructType>(StructTy);
85  return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
86}
87
88void LLVMInvalidateStructLayout(LLVMTargetDataRef TD, LLVMTypeRef StructTy) {
89  unwrap(TD)->InvalidateStructLayoutInfo(unwrap<StructType>(StructTy));
90}
91
92void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
93  delete unwrap(TD);
94}
95