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