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