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 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    LLVMPtrToAddr = 69,
173    LLVMIntToPtr = 40,
174    LLVMBitCast = 41,
175    LLVMAddrSpaceCast = 60,
176    LLVMICmp = 42,
177    LLVMFCmp = 43,
178    LLVMPHI = 44,
179    LLVMCall = 45,
180    LLVMSelect = 46,
181    LLVMUserOp1 = 47,
182    LLVMUserOp2 = 48,
183    LLVMVAArg = 49,
184    LLVMExtractElement = 50,
185    LLVMInsertElement = 51,
186    LLVMShuffleVector = 52,
187    LLVMExtractValue = 53,
188    LLVMInsertValue = 54,
189    LLVMFreeze = 68,
190    LLVMFence = 55,
191    LLVMAtomicCmpXchg = 56,
192    LLVMAtomicRMW = 57,
193    LLVMResume = 58,
194    LLVMLandingPad = 59,
195    LLVMCleanupRet = 61,
196    LLVMCatchRet = 62,
197    LLVMCatchPad = 63,
198    LLVMCleanupPad = 64,
199    LLVMCatchSwitch = 65,
200}
201
202#[repr(C)]
203#[derive(Clone, Copy, Debug, PartialEq)]
204pub enum LLVMTypeKind {
205    LLVMVoidTypeKind = 0,
206    LLVMHalfTypeKind = 1,
207    LLVMFloatTypeKind = 2,
208    LLVMDoubleTypeKind = 3,
209    LLVMX86_FP80TypeKind = 4,
210    LLVMFP128TypeKind = 5,
211    LLVMPPC_FP128TypeKind = 6,
212    LLVMLabelTypeKind = 7,
213    LLVMIntegerTypeKind = 8,
214    LLVMFunctionTypeKind = 9,
215    LLVMStructTypeKind = 10,
216    LLVMArrayTypeKind = 11,
217    LLVMPointerTypeKind = 12,
218    LLVMVectorTypeKind = 13,
219    LLVMMetadataTypeKind = 14,
220    // 15 previously used by LLVMX86_MMXTypeKind
221    LLVMTokenTypeKind = 16,
222    LLVMScalableVectorTypeKind = 17,
223    LLVMBFloatTypeKind = 18,
224    LLVMX86_AMXTypeKind = 19,
225    LLVMTargetExtTypeKind = 20,
226}
227
228#[repr(C)]
229#[derive(Clone, Copy, Debug, PartialEq)]
230pub enum LLVMLinkage {
231    LLVMExternalLinkage = 0,
232    LLVMAvailableExternallyLinkage = 1,
233    LLVMLinkOnceAnyLinkage = 2,
234    LLVMLinkOnceODRLinkage = 3,
235    LLVMLinkOnceODRAutoHideLinkage = 4,
236    LLVMWeakAnyLinkage = 5,
237    LLVMWeakODRLinkage = 6,
238    LLVMAppendingLinkage = 7,
239    LLVMInternalLinkage = 8,
240    LLVMPrivateLinkage = 9,
241    LLVMDLLImportLinkage = 10,
242    LLVMDLLExportLinkage = 11,
243    LLVMExternalWeakLinkage = 12,
244    LLVMGhostLinkage = 13,
245    LLVMCommonLinkage = 14,
246    LLVMLinkerPrivateLinkage = 15,
247    LLVMLinkerPrivateWeakLinkage = 16,
248}
249
250#[repr(C)]
251#[derive(Clone, Copy, Debug, PartialEq)]
252pub enum LLVMVisibility {
253    LLVMDefaultVisibility = 0,
254    LLVMHiddenVisibility = 1,
255    LLVMProtectedVisibility = 2,
256}
257
258#[repr(C)]
259#[derive(Clone, Copy, Debug, PartialEq)]
260pub enum LLVMUnnamedAddr {
261    /// Address of the GV is significant.
262    LLVMNoUnnamedAddr,
263    /// Address of the GV is locally insignificant.
264    LLVMLocalUnnamedAddr,
265    /// Address of the GV is globally insignificant.
266    LLVMGlobalUnnamedAddr,
267}
268
269#[repr(C)]
270#[derive(Clone, Copy, Debug, PartialEq)]
271pub enum LLVMDLLStorageClass {
272    LLVMDefaultStorageClass = 0,
273    LLVMDLLImportStorageClass = 1,
274    LLVMDLLExportStorageClass = 2,
275}
276
277#[repr(C)]
278#[derive(Clone, Copy, Debug, PartialEq)]
279pub enum LLVMCallConv {
280    LLVMCCallConv = 0,
281    LLVMFastCallConv = 8,
282    LLVMColdCallConv = 9,
283    LLVMGHCCallConv = 10,
284    LLVMHiPECallConv = 11,
285    LLVMAnyRegCallConv = 13,
286    LLVMPreserveMostCallConv = 14,
287    LLVMPreserveAllCallConv = 15,
288    LLVMSwiftCallConv = 16,
289    LLVMCXXFASTTLSCallConv = 17,
290    LLVMX86StdcallCallConv = 64,
291    LLVMX86FastcallCallConv = 65,
292    LLVMARMAPCSCallConv = 66,
293    LLVMARMAAPCSCallConv = 67,
294    LLVMARMAAPCSVFPCallConv = 68,
295    LLVMMSP430INTRCallConv = 69,
296    LLVMX86ThisCallCallConv = 70,
297    LLVMPTXKernelCallConv = 71,
298    LLVMPTXDeviceCallConv = 72,
299    LLVMSPIRFUNCCallConv = 75,
300    LLVMSPIRKERNELCallConv = 76,
301    LLVMIntelOCLBICallConv = 77,
302    LLVMX8664SysVCallConv = 78,
303    LLVMWin64CallConv = 79,
304    LLVMX86VectorCallCallConv = 80,
305    LLVMHHVMCallConv = 81,
306    LLVMHHVMCCallConv = 82,
307    LLVMX86INTRCallConv = 83,
308    LLVMAVRINTRCallConv = 84,
309    LLVMAVRSIGNALCallConv = 85,
310    LLVMAVRBUILTINCallConv = 86,
311    LLVMAMDGPUVSCallConv = 87,
312    LLVMAMDGPUGSCallConv = 88,
313    LLVMAMDGPUPSCallConv = 89,
314    LLVMAMDGPUCSCallConv = 90,
315    LLVMAMDGPUKERNELCallConv = 91,
316    LLVMX86RegCallCallConv = 92,
317    LLVMAMDGPUHSCallConv = 93,
318    LLVMMSP430BUILTINCallConv = 94,
319    LLVMAMDGPULSCallConv = 95,
320    LLVMAMDGPUESCallConv = 96,
321}
322
323#[repr(C)]
324#[derive(Clone, Copy, Debug, PartialEq)]
325pub enum LLVMValueKind {
326    LLVMArgumentValueKind,
327    LLVMBasicBlockValueKind,
328    LLVMMemoryUseValueKind,
329    LLVMMemoryDefValueKind,
330    LLVMMemoryPhiValueKind,
331
332    LLVMFunctionValueKind,
333    LLVMGlobalAliasValueKind,
334    LLVMGlobalIFuncValueKind,
335    LLVMGlobalVariableValueKind,
336    LLVMBlockAddressValueKind,
337    LLVMConstantExprValueKind,
338    LLVMConstantArrayValueKind,
339    LLVMConstantStructValueKind,
340    LLVMConstantVectorValueKind,
341    LLVMUndefValueValueKind,
342    LLVMConstantAggregateZeroValueKind,
343    LLVMConstantDataArrayValueKind,
344    LLVMConstantDataVectorValueKind,
345    LLVMConstantIntValueKind,
346    LLVMConstantFPValueKind,
347    LLVMConstantPointerNullValueKind,
348    LLVMConstantTokenNoneValueKind,
349
350    LLVMMetadataAsValueValueKind,
351    LLVMInlineAsmValueKind,
352
353    LLVMInstructionValueKind,
354    LLVMPoisonValueKind,
355    LLVMConstantTargetNoneValueKind,
356    LLVMConstantPtrAuthValueKind,
357}
358
359#[repr(C)]
360#[derive(Clone, Copy, Debug, PartialEq)]
361pub enum LLVMIntPredicate {
362    LLVMIntEQ = 32,
363    LLVMIntNE = 33,
364    LLVMIntUGT = 34,
365    LLVMIntUGE = 35,
366    LLVMIntULT = 36,
367    LLVMIntULE = 37,
368    LLVMIntSGT = 38,
369    LLVMIntSGE = 39,
370    LLVMIntSLT = 40,
371    LLVMIntSLE = 41,
372}
373
374#[repr(C)]
375#[derive(Clone, Copy, Debug, PartialEq)]
376pub enum LLVMRealPredicate {
377    LLVMRealPredicateFalse = 0,
378    LLVMRealOEQ = 1,
379    LLVMRealOGT = 2,
380    LLVMRealOGE = 3,
381    LLVMRealOLT = 4,
382    LLVMRealOLE = 5,
383    LLVMRealONE = 6,
384    LLVMRealORD = 7,
385    LLVMRealUNO = 8,
386    LLVMRealUEQ = 9,
387    LLVMRealUGT = 10,
388    LLVMRealUGE = 11,
389    LLVMRealULT = 12,
390    LLVMRealULE = 13,
391    LLVMRealUNE = 14,
392    LLVMRealPredicateTrue = 15,
393}
394
395#[repr(C)]
396#[derive(Clone, Copy, Debug, PartialEq)]
397pub enum LLVMThreadLocalMode {
398    LLVMNotThreadLocal = 0,
399    LLVMGeneralDynamicTLSModel = 1,
400    LLVMLocalDynamicTLSModel = 2,
401    LLVMInitialExecTLSModel = 3,
402    LLVMLocalExecTLSModel = 4,
403}
404
405#[repr(C)]
406#[derive(Clone, Copy, Debug, PartialEq)]
407pub enum LLVMAtomicOrdering {
408    LLVMAtomicOrderingNotAtomic = 0,
409    LLVMAtomicOrderingUnordered = 1,
410    LLVMAtomicOrderingMonotonic = 2,
411    LLVMAtomicOrderingAcquire = 4,
412    LLVMAtomicOrderingRelease = 5,
413    LLVMAtomicOrderingAcquireRelease = 6,
414    LLVMAtomicOrderingSequentiallyConsistent = 7,
415}
416
417#[repr(C)]
418#[derive(Clone, Copy, Debug, PartialEq)]
419pub enum LLVMAtomicRMWBinOp {
420    LLVMAtomicRMWBinOpXchg = 0,
421    LLVMAtomicRMWBinOpAdd = 1,
422    LLVMAtomicRMWBinOpSub = 2,
423    LLVMAtomicRMWBinOpAnd = 3,
424    LLVMAtomicRMWBinOpNand = 4,
425    LLVMAtomicRMWBinOpOr = 5,
426    LLVMAtomicRMWBinOpXor = 6,
427    LLVMAtomicRMWBinOpMax = 7,
428    LLVMAtomicRMWBinOpMin = 8,
429    LLVMAtomicRMWBinOpUMax = 9,
430    LLVMAtomicRMWBinOpUMin = 10,
431    LLVMAtomicRMWBinOpFAdd = 11,
432    LLVMAtomicRMWBinOpFSub = 12,
433    LLVMAtomicRMWBinOpFMax = 13,
434    LLVMAtomicRMWBinOpFMin = 14,
435    LLVMAtomicRMWBinOpUIncWrap = 15,
436    LLVMAtomicRMWBinOpUDecWrap = 16,
437    /// Subtracts the value only if no unsigned overflow.
438    LLVMAtomicRMWBinOpUSubCond,
439    /// Subtracts the value, clamping to zero.
440    LLVMAtomicRMWBinOpUSubSat,
441    /// Sets the value if it's greater than the original using an floating
442    /// point comparison and return the old one.
443    LLVMAtomicRMWBinOpFMaximum,
444    /// Sets the value if it's smaller than the original using an floating
445    /// point comparison and return the old one.
446    LLVMAtomicRMWBinOpFMinimum,
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
524#[repr(C)]
525#[derive(Clone, Copy, Debug, PartialEq)]
526pub enum LLVMDbgRecordKind {
527    LLVMDbgRecordLabel,
528    LLVMDbgRecordDeclare,
529    LLVMDbgRecordValue,
530    LLVMDbgRecordAssign,
531}
532
533pub const LLVMGEPFlagInBounds: LLVMGEPNoWrapFlags = 1;
534pub const LLVMGEPFlagNUSW: LLVMGEPNoWrapFlags = 1 << 1;
535pub const LLVMGEPFlagNUW: LLVMGEPNoWrapFlags = 1 << 2;
536
537pub type LLVMDiagnosticHandler =
538    Option<extern "C" fn(arg1: LLVMDiagnosticInfoRef, arg2: *mut ::libc::c_void)>;
539pub type LLVMYieldCallback = Option<extern "C" fn(arg1: LLVMContextRef, arg2: *mut ::libc::c_void)>;
540
541#[cfg(all(not(doc), not(feature = "no-llvm-linking"), LLVM_SYS_NOT_FOUND))]
542std::compile_error!(concat!(
543    "No suitable version of LLVM was found system-wide or pointed
544       to by LLVM_SYS_",
545    env!("CARGO_PKG_VERSION_MAJOR"),
546    "_PREFIX.
547
548       Consider using `llvmenv` to compile an appropriate copy of LLVM, and
549       refer to the llvm-sys documentation for more information.
550
551       llvm-sys: https://crates.io/crates/llvm-sys
552       llvmenv: https://crates.io/crates/llvmenv"
553));