blob: d21644011ad48e503dfc9e2209cada1e0b05dbbd [file] [log] [blame]
Eric Christophereec50082010-08-08 02:44:17 +00001/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
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 header declares the C interface to libLLVMTarget.a, which */
11/* implements target information. */
12/* */
13/* Many exotic languages can interoperate with C code but have a harder time */
14/* with C++ due to name mangling. So in addition to C, this interface enables */
15/* tools written in such languages. */
16/* */
17/*===----------------------------------------------------------------------===*/
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000018
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
Eric Christophereec50082010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
Chris Lattnerd686c8e2010-01-09 22:27:07 +000029enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000030
31typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
32typedef struct LLVMStructLayout *LLVMStructLayoutRef;
33
Bob Wilsona96751f2009-06-23 23:59:40 +000034/* Declare all of the target-initialization functions that are available. */
Eric Christopherca3ca132010-07-12 05:13:35 +000035#define LLVM_TARGET(TargetName) \
36 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000037#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000038#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
39
Chris Lattnerff33d832010-04-28 20:24:45 +000040#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilsona96751f2009-06-23 23:59:40 +000041#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000042#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000043
Evan Cheng1abf2cb2011-07-14 23:50:31 +000044#define LLVM_TARGET(TargetName) \
45 void LLVMInitialize##TargetName##MCAsmInfo(void);
46#include "llvm/Config/Targets.def"
47#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
48
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000049/** LLVMInitializeAllTargetInfos - The main program should call this function if
50 it wants access to all available targets that LLVM is configured to
51 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000052static inline void LLVMInitializeAllTargetInfos(void) {
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000053#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000055#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000056}
57
Bob Wilsona96751f2009-06-23 23:59:40 +000058/** LLVMInitializeAllTargets - The main program should call this function if it
59 wants to link in all available targets that LLVM is configured to
60 support. */
Chris Lattnerc799c552010-04-29 23:27:32 +000061static inline void LLVMInitializeAllTargets(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +000062#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
63#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000064#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000065}
66
67/** LLVMInitializeNativeTarget - The main program should call this function to
68 initialize the native target corresponding to the host. This is useful
69 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattnerc799c552010-04-29 23:27:32 +000070static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +000071 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christopher753f3262010-08-30 18:34:48 +000072#ifdef LLVM_NATIVE_TARGET
73 LLVM_NATIVE_TARGETINFO();
74 LLVM_NATIVE_TARGET();
Evan Cheng1abf2cb2011-07-14 23:50:31 +000075 LLVM_NATIVE_MCASMINFO();
Bob Wilsona96751f2009-06-23 23:59:40 +000076 return 0;
Bob Wilsona96751f2009-06-23 23:59:40 +000077#else
78 return 1;
79#endif
80}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000081
82/*===-- Target Data -------------------------------------------------------===*/
83
84/** Creates target data from a target layout string.
85 See the constructor llvm::TargetData::TargetData. */
86LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
87
88/** Adds target data information to a pass manager. This does not take ownership
89 of the target data.
90 See the method llvm::PassManagerBase::add. */
91void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
92
93/** Converts target data to a target layout string. The string must be disposed
94 with LLVMDisposeMessage.
95 See the constructor llvm::TargetData::TargetData. */
96char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
97
98/** Returns the byte order of a target, either LLVMBigEndian or
99 LLVMLittleEndian.
100 See the method llvm::TargetData::isLittleEndian. */
Chris Lattner10bc7552010-01-09 23:25:21 +0000101enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000102
103/** Returns the pointer size in bytes for a target.
104 See the method llvm::TargetData::getPointerSize. */
105unsigned LLVMPointerSize(LLVMTargetDataRef);
106
107/** Returns the integer type that is the same size as a pointer on a target.
108 See the method llvm::TargetData::getIntPtrType. */
109LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
110
111/** Computes the size of a type in bytes for a target.
112 See the method llvm::TargetData::getTypeSizeInBits. */
113unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
114
115/** Computes the storage size of a type in bytes for a target.
116 See the method llvm::TargetData::getTypeStoreSize. */
117unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
118
119/** Computes the ABI size of a type in bytes for a target.
Duncan Sands777d2302009-05-09 07:06:46 +0000120 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000121unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
122
123/** Computes the ABI alignment of a type in bytes for a target.
124 See the method llvm::TargetData::getTypeABISize. */
125unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
126
127/** Computes the call frame alignment of a type in bytes for a target.
128 See the method llvm::TargetData::getTypeABISize. */
129unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
130
131/** Computes the preferred alignment of a type in bytes for a target.
132 See the method llvm::TargetData::getTypeABISize. */
133unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
134
135/** Computes the preferred alignment of a global variable in bytes for a target.
136 See the method llvm::TargetData::getPreferredAlignment. */
137unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
138 LLVMValueRef GlobalVar);
139
140/** Computes the structure element that contains the byte offset for a target.
141 See the method llvm::StructLayout::getElementContainingOffset. */
142unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
143 unsigned long long Offset);
144
145/** Computes the byte offset of the indexed struct element for a target.
146 See the method llvm::StructLayout::getElementContainingOffset. */
147unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
148 unsigned Element);
149
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000150/** Deallocates a TargetData.
151 See the destructor llvm::TargetData::~TargetData. */
152void LLVMDisposeTargetData(LLVMTargetDataRef);
153
154
155#ifdef __cplusplus
156}
157
158namespace llvm {
159 class TargetData;
160
161 inline TargetData *unwrap(LLVMTargetDataRef P) {
162 return reinterpret_cast<TargetData*>(P);
163 }
164
165 inline LLVMTargetDataRef wrap(const TargetData *P) {
166 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
167 }
168}
169
170#endif /* defined(__cplusplus) */
171
172#endif