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 LLVMLandingPadClauseTy {
397    LLVMLandingPadCatch = 0,
398    LLVMLandingPadFilter = 1,
399}
400
401#[repr(C)]
402#[derive(Clone, Copy, Debug, PartialEq)]
403pub enum LLVMThreadLocalMode {
404    LLVMNotThreadLocal = 0,
405    LLVMGeneralDynamicTLSModel = 1,
406    LLVMLocalDynamicTLSModel = 2,
407    LLVMInitialExecTLSModel = 3,
408    LLVMLocalExecTLSModel = 4,
409}
410
411#[repr(C)]
412#[derive(Clone, Copy, Debug, PartialEq)]
413pub enum LLVMAtomicOrdering {
414    LLVMAtomicOrderingNotAtomic = 0,
415    LLVMAtomicOrderingUnordered = 1,
416    LLVMAtomicOrderingMonotonic = 2,
417    LLVMAtomicOrderingAcquire = 4,
418    LLVMAtomicOrderingRelease = 5,
419    LLVMAtomicOrderingAcquireRelease = 6,
420    LLVMAtomicOrderingSequentiallyConsistent = 7,
421}
422
423#[repr(C)]
424#[derive(Clone, Copy, Debug, PartialEq)]
425pub enum LLVMAtomicRMWBinOp {
426    LLVMAtomicRMWBinOpXchg = 0,
427    LLVMAtomicRMWBinOpAdd = 1,
428    LLVMAtomicRMWBinOpSub = 2,
429    LLVMAtomicRMWBinOpAnd = 3,
430    LLVMAtomicRMWBinOpNand = 4,
431    LLVMAtomicRMWBinOpOr = 5,
432    LLVMAtomicRMWBinOpXor = 6,
433    LLVMAtomicRMWBinOpMax = 7,
434    LLVMAtomicRMWBinOpMin = 8,
435    LLVMAtomicRMWBinOpUMax = 9,
436    LLVMAtomicRMWBinOpUMin = 10,
437    LLVMAtomicRMWBinOpFAdd = 11,
438    LLVMAtomicRMWBinOpFSub = 12,
439    LLVMAtomicRMWBinOpFMax = 13,
440    LLVMAtomicRMWBinOpFMin = 14,
441    LLVMAtomicRMWBinOpUIncWrap = 15,
442    LLVMAtomicRMWBinOpUDecWrap = 16,
443    /// Subtracts the value only if no unsigned overflow.
444    LLVMAtomicRMWBinOpUSubCond,
445    /// Subtracts the value, clamping to zero.
446    LLVMAtomicRMWBinOpUSubSat,
447}
448
449#[repr(C)]
450#[derive(Clone, Copy, Debug, PartialEq)]
451pub enum LLVMDiagnosticSeverity {
452    LLVMDSError = 0,
453    LLVMDSWarning = 1,
454    LLVMDSRemark = 2,
455    LLVMDSNote = 3,
456}
457
458#[repr(C)]
459#[derive(Clone, Copy, Debug, PartialEq)]
460pub enum LLVMInlineAsmDialect {
461    LLVMInlineAsmDialectATT,
462    LLVMInlineAsmDialectIntel,
463}
464
465#[repr(C)]
466#[derive(Clone, Copy, Debug, PartialEq)]
467pub enum LLVMModuleFlagBehavior {
468    /// Emits an error if two values disagree, otherwise the resulting value is that of the operands.
469    LLVMModuleFlagBehaviorError,
470    /// Emits a warning if two values disagree. The result value will be the operand for the flag from the first module being linked.
471    LLVMModuleFlagBehaviorWarning,
472    /// 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.
473    LLVMModuleFlagBehaviorRequire,
474    /// 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.
475    LLVMModuleFlagBehaviorOverride,
476    /// Appends the two values, which are required to be metadata nodes.
477    LLVMModuleFlagBehaviorAppend,
478    /// Appends the two values, which are required to be metadata nodes. However, duplicate entries in the second list are dropped during the append operation.
479    LLVMModuleFlagBehaviorAppendUnique,
480}
481
482pub const LLVMAttributeReturnIndex: ::libc::c_uint = 0;
483pub const LLVMAttributeFunctionIndex: ::libc::c_uint = !0; // -1
484/// Either LLVMAttributeReturnIndex, LLVMAttributeFunctionIndex, or a parameter
485/// number from 1 to N.
486pub type LLVMAttributeIndex = ::libc::c_uint;
487
488/// Tail call kind for LLVMSetTailCallKind and LLVMGetTailCallKind.
489///
490/// Note that `musttail` implies `tail`.
491#[repr(C)]
492#[derive(Clone, Copy, Debug, PartialEq)]
493pub enum LLVMTailCallKind {
494    LLVMTailCallKindNone = 0,
495    LLVMTailCallKindTail = 1,
496    LLVMTailCallKindMustTail = 2,
497    LLVMTailCallKindNoTail = 3,
498}
499
500pub const LLVMFastMathAllowReassoc: ::libc::c_uint = 1 << 0;
501pub const LLVMFastMathNoNaNs: ::libc::c_uint = 1 << 1;
502pub const LLVMFastMathNoInfs: ::libc::c_uint = 1 << 2;
503pub const LLVMFastMathNoSignedZeros: ::libc::c_uint = 1 << 3;
504pub const LLVMFastMathAllowReciprocal: ::libc::c_uint = 1 << 4;
505pub const LLVMFastMathAllowContract: ::libc::c_uint = 1 << 5;
506pub const LLVMFastMathApproxFunc: ::libc::c_uint = 1 << 6;
507pub const LLVMFastMathNone: ::libc::c_uint = 0;
508pub const LLVMFastMathAll: ::libc::c_uint = LLVMFastMathAllowReassoc
509    | LLVMFastMathNoNaNs
510    | LLVMFastMathNoInfs
511    | LLVMFastMathNoSignedZeros
512    | LLVMFastMathAllowReciprocal
513    | LLVMFastMathAllowContract
514    | LLVMFastMathApproxFunc;
515
516/// Flags to indicate what fast-math-style optimizations are allowed on operations.
517///
518/// See <https://llvm.org/docs/LangRef.html#fast-math-flags>
519pub type LLVMFastMathFlags = ::libc::c_uint;
520
521/// Flags that constrain the allowed wrap semantics of a gelementptr instruction.
522pub type LLVMGEPNoWrapFlags = ::libc::c_uint;
523
524pub const LLVMGEPFlagInBounds: LLVMGEPNoWrapFlags = 1;
525pub const LLVMGEPFlagNUSW: LLVMGEPNoWrapFlags = 1 << 1;
526pub const LLVMGEPFlagNUW: LLVMGEPNoWrapFlags = 1 << 2;
527
528pub type LLVMDiagnosticHandler =
529    Option<extern "C" fn(arg1: LLVMDiagnosticInfoRef, arg2: *mut ::libc::c_void)>;
530pub type LLVMYieldCallback = Option<extern "C" fn(arg1: LLVMContextRef, arg2: *mut ::libc::c_void)>;
531
532#[cfg(all(not(doc), not(feature = "no-llvm-linking"), LLVM_SYS_NOT_FOUND))]
533std::compile_error!(concat!(
534    "No suitable version of LLVM was found system-wide or pointed
535       to by LLVM_SYS_",
536    env!("CARGO_PKG_VERSION_MAJOR"),
537    "_PREFIX.
538
539       Consider using `llvmenv` to compile an appropriate copy of LLVM, and
540       refer to the llvm-sys documentation for more information.
541
542       llvm-sys: https://crates.io/crates/llvm-sys
543       llvmenv: https://crates.io/crates/llvmenv"
544));