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