zpu: managed to compile program that writes constant to global variable
[llvm/zpu.git] / lib / Target / Target.cpp
blob9609099e91494e4b3d0cad064f107d98d14e75f2
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 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"
21 #include <cstring>
23 using namespace llvm;
25 void llvm::initializeTarget(PassRegistry &Registry) {
26 initializeTargetDataPass(Registry);
29 void LLVMInitializeTarget(LLVMPassRegistryRef R) {
30 initializeTarget(*unwrap(R));
33 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
34 return wrap(new TargetData(StringRep));
37 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
38 unwrap(PM)->add(new TargetData(*unwrap(TD)));
41 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
42 std::string StringRep = unwrap(TD)->getStringRepresentation();
43 return strdup(StringRep.c_str());
46 LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
47 return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
50 unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
51 return unwrap(TD)->getPointerSize();
54 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
55 return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
58 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
59 return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
62 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
63 return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
66 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
67 return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
70 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
71 return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
74 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
75 return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
78 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
79 return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
82 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
83 LLVMValueRef GlobalVar) {
84 return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
87 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
88 unsigned long long Offset) {
89 const StructType *STy = unwrap<StructType>(StructTy);
90 return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
93 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
94 unsigned Element) {
95 const StructType *STy = unwrap<StructType>(StructTy);
96 return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
99 void LLVMInvalidateStructLayout(LLVMTargetDataRef TD, LLVMTypeRef StructTy) {
100 unwrap(TD)->InvalidateStructLayoutInfo(unwrap<StructType>(StructTy));
103 void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
104 delete unwrap(TD);