blob: 691abdfcb47acc18a6b73fcbd15c93c29664374f [file] [log] [blame]
Duncan Sandsd6b7b8f2012-04-11 10:25:24 +00001/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - 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 the Target and TargetMachine *|
11|* classes, which can be used to generate assembly or object files. *|
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\*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGETMACHINE_H
20#define LLVM_C_TARGETMACHINE_H
21
22#include "llvm-c/Core.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000023#include "llvm-c/Target.h"
Duncan Sandsd6b7b8f2012-04-11 10:25:24 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28typedef struct LLVMTargetMachine *LLVMTargetMachineRef;
29typedef struct LLVMTarget *LLVMTargetRef;
30
31typedef enum {
32 LLVMCodeGenLevelNone,
33 LLVMCodeGenLevelLess,
34 LLVMCodeGenLevelDefault,
35 LLVMCodeGenLevelAggressive
36} LLVMCodeGenOptLevel;
37
38typedef enum {
39 LLVMRelocDefault,
40 LLVMRelocStatic,
41 LLVMRelocPIC,
42 LLVMRelocDynamicNoPic
43} LLVMRelocMode;
44
45typedef enum {
46 LLVMCodeModelDefault,
47 LLVMCodeModelJITDefault,
48 LLVMCodeModelSmall,
49 LLVMCodeModelKernel,
50 LLVMCodeModelMedium,
51 LLVMCodeModelLarge
52} LLVMCodeModel;
53
54typedef enum {
55 LLVMAssemblyFile,
56 LLVMObjectFile
57} LLVMCodeGenFileType;
58
59/** Returns the first llvm::Target in the registered targets list. */
60LLVMTargetRef LLVMGetFirstTarget();
61/** Returns the next llvm::Target given a previous one (or null if there's none) */
62LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
63
64/*===-- Target ------------------------------------------------------------===*/
65/** Returns the name of a target. See llvm::Target::getName */
66const char *LLVMGetTargetName(LLVMTargetRef T);
67
68/** Returns the description of a target. See llvm::Target::getDescription */
69const char *LLVMGetTargetDescription(LLVMTargetRef T);
70
71/** Returns if the target has a JIT */
72LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
73
74/** Returns if the target has a TargetMachine associated */
75LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
76
77/** Returns if the target as an ASM backend (required for emitting output) */
78LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
79
80/*===-- Target Machine ----------------------------------------------------===*/
81/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
82LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple,
83 char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
84 LLVMCodeModel CodeModel);
85
86/** Dispose the LLVMTargetMachineRef instance generated by
87 LLVMCreateTargetMachine. */
88void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
89
90/** Returns the Target used in a TargetMachine */
91LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
92
93/** Returns the triple used creating this target machine. See
94 llvm::TargetMachine::getTriple. The result needs to be disposed with
95 LLVMDisposeMessage. */
96char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
97
98/** Returns the cpu used creating this target machine. See
99 llvm::TargetMachine::getCPU. The result needs to be disposed with
100 LLVMDisposeMessage. */
101char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
102
103/** Returns the feature string used creating this target machine. See
104 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
105 LLVMDisposeMessage. */
106char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
107
Micah Villmow3574eca2012-10-08 16:38:25 +0000108/** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
Duncan Sandsd6b7b8f2012-04-11 10:25:24 +0000109LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
110
111/** Emits an asm or object file for the given module to the filename. This
112 wraps several c++ only classes (among them a file stream). Returns any
113 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
114LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
115 char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
116
117
118
119
120#ifdef __cplusplus
121}
122
123namespace llvm {
124 class TargetMachine;
125 class Target;
126
127 inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
128 return reinterpret_cast<TargetMachine*>(P);
129 }
130 inline Target *unwrap(LLVMTargetRef P) {
131 return reinterpret_cast<Target*>(P);
132 }
133 inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
134 return reinterpret_cast<LLVMTargetMachineRef>(
135 const_cast<TargetMachine*>(P));
136 }
137 inline LLVMTargetRef wrap(const Target * P) {
138 return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
139 }
140}
Evan Cheng9313da52013-04-04 17:40:53 +0000141#endif
Duncan Sandsd6b7b8f2012-04-11 10:25:24 +0000142
143#endif