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