Skip to main content

llvm_sys/
lib.rs

1//! Bindings to LLVM's C API.
2//!
3//! Refer to the [LLVM documentation](http://llvm.org/docs/) for more
4//! information.
5
6#![allow(non_upper_case_globals)]
7#![allow(non_camel_case_types)]
8
9extern crate libc;
10
11use self::prelude::*;
12
13#[derive(Debug)]
14pub enum LLVMMemoryBuffer {}
15
16#[derive(Debug)]
17pub enum LLVMContext {}
18
19#[derive(Debug)]
20pub enum LLVMModule {}
21
22#[derive(Debug)]
23pub enum LLVMType {}
24
25#[derive(Debug)]
26pub enum LLVMValue {}
27
28#[derive(Debug)]
29pub enum LLVMBasicBlock {}
30
31#[derive(Debug)]
32pub enum LLVMOpaqueMetadata {}
33
34#[derive(Debug)]
35pub enum LLVMOpaqueNamedMDNode {}
36
37#[derive(Debug)]
38pub enum LLVMOpaqueValueMetadataEntry {}
39
40#[derive(Debug)]
41pub enum LLVMBuilder {}
42
43#[derive(Debug)]
44pub enum LLVMOpaqueDIBuilder {}
45
46#[derive(Debug)]
47pub enum LLVMModuleProvider {}
48
49#[derive(Debug)]
50pub enum LLVMPassManager {}
51
52#[derive(Debug)]
53pub enum LLVMUse {}
54
55#[derive(Debug)]
56pub enum LLVMDiagnosticInfo {}
57
58#[derive(Debug)]
59pub enum LLVMComdat {}
60
61#[derive(Debug)]
62pub enum LLVMOpaqueModuleFlagEntry {}
63
64#[derive(Debug)]
65pub enum LLVMOpaqueJITEventListener {}
66
67#[derive(Debug)]
68pub enum LLVMOpaqueAttributeRef {}
69
70/// Core types used throughout LLVM.
71///
72/// In most cases you will want to `use llvm::prelude::*`.
73pub mod prelude {
74    pub type LLVMBool = ::libc::c_int;
75    pub type LLVMMemoryBufferRef = *mut super::LLVMMemoryBuffer;
76    pub type LLVMContextRef = *mut super::LLVMContext;
77    pub type LLVMModuleRef = *mut super::LLVMModule;
78    pub type LLVMTypeRef = *mut super::LLVMType;
79    pub type LLVMValueRef = *mut super::LLVMValue;
80    pub type LLVMBasicBlockRef = *mut super::LLVMBasicBlock;
81    pub type LLVMMetadataRef = *mut super::LLVMOpaqueMetadata;
82    pub type LLVMNamedMDNodeRef = *mut super::LLVMOpaqueNamedMDNode;
83    pub type LLVMValueMetadataEntry = *mut super::LLVMOpaqueValueMetadataEntry;
84    pub type LLVMBuilderRef = *mut super::LLVMBuilder;
85    pub type LLVMDIBuilderRef = *mut super::LLVMOpaqueDIBuilder;
86    pub type LLVMModuleProviderRef = *mut super::LLVMModuleProvider;
87    pub type LLVMPassManagerRef = *mut super::LLVMPassManager;
88    pub type LLVMUseRef = *mut super::LLVMUse;
89    pub type LLVMDiagnosticInfoRef = *mut super::LLVMDiagnosticInfo;
90    pub type LLVMComdatRef = *mut super::LLVMComdat;
91    pub type LLVMModuleFlagEntry = *mut super::LLVMOpaqueModuleFlagEntry;
92    pub type LLVMJITEventListenerRef = *mut super::LLVMOpaqueJITEventListener;
93    pub type LLVMAttributeRef = *mut super::LLVMOpaqueAttributeRef;
94}
95
96pub mod analysis;
97pub mod bit_reader;
98pub mod bit_writer;
99pub mod blake3;
100pub mod comdat;
101pub mod core;
102pub mod debuginfo;
103pub mod disassembler;
104pub mod error;
105pub mod error_handling;
106pub mod execution_engine;
107pub mod ir_reader;
108pub mod linker;
109pub mod lto;
110pub mod object;
111pub mod orc2;
112pub mod remarks;
113pub mod support;
114pub mod target;
115pub mod target_machine;
116
117pub mod transforms {
118    pub mod pass_builder;
119}
120
121#[repr(C)]
122#[derive(Clone, Copy, Debug, PartialEq)]
123pub enum LLVMOpcode {
124    LLVMRet = 1,
125    LLVMBr = 2,
126    LLVMSwitch = 3,
127    LLVMIndirectBr = 4,
128    LLVMInvoke = 5,
129    LLVMUnreachable = 7,
130    LLVMCallBr = 67,
131    LLVMFNeg = 66,
132    LLVMAdd = 8,
133    LLVMFAdd = 9,
134    LLVMSub = 10,
135    LLVMFSub = 11,
136    LLVMMul = 12,
137    LLVMFMul = 13,
138    LLVMUDiv = 14,
139    LLVMSDiv = 15,
140    LLVMFDiv = 16,
141    LLVMURem = 17,
142    LLVMSRem = 18,
143    LLVMFRem = 19,
144    LLVMShl = 20,
145    LLVMLShr = 21,
146    LLVMAShr = 22,
147    LLVMAnd = 23,
148    LLVMOr = 24,
149    LLVMXor = 25,
150    LLVMAlloca = 26,
151    LLVMLoad = 27,
152    LLVMStore = 28,
153    LLVMGetElementPtr = 29,
154    LLVMTrunc = 30,
155    LLVMZExt = 31,
156    LLVMSExt = 32,
157    LLVMFPToUI = 33,
158    LLVMFPToSI = 34,
159    LLVMUIToFP = 35,
160    LLVMSIToFP = 36,
161    LLVMFPTrunc = 37,
162    LLVMFPExt = 38,
163    LLVMPtrToInt = 39,
164    LLVMIntToPtr = 40,
165    LLVMBitCast = 41,
166    LLVMAddrSpaceCast = 60,
167    LLVMICmp = 42,
168    LLVMFCmp = 43,
169    LLVMPHI = 44,
170    LLVMCall = 45,
171    LLVMSelect = 46,
172    LLVMUserOp1 = 47,
173    LLVMUserOp2 = 48,
174    LLVMVAArg = 49,
175    LLVMExtractElement = 50,
176    LLVMInsertElement = 51,
177    LLVMShuffleVector = 52,
178    LLVMExtractValue = 53,
179    LLVMInsertValue = 54,
180    LLVMFreeze = 68,
181    LLVMFence = 55,
182    LLVMAtomicCmpXchg = 56,
183    LLVMAtomicRMW = 57,
184    LLVMResume = 58,
185    LLVMLandingPad = 59,
186    LLVMCleanupRet = 61,
187    LLVMCatchRet = 62,
188    LLVMCatchPad = 63,
189    LLVMCleanupPad = 64,
190    LLVMCatchSwitch = 65,
191}
192
193#[repr(C)]
194#[derive(Clone, Copy, Debug, PartialEq)]
195pub enum LLVMTypeKind {
196    LLVMVoidTypeKind = 0,
197    LLVMHalfTypeKind = 1,
198    LLVMFloatTypeKind = 2,
199    LLVMDoubleTypeKind = 3,
200    LLVMX86_FP80TypeKind = 4,
201    LLVMFP128TypeKind = 5,
202    LLVMPPC_FP128TypeKind = 6,
203    LLVMLabelTypeKind = 7,
204    LLVMIntegerTypeKind = 8,
205    LLVMFunctionTypeKind = 9,
206    LLVMStructTypeKind = 10,
207    LLVMArrayTypeKind = 11,
208    LLVMPointerTypeKind = 12,
209    LLVMVectorTypeKind = 13,
210    LLVMMetadataTypeKind = 14,
211    LLVMX86_MMXTypeKind = 15,
212    LLVMTokenTypeKind = 16,
213    LLVMScalableVectorTypeKind = 17,
214    LLVMBFloatTypeKind = 18,
215    LLVMX86_AMXTypeKind = 19,
216    LLVMTargetExtTypeKind = 20,
217}
218
219#[repr(C)]
220#[derive(Clone, Copy, Debug, PartialEq)]
221pub enum LLVMLinkage {
222    LLVMExternalLinkage = 0,
223    LLVMAvailableExternallyLinkage = 1,
224    LLVMLinkOnceAnyLinkage = 2,
225    LLVMLinkOnceODRLinkage = 3,
226    LLVMLinkOnceODRAutoHideLinkage = 4,
227    LLVMWeakAnyLinkage = 5,
228    LLVMWeakODRLinkage = 6,
229    LLVMAppendingLinkage = 7,
230    LLVMInternalLinkage = 8,
231    LLVMPrivateLinkage = 9,
232    LLVMDLLImportLinkage = 10,
233    LLVMDLLExportLinkage = 11,
234    LLVMExternalWeakLinkage = 12,
235    LLVMGhostLinkage = 13,
236    LLVMCommonLinkage = 14,
237    LLVMLinkerPrivateLinkage = 15,
238    LLVMLinkerPrivateWeakLinkage = 16,
239}
240
241#[repr(C)]
242#[derive(Clone, Copy, Debug, PartialEq)]
243pub enum LLVMVisibility {
244    LLVMDefaultVisibility = 0,
245    LLVMHiddenVisibility = 1,
246    LLVMProtectedVisibility = 2,
247}
248
249#[repr(C)]
250#[derive(Clone, Copy, Debug, PartialEq)]
251pub enum LLVMUnnamedAddr {
252    /// Address of the GV is significant.
253    LLVMNoUnnamedAddr,
254    /// Address of the GV is locally insignificant.
255    LLVMLocalUnnamedAddr,
256    /// Address of the GV is globally insignificant.
257    LLVMGlobalUnnamedAddr,
258}
259
260#[repr(C)]
261#[derive(Clone, Copy, Debug, PartialEq)]
262pub enum LLVMDLLStorageClass {
263    LLVMDefaultStorageClass = 0,
264    LLVMDLLImportStorageClass = 1,
265    LLVMDLLExportStorageClass = 2,
266}
267
268#[repr(C)]
269#[derive(Clone, Copy, Debug, PartialEq)]
270pub enum LLVMCallConv {
271    LLVMCCallConv = 0,
272    LLVMFastCallConv = 8,
273    LLVMColdCallConv = 9,
274    LLVMGHCCallConv = 10,
275    LLVMHiPECallConv = 11,
276    LLVMWebKitJSCallConv = 12,
277    LLVMAnyRegCallConv = 13,
278    LLVMPreserveMostCallConv = 14,
279    LLVMPreserveAllCallConv = 15,
280    LLVMSwiftCallConv = 16,
281    LLVMCXXFASTTLSCallConv = 17,
282    LLVMX86StdcallCallConv = 64,
283    LLVMX86FastcallCallConv = 65,
284    LLVMARMAPCSCallConv = 66,
285    LLVMARMAAPCSCallConv = 67,
286    LLVMARMAAPCSVFPCallConv = 68,
287    LLVMMSP430INTRCallConv = 69,
288    LLVMX86ThisCallCallConv = 70,
289    LLVMPTXKernelCallConv = 71,
290    LLVMPTXDeviceCallConv = 72,
291    LLVMSPIRFUNCCallConv = 75,
292    LLVMSPIRKERNELCallConv = 76,
293    LLVMIntelOCLBICallConv = 77,
294    LLVMX8664SysVCallConv = 78,
295    LLVMWin64CallConv = 79,
296    LLVMX86VectorCallCallConv = 80,
297    LLVMHHVMCallConv = 81,
298    LLVMHHVMCCallConv = 82,
299    LLVMX86INTRCallConv = 83,
300    LLVMAVRINTRCallConv = 84,
301    LLVMAVRSIGNALCallConv = 85,
302    LLVMAVRBUILTINCallConv = 86,
303    LLVMAMDGPUVSCallConv = 87,
304    LLVMAMDGPUGSCallConv = 88,
305    LLVMAMDGPUPSCallConv = 89,
306    LLVMAMDGPUCSCallConv = 90,
307    LLVMAMDGPUKERNELCallConv = 91,
308    LLVMX86RegCallCallConv = 92,
309    LLVMAMDGPUHSCallConv = 93,
310    LLVMMSP430BUILTINCallConv = 94,
311    LLVMAMDGPULSCallConv = 95,
312    LLVMAMDGPUESCallConv = 96,
313}
314
315#[repr(C)]
316#[derive(Clone, Copy, Debug, PartialEq)]
317pub enum LLVMValueKind {
318    LLVMArgumentValueKind,
319    LLVMBasicBlockValueKind,
320    LLVMMemoryUseValueKind,
321    LLVMMemoryDefValueKind,
322    LLVMMemoryPhiValueKind,
323
324    LLVMFunctionValueKind,
325    LLVMGlobalAliasValueKind,
326    LLVMGlobalIFuncValueKind,
327    LLVMGlobalVariableValueKind,
328    LLVMBlockAddressValueKind,
329    LLVMConstantExprValueKind,
330    LLVMConstantArrayValueKind,
331    LLVMConstantStructValueKind,
332    LLVMConstantVectorValueKind,
333    LLVMUndefValueValueKind,
334    LLVMConstantAggregateZeroValueKind,
335    LLVMConstantDataArrayValueKind,
336    LLVMConstantDataVectorValueKind,
337    LLVMConstantIntValueKind,
338    LLVMConstantFPValueKind,
339    LLVMConstantPointerNullValueKind,
340    LLVMConstantTokenNoneValueKind,
341
342    LLVMMetadataAsValueValueKind,
343    LLVMInlineAsmValueKind,
344
345    LLVMInstructionValueKind,
346    LLVMPoisonValueKind,
347    LLVMConstantTargetNoneValueKind,
348}
349
350#[repr(C)]
351#[derive(Clone, Copy, Debug, PartialEq)]
352pub enum LLVMIntPredicate {
353    LLVMIntEQ = 32,
354    LLVMIntNE = 33,
355    LLVMIntUGT = 34,
356    LLVMIntUGE = 35,
357    LLVMIntULT = 36,
358    LLVMIntULE = 37,
359    LLVMIntSGT = 38,
360    LLVMIntSGE = 39,
361    LLVMIntSLT = 40,
362    LLVMIntSLE = 41,
363}
364
365#[repr(C)]
366#[derive(Clone, Copy, Debug, PartialEq)]
367pub enum LLVMRealPredicate {
368    LLVMRealPredicateFalse = 0,
369    LLVMRealOEQ = 1,
370    LLVMRealOGT = 2,
371    LLVMRealOGE = 3,
372    LLVMRealOLT = 4,
373    LLVMRealOLE = 5,
374    LLVMRealONE = 6,
375    LLVMRealORD = 7,
376    LLVMRealUNO = 8,
377    LLVMRealUEQ = 9,
378    LLVMRealUGT = 10,
379    LLVMRealUGE = 11,
380    LLVMRealULT = 12,
381    LLVMRealULE = 13,
382    LLVMRealUNE = 14,
383    LLVMRealPredicateTrue = 15,
384}
385
386#[repr(C)]
387#[derive(Clone, Copy, Debug, PartialEq)]
388pub enum LLVMLandingPadClauseTy {
389    LLVMLandingPadCatch = 0,
390    LLVMLandingPadFilter = 1,
391}
392
393#[repr(C)]
394#[derive(Clone, Copy, Debug, PartialEq)]
395pub enum LLVMThreadLocalMode {
396    LLVMNotThreadLocal = 0,
397    LLVMGeneralDynamicTLSModel = 1,
398    LLVMLocalDynamicTLSModel = 2,
399    LLVMInitialExecTLSModel = 3,
400    LLVMLocalExecTLSModel = 4,
401}
402
403#[repr(C)]
404#[derive(Clone, Copy, Debug, PartialEq)]
405pub enum LLVMAtomicOrdering {
406    LLVMAtomicOrderingNotAtomic = 0,
407    LLVMAtomicOrderingUnordered = 1,
408    LLVMAtomicOrderingMonotonic = 2,
409    LLVMAtomicOrderingAcquire = 4,
410    LLVMAtomicOrderingRelease = 5,
411    LLVMAtomicOrderingAcquireRelease = 6,
412    LLVMAtomicOrderingSequentiallyConsistent = 7,
413}
414
415#[repr(C)]
416#[derive(Clone, Copy, Debug, PartialEq)]
417pub enum LLVMAtomicRMWBinOp {
418    LLVMAtomicRMWBinOpXchg = 0,
419    LLVMAtomicRMWBinOpAdd = 1,
420    LLVMAtomicRMWBinOpSub = 2,
421    LLVMAtomicRMWBinOpAnd = 3,
422    LLVMAtomicRMWBinOpNand = 4,
423    LLVMAtomicRMWBinOpOr = 5,
424    LLVMAtomicRMWBinOpXor = 6,
425    LLVMAtomicRMWBinOpMax = 7,
426    LLVMAtomicRMWBinOpMin = 8,
427    LLVMAtomicRMWBinOpUMax = 9,
428    LLVMAtomicRMWBinOpUMin = 10,
429    LLVMAtomicRMWBinOpFAdd = 11,
430    LLVMAtomicRMWBinOpFSub = 12,
431    LLVMAtomicRMWBinOpFMax = 13,
432    LLVMAtomicRMWBinOpFMin = 14,
433}
434
435#[repr(C)]
436#[derive(Clone, Copy, Debug, PartialEq)]
437pub enum LLVMDiagnosticSeverity {
438    LLVMDSError = 0,
439    LLVMDSWarning = 1,
440    LLVMDSRemark = 2,
441    LLVMDSNote = 3,
442}
443
444#[repr(C)]
445#[derive(Clone, Copy, Debug, PartialEq)]
446pub enum LLVMInlineAsmDialect {
447    LLVMInlineAsmDialectATT,
448    LLVMInlineAsmDialectIntel,
449}
450
451#[repr(C)]
452#[derive(Clone, Copy, Debug, PartialEq)]
453pub enum LLVMModuleFlagBehavior {
454    /// Emits an error if two values disagree, otherwise the resulting value is that of the operands.
455    LLVMModuleFlagBehaviorError,
456    /// Emits a warning if two values disagree. The result value will be the operand for the flag from the first module being linked.
457    LLVMModuleFlagBehaviorWarning,
458    /// Adds a requirement that another module flag be present and have a specified value after linking is performed. The value must be a metadata pair, where the first element of the pair is the ID of the module flag to be restricted, and the second element of the pair is the value the module flag should be restricted to. This behavior can be used to restrict the allowable results (via triggering of an error) of linking IDs with the **Override** behavior.
459    LLVMModuleFlagBehaviorRequire,
460    /// Uses the specified value, regardless of the behavior or value of the other module. If both modules specify **Override**, but the values differ, an error will be emitted.
461    LLVMModuleFlagBehaviorOverride,
462    /// Appends the two values, which are required to be metadata nodes.
463    LLVMModuleFlagBehaviorAppend,
464    /// Appends the two values, which are required to be metadata nodes. However, duplicate entries in the second list are dropped during the append operation.
465    LLVMModuleFlagBehaviorAppendUnique,
466}
467
468pub const LLVMAttributeReturnIndex: ::libc::c_uint = 0;
469pub const LLVMAttributeFunctionIndex: ::libc::c_uint = !0; // -1
470/// Either LLVMAttributeReturnIndex, LLVMAttributeFunctionIndex, or a parameter
471/// number from 1 to N.
472pub type LLVMAttributeIndex = ::libc::c_uint;
473
474pub type LLVMDiagnosticHandler =
475    Option<extern "C" fn(arg1: LLVMDiagnosticInfoRef, arg2: *mut ::libc::c_void)>;
476pub type LLVMYieldCallback = Option<extern "C" fn(arg1: LLVMContextRef, arg2: *mut ::libc::c_void)>;
477
478#[cfg(all(not(doc), not(feature = "no-llvm-linking"), LLVM_SYS_NOT_FOUND))]
479std::compile_error!(concat!(
480    "No suitable version of LLVM was found system-wide or pointed
481       to by LLVM_SYS_",
482    env!("CARGO_PKG_VERSION_MAJOR"),
483    "_PREFIX.
484
485       Consider using `llvmenv` to compile an appropriate copy of LLVM, and
486       refer to the llvm-sys documentation for more information.
487
488       llvm-sys: https://crates.io/crates/llvm-sys
489       llvmenv: https://crates.io/crates/llvmenv"
490));