2008-03-16 21:08:03 +01:00
|
|
|
//===-- Target.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-10-07 22:05:18 +02:00
|
|
|
// This file implements the common infrastructure (including C bindings) for
|
2010-10-07 20:50:11 +02:00
|
|
|
// libLLVMTarget.a, which implements target information.
|
2008-03-16 21:08:03 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Target.h"
|
2010-10-07 20:50:11 +02:00
|
|
|
#include "llvm-c/Initialization.h"
|
|
|
|
#include "llvm/InitializePasses.h"
|
2008-03-16 21:08:03 +01:00
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
2009-12-28 22:45:40 +01:00
|
|
|
#include "llvm/LLVMContext.h"
|
2008-04-04 18:08:00 +02:00
|
|
|
#include <cstring>
|
2008-03-16 21:08:03 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-10-07 20:50:11 +02:00
|
|
|
void llvm::initializeTarget(PassRegistry &Registry) {
|
|
|
|
initializeTargetDataPass(Registry);
|
2011-02-18 22:50:34 +01:00
|
|
|
initializeTargetLibraryInfoPass(Registry);
|
2010-10-07 20:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeTarget(LLVMPassRegistryRef R) {
|
|
|
|
initializeTarget(*unwrap(R));
|
|
|
|
}
|
|
|
|
|
2008-03-16 21:08:03 +01:00
|
|
|
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
|
|
|
|
return wrap(new TargetData(StringRep));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
|
|
|
|
unwrap(PM)->add(new TargetData(*unwrap(TD)));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
|
|
|
|
std::string StringRep = unwrap(TD)->getStringRepresentation();
|
|
|
|
return strdup(StringRep.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
|
2010-01-09 23:27:07 +01:00
|
|
|
return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
|
2008-03-16 21:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
|
|
|
|
return unwrap(TD)->getPointerSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
|
2009-08-13 23:58:54 +02:00
|
|
|
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
|
2008-03-16 21:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
2009-05-09 09:06:46 +02:00
|
|
|
return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
|
2008-03-16 21:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
|
|
|
|
LLVMValueRef GlobalVar) {
|
|
|
|
return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
|
|
|
|
unsigned long long Offset) {
|
2011-07-18 06:54:35 +02:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2008-03-16 21:08:03 +01:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
|
|
|
|
unsigned Element) {
|
2011-07-18 06:54:35 +02:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2008-03-16 21:08:03 +01:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
|
|
|
|
delete unwrap(TD);
|
|
|
|
}
|