]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/llvm/ffi.rs
Rollup merge of #67055 - lqd:const_qualif, r=oli-obk
[rust.git] / src / librustc_codegen_llvm / llvm / ffi.rs
1 #![allow(non_camel_case_types)]
2 #![allow(non_upper_case_globals)]
3
4 use super::debuginfo::{
5     DIBuilder, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
6     DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
7     DIGlobalVariableExpression, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
8     DINameSpace, DIFlags, DISPFlags, DebugEmissionKind,
9 };
10
11 use libc::{c_uint, c_int, size_t, c_char};
12 use libc::{c_ulonglong, c_void};
13
14 use std::marker::PhantomData;
15
16 use super::RustString;
17
18 pub type Bool = c_uint;
19
20 pub const True: Bool = 1 as Bool;
21 pub const False: Bool = 0 as Bool;
22
23 #[derive(Copy, Clone, PartialEq)]
24 #[repr(C)]
25 #[allow(dead_code)] // Variants constructed by C++.
26 pub enum LLVMRustResult {
27     Success,
28     Failure,
29 }
30 // Consts for the LLVM CallConv type, pre-cast to usize.
31
32 /// LLVM CallingConv::ID. Should we wrap this?
33 #[derive(Copy, Clone, PartialEq, Debug)]
34 #[repr(C)]
35 pub enum CallConv {
36     CCallConv = 0,
37     FastCallConv = 8,
38     ColdCallConv = 9,
39     X86StdcallCallConv = 64,
40     X86FastcallCallConv = 65,
41     ArmAapcsCallConv = 67,
42     Msp430Intr = 69,
43     X86_ThisCall = 70,
44     PtxKernel = 71,
45     X86_64_SysV = 78,
46     X86_64_Win64 = 79,
47     X86_VectorCall = 80,
48     X86_Intr = 83,
49     AmdGpuKernel = 91,
50 }
51
52 /// LLVMRustLinkage
53 #[derive(PartialEq)]
54 #[repr(C)]
55 pub enum Linkage {
56     ExternalLinkage = 0,
57     AvailableExternallyLinkage = 1,
58     LinkOnceAnyLinkage = 2,
59     LinkOnceODRLinkage = 3,
60     WeakAnyLinkage = 4,
61     WeakODRLinkage = 5,
62     AppendingLinkage = 6,
63     InternalLinkage = 7,
64     PrivateLinkage = 8,
65     ExternalWeakLinkage = 9,
66     CommonLinkage = 10,
67 }
68
69 // LLVMRustVisibility
70 #[repr(C)]
71 pub enum Visibility {
72     Default = 0,
73     Hidden = 1,
74     Protected = 2,
75 }
76
77 /// LLVMDLLStorageClass
78 #[derive(Copy, Clone)]
79 #[repr(C)]
80 pub enum DLLStorageClass {
81     #[allow(dead_code)]
82     Default = 0,
83     DllImport = 1, // Function to be imported from DLL.
84     #[allow(dead_code)]
85     DllExport = 2, // Function to be accessible from DLL.
86 }
87
88 /// Matches LLVMRustAttribute in rustllvm.h
89 /// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
90 /// though it is not ABI compatible (since it's a C++ enum)
91 #[repr(C)]
92 #[derive(Copy, Clone, Debug)]
93 pub enum Attribute {
94     AlwaysInline    = 0,
95     ByVal           = 1,
96     Cold            = 2,
97     InlineHint      = 3,
98     MinSize         = 4,
99     Naked           = 5,
100     NoAlias         = 6,
101     NoCapture       = 7,
102     NoInline        = 8,
103     NonNull         = 9,
104     NoRedZone       = 10,
105     NoReturn        = 11,
106     NoUnwind        = 12,
107     OptimizeForSize = 13,
108     ReadOnly        = 14,
109     SExt            = 15,
110     StructRet       = 16,
111     UWTable         = 17,
112     ZExt            = 18,
113     InReg           = 19,
114     SanitizeThread  = 20,
115     SanitizeAddress = 21,
116     SanitizeMemory  = 22,
117     NonLazyBind     = 23,
118     OptimizeNone    = 24,
119     ReturnsTwice    = 25,
120 }
121
122 /// LLVMIntPredicate
123 #[derive(Copy, Clone)]
124 #[repr(C)]
125 pub enum IntPredicate {
126     IntEQ = 32,
127     IntNE = 33,
128     IntUGT = 34,
129     IntUGE = 35,
130     IntULT = 36,
131     IntULE = 37,
132     IntSGT = 38,
133     IntSGE = 39,
134     IntSLT = 40,
135     IntSLE = 41,
136 }
137
138 impl IntPredicate {
139     pub fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
140         match intpre {
141             rustc_codegen_ssa::common::IntPredicate::IntEQ => IntPredicate::IntEQ,
142             rustc_codegen_ssa::common::IntPredicate::IntNE => IntPredicate::IntNE,
143             rustc_codegen_ssa::common::IntPredicate::IntUGT => IntPredicate::IntUGT,
144             rustc_codegen_ssa::common::IntPredicate::IntUGE => IntPredicate::IntUGE,
145             rustc_codegen_ssa::common::IntPredicate::IntULT => IntPredicate::IntULT,
146             rustc_codegen_ssa::common::IntPredicate::IntULE => IntPredicate::IntULE,
147             rustc_codegen_ssa::common::IntPredicate::IntSGT => IntPredicate::IntSGT,
148             rustc_codegen_ssa::common::IntPredicate::IntSGE => IntPredicate::IntSGE,
149             rustc_codegen_ssa::common::IntPredicate::IntSLT => IntPredicate::IntSLT,
150             rustc_codegen_ssa::common::IntPredicate::IntSLE => IntPredicate::IntSLE,
151         }
152     }
153 }
154
155 /// LLVMRealPredicate
156 #[derive(Copy, Clone)]
157 #[repr(C)]
158 pub enum RealPredicate {
159     RealPredicateFalse = 0,
160     RealOEQ = 1,
161     RealOGT = 2,
162     RealOGE = 3,
163     RealOLT = 4,
164     RealOLE = 5,
165     RealONE = 6,
166     RealORD = 7,
167     RealUNO = 8,
168     RealUEQ = 9,
169     RealUGT = 10,
170     RealUGE = 11,
171     RealULT = 12,
172     RealULE = 13,
173     RealUNE = 14,
174     RealPredicateTrue = 15,
175 }
176
177 impl RealPredicate {
178     pub fn from_generic(realpred: rustc_codegen_ssa::common::RealPredicate) -> Self {
179         match realpred {
180             rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse =>
181                 RealPredicate::RealPredicateFalse,
182             rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
183             rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
184             rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
185             rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
186             rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
187             rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
188             rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
189             rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
190             rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
191             rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
192             rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
193             rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
194             rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
195             rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
196             rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue =>
197                 RealPredicate::RealPredicateTrue
198         }
199     }
200 }
201
202 /// LLVMTypeKind
203 #[derive(Copy, Clone, PartialEq, Debug)]
204 #[repr(C)]
205 pub enum TypeKind {
206     Void = 0,
207     Half = 1,
208     Float = 2,
209     Double = 3,
210     X86_FP80 = 4,
211     FP128 = 5,
212     PPC_FP128 = 6,
213     Label = 7,
214     Integer = 8,
215     Function = 9,
216     Struct = 10,
217     Array = 11,
218     Pointer = 12,
219     Vector = 13,
220     Metadata = 14,
221     X86_MMX = 15,
222     Token = 16,
223 }
224
225 impl TypeKind {
226     pub fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
227         match self {
228             TypeKind::Void => rustc_codegen_ssa::common::TypeKind::Void,
229             TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
230             TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
231             TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
232             TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
233             TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
234             TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
235             TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
236             TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
237             TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,
238             TypeKind::Struct => rustc_codegen_ssa::common::TypeKind::Struct,
239             TypeKind::Array => rustc_codegen_ssa::common::TypeKind::Array,
240             TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer,
241             TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector,
242             TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
243             TypeKind::X86_MMX => rustc_codegen_ssa::common::TypeKind::X86_MMX,
244             TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
245         }
246     }
247 }
248
249 /// LLVMAtomicRmwBinOp
250 #[derive(Copy, Clone)]
251 #[repr(C)]
252 pub enum AtomicRmwBinOp {
253     AtomicXchg = 0,
254     AtomicAdd = 1,
255     AtomicSub = 2,
256     AtomicAnd = 3,
257     AtomicNand = 4,
258     AtomicOr = 5,
259     AtomicXor = 6,
260     AtomicMax = 7,
261     AtomicMin = 8,
262     AtomicUMax = 9,
263     AtomicUMin = 10,
264 }
265
266 impl AtomicRmwBinOp {
267     pub fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
268         match op {
269             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg => AtomicRmwBinOp::AtomicXchg,
270             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAdd => AtomicRmwBinOp::AtomicAdd,
271             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicSub => AtomicRmwBinOp::AtomicSub,
272             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAnd => AtomicRmwBinOp::AtomicAnd,
273             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicNand => AtomicRmwBinOp::AtomicNand,
274             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicOr => AtomicRmwBinOp::AtomicOr,
275             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXor => AtomicRmwBinOp::AtomicXor,
276             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMax => AtomicRmwBinOp::AtomicMax,
277             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMin => AtomicRmwBinOp::AtomicMin,
278             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMax => AtomicRmwBinOp::AtomicUMax,
279             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin
280         }
281     }
282 }
283
284 /// LLVMAtomicOrdering
285 #[derive(Copy, Clone)]
286 #[repr(C)]
287 pub enum AtomicOrdering {
288     #[allow(dead_code)]
289     NotAtomic = 0,
290     Unordered = 1,
291     Monotonic = 2,
292     // Consume = 3,  // Not specified yet.
293     Acquire = 4,
294     Release = 5,
295     AcquireRelease = 6,
296     SequentiallyConsistent = 7,
297 }
298
299 impl AtomicOrdering {
300     pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
301         match ao {
302             rustc_codegen_ssa::common::AtomicOrdering::NotAtomic => AtomicOrdering::NotAtomic,
303             rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
304             rustc_codegen_ssa::common::AtomicOrdering::Monotonic => AtomicOrdering::Monotonic,
305             rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
306             rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
307             rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease =>
308                 AtomicOrdering::AcquireRelease,
309             rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent =>
310                 AtomicOrdering::SequentiallyConsistent
311         }
312     }
313 }
314
315
316 /// LLVMRustSynchronizationScope
317 #[derive(Copy, Clone)]
318 #[repr(C)]
319 pub enum SynchronizationScope {
320     // FIXME: figure out if this variant is needed at all.
321     #[allow(dead_code)]
322     Other,
323     SingleThread,
324     CrossThread,
325 }
326
327 impl SynchronizationScope {
328     pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
329         match sc {
330             rustc_codegen_ssa::common::SynchronizationScope::Other => SynchronizationScope::Other,
331             rustc_codegen_ssa::common::SynchronizationScope::SingleThread =>
332                 SynchronizationScope::SingleThread,
333             rustc_codegen_ssa::common::SynchronizationScope::CrossThread =>
334                 SynchronizationScope::CrossThread,
335         }
336     }
337 }
338
339 /// LLVMRustFileType
340 #[derive(Copy, Clone)]
341 #[repr(C)]
342 pub enum FileType {
343     // FIXME: figure out if this variant is needed at all.
344     #[allow(dead_code)]
345     Other,
346     AssemblyFile,
347     ObjectFile,
348 }
349
350 /// LLVMMetadataType
351 #[derive(Copy, Clone)]
352 #[repr(C)]
353 pub enum MetadataType {
354     MD_dbg = 0,
355     MD_tbaa = 1,
356     MD_prof = 2,
357     MD_fpmath = 3,
358     MD_range = 4,
359     MD_tbaa_struct = 5,
360     MD_invariant_load = 6,
361     MD_alias_scope = 7,
362     MD_noalias = 8,
363     MD_nontemporal = 9,
364     MD_mem_parallel_loop_access = 10,
365     MD_nonnull = 11,
366 }
367
368 /// LLVMRustAsmDialect
369 #[derive(Copy, Clone)]
370 #[repr(C)]
371 pub enum AsmDialect {
372     // FIXME: figure out if this variant is needed at all.
373     #[allow(dead_code)]
374     Other,
375     Att,
376     Intel,
377 }
378
379 impl AsmDialect {
380     pub fn from_generic(asm: syntax::ast::AsmDialect) -> Self {
381         match asm {
382             syntax::ast::AsmDialect::Att => AsmDialect::Att,
383             syntax::ast::AsmDialect::Intel => AsmDialect::Intel
384         }
385     }
386 }
387
388 /// LLVMRustCodeGenOptLevel
389 #[derive(Copy, Clone, PartialEq)]
390 #[repr(C)]
391 pub enum CodeGenOptLevel {
392     // FIXME: figure out if this variant is needed at all.
393     #[allow(dead_code)]
394     Other,
395     None,
396     Less,
397     Default,
398     Aggressive,
399 }
400
401 /// LLVMRelocMode
402 #[derive(Copy, Clone, PartialEq)]
403 #[repr(C)]
404 pub enum RelocMode {
405     Default,
406     Static,
407     PIC,
408     DynamicNoPic,
409     ROPI,
410     RWPI,
411     ROPI_RWPI,
412 }
413
414 /// LLVMRustCodeModel
415 #[derive(Copy, Clone)]
416 #[repr(C)]
417 pub enum CodeModel {
418     // FIXME: figure out if this variant is needed at all.
419     #[allow(dead_code)]
420     Other,
421     Small,
422     Kernel,
423     Medium,
424     Large,
425     None,
426 }
427
428 /// LLVMRustDiagnosticKind
429 #[derive(Copy, Clone)]
430 #[repr(C)]
431 #[allow(dead_code)] // Variants constructed by C++.
432 pub enum DiagnosticKind {
433     Other,
434     InlineAsm,
435     StackSize,
436     DebugMetadataVersion,
437     SampleProfile,
438     OptimizationRemark,
439     OptimizationRemarkMissed,
440     OptimizationRemarkAnalysis,
441     OptimizationRemarkAnalysisFPCommute,
442     OptimizationRemarkAnalysisAliasing,
443     OptimizationRemarkOther,
444     OptimizationFailure,
445     PGOProfile,
446     Linker,
447 }
448
449 /// LLVMRustArchiveKind
450 #[derive(Copy, Clone)]
451 #[repr(C)]
452 pub enum ArchiveKind {
453     // FIXME: figure out if this variant is needed at all.
454     #[allow(dead_code)]
455     Other,
456     K_GNU,
457     K_BSD,
458     K_COFF,
459 }
460
461 /// LLVMRustPassKind
462 #[derive(Copy, Clone, PartialEq, Debug)]
463 #[repr(C)]
464 #[allow(dead_code)] // Variants constructed by C++.
465 pub enum PassKind {
466     Other,
467     Function,
468     Module,
469 }
470
471 /// LLVMRustThinLTOData
472 extern { pub type ThinLTOData; }
473
474 /// LLVMRustThinLTOBuffer
475 extern { pub type ThinLTOBuffer; }
476
477 // LLVMRustModuleNameCallback
478 pub type ThinLTOModuleNameCallback =
479     unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
480
481 /// LLVMRustThinLTOModule
482 #[repr(C)]
483 pub struct ThinLTOModule {
484     pub identifier: *const c_char,
485     pub data: *const u8,
486     pub len: usize,
487 }
488
489 /// LLVMThreadLocalMode
490 #[derive(Copy, Clone)]
491 #[repr(C)]
492 pub enum ThreadLocalMode {
493   NotThreadLocal,
494   GeneralDynamic,
495   LocalDynamic,
496   InitialExec,
497   LocalExec
498 }
499
500 extern { type Opaque; }
501 #[repr(C)]
502 struct InvariantOpaque<'a> {
503     _marker: PhantomData<&'a mut &'a ()>,
504     _opaque: Opaque,
505 }
506
507 // Opaque pointer types
508 extern { pub type Module; }
509 extern { pub type Context; }
510 extern { pub type Type; }
511 extern { pub type Value; }
512 extern { pub type ConstantInt; }
513 extern { pub type Metadata; }
514 extern { pub type BasicBlock; }
515 #[repr(C)]
516 pub struct Builder<'a>(InvariantOpaque<'a>);
517 extern { pub type MemoryBuffer; }
518 #[repr(C)]
519 pub struct PassManager<'a>(InvariantOpaque<'a>);
520 extern { pub type PassManagerBuilder; }
521 extern { pub type ObjectFile; }
522 #[repr(C)]
523 pub struct SectionIterator<'a>(InvariantOpaque<'a>);
524 extern { pub type Pass; }
525 extern { pub type TargetMachine; }
526 extern { pub type Archive; }
527 #[repr(C)]
528 pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
529 #[repr(C)]
530 pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
531 extern { pub type Twine; }
532 extern { pub type DiagnosticInfo; }
533 extern { pub type SMDiagnostic; }
534 #[repr(C)]
535 pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
536 #[repr(C)]
537 pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
538 #[repr(C)]
539 pub struct Linker<'a>(InvariantOpaque<'a>);
540
541 pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
542 pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
543
544
545 pub mod debuginfo {
546     use super::{InvariantOpaque, Metadata};
547
548     #[repr(C)]
549     pub struct DIBuilder<'a>(InvariantOpaque<'a>);
550
551     pub type DIDescriptor = Metadata;
552     pub type DIScope = DIDescriptor;
553     pub type DIFile = DIScope;
554     pub type DILexicalBlock = DIScope;
555     pub type DISubprogram = DIScope;
556     pub type DINameSpace = DIScope;
557     pub type DIType = DIDescriptor;
558     pub type DIBasicType = DIType;
559     pub type DIDerivedType = DIType;
560     pub type DICompositeType = DIDerivedType;
561     pub type DIVariable = DIDescriptor;
562     pub type DIGlobalVariableExpression = DIDescriptor;
563     pub type DIArray = DIDescriptor;
564     pub type DISubrange = DIDescriptor;
565     pub type DIEnumerator = DIDescriptor;
566     pub type DITemplateTypeParameter = DIDescriptor;
567
568     // These values **must** match with LLVMRustDIFlags!!
569     bitflags! {
570         #[repr(transparent)]
571         #[derive(Default)]
572         pub struct DIFlags: u32 {
573             const FlagZero                = 0;
574             const FlagPrivate             = 1;
575             const FlagProtected           = 2;
576             const FlagPublic              = 3;
577             const FlagFwdDecl             = (1 << 2);
578             const FlagAppleBlock          = (1 << 3);
579             const FlagBlockByrefStruct    = (1 << 4);
580             const FlagVirtual             = (1 << 5);
581             const FlagArtificial          = (1 << 6);
582             const FlagExplicit            = (1 << 7);
583             const FlagPrototyped          = (1 << 8);
584             const FlagObjcClassComplete   = (1 << 9);
585             const FlagObjectPointer       = (1 << 10);
586             const FlagVector              = (1 << 11);
587             const FlagStaticMember        = (1 << 12);
588             const FlagLValueReference     = (1 << 13);
589             const FlagRValueReference     = (1 << 14);
590             const FlagExternalTypeRef     = (1 << 15);
591             const FlagIntroducedVirtual   = (1 << 18);
592             const FlagBitField            = (1 << 19);
593             const FlagNoReturn            = (1 << 20);
594         }
595     }
596
597     // These values **must** match with LLVMRustDISPFlags!!
598     bitflags! {
599         #[repr(transparent)]
600         #[derive(Default)]
601         pub struct DISPFlags: u32 {
602             const SPFlagZero              = 0;
603             const SPFlagVirtual           = 1;
604             const SPFlagPureVirtual       = 2;
605             const SPFlagLocalToUnit       = (1 << 2);
606             const SPFlagDefinition        = (1 << 3);
607             const SPFlagOptimized         = (1 << 4);
608             const SPFlagMainSubprogram    = (1 << 5);
609         }
610     }
611
612     /// LLVMRustDebugEmissionKind
613     #[derive(Copy, Clone)]
614     #[repr(C)]
615     pub enum DebugEmissionKind {
616         NoDebug,
617         FullDebug,
618         LineTablesOnly,
619     }
620
621     impl DebugEmissionKind {
622         pub fn from_generic(kind: rustc::session::config::DebugInfo) -> Self {
623             use rustc::session::config::DebugInfo;
624             match kind {
625                 DebugInfo::None => DebugEmissionKind::NoDebug,
626                 DebugInfo::Limited => DebugEmissionKind::LineTablesOnly,
627                 DebugInfo::Full => DebugEmissionKind::FullDebug,
628             }
629         }
630     }
631 }
632
633 extern { pub type ModuleBuffer; }
634
635 extern "C" {
636     pub fn LLVMRustInstallFatalErrorHandler();
637
638     // Create and destroy contexts.
639     pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
640     pub fn LLVMContextDispose(C: &'static mut Context);
641     pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
642
643     // Create modules.
644     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module;
645     pub fn LLVMGetModuleContext(M: &Module) -> &Context;
646     pub fn LLVMCloneModule(M: &Module) -> &Module;
647
648     /// Data layout. See Module::getDataLayout.
649     pub fn LLVMGetDataLayout(M: &Module) -> *const c_char;
650     pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
651
652     /// See Module::setModuleInlineAsm.
653     pub fn LLVMSetModuleInlineAsm(M: &Module, Asm: *const c_char);
654     pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char);
655
656     /// See llvm::LLVMTypeKind::getTypeID.
657     pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
658
659     // Operations on integer types
660     pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
661     pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
662     pub fn LLVMInt16TypeInContext(C: &Context) -> &Type;
663     pub fn LLVMInt32TypeInContext(C: &Context) -> &Type;
664     pub fn LLVMInt64TypeInContext(C: &Context) -> &Type;
665     pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
666
667     pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
668
669     // Operations on real types
670     pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
671     pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
672
673     // Operations on function types
674     pub fn LLVMFunctionType(ReturnType: &'a Type,
675                             ParamTypes: *const &'a Type,
676                             ParamCount: c_uint,
677                             IsVarArg: Bool)
678                             -> &'a Type;
679     pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
680     pub fn LLVMGetParamTypes(FunctionTy: &'a Type, Dest: *mut &'a Type);
681
682     // Operations on struct types
683     pub fn LLVMStructTypeInContext(C: &'a Context,
684                                    ElementTypes: *const &'a Type,
685                                    ElementCount: c_uint,
686                                    Packed: Bool)
687                                    -> &'a Type;
688
689     // Operations on array, pointer, and vector types (sequence types)
690     pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
691     pub fn LLVMPointerType(ElementType: &Type, AddressSpace: c_uint) -> &Type;
692     pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
693
694     pub fn LLVMGetElementType(Ty: &Type) -> &Type;
695     pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
696
697     // Operations on other types
698     pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
699     pub fn LLVMX86MMXTypeInContext(C: &Context) -> &Type;
700     pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
701
702     // Operations on all values
703     pub fn LLVMTypeOf(Val: &Value) -> &Type;
704     pub fn LLVMGetValueName(Val: &Value) -> *const c_char;
705     pub fn LLVMSetValueName(Val: &Value, Name: *const c_char);
706     pub fn LLVMReplaceAllUsesWith(OldVal: &'a Value, NewVal: &'a Value);
707     pub fn LLVMSetMetadata(Val: &'a Value, KindID: c_uint, Node: &'a Value);
708
709     // Operations on constants of any type
710     pub fn LLVMConstNull(Ty: &Type) -> &Value;
711     pub fn LLVMGetUndef(Ty: &Type) -> &Value;
712
713     // Operations on metadata
714     pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
715     pub fn LLVMMDNodeInContext(C: &'a Context, Vals: *const &'a Value, Count: c_uint) -> &'a Value;
716     pub fn LLVMAddNamedMetadataOperand(M: &'a Module, Name: *const c_char, Val: &'a Value);
717
718     // Operations on scalar constants
719     pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
720     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
721     pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
722     pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
723     pub fn LLVMRustConstInt128Get(ConstantVal: &ConstantInt, SExt: bool,
724                                   high: &mut u64, low: &mut u64) -> bool;
725
726
727     // Operations on composite constants
728     pub fn LLVMConstStringInContext(C: &Context,
729                                     Str: *const c_char,
730                                     Length: c_uint,
731                                     DontNullTerminate: Bool)
732                                     -> &Value;
733     pub fn LLVMConstStructInContext(C: &'a Context,
734                                     ConstantVals: *const &'a Value,
735                                     Count: c_uint,
736                                     Packed: Bool)
737                                     -> &'a Value;
738
739     pub fn LLVMConstArray(ElementTy: &'a Type,
740                           ConstantVals: *const &'a Value,
741                           Length: c_uint)
742                           -> &'a Value;
743     pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
744
745     // Constant expressions
746     pub fn LLVMConstInBoundsGEP(
747         ConstantVal: &'a Value,
748         ConstantIndices: *const &'a Value,
749         NumIndices: c_uint,
750     ) -> &'a Value;
751     pub fn LLVMConstZExt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
752     pub fn LLVMConstPtrToInt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
753     pub fn LLVMConstIntToPtr(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
754     pub fn LLVMConstBitCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
755     pub fn LLVMConstPointerCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
756     pub fn LLVMConstExtractValue(AggConstant: &Value,
757                                  IdxList: *const c_uint,
758                                  NumIdx: c_uint)
759                                  -> &Value;
760
761     // Operations on global variables, functions, and aliases (globals)
762     pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
763     pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
764     pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
765     pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
766     pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
767     pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
768     pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
769     pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
770     pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
771
772
773     // Operations on global variables
774     pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
775     pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
776     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
777     pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
778     pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
779     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
780     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
781     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
782     pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
783     pub fn LLVMSetInitializer(GlobalVar: &'a Value, ConstantVal: &'a Value);
784     pub fn LLVMSetThreadLocal(GlobalVar: &Value, IsThreadLocal: Bool);
785     pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
786     pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
787     pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
788     pub fn LLVMRustGetNamedValue(M: &Module, Name: *const c_char) -> Option<&Value>;
789     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
790
791     // Operations on functions
792     pub fn LLVMRustGetOrInsertFunction(M: &'a Module,
793                                        Name: *const c_char,
794                                        FunctionTy: &'a Type)
795                                        -> &'a Value;
796     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
797     pub fn LLVMRustAddAlignmentAttr(Fn: &Value, index: c_uint, bytes: u32);
798     pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
799     pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
800     pub fn LLVMRustAddByValAttr(Fn: &Value, index: c_uint, ty: &Type);
801     pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
802     pub fn LLVMRustAddFunctionAttrStringValue(Fn: &Value,
803                                               index: c_uint,
804                                               Name: *const c_char,
805                                               Value: *const c_char);
806     pub fn LLVMRustRemoveFunctionAttributes(Fn: &Value, index: c_uint, attr: Attribute);
807
808     // Operations on parameters
809     pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
810     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
811     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
812
813     // Operations on basic blocks
814     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
815     pub fn LLVMAppendBasicBlockInContext(C: &'a Context,
816                                          Fn: &'a Value,
817                                          Name: *const c_char)
818                                          -> &'a BasicBlock;
819     pub fn LLVMDeleteBasicBlock(BB: &BasicBlock);
820
821     // Operations on instructions
822     pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
823     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
824
825     // Operations on call sites
826     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
827     pub fn LLVMRustAddCallSiteAttribute(Instr: &Value, index: c_uint, attr: Attribute);
828     pub fn LLVMRustAddAlignmentCallSiteAttr(Instr: &Value, index: c_uint, bytes: u32);
829     pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
830     pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value,
831                                                         index: c_uint,
832                                                         bytes: u64);
833     pub fn LLVMRustAddByValCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);
834
835     // Operations on load/store instructions (only)
836     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
837
838     // Operations on phi nodes
839     pub fn LLVMAddIncoming(PhiNode: &'a Value,
840                            IncomingValues: *const &'a Value,
841                            IncomingBlocks: *const &'a BasicBlock,
842                            Count: c_uint);
843
844     // Instruction builders
845     pub fn LLVMCreateBuilderInContext(C: &'a Context) -> &'a mut Builder<'a>;
846     pub fn LLVMPositionBuilderAtEnd(Builder: &Builder<'a>, Block: &'a BasicBlock);
847     pub fn LLVMGetInsertBlock(Builder: &Builder<'a>) -> &'a BasicBlock;
848     pub fn LLVMDisposeBuilder(Builder: &'a mut Builder<'a>);
849
850     // Metadata
851     pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>);
852     pub fn LLVMGetCurrentDebugLocation(Builder: &Builder<'a>) -> &'a Value;
853     pub fn LLVMSetInstDebugLocation(Builder: &Builder<'a>, Inst: &'a Value);
854
855     // Terminators
856     pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;
857     pub fn LLVMBuildRet(B: &Builder<'a>, V: &'a Value) -> &'a Value;
858     pub fn LLVMBuildBr(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
859     pub fn LLVMBuildCondBr(B: &Builder<'a>,
860                            If: &'a Value,
861                            Then: &'a BasicBlock,
862                            Else: &'a BasicBlock)
863                            -> &'a Value;
864     pub fn LLVMBuildSwitch(B: &Builder<'a>,
865                            V: &'a Value,
866                            Else: &'a BasicBlock,
867                            NumCases: c_uint)
868                            -> &'a Value;
869     pub fn LLVMRustBuildInvoke(B: &Builder<'a>,
870                                Fn: &'a Value,
871                                Args: *const &'a Value,
872                                NumArgs: c_uint,
873                                Then: &'a BasicBlock,
874                                Catch: &'a BasicBlock,
875                                Bundle: Option<&OperandBundleDef<'a>>,
876                                Name: *const c_char)
877                                -> &'a Value;
878     pub fn LLVMBuildLandingPad(B: &Builder<'a>,
879                                Ty: &'a Type,
880                                PersFn: &'a Value,
881                                NumClauses: c_uint,
882                                Name: *const c_char)
883                                -> &'a Value;
884     pub fn LLVMBuildResume(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
885     pub fn LLVMBuildUnreachable(B: &Builder<'a>) -> &'a Value;
886
887     pub fn LLVMRustBuildCleanupPad(B: &Builder<'a>,
888                                    ParentPad: Option<&'a Value>,
889                                    ArgCnt: c_uint,
890                                    Args: *const &'a Value,
891                                    Name: *const c_char)
892                                    -> Option<&'a Value>;
893     pub fn LLVMRustBuildCleanupRet(B: &Builder<'a>,
894                                    CleanupPad: &'a Value,
895                                    UnwindBB: Option<&'a BasicBlock>)
896                                    -> Option<&'a Value>;
897     pub fn LLVMRustBuildCatchPad(B: &Builder<'a>,
898                                  ParentPad: &'a Value,
899                                  ArgCnt: c_uint,
900                                  Args: *const &'a Value,
901                                  Name: *const c_char)
902                                  -> Option<&'a Value>;
903     pub fn LLVMRustBuildCatchRet(
904         B: &Builder<'a>,
905         Pad: &'a Value,
906         BB: &'a BasicBlock,
907     ) -> Option<&'a Value>;
908     pub fn LLVMRustBuildCatchSwitch(Builder: &Builder<'a>,
909                                     ParentPad: Option<&'a Value>,
910                                     BB: Option<&'a BasicBlock>,
911                                     NumHandlers: c_uint,
912                                     Name: *const c_char)
913                                     -> Option<&'a Value>;
914     pub fn LLVMRustAddHandler(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
915     pub fn LLVMSetPersonalityFn(Func: &'a Value, Pers: &'a Value);
916
917     // Add a case to the switch instruction
918     pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
919
920     // Add a clause to the landing pad instruction
921     pub fn LLVMAddClause(LandingPad: &'a Value, ClauseVal: &'a Value);
922
923     // Set the cleanup on a landing pad instruction
924     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
925
926     // Arithmetic
927     pub fn LLVMBuildAdd(B: &Builder<'a>,
928                         LHS: &'a Value,
929                         RHS: &'a Value,
930                         Name: *const c_char)
931                         -> &'a Value;
932     pub fn LLVMBuildFAdd(B: &Builder<'a>,
933                          LHS: &'a Value,
934                          RHS: &'a Value,
935                          Name: *const c_char)
936                          -> &'a Value;
937     pub fn LLVMBuildSub(B: &Builder<'a>,
938                         LHS: &'a Value,
939                         RHS: &'a Value,
940                         Name: *const c_char)
941                         -> &'a Value;
942     pub fn LLVMBuildFSub(B: &Builder<'a>,
943                          LHS: &'a Value,
944                          RHS: &'a Value,
945                          Name: *const c_char)
946                          -> &'a Value;
947     pub fn LLVMBuildMul(B: &Builder<'a>,
948                         LHS: &'a Value,
949                         RHS: &'a Value,
950                         Name: *const c_char)
951                         -> &'a Value;
952     pub fn LLVMBuildFMul(B: &Builder<'a>,
953                          LHS: &'a Value,
954                          RHS: &'a Value,
955                          Name: *const c_char)
956                          -> &'a Value;
957     pub fn LLVMBuildUDiv(B: &Builder<'a>,
958                          LHS: &'a Value,
959                          RHS: &'a Value,
960                          Name: *const c_char)
961                          -> &'a Value;
962     pub fn LLVMBuildExactUDiv(B: &Builder<'a>,
963                               LHS: &'a Value,
964                               RHS: &'a Value,
965                               Name: *const c_char)
966                               -> &'a Value;
967     pub fn LLVMBuildSDiv(B: &Builder<'a>,
968                          LHS: &'a Value,
969                          RHS: &'a Value,
970                          Name: *const c_char)
971                          -> &'a Value;
972     pub fn LLVMBuildExactSDiv(B: &Builder<'a>,
973                               LHS: &'a Value,
974                               RHS: &'a Value,
975                               Name: *const c_char)
976                               -> &'a Value;
977     pub fn LLVMBuildFDiv(B: &Builder<'a>,
978                          LHS: &'a Value,
979                          RHS: &'a Value,
980                          Name: *const c_char)
981                          -> &'a Value;
982     pub fn LLVMBuildURem(B: &Builder<'a>,
983                          LHS: &'a Value,
984                          RHS: &'a Value,
985                          Name: *const c_char)
986                          -> &'a Value;
987     pub fn LLVMBuildSRem(B: &Builder<'a>,
988                          LHS: &'a Value,
989                          RHS: &'a Value,
990                          Name: *const c_char)
991                          -> &'a Value;
992     pub fn LLVMBuildFRem(B: &Builder<'a>,
993                          LHS: &'a Value,
994                          RHS: &'a Value,
995                          Name: *const c_char)
996                          -> &'a Value;
997     pub fn LLVMBuildShl(B: &Builder<'a>,
998                         LHS: &'a Value,
999                         RHS: &'a Value,
1000                         Name: *const c_char)
1001                         -> &'a Value;
1002     pub fn LLVMBuildLShr(B: &Builder<'a>,
1003                          LHS: &'a Value,
1004                          RHS: &'a Value,
1005                          Name: *const c_char)
1006                          -> &'a Value;
1007     pub fn LLVMBuildAShr(B: &Builder<'a>,
1008                          LHS: &'a Value,
1009                          RHS: &'a Value,
1010                          Name: *const c_char)
1011                          -> &'a Value;
1012     pub fn LLVMBuildNSWAdd(B: &Builder<'a>,
1013                            LHS: &'a Value,
1014                            RHS: &'a Value,
1015                            Name: *const c_char)
1016                            -> &'a Value;
1017     pub fn LLVMBuildNUWAdd(B: &Builder<'a>,
1018                            LHS: &'a Value,
1019                            RHS: &'a Value,
1020                            Name: *const c_char)
1021                            -> &'a Value;
1022     pub fn LLVMBuildNSWSub(B: &Builder<'a>,
1023                            LHS: &'a Value,
1024                            RHS: &'a Value,
1025                            Name: *const c_char)
1026                            -> &'a Value;
1027     pub fn LLVMBuildNUWSub(B: &Builder<'a>,
1028                            LHS: &'a Value,
1029                            RHS: &'a Value,
1030                            Name: *const c_char)
1031                            -> &'a Value;
1032     pub fn LLVMBuildNSWMul(B: &Builder<'a>,
1033                            LHS: &'a Value,
1034                            RHS: &'a Value,
1035                            Name: *const c_char)
1036                            -> &'a Value;
1037     pub fn LLVMBuildNUWMul(B: &Builder<'a>,
1038                            LHS: &'a Value,
1039                            RHS: &'a Value,
1040                            Name: *const c_char)
1041                            -> &'a Value;
1042     pub fn LLVMBuildAnd(B: &Builder<'a>,
1043                         LHS: &'a Value,
1044                         RHS: &'a Value,
1045                         Name: *const c_char)
1046                         -> &'a Value;
1047     pub fn LLVMBuildOr(B: &Builder<'a>,
1048                        LHS: &'a Value,
1049                        RHS: &'a Value,
1050                        Name: *const c_char)
1051                        -> &'a Value;
1052     pub fn LLVMBuildXor(B: &Builder<'a>,
1053                         LHS: &'a Value,
1054                         RHS: &'a Value,
1055                         Name: *const c_char)
1056                         -> &'a Value;
1057     pub fn LLVMBuildNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1058     pub fn LLVMBuildFNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1059     pub fn LLVMBuildNot(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1060     pub fn LLVMRustSetHasUnsafeAlgebra(Instr: &Value);
1061
1062     // Memory
1063     pub fn LLVMBuildAlloca(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1064     pub fn LLVMBuildArrayAlloca(B: &Builder<'a>,
1065                                 Ty: &'a Type,
1066                                 Val: &'a Value,
1067                                 Name: *const c_char)
1068                                 -> &'a Value;
1069     pub fn LLVMBuildLoad(B: &Builder<'a>, PointerVal: &'a Value, Name: *const c_char) -> &'a Value;
1070
1071     pub fn LLVMBuildStore(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1072
1073     pub fn LLVMBuildGEP(B: &Builder<'a>,
1074                         Pointer: &'a Value,
1075                         Indices: *const &'a Value,
1076                         NumIndices: c_uint,
1077                         Name: *const c_char)
1078                         -> &'a Value;
1079     pub fn LLVMBuildInBoundsGEP(B: &Builder<'a>,
1080                                 Pointer: &'a Value,
1081                                 Indices: *const &'a Value,
1082                                 NumIndices: c_uint,
1083                                 Name: *const c_char)
1084                                 -> &'a Value;
1085     pub fn LLVMBuildStructGEP(B: &Builder<'a>,
1086                               Pointer: &'a Value,
1087                               Idx: c_uint,
1088                               Name: *const c_char)
1089                               -> &'a Value;
1090
1091     // Casts
1092     pub fn LLVMBuildTrunc(B: &Builder<'a>,
1093                           Val: &'a Value,
1094                           DestTy: &'a Type,
1095                           Name: *const c_char)
1096                           -> &'a Value;
1097     pub fn LLVMBuildZExt(B: &Builder<'a>,
1098                          Val: &'a Value,
1099                          DestTy: &'a Type,
1100                          Name: *const c_char)
1101                          -> &'a Value;
1102     pub fn LLVMBuildSExt(B: &Builder<'a>,
1103                          Val: &'a Value,
1104                          DestTy: &'a Type,
1105                          Name: *const c_char)
1106                          -> &'a Value;
1107     pub fn LLVMBuildFPToUI(B: &Builder<'a>,
1108                            Val: &'a Value,
1109                            DestTy: &'a Type,
1110                            Name: *const c_char)
1111                            -> &'a Value;
1112     pub fn LLVMBuildFPToSI(B: &Builder<'a>,
1113                            Val: &'a Value,
1114                            DestTy: &'a Type,
1115                            Name: *const c_char)
1116                            -> &'a Value;
1117     pub fn LLVMBuildUIToFP(B: &Builder<'a>,
1118                            Val: &'a Value,
1119                            DestTy: &'a Type,
1120                            Name: *const c_char)
1121                            -> &'a Value;
1122     pub fn LLVMBuildSIToFP(B: &Builder<'a>,
1123                            Val: &'a Value,
1124                            DestTy: &'a Type,
1125                            Name: *const c_char)
1126                            -> &'a Value;
1127     pub fn LLVMBuildFPTrunc(B: &Builder<'a>,
1128                             Val: &'a Value,
1129                             DestTy: &'a Type,
1130                             Name: *const c_char)
1131                             -> &'a Value;
1132     pub fn LLVMBuildFPExt(B: &Builder<'a>,
1133                           Val: &'a Value,
1134                           DestTy: &'a Type,
1135                           Name: *const c_char)
1136                           -> &'a Value;
1137     pub fn LLVMBuildPtrToInt(B: &Builder<'a>,
1138                              Val: &'a Value,
1139                              DestTy: &'a Type,
1140                              Name: *const c_char)
1141                              -> &'a Value;
1142     pub fn LLVMBuildIntToPtr(B: &Builder<'a>,
1143                              Val: &'a Value,
1144                              DestTy: &'a Type,
1145                              Name: *const c_char)
1146                              -> &'a Value;
1147     pub fn LLVMBuildBitCast(B: &Builder<'a>,
1148                             Val: &'a Value,
1149                             DestTy: &'a Type,
1150                             Name: *const c_char)
1151                             -> &'a Value;
1152     pub fn LLVMBuildPointerCast(B: &Builder<'a>,
1153                                 Val: &'a Value,
1154                                 DestTy: &'a Type,
1155                                 Name: *const c_char)
1156                                 -> &'a Value;
1157     pub fn LLVMRustBuildIntCast(B: &Builder<'a>,
1158                                 Val: &'a Value,
1159                                 DestTy: &'a Type,
1160                                 IsSized: bool)
1161                                 -> &'a Value;
1162
1163     // Comparisons
1164     pub fn LLVMBuildICmp(B: &Builder<'a>,
1165                          Op: c_uint,
1166                          LHS: &'a Value,
1167                          RHS: &'a Value,
1168                          Name: *const c_char)
1169                          -> &'a Value;
1170     pub fn LLVMBuildFCmp(B: &Builder<'a>,
1171                          Op: c_uint,
1172                          LHS: &'a Value,
1173                          RHS: &'a Value,
1174                          Name: *const c_char)
1175                          -> &'a Value;
1176
1177     // Miscellaneous instructions
1178     pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1179     pub fn LLVMRustBuildCall(B: &Builder<'a>,
1180                              Fn: &'a Value,
1181                              Args: *const &'a Value,
1182                              NumArgs: c_uint,
1183                              Bundle: Option<&OperandBundleDef<'a>>,
1184                              Name: *const c_char)
1185                              -> &'a Value;
1186     pub fn LLVMRustBuildMemCpy(B: &Builder<'a>,
1187                                Dst: &'a Value,
1188                                DstAlign: c_uint,
1189                                Src: &'a Value,
1190                                SrcAlign: c_uint,
1191                                Size: &'a Value,
1192                                IsVolatile: bool)
1193                                -> &'a Value;
1194     pub fn LLVMRustBuildMemMove(B: &Builder<'a>,
1195                                 Dst: &'a Value,
1196                                 DstAlign: c_uint,
1197                                 Src: &'a Value,
1198                                 SrcAlign: c_uint,
1199                                 Size: &'a Value,
1200                                 IsVolatile: bool)
1201                                 -> &'a Value;
1202     pub fn LLVMBuildSelect(B: &Builder<'a>,
1203                            If: &'a Value,
1204                            Then: &'a Value,
1205                            Else: &'a Value,
1206                            Name: *const c_char)
1207                            -> &'a Value;
1208     pub fn LLVMBuildVAArg(B: &Builder<'a>,
1209                           list: &'a Value,
1210                           Ty: &'a Type,
1211                           Name: *const c_char)
1212                           -> &'a Value;
1213     pub fn LLVMBuildExtractElement(B: &Builder<'a>,
1214                                    VecVal: &'a Value,
1215                                    Index: &'a Value,
1216                                    Name: *const c_char)
1217                                    -> &'a Value;
1218     pub fn LLVMBuildInsertElement(B: &Builder<'a>,
1219                                   VecVal: &'a Value,
1220                                   EltVal: &'a Value,
1221                                   Index: &'a Value,
1222                                   Name: *const c_char)
1223                                   -> &'a Value;
1224     pub fn LLVMBuildShuffleVector(B: &Builder<'a>,
1225                                   V1: &'a Value,
1226                                   V2: &'a Value,
1227                                   Mask: &'a Value,
1228                                   Name: *const c_char)
1229                                   -> &'a Value;
1230     pub fn LLVMBuildExtractValue(B: &Builder<'a>,
1231                                  AggVal: &'a Value,
1232                                  Index: c_uint,
1233                                  Name: *const c_char)
1234                                  -> &'a Value;
1235     pub fn LLVMBuildInsertValue(B: &Builder<'a>,
1236                                 AggVal: &'a Value,
1237                                 EltVal: &'a Value,
1238                                 Index: c_uint,
1239                                 Name: *const c_char)
1240                                 -> &'a Value;
1241
1242     pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
1243                                          Acc: &'a Value,
1244                                          Src: &'a Value)
1245                                          -> &'a Value;
1246     pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
1247                                          Acc: &'a Value,
1248                                          Src: &'a Value)
1249                                          -> &'a Value;
1250     pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
1251                                         Src: &'a Value)
1252                                         -> &'a Value;
1253     pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
1254                                         Src: &'a Value)
1255                                         -> &'a Value;
1256     pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
1257                                         Src: &'a Value)
1258                                         -> &'a Value;
1259     pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
1260                                        Src: &'a Value)
1261                                        -> &'a Value;
1262     pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
1263                                         Src: &'a Value)
1264                                         -> &'a Value;
1265     pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
1266                                         Src: &'a Value,
1267                                         IsSigned: bool)
1268                                         -> &'a Value;
1269     pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
1270                                         Src: &'a Value,
1271                                         IsSigned: bool)
1272                                         -> &'a Value;
1273     pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
1274                                          Src: &'a Value,
1275                                          IsNaN: bool)
1276                                          -> &'a Value;
1277     pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
1278                                          Src: &'a Value,
1279                                          IsNaN: bool)
1280                                          -> &'a Value;
1281
1282     pub fn LLVMRustBuildMinNum(
1283         B: &Builder<'a>,
1284         LHS: &'a Value,
1285         LHS: &'a Value,
1286     ) -> &'a Value;
1287     pub fn LLVMRustBuildMaxNum(
1288         B: &Builder<'a>,
1289         LHS: &'a Value,
1290         LHS: &'a Value,
1291     ) -> &'a Value;
1292
1293     // Atomic Operations
1294     pub fn LLVMRustBuildAtomicLoad(B: &Builder<'a>,
1295                                    PointerVal: &'a Value,
1296                                    Name: *const c_char,
1297                                    Order: AtomicOrdering)
1298                                    -> &'a Value;
1299
1300     pub fn LLVMRustBuildAtomicStore(B: &Builder<'a>,
1301                                     Val: &'a Value,
1302                                     Ptr: &'a Value,
1303                                     Order: AtomicOrdering)
1304                                     -> &'a Value;
1305
1306     pub fn LLVMRustBuildAtomicCmpXchg(B: &Builder<'a>,
1307                                       LHS: &'a Value,
1308                                       CMP: &'a Value,
1309                                       RHS: &'a Value,
1310                                       Order: AtomicOrdering,
1311                                       FailureOrder: AtomicOrdering,
1312                                       Weak: Bool)
1313                                       -> &'a Value;
1314
1315     pub fn LLVMBuildAtomicRMW(B: &Builder<'a>,
1316                               Op: AtomicRmwBinOp,
1317                               LHS: &'a Value,
1318                               RHS: &'a Value,
1319                               Order: AtomicOrdering,
1320                               SingleThreaded: Bool)
1321                               -> &'a Value;
1322
1323     pub fn LLVMRustBuildAtomicFence(B: &Builder<'_>,
1324                                     Order: AtomicOrdering,
1325                                     Scope: SynchronizationScope);
1326
1327     /// Writes a module to the specified path. Returns 0 on success.
1328     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1329
1330     /// Creates a pass manager.
1331     pub fn LLVMCreatePassManager() -> &'a mut PassManager<'a>;
1332
1333     /// Creates a function-by-function pass manager
1334     pub fn LLVMCreateFunctionPassManagerForModule(M: &'a Module) -> &'a mut PassManager<'a>;
1335
1336     /// Disposes a pass manager.
1337     pub fn LLVMDisposePassManager(PM: &'a mut PassManager<'a>);
1338
1339     /// Runs a pass manager on a module.
1340     pub fn LLVMRunPassManager(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1341
1342     pub fn LLVMInitializePasses();
1343
1344     pub fn LLVMAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>);
1345
1346     pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1347     pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1348     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1349     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1350     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: &PassManagerBuilder,
1351                                                          threshold: c_uint);
1352     pub fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: &PassManagerBuilder,
1353                                                            PM: &PassManager<'_>);
1354
1355     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: &PassManagerBuilder,
1356                                                              PM: &PassManager<'_>);
1357     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(PMB: &PassManagerBuilder,
1358                                                         PM: &PassManager<'_>,
1359                                                         Internalize: Bool,
1360                                                         RunInliner: Bool);
1361     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1362         PMB: &PassManagerBuilder,
1363         PM: &PassManager<'_>);
1364
1365     // Stuff that's in rustllvm/ because it's not upstream yet.
1366
1367     /// Opens an object file.
1368     pub fn LLVMCreateObjectFile(
1369         MemBuf: &'static mut MemoryBuffer,
1370     ) -> Option<&'static mut ObjectFile>;
1371     /// Closes an object file.
1372     pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
1373
1374     /// Enumerates the sections in an object file.
1375     pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
1376     /// Destroys a section iterator.
1377     pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
1378     /// Returns `true` if the section iterator is at the end of the section
1379     /// list:
1380     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
1381     /// Moves the section iterator to point to the next section.
1382     pub fn LLVMMoveToNextSection(SI: &SectionIterator<'_>);
1383     /// Returns the current section size.
1384     pub fn LLVMGetSectionSize(SI: &SectionIterator<'_>) -> c_ulonglong;
1385     /// Returns the current section contents as a string buffer.
1386     pub fn LLVMGetSectionContents(SI: &SectionIterator<'_>) -> *const c_char;
1387
1388     /// Reads the given file and returns it as a memory buffer. Use
1389     /// LLVMDisposeMemoryBuffer() to get rid of it.
1390     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1391         Path: *const c_char,
1392     ) -> Option<&'static mut MemoryBuffer>;
1393
1394     pub fn LLVMStartMultithreaded() -> Bool;
1395
1396     /// Returns a string describing the last error caused by an LLVMRust* call.
1397     pub fn LLVMRustGetLastError() -> *const c_char;
1398
1399     /// Print the pass timings since static dtors aren't picking them up.
1400     pub fn LLVMRustPrintPassTimings();
1401
1402     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1403
1404     pub fn LLVMStructSetBody(StructTy: &'a Type,
1405                              ElementTypes: *const &'a Type,
1406                              ElementCount: c_uint,
1407                              Packed: Bool);
1408
1409     /// Prepares inline assembly.
1410     pub fn LLVMRustInlineAsm(Ty: &Type,
1411                              AsmString: *const c_char,
1412                              Constraints: *const c_char,
1413                              SideEffects: Bool,
1414                              AlignStack: Bool,
1415                              Dialect: AsmDialect)
1416                              -> &Value;
1417     pub fn LLVMRustInlineAsmVerify(Ty: &Type,
1418                                    Constraints: *const c_char)
1419                                    -> bool;
1420
1421     pub fn LLVMRustDebugMetadataVersion() -> u32;
1422     pub fn LLVMRustVersionMajor() -> u32;
1423     pub fn LLVMRustVersionMinor() -> u32;
1424
1425     pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);
1426
1427     pub fn LLVMRustMetadataAsValue(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1428
1429     pub fn LLVMRustDIBuilderCreate(M: &'a Module) -> &'a mut DIBuilder<'a>;
1430
1431     pub fn LLVMRustDIBuilderDispose(Builder: &'a mut DIBuilder<'a>);
1432
1433     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder<'_>);
1434
1435     pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: &DIBuilder<'a>,
1436                                               Lang: c_uint,
1437                                               File: &'a DIFile,
1438                                               Producer: *const c_char,
1439                                               isOptimized: bool,
1440                                               Flags: *const c_char,
1441                                               RuntimeVer: c_uint,
1442                                               SplitName: *const c_char,
1443                                               kind: DebugEmissionKind)
1444                                               -> &'a DIDescriptor;
1445
1446     pub fn LLVMRustDIBuilderCreateFile(Builder: &DIBuilder<'a>,
1447                                        Filename: *const c_char,
1448                                        Directory: *const c_char)
1449                                        -> &'a DIFile;
1450
1451     pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: &DIBuilder<'a>,
1452                                                  File: &'a DIFile,
1453                                                  ParameterTypes: &'a DIArray)
1454                                                  -> &'a DICompositeType;
1455
1456     pub fn LLVMRustDIBuilderCreateFunction(Builder: &DIBuilder<'a>,
1457                                            Scope: &'a DIDescriptor,
1458                                            Name: *const c_char,
1459                                            LinkageName: *const c_char,
1460                                            File: &'a DIFile,
1461                                            LineNo: c_uint,
1462                                            Ty: &'a DIType,
1463                                            ScopeLine: c_uint,
1464                                            Flags: DIFlags,
1465                                            SPFlags: DISPFlags,
1466                                            Fn: &'a Value,
1467                                            TParam: &'a DIArray,
1468                                            Decl: Option<&'a DIDescriptor>)
1469                                            -> &'a DISubprogram;
1470
1471     pub fn LLVMRustDIBuilderCreateBasicType(Builder: &DIBuilder<'a>,
1472                                             Name: *const c_char,
1473                                             SizeInBits: u64,
1474                                             AlignInBits: u32,
1475                                             Encoding: c_uint)
1476                                             -> &'a DIBasicType;
1477
1478     pub fn LLVMRustDIBuilderCreatePointerType(Builder: &DIBuilder<'a>,
1479                                               PointeeTy: &'a DIType,
1480                                               SizeInBits: u64,
1481                                               AlignInBits: u32,
1482                                               Name: *const c_char)
1483                                               -> &'a DIDerivedType;
1484
1485     pub fn LLVMRustDIBuilderCreateStructType(Builder: &DIBuilder<'a>,
1486                                              Scope: Option<&'a DIDescriptor>,
1487                                              Name: *const c_char,
1488                                              File: &'a DIFile,
1489                                              LineNumber: c_uint,
1490                                              SizeInBits: u64,
1491                                              AlignInBits: u32,
1492                                              Flags: DIFlags,
1493                                              DerivedFrom: Option<&'a DIType>,
1494                                              Elements: &'a DIArray,
1495                                              RunTimeLang: c_uint,
1496                                              VTableHolder: Option<&'a DIType>,
1497                                              UniqueId: *const c_char)
1498                                              -> &'a DICompositeType;
1499
1500     pub fn LLVMRustDIBuilderCreateMemberType(Builder: &DIBuilder<'a>,
1501                                              Scope: &'a DIDescriptor,
1502                                              Name: *const c_char,
1503                                              File: &'a DIFile,
1504                                              LineNo: c_uint,
1505                                              SizeInBits: u64,
1506                                              AlignInBits: u32,
1507                                              OffsetInBits: u64,
1508                                              Flags: DIFlags,
1509                                              Ty: &'a DIType)
1510                                              -> &'a DIDerivedType;
1511
1512     pub fn LLVMRustDIBuilderCreateVariantMemberType(Builder: &DIBuilder<'a>,
1513                                                     Scope: &'a DIScope,
1514                                                     Name: *const c_char,
1515                                                     File: &'a DIFile,
1516                                                     LineNumber: c_uint,
1517                                                     SizeInBits: u64,
1518                                                     AlignInBits: u32,
1519                                                     OffsetInBits: u64,
1520                                                     Discriminant: Option<&'a Value>,
1521                                                     Flags: DIFlags,
1522                                                     Ty: &'a DIType)
1523                                                     -> &'a DIType;
1524
1525     pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: &DIBuilder<'a>,
1526                                                Scope: &'a DIScope,
1527                                                File: &'a DIFile,
1528                                                Line: c_uint,
1529                                                Col: c_uint)
1530                                                -> &'a DILexicalBlock;
1531
1532     pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: &DIBuilder<'a>,
1533                                                    Scope: &'a DIScope,
1534                                                    File: &'a DIFile)
1535                                                    -> &'a DILexicalBlock;
1536
1537     pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: &DIBuilder<'a>,
1538                                                  Context: Option<&'a DIScope>,
1539                                                  Name: *const c_char,
1540                                                  LinkageName: *const c_char,
1541                                                  File: &'a DIFile,
1542                                                  LineNo: c_uint,
1543                                                  Ty: &'a DIType,
1544                                                  isLocalToUnit: bool,
1545                                                  Val: &'a Value,
1546                                                  Decl: Option<&'a DIDescriptor>,
1547                                                  AlignInBits: u32)
1548                                                  -> &'a DIGlobalVariableExpression;
1549
1550     pub fn LLVMRustDIBuilderCreateVariable(Builder: &DIBuilder<'a>,
1551                                            Tag: c_uint,
1552                                            Scope: &'a DIDescriptor,
1553                                            Name: *const c_char,
1554                                            File: &'a DIFile,
1555                                            LineNo: c_uint,
1556                                            Ty: &'a DIType,
1557                                            AlwaysPreserve: bool,
1558                                            Flags: DIFlags,
1559                                            ArgNo: c_uint,
1560                                            AlignInBits: u32)
1561                                            -> &'a DIVariable;
1562
1563     pub fn LLVMRustDIBuilderCreateArrayType(Builder: &DIBuilder<'a>,
1564                                             Size: u64,
1565                                             AlignInBits: u32,
1566                                             Ty: &'a DIType,
1567                                             Subscripts: &'a DIArray)
1568                                             -> &'a DIType;
1569
1570     pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: &DIBuilder<'a>,
1571                                                 Lo: i64,
1572                                                 Count: i64)
1573                                                 -> &'a DISubrange;
1574
1575     pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: &DIBuilder<'a>,
1576                                              Ptr: *const Option<&'a DIDescriptor>,
1577                                              Count: c_uint)
1578                                              -> &'a DIArray;
1579
1580     pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: &DIBuilder<'a>,
1581                                                Val: &'a Value,
1582                                                VarInfo: &'a DIVariable,
1583                                                AddrOps: *const i64,
1584                                                AddrOpsCount: c_uint,
1585                                                DL: &'a Value,
1586                                                InsertAtEnd: &'a BasicBlock)
1587                                                -> &'a Value;
1588
1589     pub fn LLVMRustDIBuilderCreateEnumerator(Builder: &DIBuilder<'a>,
1590                                              Name: *const c_char,
1591                                              Val: u64)
1592                                              -> &'a DIEnumerator;
1593
1594     pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: &DIBuilder<'a>,
1595                                                   Scope: &'a DIScope,
1596                                                   Name: *const c_char,
1597                                                   File: &'a DIFile,
1598                                                   LineNumber: c_uint,
1599                                                   SizeInBits: u64,
1600                                                   AlignInBits: u32,
1601                                                   Elements: &'a DIArray,
1602                                                   ClassType: &'a DIType,
1603                                                   IsScoped: bool)
1604                                                   -> &'a DIType;
1605
1606     pub fn LLVMRustDIBuilderCreateUnionType(Builder: &DIBuilder<'a>,
1607                                             Scope: &'a DIScope,
1608                                             Name: *const c_char,
1609                                             File: &'a DIFile,
1610                                             LineNumber: c_uint,
1611                                             SizeInBits: u64,
1612                                             AlignInBits: u32,
1613                                             Flags: DIFlags,
1614                                             Elements: Option<&'a DIArray>,
1615                                             RunTimeLang: c_uint,
1616                                             UniqueId: *const c_char)
1617                                             -> &'a DIType;
1618
1619     pub fn LLVMRustDIBuilderCreateVariantPart(Builder: &DIBuilder<'a>,
1620                                               Scope: &'a DIScope,
1621                                               Name: *const c_char,
1622                                               File: &'a DIFile,
1623                                               LineNo: c_uint,
1624                                               SizeInBits: u64,
1625                                               AlignInBits: u32,
1626                                               Flags: DIFlags,
1627                                               Discriminator: Option<&'a DIDerivedType>,
1628                                               Elements: &'a DIArray,
1629                                               UniqueId: *const c_char)
1630                                               -> &'a DIDerivedType;
1631
1632     pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
1633
1634     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: &DIBuilder<'a>,
1635                                                         Scope: Option<&'a DIScope>,
1636                                                         Name: *const c_char,
1637                                                         Ty: &'a DIType,
1638                                                         File: &'a DIFile,
1639                                                         LineNo: c_uint,
1640                                                         ColumnNo: c_uint)
1641                                                         -> &'a DITemplateTypeParameter;
1642
1643
1644     pub fn LLVMRustDIBuilderCreateNameSpace(Builder: &DIBuilder<'a>,
1645                                             Scope: Option<&'a DIScope>,
1646                                             Name: *const c_char,
1647                                             File: &'a DIFile,
1648                                             LineNo: c_uint)
1649                                             -> &'a DINameSpace;
1650
1651     pub fn LLVMRustDICompositeTypeReplaceArrays(Builder: &DIBuilder<'a>,
1652                                                 CompositeType: &'a DIType,
1653                                                 Elements: Option<&'a DIArray>,
1654                                                 Params: Option<&'a DIArray>);
1655
1656
1657     pub fn LLVMRustDIBuilderCreateDebugLocation(Context: &'a Context,
1658                                                 Line: c_uint,
1659                                                 Column: c_uint,
1660                                                 Scope: &'a DIScope,
1661                                                 InlinedAt: Option<&'a Metadata>)
1662                                                 -> &'a Value;
1663     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
1664     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
1665
1666     #[allow(improper_ctypes)]
1667     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
1668     #[allow(improper_ctypes)]
1669     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
1670
1671     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1672
1673     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
1674     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
1675     pub fn LLVMRustCreateAddressSanitizerFunctionPass(Recover: bool) -> &'static mut Pass;
1676     pub fn LLVMRustCreateModuleAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
1677     pub fn LLVMRustCreateMemorySanitizerPass(TrackOrigins: c_int,
1678                                              Recover: bool) -> &'static mut Pass;
1679     pub fn LLVMRustCreateThreadSanitizerPass() -> &'static mut Pass;
1680     pub fn LLVMRustAddPass(PM: &PassManager<'_>, Pass: &'static mut Pass);
1681     pub fn LLVMRustAddLastExtensionPasses(PMB: &PassManagerBuilder,
1682                                           Passes: *const &'static mut Pass,
1683                                           NumPasses: size_t);
1684
1685     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
1686
1687     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
1688     pub fn LLVMRustPrintTargetFeatures(T: &TargetMachine);
1689
1690     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
1691     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
1692                                        CPU: *const c_char,
1693                                        Features: *const c_char,
1694                                        Abi: *const c_char,
1695                                        Model: CodeModel,
1696                                        Reloc: RelocMode,
1697                                        Level: CodeGenOptLevel,
1698                                        UseSoftFP: bool,
1699                                        PositionIndependentExecutable: bool,
1700                                        FunctionSections: bool,
1701                                        DataSections: bool,
1702                                        TrapUnreachable: bool,
1703                                        Singlethread: bool,
1704                                        AsmComments: bool,
1705                                        EmitStackSizeSection: bool,
1706                                        RelaxELFRelocations: bool)
1707                                        -> Option<&'static mut TargetMachine>;
1708     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
1709     pub fn LLVMRustAddBuilderLibraryInfo(PMB: &'a PassManagerBuilder,
1710                                          M: &'a Module,
1711                                          DisableSimplifyLibCalls: bool);
1712     pub fn LLVMRustConfigurePassManagerBuilder(PMB: &PassManagerBuilder,
1713                                                OptLevel: CodeGenOptLevel,
1714                                                MergeFunctions: bool,
1715                                                SLPVectorize: bool,
1716                                                LoopVectorize: bool,
1717                                                PrepareForThinLTO: bool,
1718                                                PGOGenPath: *const c_char,
1719                                                PGOUsePath: *const c_char);
1720     pub fn LLVMRustAddLibraryInfo(PM: &PassManager<'a>,
1721                                   M: &'a Module,
1722                                   DisableSimplifyLibCalls: bool);
1723     pub fn LLVMRustRunFunctionPassManager(PM: &PassManager<'a>, M: &'a Module);
1724     pub fn LLVMRustWriteOutputFile(T: &'a TargetMachine,
1725                                    PM: &PassManager<'a>,
1726                                    M: &'a Module,
1727                                    Output: *const c_char,
1728                                    FileType: FileType)
1729                                    -> LLVMRustResult;
1730     pub fn LLVMRustPrintModule(M: &'a Module,
1731                                Output: *const c_char,
1732                                Demangle: extern fn(*const c_char,
1733                                                    size_t,
1734                                                    *mut c_char,
1735                                                    size_t) -> size_t,
1736                                ) -> LLVMRustResult;
1737     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1738     pub fn LLVMRustPrintPasses();
1739     pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
1740     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
1741     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
1742     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
1743     pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
1744
1745     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
1746     pub fn LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
1747     pub fn LLVMRustArchiveIteratorNext(
1748         AIR: &ArchiveIterator<'a>,
1749     ) -> Option<&'a mut ArchiveChild<'a>>;
1750     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
1751     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
1752     pub fn LLVMRustArchiveChildFree(ACR: &'a mut ArchiveChild<'a>);
1753     pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
1754     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
1755
1756     #[allow(improper_ctypes)]
1757     pub fn LLVMRustGetSectionName(SI: &SectionIterator<'_>,
1758                                   data: &mut Option<std::ptr::NonNull<c_char>>) -> size_t;
1759
1760     #[allow(improper_ctypes)]
1761     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
1762
1763     pub fn LLVMContextSetDiagnosticHandler(C: &Context,
1764                                            Handler: DiagnosticHandler,
1765                                            DiagnosticContext: *mut c_void);
1766
1767     #[allow(improper_ctypes)]
1768     pub fn LLVMRustUnpackOptimizationDiagnostic(DI: &'a DiagnosticInfo,
1769                                                 pass_name_out: &RustString,
1770                                                 function_out: &mut Option<&'a Value>,
1771                                                 loc_line_out: &mut c_uint,
1772                                                 loc_column_out: &mut c_uint,
1773                                                 loc_filename_out: &RustString,
1774                                                 message_out: &RustString);
1775
1776     pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: &'a DiagnosticInfo,
1777                                              cookie_out: &mut c_uint,
1778                                              message_out: &mut Option<&'a Twine>,
1779                                              instruction_out: &mut Option<&'a Value>);
1780
1781     #[allow(improper_ctypes)]
1782     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
1783     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
1784
1785     pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: &Context,
1786                                                  H: InlineAsmDiagHandler,
1787                                                  CX: *mut c_void);
1788
1789     #[allow(improper_ctypes)]
1790     pub fn LLVMRustWriteSMDiagnosticToString(d: &SMDiagnostic, s: &RustString);
1791
1792     pub fn LLVMRustWriteArchive(Dst: *const c_char,
1793                                 NumMembers: size_t,
1794                                 Members: *const &RustArchiveMember<'_>,
1795                                 WriteSymbtab: bool,
1796                                 Kind: ArchiveKind)
1797                                 -> LLVMRustResult;
1798     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
1799                                     Name: *const c_char,
1800                                     Child: Option<&ArchiveChild<'a>>)
1801                                     -> &'a mut RustArchiveMember<'a>;
1802     pub fn LLVMRustArchiveMemberFree(Member: &'a mut RustArchiveMember<'a>);
1803
1804     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: &'a Module, TM: &'a TargetMachine);
1805
1806     pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
1807                                          Inputs: *const &'a Value,
1808                                          NumInputs: c_uint)
1809                                          -> &'a mut OperandBundleDef<'a>;
1810     pub fn LLVMRustFreeOperandBundleDef(Bundle: &'a mut OperandBundleDef<'a>);
1811
1812     pub fn LLVMRustPositionBuilderAtStart(B: &Builder<'a>, BB: &'a BasicBlock);
1813
1814     pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
1815     pub fn LLVMRustUnsetComdat(V: &Value);
1816     pub fn LLVMRustSetModulePICLevel(M: &Module);
1817     pub fn LLVMRustSetModulePIELevel(M: &Module);
1818     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
1819     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
1820     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
1821     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
1822     pub fn LLVMRustModuleCost(M: &Module) -> u64;
1823
1824     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
1825     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
1826     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
1827     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
1828     pub fn LLVMRustCreateThinLTOData(
1829         Modules: *const ThinLTOModule,
1830         NumModules: c_uint,
1831         PreservedSymbols: *const *const c_char,
1832         PreservedSymbolsLen: c_uint,
1833     ) -> Option<&'static mut ThinLTOData>;
1834     pub fn LLVMRustPrepareThinLTORename(
1835         Data: &ThinLTOData,
1836         Module: &Module,
1837     ) -> bool;
1838     pub fn LLVMRustPrepareThinLTOResolveWeak(
1839         Data: &ThinLTOData,
1840         Module: &Module,
1841     ) -> bool;
1842     pub fn LLVMRustPrepareThinLTOInternalize(
1843         Data: &ThinLTOData,
1844         Module: &Module,
1845     ) -> bool;
1846     pub fn LLVMRustPrepareThinLTOImport(
1847         Data: &ThinLTOData,
1848         Module: &Module,
1849     ) -> bool;
1850     pub fn LLVMRustGetThinLTOModuleImports(
1851         Data: *const ThinLTOData,
1852         ModuleNameCallback: ThinLTOModuleNameCallback,
1853         CallbackPayload: *mut c_void,
1854     );
1855     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
1856     pub fn LLVMRustParseBitcodeForLTO(
1857         Context: &Context,
1858         Data: *const u8,
1859         len: usize,
1860         Identifier: *const c_char,
1861     ) -> Option<&Module>;
1862     pub fn LLVMRustThinLTOGetDICompileUnit(M: &Module,
1863                                            CU1: &mut *mut c_void,
1864                                            CU2: &mut *mut c_void);
1865     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
1866
1867     pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
1868     pub fn LLVMRustLinkerAdd(linker: &Linker<'_>,
1869                              bytecode: *const c_char,
1870                              bytecode_len: usize) -> bool;
1871     pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
1872 }