1 module llvm.types;
2 
3 public import std.stdint : uintptr_t;
4 
5 import llvm.config;
6 
7 /+ Analysis +/
8 
9 alias int LLVMVerifierFailureAction;
10 
11 /+ Transforms +/
12 
13 /++ Pass manager builder ++/
14 
15 struct LLVMOpaquePassManagerBuilder {}; alias LLVMOpaquePassManagerBuilder* LLVMPassManagerBuilderRef;
16 
17 /+ Core +/
18 
19 static if (LLVM_Version >= asVersion(3, 4, 0))
20 {
21 	alias extern(C) void function(const char* Reason) LLVMFatalErrorHandler;
22 }
23 
24 static if (LLVM_Version >= asVersion(3, 5, 0))
25 {
26 	//This is here because putting it where it semantically belongs creates a forward reference issues.
27 	struct LLVMOpaqueDiagnosticInfo {}; alias LLVMOpaqueDiagnosticInfo* LLVMDiagnosticInfoRef;
28 
29 	alias extern(C) void function(LLVMDiagnosticInfoRef, void*) LLVMDiagnosticHandler;
30 	alias extern(C) void function(LLVMContextRef, void *) LLVMYieldCallback;
31 }
32 
33 /++ Types and Enumerations ++/
34 
35 alias int LLVMBool;
36 struct LLVMOpaqueContext {}; alias LLVMOpaqueContext* LLVMContextRef;
37 struct LLVMOpaqueModule {}; alias LLVMOpaqueModule* LLVMModuleRef;
38 struct LLVMOpaqueType {}; alias LLVMOpaqueType* LLVMTypeRef;
39 struct LLVMOpaqueValue {}; alias LLVMOpaqueValue* LLVMValueRef;
40 struct LLVMOpaqueBasicBlock {}; alias LLVMOpaqueBasicBlock* LLVMBasicBlockRef;
41 struct LLVMOpaqueBuilder {}; alias LLVMOpaqueBuilder* LLVMBuilderRef;
42 struct LLVMOpaqueModuleProvider {}; alias LLVMOpaqueModuleProvider* LLVMModuleProviderRef;
43 struct LLVMOpaqueMemoryBuffer {}; alias LLVMOpaqueMemoryBuffer* LLVMMemoryBufferRef;
44 struct LLVMOpaquePassManager {}; alias LLVMOpaquePassManager* LLVMPassManagerRef;
45 struct LLVMOpaquePassRegistry {}; alias LLVMOpaquePassRegistry* LLVMPassRegistryRef;
46 struct LLVMOpaqueUse {}; alias LLVMOpaqueUse* LLVMUseRef;
47 
48 static if (LLVM_Version >= asVersion(3, 9, 0))
49 {
50 	struct LLVMOpaqueAttributeRef {}; alias LLVMOpaqueAttributeRef* LLVMAttributeRef;
51 }
52 
53 alias long LLVMAttribute;
54 alias int LLVMOpcode;
55 alias int LLVMTypeKind;
56 alias int LLVMLinkage;
57 alias int LLVMVisibility;
58 alias int LLVMDLLStorageClass;
59 alias int LLVMCallConv;
60 alias int LLVMIntPredicate;
61 alias int LLVMRealPredicate;
62 alias int LLVMLandingPadClauseTy;
63 static if (LLVM_Version >= asVersion(3, 3, 0))
64 {
65 	alias int LLVMThreadLocalMode;
66 	alias int LLVMAtomicOrdering;
67 	alias int LLVMAtomicRMWBinOp;
68 }
69 static if (LLVM_Version >= asVersion(3, 5, 0))
70 {
71 	alias int LLVMDiagnosticSeverity;
72 }
73 static if (LLVM_Version >= asVersion(3, 9, 0))
74 {
75 	alias int LLVMValueKind;
76 	alias uint LLVMAttributeIndex;
77 }
78 /+ Disassembler +/
79 
80 alias void* LLVMDisasmContextRef;
81 alias extern(C) int function(void* DisInfo, ulong PC, ulong Offset, ulong Size, int TagType, void* TagBuf) LLVMOpInfoCallback;
82 alias extern(C) const char* function(void* DisInfo, ulong ReferenceValue, ulong* ReferenceType, ulong ReferencePC, const char** ReferenceName) LLVMSymbolLookupCallback;
83 
84 struct LLVMOpInfoSymbol1
85 {
86 	ulong Present;
87 	const char* Name;
88 	ulong Value;
89 }
90 
91 struct LLVMOpInfo1
92 {
93 	LLVMOpInfoSymbol1 AddSymbol;
94 	LLVMOpInfoSymbol1 SubtractSymbol;
95 	ulong Value;
96 	ulong VariantKind;
97 }
98 
99 static if (LLVM_Version < asVersion(3, 3, 0))
100 {
101 	/+ Enhanced Disassembly +/
102 
103 	alias void* EDDisassemblerRef;
104 	alias void* EDInstRef;
105 	alias void* EDTokenRef;
106 	alias void* EDOperandRef;
107 
108 	alias int EDAssemblySyntax_t;
109 
110 	alias extern(C) int function(ubyte* Byte, ulong address, void* arg) EDByteReaderCallback;
111 	alias extern(C) int function(ulong* value, uint regID, void* arg) EDRegisterReaderCallback;
112 
113 	alias extern(C) int function(ubyte* Byte, ulong address) EDByteBlock_t;
114 	alias extern(C) int function(ulong* value, uint regID) EDRegisterBlock_t;
115 	alias extern(C) int function(EDTokenRef token) EDTokenVisitor_t;
116 }
117 
118 /+ Execution Engine +/
119 
120 struct LLVMOpaqueGenericValue {}; alias LLVMOpaqueGenericValue* LLVMGenericValueRef;
121 struct LLVMOpaqueExecutionEngine {}; alias LLVMOpaqueExecutionEngine* LLVMExecutionEngineRef;
122 
123 static if (LLVM_Version >= asVersion(3, 3, 0))
124 {
125 	static if (LLVM_Version >= asVersion(3, 4, 0))
126 	{
127 		struct LLVMOpaqueMCJITMemoryManager {}; alias LLVMOpaqueMCJITMemoryManager* LLVMMCJITMemoryManagerRef;
128 
129 		struct LLVMMCJITCompilerOptions
130 		{
131 			uint OptLevel;
132 			LLVMCodeModel CodeModel;
133 			LLVMBool NoFramePointerElim;
134 			LLVMBool EnableFastISel;
135 			LLVMMCJITMemoryManagerRef MCJMM;
136 		}
137 
138 		alias extern(C) ubyte function(void* Opaque, uintptr_t Size, uint Alignment, uint SectionID, const char* SectionName) LLVMMemoryManagerAllocateCodeSectionCallback;
139 		alias extern(C) ubyte function(void* Opaque, uintptr_t Size, uint Alignment, uint SectionID, const char* SectionName, LLVMBool IsReadOnly) LLVMMemoryManagerAllocateDataSectionCallback;
140 		alias extern(C) LLVMBool function(void* Opaque, char** ErrMsg) LLVMMemoryManagerFinalizeMemoryCallback;
141 		alias extern(C) void function(void* Opaque) LLVMMemoryManagerDestroyCallback;
142 	}
143 	else
144 	{
145 		struct LLVMMCJITCompilerOptions
146 		{
147 			uint OptLevel;
148 			LLVMCodeModel CodeModel;
149 			LLVMBool NoFramePointerElim;
150 			LLVMBool EnableFastISel;
151 		}
152 	}
153 }
154 
155 static if (LLVM_Version >= asVersion(3, 2, 0))
156 {
157 	/+ Linker +/
158 
159 	alias int LLVMLinkerMode;
160 }
161 
162 /+ Link Time Optimization +/
163 alias bool lto_bool_t;
164 alias void* llvm_lto_t;
165 alias llvm_lto_status llvm_lto_status_t;
166 
167 
168 alias int llvm_lto_status;
169 
170 /+ LTO +/
171 
172 static if (LLVM_Version >= asVersion(3, 5, 0))
173 {
174 	struct LLVMOpaqueLTOModule {}; alias LLVMOpaqueLTOModule* lto_module_t;
175 }
176 else
177 {
178 	struct LTOModule {}; alias LTOModule* lto_module_t;
179 }
180 static if (LLVM_Version >= asVersion(3, 5, 0))
181 {
182 	struct LLVMOpaqueLTOCodeGenerator {}; alias LLVMOpaqueLTOCodeGenerator* lto_code_gen_t;
183 }
184 else
185 {
186 	struct LTOCodeGenerator {}; alias LTOCodeGenerator* lto_code_gen_t;
187 }
188 static if (LLVM_Version >= asVersion(3, 9, 0))
189 {
190 	struct LLVMOpaqueThinLTOCodeGenerator {}; alias LLVMOpaqueThinLTOCodeGenerator* thinlto_code_gen_t;
191 }
192 
193 alias int lto_symbol_attributes;
194 alias int lto_debug_model;
195 alias int lto_codegen_model;
196 alias int lto_codegen_diagnostic_severity_t;
197 alias extern(C) void function(lto_codegen_diagnostic_severity_t severity, const(char)* diag, void* ctxt) lto_diagnostic_handler_t;
198 
199 /+ Object file reading and writing +/
200 
201 struct LLVMOpaqueObjectFile {}; alias LLVMOpaqueObjectFile* LLVMObjectFileRef;
202 struct LLVMOpaqueSectionIterator {}; alias LLVMOpaqueSectionIterator* LLVMSectionIteratorRef;
203 struct LLVMOpaqueSymbolIterator {}; alias LLVMOpaqueSymbolIterator* LLVMSymbolIteratorRef;
204 struct LLVMOpaqueRelocationIterator {}; alias LLVMOpaqueRelocationIterator* LLVMRelocationIteratorRef;
205 
206 /+ Target information +/
207 
208 struct LLVMOpaqueTargetData {}; alias LLVMOpaqueTargetData* LLVMTargetDataRef;
209 struct LLVMOpaqueTargetLibraryInfotData {}; alias LLVMOpaqueTargetLibraryInfotData* LLVMTargetLibraryInfoRef;
210 static if (LLVM_Version < asVersion(3, 4, 0))
211 {
212 	struct LLVMStructLayout {}; alias LLVMStructLayout* LLVMStructLayoutRef;
213 }
214 alias int LLVMByteOrdering;
215 
216 /+ Target machine +/
217 
218 struct LLVMOpaqueTargetMachine {}; alias LLVMOpaqueTargetMachine* LLVMTargetMachineRef;
219 struct LLVMTarget {}; alias LLVMTarget* LLVMTargetRef;
220 
221 alias int LLVMCodeGenOptLevel;
222 alias int LLVMRelocMode;
223 alias int LLVMCodeModel;
224 alias int LLVMCodeGenFileType;
225 
226 static if (LLVM_Version >= asVersion(3, 8, 0))
227 {
228 	/+ JIT compilation of LLVM IR +/
229 	
230 	struct LLVMOrcOpaqueJITStack {}; alias LLVMOrcOpaqueJITStack* LLVMOrcJITStackRef;
231 
232 	alias uint LLVMOrcModuleHandle;
233 	alias ulong LLVMOrcTargetAddress;
234 
235 	alias extern(C) ulong function(const(char)* Name, void* LookupCtx) LLVMOrcSymbolResolverFn;
236 	alias extern(C) ulong function(LLVMOrcJITStackRef JITStack, void* CallbackCtx) LLVMOrcLazyCompileCallbackFn;
237 }
238 
239 static if (LLVM_Version >= asVersion(3, 9, 0))
240 {
241 	alias int LLVMOrcErrorCode;
242 
243 	struct LTOObjectBuffer
244 	{
245 		const(char)* Buffer;
246 		size_t Size;
247 	}
248 }