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