]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/lib.rs
Auto merge of #27630 - sylvestre:master, r=dotdash
[rust.git] / src / librustc_llvm / lib.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 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
12 #![cfg_attr(stage0, feature(custom_attribute))]
13 #![allow(non_upper_case_globals)]
14 #![allow(non_camel_case_types)]
15 #![allow(non_snake_case)]
16 #![allow(dead_code)]
17 #![allow(trivial_casts)]
18
19 #![crate_name = "rustc_llvm"]
20 #![unstable(feature = "rustc_private")]
21 #![staged_api]
22 #![crate_type = "dylib"]
23 #![crate_type = "rlib"]
24 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
25        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
26        html_root_url = "http://doc.rust-lang.org/nightly/")]
27
28 #![feature(associated_consts)]
29 #![feature(box_syntax)]
30 #![feature(libc)]
31 #![feature(link_args)]
32 #![feature(staged_api)]
33 #![feature(vec_push_all)]
34 #![cfg_attr(not(stage0), feature(linked_from))]
35
36 extern crate libc;
37 #[macro_use] #[no_link] extern crate rustc_bitflags;
38
39 pub use self::OtherAttribute::*;
40 pub use self::SpecialAttribute::*;
41 pub use self::AttributeSet::*;
42 pub use self::IntPredicate::*;
43 pub use self::RealPredicate::*;
44 pub use self::TypeKind::*;
45 pub use self::AtomicBinOp::*;
46 pub use self::AtomicOrdering::*;
47 pub use self::SynchronizationScope::*;
48 pub use self::FileType::*;
49 pub use self::MetadataType::*;
50 pub use self::AsmDialect::*;
51 pub use self::CodeGenOptLevel::*;
52 pub use self::RelocMode::*;
53 pub use self::CodeGenModel::*;
54 pub use self::DiagnosticKind::*;
55 pub use self::CallConv::*;
56 pub use self::Visibility::*;
57 pub use self::DiagnosticSeverity::*;
58 pub use self::Linkage::*;
59 pub use self::DLLStorageClassTypes::*;
60
61 use std::ffi::CString;
62 use std::cell::RefCell;
63 use std::{slice, mem};
64 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
65 use libc::{c_longlong, c_ulonglong, c_void};
66 use debuginfo::{DIBuilderRef, DIDescriptor,
67                 DIFile, DILexicalBlock, DISubprogram, DIType,
68                 DIBasicType, DIDerivedType, DICompositeType, DIScope,
69                 DIVariable, DIGlobalVariable, DIArray, DISubrange,
70                 DITemplateTypeParameter, DIEnumerator, DINameSpace};
71
72 pub mod archive_ro;
73 pub mod diagnostic;
74
75 pub type Opcode = u32;
76 pub type Bool = c_uint;
77
78 pub const True: Bool = 1 as Bool;
79 pub const False: Bool = 0 as Bool;
80
81 // Consts for the LLVM CallConv type, pre-cast to usize.
82
83 #[derive(Copy, Clone, PartialEq)]
84 pub enum CallConv {
85     CCallConv = 0,
86     FastCallConv = 8,
87     ColdCallConv = 9,
88     X86StdcallCallConv = 64,
89     X86FastcallCallConv = 65,
90     X86_64_Win64 = 79,
91 }
92
93 #[derive(Copy, Clone)]
94 pub enum Visibility {
95     LLVMDefaultVisibility = 0,
96     HiddenVisibility = 1,
97     ProtectedVisibility = 2,
98 }
99
100 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
101 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
102 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
103 // they've been removed in upstream LLVM commit r203866.
104 #[derive(Copy, Clone)]
105 pub enum Linkage {
106     ExternalLinkage = 0,
107     AvailableExternallyLinkage = 1,
108     LinkOnceAnyLinkage = 2,
109     LinkOnceODRLinkage = 3,
110     WeakAnyLinkage = 5,
111     WeakODRLinkage = 6,
112     AppendingLinkage = 7,
113     InternalLinkage = 8,
114     PrivateLinkage = 9,
115     ExternalWeakLinkage = 12,
116     CommonLinkage = 14,
117 }
118
119 #[repr(C)]
120 #[derive(Copy, Clone, Debug)]
121 pub enum DiagnosticSeverity {
122     Error,
123     Warning,
124     Remark,
125     Note,
126 }
127
128
129 #[repr(C)]
130 #[derive(Copy, Clone)]
131 pub enum DLLStorageClassTypes {
132     DefaultStorageClass = 0,
133     DLLImportStorageClass = 1,
134     DLLExportStorageClass = 2,
135 }
136
137 bitflags! {
138     flags Attribute : u64 {
139         const ZExt            = 1 << 0,
140         const SExt            = 1 << 1,
141         const NoReturn        = 1 << 2,
142         const InReg           = 1 << 3,
143         const StructRet       = 1 << 4,
144         const NoUnwind        = 1 << 5,
145         const NoAlias         = 1 << 6,
146         const ByVal           = 1 << 7,
147         const Nest            = 1 << 8,
148         const ReadNone        = 1 << 9,
149         const ReadOnly        = 1 << 10,
150         const NoInline        = 1 << 11,
151         const AlwaysInline    = 1 << 12,
152         const OptimizeForSize = 1 << 13,
153         const StackProtect    = 1 << 14,
154         const StackProtectReq = 1 << 15,
155         const Alignment       = 1 << 16,
156         const NoCapture       = 1 << 21,
157         const NoRedZone       = 1 << 22,
158         const NoImplicitFloat = 1 << 23,
159         const Naked           = 1 << 24,
160         const InlineHint      = 1 << 25,
161         const Stack           = 7 << 26,
162         const ReturnsTwice    = 1 << 29,
163         const UWTable         = 1 << 30,
164         const NonLazyBind     = 1 << 31,
165         const OptimizeNone    = 1 << 42,
166     }
167 }
168
169
170 #[repr(u64)]
171 #[derive(Copy, Clone)]
172 pub enum OtherAttribute {
173     // The following are not really exposed in
174     // the LLVM C api so instead to add these
175     // we call a wrapper function in RustWrapper
176     // that uses the C++ api.
177     SanitizeAddressAttribute = 1 << 32,
178     MinSizeAttribute = 1 << 33,
179     NoDuplicateAttribute = 1 << 34,
180     StackProtectStrongAttribute = 1 << 35,
181     SanitizeThreadAttribute = 1 << 36,
182     SanitizeMemoryAttribute = 1 << 37,
183     NoBuiltinAttribute = 1 << 38,
184     ReturnedAttribute = 1 << 39,
185     ColdAttribute = 1 << 40,
186     BuiltinAttribute = 1 << 41,
187     OptimizeNoneAttribute = 1 << 42,
188     InAllocaAttribute = 1 << 43,
189     NonNullAttribute = 1 << 44,
190 }
191
192 #[derive(Copy, Clone)]
193 pub enum SpecialAttribute {
194     DereferenceableAttribute(u64)
195 }
196
197 #[repr(C)]
198 #[derive(Copy, Clone)]
199 pub enum AttributeSet {
200     ReturnIndex = 0,
201     FunctionIndex = !0
202 }
203
204 pub trait AttrHelper {
205     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
206     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
207 }
208
209 impl AttrHelper for Attribute {
210     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
211         unsafe {
212             LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
213         }
214     }
215
216     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
217         unsafe {
218             LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
219         }
220     }
221 }
222
223 impl AttrHelper for OtherAttribute {
224     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
225         unsafe {
226             LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
227         }
228     }
229
230     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
231         unsafe {
232             LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
233         }
234     }
235 }
236
237 impl AttrHelper for SpecialAttribute {
238     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
239         match *self {
240             DereferenceableAttribute(bytes) => unsafe {
241                 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
242             }
243         }
244     }
245
246     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
247         match *self {
248             DereferenceableAttribute(bytes) => unsafe {
249                 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
250             }
251         }
252     }
253 }
254
255 pub struct AttrBuilder {
256     attrs: Vec<(usize, Box<AttrHelper+'static>)>
257 }
258
259 impl AttrBuilder {
260     pub fn new() -> AttrBuilder {
261         AttrBuilder {
262             attrs: Vec::new()
263         }
264     }
265
266     pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
267         self.attrs.push((idx, box a as Box<AttrHelper+'static>));
268         self
269     }
270
271     pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
272         self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
273         self
274     }
275
276     pub fn apply_llfn(&self, llfn: ValueRef) {
277         for &(idx, ref attr) in &self.attrs {
278             attr.apply_llfn(idx as c_uint, llfn);
279         }
280     }
281
282     pub fn apply_callsite(&self, callsite: ValueRef) {
283         for &(idx, ref attr) in &self.attrs {
284             attr.apply_callsite(idx as c_uint, callsite);
285         }
286     }
287 }
288
289 // enum for the LLVM IntPredicate type
290 #[derive(Copy, Clone)]
291 pub enum IntPredicate {
292     IntEQ = 32,
293     IntNE = 33,
294     IntUGT = 34,
295     IntUGE = 35,
296     IntULT = 36,
297     IntULE = 37,
298     IntSGT = 38,
299     IntSGE = 39,
300     IntSLT = 40,
301     IntSLE = 41,
302 }
303
304 // enum for the LLVM RealPredicate type
305 #[derive(Copy, Clone)]
306 pub enum RealPredicate {
307     RealPredicateFalse = 0,
308     RealOEQ = 1,
309     RealOGT = 2,
310     RealOGE = 3,
311     RealOLT = 4,
312     RealOLE = 5,
313     RealONE = 6,
314     RealORD = 7,
315     RealUNO = 8,
316     RealUEQ = 9,
317     RealUGT = 10,
318     RealUGE = 11,
319     RealULT = 12,
320     RealULE = 13,
321     RealUNE = 14,
322     RealPredicateTrue = 15,
323 }
324
325 // The LLVM TypeKind type - must stay in sync with the def of
326 // LLVMTypeKind in llvm/include/llvm-c/Core.h
327 #[derive(Copy, Clone, PartialEq, Debug)]
328 #[repr(C)]
329 pub enum TypeKind {
330     Void      = 0,
331     Half      = 1,
332     Float     = 2,
333     Double    = 3,
334     X86_FP80  = 4,
335     FP128     = 5,
336     PPC_FP128 = 6,
337     Label     = 7,
338     Integer   = 8,
339     Function  = 9,
340     Struct    = 10,
341     Array     = 11,
342     Pointer   = 12,
343     Vector    = 13,
344     Metadata  = 14,
345     X86_MMX   = 15,
346 }
347
348 #[repr(C)]
349 #[derive(Copy, Clone)]
350 pub enum AtomicBinOp {
351     AtomicXchg = 0,
352     AtomicAdd  = 1,
353     AtomicSub  = 2,
354     AtomicAnd  = 3,
355     AtomicNand = 4,
356     AtomicOr   = 5,
357     AtomicXor  = 6,
358     AtomicMax  = 7,
359     AtomicMin  = 8,
360     AtomicUMax = 9,
361     AtomicUMin = 10,
362 }
363
364 #[repr(C)]
365 #[derive(Copy, Clone)]
366 pub enum AtomicOrdering {
367     NotAtomic = 0,
368     Unordered = 1,
369     Monotonic = 2,
370     // Consume = 3,  // Not specified yet.
371     Acquire = 4,
372     Release = 5,
373     AcquireRelease = 6,
374     SequentiallyConsistent = 7
375 }
376
377 #[repr(C)]
378 #[derive(Copy, Clone)]
379 pub enum SynchronizationScope {
380     SingleThread = 0,
381     CrossThread = 1
382 }
383
384 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
385 #[repr(C)]
386 #[derive(Copy, Clone)]
387 pub enum FileType {
388     AssemblyFileType = 0,
389     ObjectFileType = 1
390 }
391
392 #[derive(Copy, Clone)]
393 pub enum MetadataType {
394     MD_dbg = 0,
395     MD_tbaa = 1,
396     MD_prof = 2,
397     MD_fpmath = 3,
398     MD_range = 4,
399     MD_tbaa_struct = 5,
400     MD_invariant_load = 6,
401     MD_alias_scope = 7,
402     MD_noalias = 8,
403     MD_nontemporal = 9,
404     MD_mem_parallel_loop_access = 10,
405     MD_nonnull = 11,
406 }
407
408 // Inline Asm Dialect
409 #[derive(Copy, Clone)]
410 pub enum AsmDialect {
411     AD_ATT   = 0,
412     AD_Intel = 1
413 }
414
415 #[derive(Copy, Clone, PartialEq)]
416 #[repr(C)]
417 pub enum CodeGenOptLevel {
418     CodeGenLevelNone = 0,
419     CodeGenLevelLess = 1,
420     CodeGenLevelDefault = 2,
421     CodeGenLevelAggressive = 3,
422 }
423
424 #[derive(Copy, Clone, PartialEq)]
425 #[repr(C)]
426 pub enum RelocMode {
427     RelocDefault = 0,
428     RelocStatic = 1,
429     RelocPIC = 2,
430     RelocDynamicNoPic = 3,
431 }
432
433 #[repr(C)]
434 #[derive(Copy, Clone)]
435 pub enum CodeGenModel {
436     CodeModelDefault = 0,
437     CodeModelJITDefault = 1,
438     CodeModelSmall = 2,
439     CodeModelKernel = 3,
440     CodeModelMedium = 4,
441     CodeModelLarge = 5,
442 }
443
444 #[repr(C)]
445 #[derive(Copy, Clone)]
446 pub enum DiagnosticKind {
447     DK_InlineAsm = 0,
448     DK_StackSize,
449     DK_DebugMetadataVersion,
450     DK_SampleProfile,
451     DK_OptimizationRemark,
452     DK_OptimizationRemarkMissed,
453     DK_OptimizationRemarkAnalysis,
454     DK_OptimizationFailure,
455 }
456
457 #[repr(C)]
458 #[derive(Copy, Clone)]
459 pub enum ArchiveKind {
460     K_GNU,
461     K_MIPS64,
462     K_BSD,
463     K_COFF,
464 }
465
466 // Opaque pointer types
467 #[allow(missing_copy_implementations)]
468 pub enum Module_opaque {}
469 pub type ModuleRef = *mut Module_opaque;
470 #[allow(missing_copy_implementations)]
471 pub enum Context_opaque {}
472 pub type ContextRef = *mut Context_opaque;
473 #[allow(missing_copy_implementations)]
474 pub enum Type_opaque {}
475 pub type TypeRef = *mut Type_opaque;
476 #[allow(missing_copy_implementations)]
477 pub enum Value_opaque {}
478 pub type ValueRef = *mut Value_opaque;
479 #[allow(missing_copy_implementations)]
480 pub enum Metadata_opaque {}
481 pub type MetadataRef = *mut Metadata_opaque;
482 #[allow(missing_copy_implementations)]
483 pub enum BasicBlock_opaque {}
484 pub type BasicBlockRef = *mut BasicBlock_opaque;
485 #[allow(missing_copy_implementations)]
486 pub enum Builder_opaque {}
487 pub type BuilderRef = *mut Builder_opaque;
488 #[allow(missing_copy_implementations)]
489 pub enum ExecutionEngine_opaque {}
490 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
491 #[allow(missing_copy_implementations)]
492 pub enum MemoryBuffer_opaque {}
493 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
494 #[allow(missing_copy_implementations)]
495 pub enum PassManager_opaque {}
496 pub type PassManagerRef = *mut PassManager_opaque;
497 #[allow(missing_copy_implementations)]
498 pub enum PassManagerBuilder_opaque {}
499 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
500 #[allow(missing_copy_implementations)]
501 pub enum Use_opaque {}
502 pub type UseRef = *mut Use_opaque;
503 #[allow(missing_copy_implementations)]
504 pub enum TargetData_opaque {}
505 pub type TargetDataRef = *mut TargetData_opaque;
506 #[allow(missing_copy_implementations)]
507 pub enum ObjectFile_opaque {}
508 pub type ObjectFileRef = *mut ObjectFile_opaque;
509 #[allow(missing_copy_implementations)]
510 pub enum SectionIterator_opaque {}
511 pub type SectionIteratorRef = *mut SectionIterator_opaque;
512 #[allow(missing_copy_implementations)]
513 pub enum Pass_opaque {}
514 pub type PassRef = *mut Pass_opaque;
515 #[allow(missing_copy_implementations)]
516 pub enum TargetMachine_opaque {}
517 pub type TargetMachineRef = *mut TargetMachine_opaque;
518 pub enum Archive_opaque {}
519 pub type ArchiveRef = *mut Archive_opaque;
520 pub enum ArchiveIterator_opaque {}
521 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
522 pub enum ArchiveChild_opaque {}
523 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
524 #[allow(missing_copy_implementations)]
525 pub enum Twine_opaque {}
526 pub type TwineRef = *mut Twine_opaque;
527 #[allow(missing_copy_implementations)]
528 pub enum DiagnosticInfo_opaque {}
529 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
530 #[allow(missing_copy_implementations)]
531 pub enum DebugLoc_opaque {}
532 pub type DebugLocRef = *mut DebugLoc_opaque;
533 #[allow(missing_copy_implementations)]
534 pub enum SMDiagnostic_opaque {}
535 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
536 #[allow(missing_copy_implementations)]
537 pub enum RustArchiveMember_opaque {}
538 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
539
540 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
541 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
542
543 pub mod debuginfo {
544     pub use self::DIDescriptorFlags::*;
545     use super::{MetadataRef};
546
547     #[allow(missing_copy_implementations)]
548     pub enum DIBuilder_opaque {}
549     pub type DIBuilderRef = *mut DIBuilder_opaque;
550
551     pub type DIDescriptor = MetadataRef;
552     pub type DIScope = DIDescriptor;
553     pub type DILocation = 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 DIGlobalVariable = DIDescriptor;
564     pub type DIArray = DIDescriptor;
565     pub type DISubrange = DIDescriptor;
566     pub type DIEnumerator = DIDescriptor;
567     pub type DITemplateTypeParameter = DIDescriptor;
568
569     #[derive(Copy, Clone)]
570     pub enum DIDescriptorFlags {
571       FlagPrivate            = 1 << 0,
572       FlagProtected          = 1 << 1,
573       FlagFwdDecl            = 1 << 2,
574       FlagAppleBlock         = 1 << 3,
575       FlagBlockByrefStruct   = 1 << 4,
576       FlagVirtual            = 1 << 5,
577       FlagArtificial         = 1 << 6,
578       FlagExplicit           = 1 << 7,
579       FlagPrototyped         = 1 << 8,
580       FlagObjcClassComplete  = 1 << 9,
581       FlagObjectPointer      = 1 << 10,
582       FlagVector             = 1 << 11,
583       FlagStaticMember       = 1 << 12,
584       FlagIndirectVariable   = 1 << 13,
585       FlagLValueReference    = 1 << 14,
586       FlagRValueReference    = 1 << 15
587     }
588 }
589
590
591 // Link to our native llvm bindings (things that we need to use the C++ api
592 // for) and because llvm is written in C++ we need to link against libstdc++
593 //
594 // You'll probably notice that there is an omission of all LLVM libraries
595 // from this location. This is because the set of LLVM libraries that we
596 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
597 // figure out the exact set of libraries. To do this, the build system
598 // generates an llvmdeps.rs file next to this one which will be
599 // automatically updated whenever LLVM is updated to include an up-to-date
600 // set of the libraries we need to link to LLVM for.
601 #[link(name = "rustllvm", kind = "static")]
602 #[cfg_attr(not(stage0), linked_from = "rustllvm")] // not quite true but good enough
603 extern {
604     /* Create and destroy contexts. */
605     pub fn LLVMContextCreate() -> ContextRef;
606     pub fn LLVMContextDispose(C: ContextRef);
607     pub fn LLVMGetMDKindIDInContext(C: ContextRef,
608                                     Name: *const c_char,
609                                     SLen: c_uint)
610                                     -> c_uint;
611
612     /* Create and destroy modules. */
613     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
614                                              C: ContextRef)
615                                              -> ModuleRef;
616     pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
617     pub fn LLVMDisposeModule(M: ModuleRef);
618
619     /// Data layout. See Module::getDataLayout.
620     pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
621     pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
622
623     /// Target triple. See Module::getTargetTriple.
624     pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
625     pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
626
627     /// See Module::dump.
628     pub fn LLVMDumpModule(M: ModuleRef);
629
630     /// See Module::setModuleInlineAsm.
631     pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
632
633     /// See llvm::LLVMTypeKind::getTypeID.
634     pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
635
636     /// See llvm::LLVMType::getContext.
637     pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
638
639     /* Operations on integer types */
640     pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
641     pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
642     pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
643     pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
644     pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
645     pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
646                                 -> TypeRef;
647
648     pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
649
650     /* Operations on real types */
651     pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
652     pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
653     pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
654     pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
655     pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
656
657     /* Operations on function types */
658     pub fn LLVMFunctionType(ReturnType: TypeRef,
659                             ParamTypes: *const TypeRef,
660                             ParamCount: c_uint,
661                             IsVarArg: Bool)
662                             -> TypeRef;
663     pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
664     pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
665     pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
666     pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
667
668     /* Operations on struct types */
669     pub fn LLVMStructTypeInContext(C: ContextRef,
670                                    ElementTypes: *const TypeRef,
671                                    ElementCount: c_uint,
672                                    Packed: Bool)
673                                    -> TypeRef;
674     pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
675     pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
676                                      Dest: *mut TypeRef);
677     pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
678
679     /* Operations on array, pointer, and vector types (sequence types) */
680     pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
681     pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
682                            -> TypeRef;
683     pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
684                           -> TypeRef;
685
686     pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
687     pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
688     pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
689     pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
690                                   -> *const c_void;
691     pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
692
693     /* Operations on other types */
694     pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
695     pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
696     pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
697
698     /* Operations on all values */
699     pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
700     pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
701     pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
702     pub fn LLVMDumpValue(Val: ValueRef);
703     pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
704     pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
705     pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
706     pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
707
708     /* Operations on Uses */
709     pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
710     pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
711     pub fn LLVMGetUser(U: UseRef) -> ValueRef;
712     pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
713
714     /* Operations on Users */
715     pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
716     pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
717     pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
718
719     /* Operations on constants of any type */
720     pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
721     /* all zeroes */
722     pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
723     pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
724                          -> ValueRef;
725     pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
726                          -> ValueRef;
727     /* only for isize/vector */
728     pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
729     pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
730     pub fn LLVMIsNull(Val: ValueRef) -> Bool;
731     pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
732     pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
733
734     /* Operations on metadata */
735     pub fn LLVMMDStringInContext(C: ContextRef,
736                                  Str: *const c_char,
737                                  SLen: c_uint)
738                                  -> ValueRef;
739     pub fn LLVMMDNodeInContext(C: ContextRef,
740                                Vals: *const ValueRef,
741                                Count: c_uint)
742                                -> ValueRef;
743     pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
744                                        Str: *const c_char,
745                                        Val: ValueRef);
746
747     /* Operations on scalar constants */
748     pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
749                         -> ValueRef;
750     pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
751                                 -> ValueRef;
752     pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
753                                        Text: *const c_char,
754                                        SLen: c_uint,
755                                        Radix: u8)
756                                        -> ValueRef;
757     pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
758     pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
759                                  -> ValueRef;
760     pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
761                                         Text: *const c_char,
762                                         SLen: c_uint)
763                                         -> ValueRef;
764     pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
765     pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
766
767
768     /* Operations on composite constants */
769     pub fn LLVMConstStringInContext(C: ContextRef,
770                                     Str: *const c_char,
771                                     Length: c_uint,
772                                     DontNullTerminate: Bool)
773                                     -> ValueRef;
774     pub fn LLVMConstStructInContext(C: ContextRef,
775                                     ConstantVals: *const ValueRef,
776                                     Count: c_uint,
777                                     Packed: Bool)
778                                     -> ValueRef;
779
780     pub fn LLVMConstArray(ElementTy: TypeRef,
781                           ConstantVals: *const ValueRef,
782                           Length: c_uint)
783                           -> ValueRef;
784     pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
785                            -> ValueRef;
786
787     /* Constant expressions */
788     pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
789     pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
790     pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
791     pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
792     pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
793     pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
794     pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
795     pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
796                         -> ValueRef;
797     pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
798                            -> ValueRef;
799     pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
800                            -> ValueRef;
801     pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
802                          -> ValueRef;
803     pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
804                         -> ValueRef;
805     pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
806                            -> ValueRef;
807     pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
808                            -> ValueRef;
809     pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
810                          -> ValueRef;
811     pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
812                         -> ValueRef;
813     pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
814                            -> ValueRef;
815     pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
816                            -> ValueRef;
817     pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
818                          -> ValueRef;
819     pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
820                          -> ValueRef;
821     pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
822                          -> ValueRef;
823     pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
824                               RHSConstant: ValueRef)
825                               -> ValueRef;
826     pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
827                          -> ValueRef;
828     pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
829                          -> ValueRef;
830     pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
831                          -> ValueRef;
832     pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
833                          -> ValueRef;
834     pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
835                         -> ValueRef;
836     pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
837                        -> ValueRef;
838     pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
839                         -> ValueRef;
840     pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
841                         -> ValueRef;
842     pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
843                          -> ValueRef;
844     pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
845                          -> ValueRef;
846     pub fn LLVMConstGEP(ConstantVal: ValueRef,
847                         ConstantIndices: *const ValueRef,
848                         NumIndices: c_uint)
849                         -> ValueRef;
850     pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
851                                 ConstantIndices: *const ValueRef,
852                                 NumIndices: c_uint)
853                                 -> ValueRef;
854     pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
855                           -> ValueRef;
856     pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
857                          -> ValueRef;
858     pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
859                          -> ValueRef;
860     pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
861                             -> ValueRef;
862     pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
863                           -> ValueRef;
864     pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
865                            -> ValueRef;
866     pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
867                            -> ValueRef;
868     pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
869                            -> ValueRef;
870     pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
871                            -> ValueRef;
872     pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
873                              -> ValueRef;
874     pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
875                              -> ValueRef;
876     pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
877                             -> ValueRef;
878     pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
879                                   -> ValueRef;
880     pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
881                                   -> ValueRef;
882     pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
883                                    -> ValueRef;
884     pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
885                                 -> ValueRef;
886     pub fn LLVMConstIntCast(ConstantVal: ValueRef,
887                             ToType: TypeRef,
888                             isSigned: Bool)
889                             -> ValueRef;
890     pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
891                            -> ValueRef;
892     pub fn LLVMConstSelect(ConstantCondition: ValueRef,
893                            ConstantIfTrue: ValueRef,
894                            ConstantIfFalse: ValueRef)
895                            -> ValueRef;
896     pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
897                                    IndexConstant: ValueRef)
898                                    -> ValueRef;
899     pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
900                                   ElementValueConstant: ValueRef,
901                                   IndexConstant: ValueRef)
902                                   -> ValueRef;
903     pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
904                                   VectorBConstant: ValueRef,
905                                   MaskConstant: ValueRef)
906                                   -> ValueRef;
907     pub fn LLVMConstExtractValue(AggConstant: ValueRef,
908                                  IdxList: *const c_uint,
909                                  NumIdx: c_uint)
910                                  -> ValueRef;
911     pub fn LLVMConstInsertValue(AggConstant: ValueRef,
912                                 ElementValueConstant: ValueRef,
913                                 IdxList: *const c_uint,
914                                 NumIdx: c_uint)
915                                 -> ValueRef;
916     pub fn LLVMConstInlineAsm(Ty: TypeRef,
917                               AsmString: *const c_char,
918                               Constraints: *const c_char,
919                               HasSideEffects: Bool,
920                               IsAlignStack: Bool)
921                               -> ValueRef;
922     pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
923
924
925
926     /* Operations on global variables, functions, and aliases (globals) */
927     pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
928     pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
929     pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
930     pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
931     pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
932     pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
933     pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
934     pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
935     pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
936     pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
937
938
939     /* Operations on global variables */
940     pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
941     pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
942                          -> ValueRef;
943     pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
944                                        Ty: TypeRef,
945                                        Name: *const c_char,
946                                        AddressSpace: c_uint)
947                                        -> ValueRef;
948     pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
949     pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
950     pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
951     pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
952     pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
953     pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
954     pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
955     pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
956     pub fn LLVMSetInitializer(GlobalVar: ValueRef,
957                               ConstantVal: ValueRef);
958     pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
959     pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
960     pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
961     pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
962     pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
963
964     /* Operations on aliases */
965     pub fn LLVMAddAlias(M: ModuleRef,
966                         Ty: TypeRef,
967                         Aliasee: ValueRef,
968                         Name: *const c_char)
969                         -> ValueRef;
970
971     /* Operations on functions */
972     pub fn LLVMAddFunction(M: ModuleRef,
973                            Name: *const c_char,
974                            FunctionTy: TypeRef)
975                            -> ValueRef;
976     pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
977     pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
978     pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
979     pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
980     pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
981     pub fn LLVMDeleteFunction(Fn: ValueRef);
982     pub fn LLVMGetOrInsertFunction(M: ModuleRef,
983                                    Name: *const c_char,
984                                    FunctionTy: TypeRef)
985                                    -> ValueRef;
986     pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
987     pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
988     pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
989     pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
990     pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
991     pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
992     pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
993     pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
994     pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
995                                           Name: *const c_char,
996                                           Value: *const c_char);
997     pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
998     pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
999     pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1000
1001     /* Operations on parameters */
1002     pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1003     pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1004     pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1005     pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1006     pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1007     pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1008     pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1009     pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1010     pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1011     pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1012     pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1013     pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1014
1015     /* Operations on basic blocks */
1016     pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1017     pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1018     pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1019     pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1020     pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1021     pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1022     pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1023     pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1024     pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1025     pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1026     pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1027
1028     pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1029                                          Fn: ValueRef,
1030                                          Name: *const c_char)
1031                                          -> BasicBlockRef;
1032     pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1033                                          BB: BasicBlockRef,
1034                                          Name: *const c_char)
1035                                          -> BasicBlockRef;
1036     pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1037
1038     pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1039                                    MoveAfter: BasicBlockRef);
1040
1041     pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1042                                     MoveBefore: BasicBlockRef);
1043
1044     /* Operations on instructions */
1045     pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1046     pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1047     pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1048     pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1049     pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1050     pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1051
1052     /* Operations on call sites */
1053     pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1054     pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1055     pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1056                                  index: c_uint,
1057                                  IA: c_uint);
1058     pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1059                                     index: c_uint,
1060                                     IA: c_uint);
1061     pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1062                                       index: c_uint,
1063                                       align: c_uint);
1064     pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1065                                     index: c_uint,
1066                                     Val: uint64_t);
1067     pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1068                                               index: c_uint,
1069                                               bytes: uint64_t);
1070
1071     /* Operations on call instructions (only) */
1072     pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1073     pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1074
1075     /* Operations on load/store instructions (only) */
1076     pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1077     pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1078
1079     /* Operations on phi nodes */
1080     pub fn LLVMAddIncoming(PhiNode: ValueRef,
1081                            IncomingValues: *const ValueRef,
1082                            IncomingBlocks: *const BasicBlockRef,
1083                            Count: c_uint);
1084     pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1085     pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1086                                 -> ValueRef;
1087     pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1088                                 -> BasicBlockRef;
1089
1090     /* Instruction builders */
1091     pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1092     pub fn LLVMPositionBuilder(Builder: BuilderRef,
1093                                Block: BasicBlockRef,
1094                                Instr: ValueRef);
1095     pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1096                                      Instr: ValueRef);
1097     pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1098                                     Block: BasicBlockRef);
1099     pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1100     pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1101     pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1102     pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1103                                          Instr: ValueRef,
1104                                          Name: *const c_char);
1105     pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1106
1107     /* Execution engine */
1108     pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1109     pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1110     pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1111     pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1112     pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1113     pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1114                                            -> Bool;
1115
1116     /* Metadata */
1117     pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1118     pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1119     pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1120
1121     /* Terminators */
1122     pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1123     pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1124     pub fn LLVMBuildAggregateRet(B: BuilderRef,
1125                                  RetVals: *const ValueRef,
1126                                  N: c_uint)
1127                                  -> ValueRef;
1128     pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1129     pub fn LLVMBuildCondBr(B: BuilderRef,
1130                            If: ValueRef,
1131                            Then: BasicBlockRef,
1132                            Else: BasicBlockRef)
1133                            -> ValueRef;
1134     pub fn LLVMBuildSwitch(B: BuilderRef,
1135                            V: ValueRef,
1136                            Else: BasicBlockRef,
1137                            NumCases: c_uint)
1138                            -> ValueRef;
1139     pub fn LLVMBuildIndirectBr(B: BuilderRef,
1140                                Addr: ValueRef,
1141                                NumDests: c_uint)
1142                                -> ValueRef;
1143     pub fn LLVMBuildInvoke(B: BuilderRef,
1144                            Fn: ValueRef,
1145                            Args: *const ValueRef,
1146                            NumArgs: c_uint,
1147                            Then: BasicBlockRef,
1148                            Catch: BasicBlockRef,
1149                            Name: *const c_char)
1150                            -> ValueRef;
1151     pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1152                                    Ty: TypeRef,
1153                                    PersFn: ValueRef,
1154                                    NumClauses: c_uint,
1155                                    Name: *const c_char,
1156                                    F: ValueRef)
1157                                    -> ValueRef;
1158     pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1159     pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1160
1161     /* Add a case to the switch instruction */
1162     pub fn LLVMAddCase(Switch: ValueRef,
1163                        OnVal: ValueRef,
1164                        Dest: BasicBlockRef);
1165
1166     /* Add a destination to the indirectbr instruction */
1167     pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1168
1169     /* Add a clause to the landing pad instruction */
1170     pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1171
1172     /* Set the cleanup on a landing pad instruction */
1173     pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1174
1175     /* Arithmetic */
1176     pub fn LLVMBuildAdd(B: BuilderRef,
1177                         LHS: ValueRef,
1178                         RHS: ValueRef,
1179                         Name: *const c_char)
1180                         -> ValueRef;
1181     pub fn LLVMBuildNSWAdd(B: BuilderRef,
1182                            LHS: ValueRef,
1183                            RHS: ValueRef,
1184                            Name: *const c_char)
1185                            -> ValueRef;
1186     pub fn LLVMBuildNUWAdd(B: BuilderRef,
1187                            LHS: ValueRef,
1188                            RHS: ValueRef,
1189                            Name: *const c_char)
1190                            -> ValueRef;
1191     pub fn LLVMBuildFAdd(B: BuilderRef,
1192                          LHS: ValueRef,
1193                          RHS: ValueRef,
1194                          Name: *const c_char)
1195                          -> ValueRef;
1196     pub fn LLVMBuildSub(B: BuilderRef,
1197                         LHS: ValueRef,
1198                         RHS: ValueRef,
1199                         Name: *const c_char)
1200                         -> ValueRef;
1201     pub fn LLVMBuildNSWSub(B: BuilderRef,
1202                            LHS: ValueRef,
1203                            RHS: ValueRef,
1204                            Name: *const c_char)
1205                            -> ValueRef;
1206     pub fn LLVMBuildNUWSub(B: BuilderRef,
1207                            LHS: ValueRef,
1208                            RHS: ValueRef,
1209                            Name: *const c_char)
1210                            -> ValueRef;
1211     pub fn LLVMBuildFSub(B: BuilderRef,
1212                          LHS: ValueRef,
1213                          RHS: ValueRef,
1214                          Name: *const c_char)
1215                          -> ValueRef;
1216     pub fn LLVMBuildMul(B: BuilderRef,
1217                         LHS: ValueRef,
1218                         RHS: ValueRef,
1219                         Name: *const c_char)
1220                         -> ValueRef;
1221     pub fn LLVMBuildNSWMul(B: BuilderRef,
1222                            LHS: ValueRef,
1223                            RHS: ValueRef,
1224                            Name: *const c_char)
1225                            -> ValueRef;
1226     pub fn LLVMBuildNUWMul(B: BuilderRef,
1227                            LHS: ValueRef,
1228                            RHS: ValueRef,
1229                            Name: *const c_char)
1230                            -> ValueRef;
1231     pub fn LLVMBuildFMul(B: BuilderRef,
1232                          LHS: ValueRef,
1233                          RHS: ValueRef,
1234                          Name: *const c_char)
1235                          -> ValueRef;
1236     pub fn LLVMBuildUDiv(B: BuilderRef,
1237                          LHS: ValueRef,
1238                          RHS: ValueRef,
1239                          Name: *const c_char)
1240                          -> ValueRef;
1241     pub fn LLVMBuildSDiv(B: BuilderRef,
1242                          LHS: ValueRef,
1243                          RHS: ValueRef,
1244                          Name: *const c_char)
1245                          -> ValueRef;
1246     pub fn LLVMBuildExactSDiv(B: BuilderRef,
1247                               LHS: ValueRef,
1248                               RHS: ValueRef,
1249                               Name: *const c_char)
1250                               -> ValueRef;
1251     pub fn LLVMBuildFDiv(B: BuilderRef,
1252                          LHS: ValueRef,
1253                          RHS: ValueRef,
1254                          Name: *const c_char)
1255                          -> ValueRef;
1256     pub fn LLVMBuildURem(B: BuilderRef,
1257                          LHS: ValueRef,
1258                          RHS: ValueRef,
1259                          Name: *const c_char)
1260                          -> ValueRef;
1261     pub fn LLVMBuildSRem(B: BuilderRef,
1262                          LHS: ValueRef,
1263                          RHS: ValueRef,
1264                          Name: *const c_char)
1265                          -> ValueRef;
1266     pub fn LLVMBuildFRem(B: BuilderRef,
1267                          LHS: ValueRef,
1268                          RHS: ValueRef,
1269                          Name: *const c_char)
1270                          -> ValueRef;
1271     pub fn LLVMBuildShl(B: BuilderRef,
1272                         LHS: ValueRef,
1273                         RHS: ValueRef,
1274                         Name: *const c_char)
1275                         -> ValueRef;
1276     pub fn LLVMBuildLShr(B: BuilderRef,
1277                          LHS: ValueRef,
1278                          RHS: ValueRef,
1279                          Name: *const c_char)
1280                          -> ValueRef;
1281     pub fn LLVMBuildAShr(B: BuilderRef,
1282                          LHS: ValueRef,
1283                          RHS: ValueRef,
1284                          Name: *const c_char)
1285                          -> ValueRef;
1286     pub fn LLVMBuildAnd(B: BuilderRef,
1287                         LHS: ValueRef,
1288                         RHS: ValueRef,
1289                         Name: *const c_char)
1290                         -> ValueRef;
1291     pub fn LLVMBuildOr(B: BuilderRef,
1292                        LHS: ValueRef,
1293                        RHS: ValueRef,
1294                        Name: *const c_char)
1295                            -> ValueRef;
1296     pub fn LLVMBuildXor(B: BuilderRef,
1297                         LHS: ValueRef,
1298                         RHS: ValueRef,
1299                         Name: *const c_char)
1300                         -> ValueRef;
1301     pub fn LLVMBuildBinOp(B: BuilderRef,
1302                           Op: Opcode,
1303                           LHS: ValueRef,
1304                           RHS: ValueRef,
1305                           Name: *const c_char)
1306                           -> ValueRef;
1307     pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1308                         -> ValueRef;
1309     pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1310                            -> ValueRef;
1311     pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1312                            -> ValueRef;
1313     pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1314                          -> ValueRef;
1315     pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1316                         -> ValueRef;
1317
1318     /* Memory */
1319     pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1320                            -> ValueRef;
1321     pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1322     pub fn LLVMBuildLoad(B: BuilderRef,
1323                          PointerVal: ValueRef,
1324                          Name: *const c_char)
1325                          -> ValueRef;
1326
1327     pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1328                           -> ValueRef;
1329
1330     pub fn LLVMBuildGEP(B: BuilderRef,
1331                         Pointer: ValueRef,
1332                         Indices: *const ValueRef,
1333                         NumIndices: c_uint,
1334                         Name: *const c_char)
1335                         -> ValueRef;
1336     pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1337                                 Pointer: ValueRef,
1338                                 Indices: *const ValueRef,
1339                                 NumIndices: c_uint,
1340                                 Name: *const c_char)
1341                                 -> ValueRef;
1342     pub fn LLVMBuildStructGEP(B: BuilderRef,
1343                               Pointer: ValueRef,
1344                               Idx: c_uint,
1345                               Name: *const c_char)
1346                               -> ValueRef;
1347     pub fn LLVMBuildGlobalString(B: BuilderRef,
1348                                  Str: *const c_char,
1349                                  Name: *const c_char)
1350                                  -> ValueRef;
1351     pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1352                                     Str: *const c_char,
1353                                     Name: *const c_char)
1354                                     -> ValueRef;
1355
1356     /* Casts */
1357     pub fn LLVMBuildTrunc(B: BuilderRef,
1358                           Val: ValueRef,
1359                           DestTy: TypeRef,
1360                           Name: *const c_char)
1361                           -> ValueRef;
1362     pub fn LLVMBuildZExt(B: BuilderRef,
1363                          Val: ValueRef,
1364                          DestTy: TypeRef,
1365                          Name: *const c_char)
1366                          -> ValueRef;
1367     pub fn LLVMBuildSExt(B: BuilderRef,
1368                          Val: ValueRef,
1369                          DestTy: TypeRef,
1370                          Name: *const c_char)
1371                          -> ValueRef;
1372     pub fn LLVMBuildFPToUI(B: BuilderRef,
1373                            Val: ValueRef,
1374                            DestTy: TypeRef,
1375                            Name: *const c_char)
1376                            -> ValueRef;
1377     pub fn LLVMBuildFPToSI(B: BuilderRef,
1378                            Val: ValueRef,
1379                            DestTy: TypeRef,
1380                            Name: *const c_char)
1381                            -> ValueRef;
1382     pub fn LLVMBuildUIToFP(B: BuilderRef,
1383                            Val: ValueRef,
1384                            DestTy: TypeRef,
1385                            Name: *const c_char)
1386                            -> ValueRef;
1387     pub fn LLVMBuildSIToFP(B: BuilderRef,
1388                            Val: ValueRef,
1389                            DestTy: TypeRef,
1390                            Name: *const c_char)
1391                            -> ValueRef;
1392     pub fn LLVMBuildFPTrunc(B: BuilderRef,
1393                             Val: ValueRef,
1394                             DestTy: TypeRef,
1395                             Name: *const c_char)
1396                             -> ValueRef;
1397     pub fn LLVMBuildFPExt(B: BuilderRef,
1398                           Val: ValueRef,
1399                           DestTy: TypeRef,
1400                           Name: *const c_char)
1401                           -> ValueRef;
1402     pub fn LLVMBuildPtrToInt(B: BuilderRef,
1403                              Val: ValueRef,
1404                              DestTy: TypeRef,
1405                              Name: *const c_char)
1406                              -> ValueRef;
1407     pub fn LLVMBuildIntToPtr(B: BuilderRef,
1408                              Val: ValueRef,
1409                              DestTy: TypeRef,
1410                              Name: *const c_char)
1411                              -> ValueRef;
1412     pub fn LLVMBuildBitCast(B: BuilderRef,
1413                             Val: ValueRef,
1414                             DestTy: TypeRef,
1415                             Name: *const c_char)
1416                             -> ValueRef;
1417     pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1418                                   Val: ValueRef,
1419                                   DestTy: TypeRef,
1420                                   Name: *const c_char)
1421                                   -> ValueRef;
1422     pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1423                                   Val: ValueRef,
1424                                   DestTy: TypeRef,
1425                                   Name: *const c_char)
1426                                   -> ValueRef;
1427     pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1428                                    Val: ValueRef,
1429                                    DestTy: TypeRef,
1430                                    Name: *const c_char)
1431                                    -> ValueRef;
1432     pub fn LLVMBuildCast(B: BuilderRef,
1433                          Op: Opcode,
1434                          Val: ValueRef,
1435                          DestTy: TypeRef,
1436                          Name: *const c_char) -> ValueRef;
1437     pub fn LLVMBuildPointerCast(B: BuilderRef,
1438                                 Val: ValueRef,
1439                                 DestTy: TypeRef,
1440                                 Name: *const c_char)
1441                                 -> ValueRef;
1442     pub fn LLVMBuildIntCast(B: BuilderRef,
1443                             Val: ValueRef,
1444                             DestTy: TypeRef,
1445                             Name: *const c_char)
1446                             -> ValueRef;
1447     pub fn LLVMBuildFPCast(B: BuilderRef,
1448                            Val: ValueRef,
1449                            DestTy: TypeRef,
1450                            Name: *const c_char)
1451                            -> ValueRef;
1452
1453     /* Comparisons */
1454     pub fn LLVMBuildICmp(B: BuilderRef,
1455                          Op: c_uint,
1456                          LHS: ValueRef,
1457                          RHS: ValueRef,
1458                          Name: *const c_char)
1459                          -> ValueRef;
1460     pub fn LLVMBuildFCmp(B: BuilderRef,
1461                          Op: c_uint,
1462                          LHS: ValueRef,
1463                          RHS: ValueRef,
1464                          Name: *const c_char)
1465                          -> ValueRef;
1466
1467     /* Miscellaneous instructions */
1468     pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1469                         -> ValueRef;
1470     pub fn LLVMBuildCall(B: BuilderRef,
1471                          Fn: ValueRef,
1472                          Args: *const ValueRef,
1473                          NumArgs: c_uint,
1474                          Name: *const c_char)
1475                          -> ValueRef;
1476     pub fn LLVMBuildSelect(B: BuilderRef,
1477                            If: ValueRef,
1478                            Then: ValueRef,
1479                            Else: ValueRef,
1480                            Name: *const c_char)
1481                            -> ValueRef;
1482     pub fn LLVMBuildVAArg(B: BuilderRef,
1483                           list: ValueRef,
1484                           Ty: TypeRef,
1485                           Name: *const c_char)
1486                           -> ValueRef;
1487     pub fn LLVMBuildExtractElement(B: BuilderRef,
1488                                    VecVal: ValueRef,
1489                                    Index: ValueRef,
1490                                    Name: *const c_char)
1491                                    -> ValueRef;
1492     pub fn LLVMBuildInsertElement(B: BuilderRef,
1493                                   VecVal: ValueRef,
1494                                   EltVal: ValueRef,
1495                                   Index: ValueRef,
1496                                   Name: *const c_char)
1497                                   -> ValueRef;
1498     pub fn LLVMBuildShuffleVector(B: BuilderRef,
1499                                   V1: ValueRef,
1500                                   V2: ValueRef,
1501                                   Mask: ValueRef,
1502                                   Name: *const c_char)
1503                                   -> ValueRef;
1504     pub fn LLVMBuildExtractValue(B: BuilderRef,
1505                                  AggVal: ValueRef,
1506                                  Index: c_uint,
1507                                  Name: *const c_char)
1508                                  -> ValueRef;
1509     pub fn LLVMBuildInsertValue(B: BuilderRef,
1510                                 AggVal: ValueRef,
1511                                 EltVal: ValueRef,
1512                                 Index: c_uint,
1513                                 Name: *const c_char)
1514                                 -> ValueRef;
1515
1516     pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1517                            -> ValueRef;
1518     pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1519                               -> ValueRef;
1520     pub fn LLVMBuildPtrDiff(B: BuilderRef,
1521                             LHS: ValueRef,
1522                             RHS: ValueRef,
1523                             Name: *const c_char)
1524                             -> ValueRef;
1525
1526     /* Atomic Operations */
1527     pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1528                                PointerVal: ValueRef,
1529                                Name: *const c_char,
1530                                Order: AtomicOrdering,
1531                                Alignment: c_uint)
1532                                -> ValueRef;
1533
1534     pub fn LLVMBuildAtomicStore(B: BuilderRef,
1535                                 Val: ValueRef,
1536                                 Ptr: ValueRef,
1537                                 Order: AtomicOrdering,
1538                                 Alignment: c_uint)
1539                                 -> ValueRef;
1540
1541     pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1542                                   LHS: ValueRef,
1543                                   CMP: ValueRef,
1544                                   RHS: ValueRef,
1545                                   Order: AtomicOrdering,
1546                                   FailureOrder: AtomicOrdering)
1547                                   -> ValueRef;
1548     pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1549                               Op: AtomicBinOp,
1550                               LHS: ValueRef,
1551                               RHS: ValueRef,
1552                               Order: AtomicOrdering,
1553                               SingleThreaded: Bool)
1554                               -> ValueRef;
1555
1556     pub fn LLVMBuildAtomicFence(B: BuilderRef,
1557                                 Order: AtomicOrdering,
1558                                 Scope: SynchronizationScope);
1559
1560
1561     /* Selected entries from the downcasts. */
1562     pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1563     pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1564
1565     /// Writes a module to the specified path. Returns 0 on success.
1566     pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1567
1568     /// Creates target data from a target layout string.
1569     pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1570     /// Adds the target data to the given pass manager. The pass manager
1571     /// references the target data only weakly.
1572     pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1573     /// Number of bytes clobbered when doing a Store to *T.
1574     pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1575                                -> c_ulonglong;
1576
1577     /// Number of bytes clobbered when doing a Store to *T.
1578     pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1579                                 -> c_ulonglong;
1580
1581     /// Distance between successive elements in an array of T. Includes ABI padding.
1582     pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1583
1584     /// Returns the preferred alignment of a type.
1585     pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1586                                         -> c_uint;
1587     /// Returns the minimum alignment of a type.
1588     pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1589                                   -> c_uint;
1590
1591     /// Computes the byte offset of the indexed struct element for a
1592     /// target.
1593     pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1594                                StructTy: TypeRef,
1595                                Element: c_uint)
1596                                -> c_ulonglong;
1597
1598     /// Returns the minimum alignment of a type when part of a call frame.
1599     pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1600                                         -> c_uint;
1601
1602     /// Disposes target data.
1603     pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1604
1605     /// Creates a pass manager.
1606     pub fn LLVMCreatePassManager() -> PassManagerRef;
1607
1608     /// Creates a function-by-function pass manager
1609     pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1610                                                   -> PassManagerRef;
1611
1612     /// Disposes a pass manager.
1613     pub fn LLVMDisposePassManager(PM: PassManagerRef);
1614
1615     /// Runs a pass manager on a module.
1616     pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1617
1618     /// Runs the function passes on the provided function.
1619     pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1620                                       -> Bool;
1621
1622     /// Initializes all the function passes scheduled in the manager
1623     pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1624
1625     /// Finalizes all the function passes scheduled in the manager
1626     pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1627
1628     pub fn LLVMInitializePasses();
1629
1630     /// Adds a verification pass.
1631     pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1632
1633     pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1634     pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1635     pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1636     pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1637     pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1638     pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1639     pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1640     pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1641     pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1642     pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1643     pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1644     pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1645     pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1646     pub fn LLVMAddLICMPass(PM: PassManagerRef);
1647     pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1648     pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1649     pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1650     pub fn LLVMAddGVNPass(PM: PassManagerRef);
1651     pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1652     pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1653     pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1654     pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1655     pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1656     pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1657     pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1658     pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1659     pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1660     pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1661     pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1662     pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1663     pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1664     pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1665     pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1666     pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1667     pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1668
1669     pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1670     pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1671     pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1672                                              OptimizationLevel: c_uint);
1673     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1674                                               Value: Bool);
1675     pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1676         PMB: PassManagerBuilderRef,
1677         Value: Bool);
1678     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1679         PMB: PassManagerBuilderRef,
1680         Value: Bool);
1681     pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1682         PMB: PassManagerBuilderRef,
1683         Value: Bool);
1684     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1685         PMB: PassManagerBuilderRef,
1686         threshold: c_uint);
1687     pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1688         PMB: PassManagerBuilderRef,
1689         PM: PassManagerRef);
1690
1691     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1692         PMB: PassManagerBuilderRef,
1693         PM: PassManagerRef);
1694     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1695         PMB: PassManagerBuilderRef,
1696         PM: PassManagerRef,
1697         Internalize: Bool,
1698         RunInliner: Bool);
1699
1700     /// Destroys a memory buffer.
1701     pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1702
1703
1704     /* Stuff that's in rustllvm/ because it's not upstream yet. */
1705
1706     /// Opens an object file.
1707     pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1708     /// Closes an object file.
1709     pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1710
1711     /// Enumerates the sections in an object file.
1712     pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1713     /// Destroys a section iterator.
1714     pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1715     /// Returns true if the section iterator is at the end of the section
1716     /// list:
1717     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1718                                       SI: SectionIteratorRef)
1719                                       -> Bool;
1720     /// Moves the section iterator to point to the next section.
1721     pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1722     /// Returns the current section size.
1723     pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1724     /// Returns the current section contents as a string buffer.
1725     pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1726
1727     /// Reads the given file and returns it as a memory buffer. Use
1728     /// LLVMDisposeMemoryBuffer() to get rid of it.
1729     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1730                                                         -> MemoryBufferRef;
1731     /// Borrows the contents of the memory buffer (doesn't copy it)
1732     pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1733                                                  InputDataLength: size_t,
1734                                                  BufferName: *const c_char,
1735                                                  RequiresNull: Bool)
1736                                                  -> MemoryBufferRef;
1737     pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1738                                                      InputDataLength: size_t,
1739                                                      BufferName: *const c_char)
1740                                                      -> MemoryBufferRef;
1741
1742     pub fn LLVMIsMultithreaded() -> Bool;
1743     pub fn LLVMStartMultithreaded() -> Bool;
1744
1745     /// Returns a string describing the last error caused by an LLVMRust* call.
1746     pub fn LLVMRustGetLastError() -> *const c_char;
1747
1748     /// Print the pass timings since static dtors aren't picking them up.
1749     pub fn LLVMRustPrintPassTimings();
1750
1751     pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1752
1753     pub fn LLVMStructSetBody(StructTy: TypeRef,
1754                              ElementTypes: *const TypeRef,
1755                              ElementCount: c_uint,
1756                              Packed: Bool);
1757
1758     pub fn LLVMConstNamedStruct(S: TypeRef,
1759                                 ConstantVals: *const ValueRef,
1760                                 Count: c_uint)
1761                                 -> ValueRef;
1762
1763     /// Enables LLVM debug output.
1764     pub fn LLVMSetDebug(Enabled: c_int);
1765
1766     /// Prepares inline assembly.
1767     pub fn LLVMInlineAsm(Ty: TypeRef,
1768                          AsmString: *const c_char,
1769                          Constraints: *const c_char,
1770                          SideEffects: Bool,
1771                          AlignStack: Bool,
1772                          Dialect: c_uint)
1773                          -> ValueRef;
1774
1775     pub fn LLVMRustDebugMetadataVersion() -> u32;
1776     pub fn LLVMVersionMajor() -> u32;
1777     pub fn LLVMVersionMinor() -> u32;
1778
1779     pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1780                                  name: *const c_char,
1781                                  value: u32);
1782
1783     pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1784
1785     pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1786
1787     pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1788
1789     pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1790                                           Lang: c_uint,
1791                                           File: *const c_char,
1792                                           Dir: *const c_char,
1793                                           Producer: *const c_char,
1794                                           isOptimized: bool,
1795                                           Flags: *const c_char,
1796                                           RuntimeVer: c_uint,
1797                                           SplitName: *const c_char)
1798                                           -> DIDescriptor;
1799
1800     pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1801                                    Filename: *const c_char,
1802                                    Directory: *const c_char)
1803                                    -> DIFile;
1804
1805     pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1806                                              File: DIFile,
1807                                              ParameterTypes: DIArray)
1808                                              -> DICompositeType;
1809
1810     pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1811                                        Scope: DIDescriptor,
1812                                        Name: *const c_char,
1813                                        LinkageName: *const c_char,
1814                                        File: DIFile,
1815                                        LineNo: c_uint,
1816                                        Ty: DIType,
1817                                        isLocalToUnit: bool,
1818                                        isDefinition: bool,
1819                                        ScopeLine: c_uint,
1820                                        Flags: c_uint,
1821                                        isOptimized: bool,
1822                                        Fn: ValueRef,
1823                                        TParam: DIArray,
1824                                        Decl: DIDescriptor)
1825                                        -> DISubprogram;
1826
1827     pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1828                                         Name: *const c_char,
1829                                         SizeInBits: c_ulonglong,
1830                                         AlignInBits: c_ulonglong,
1831                                         Encoding: c_uint)
1832                                         -> DIBasicType;
1833
1834     pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1835                                           PointeeTy: DIType,
1836                                           SizeInBits: c_ulonglong,
1837                                           AlignInBits: c_ulonglong,
1838                                           Name: *const c_char)
1839                                           -> DIDerivedType;
1840
1841     pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1842                                          Scope: DIDescriptor,
1843                                          Name: *const c_char,
1844                                          File: DIFile,
1845                                          LineNumber: c_uint,
1846                                          SizeInBits: c_ulonglong,
1847                                          AlignInBits: c_ulonglong,
1848                                          Flags: c_uint,
1849                                          DerivedFrom: DIType,
1850                                          Elements: DIArray,
1851                                          RunTimeLang: c_uint,
1852                                          VTableHolder: DIType,
1853                                          UniqueId: *const c_char)
1854                                          -> DICompositeType;
1855
1856     pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1857                                          Scope: DIDescriptor,
1858                                          Name: *const c_char,
1859                                          File: DIFile,
1860                                          LineNo: c_uint,
1861                                          SizeInBits: c_ulonglong,
1862                                          AlignInBits: c_ulonglong,
1863                                          OffsetInBits: c_ulonglong,
1864                                          Flags: c_uint,
1865                                          Ty: DIType)
1866                                          -> DIDerivedType;
1867
1868     pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1869                                            Scope: DIScope,
1870                                            File: DIFile,
1871                                            Line: c_uint,
1872                                            Col: c_uint)
1873                                            -> DILexicalBlock;
1874
1875     pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1876                                              Context: DIScope,
1877                                              Name: *const c_char,
1878                                              LinkageName: *const c_char,
1879                                              File: DIFile,
1880                                              LineNo: c_uint,
1881                                              Ty: DIType,
1882                                              isLocalToUnit: bool,
1883                                              Val: ValueRef,
1884                                              Decl: DIDescriptor)
1885                                              -> DIGlobalVariable;
1886
1887     pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1888                                             Tag: c_uint,
1889                                             Scope: DIDescriptor,
1890                                             Name: *const c_char,
1891                                             File: DIFile,
1892                                             LineNo: c_uint,
1893                                             Ty: DIType,
1894                                             AlwaysPreserve: bool,
1895                                             Flags: c_uint,
1896                                             AddrOps: *const i64,
1897                                             AddrOpsCount: c_uint,
1898                                             ArgNo: c_uint)
1899                                             -> DIVariable;
1900
1901     pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1902                                         Size: c_ulonglong,
1903                                         AlignInBits: c_ulonglong,
1904                                         Ty: DIType,
1905                                         Subscripts: DIArray)
1906                                         -> DIType;
1907
1908     pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1909                                          Size: c_ulonglong,
1910                                          AlignInBits: c_ulonglong,
1911                                          Ty: DIType,
1912                                          Subscripts: DIArray)
1913                                          -> DIType;
1914
1915     pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1916                                             Lo: c_longlong,
1917                                             Count: c_longlong)
1918                                             -> DISubrange;
1919
1920     pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1921                                          Ptr: *const DIDescriptor,
1922                                          Count: c_uint)
1923                                          -> DIArray;
1924
1925     pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1926                                            Val: ValueRef,
1927                                            VarInfo: DIVariable,
1928                                            AddrOps: *const i64,
1929                                            AddrOpsCount: c_uint,
1930                                            DL: ValueRef,
1931                                            InsertAtEnd: BasicBlockRef)
1932                                            -> ValueRef;
1933
1934     pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1935                                             Val: ValueRef,
1936                                             VarInfo: DIVariable,
1937                                             AddrOps: *const i64,
1938                                             AddrOpsCount: c_uint,
1939                                             DL: ValueRef,
1940                                             InsertBefore: ValueRef)
1941                                             -> ValueRef;
1942
1943     pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1944                                          Name: *const c_char,
1945                                          Val: c_ulonglong)
1946                                          -> DIEnumerator;
1947
1948     pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1949                                               Scope: DIScope,
1950                                               Name: *const c_char,
1951                                               File: DIFile,
1952                                               LineNumber: c_uint,
1953                                               SizeInBits: c_ulonglong,
1954                                               AlignInBits: c_ulonglong,
1955                                               Elements: DIArray,
1956                                               ClassType: DIType)
1957                                               -> DIType;
1958
1959     pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1960                                         Scope: DIScope,
1961                                         Name: *const c_char,
1962                                         File: DIFile,
1963                                         LineNumber: c_uint,
1964                                         SizeInBits: c_ulonglong,
1965                                         AlignInBits: c_ulonglong,
1966                                         Flags: c_uint,
1967                                         Elements: DIArray,
1968                                         RunTimeLang: c_uint,
1969                                         UniqueId: *const c_char)
1970                                         -> DIType;
1971
1972     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1973
1974     pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1975                                                     Scope: DIScope,
1976                                                     Name: *const c_char,
1977                                                     Ty: DIType,
1978                                                     File: DIFile,
1979                                                     LineNo: c_uint,
1980                                                     ColumnNo: c_uint)
1981                                                     -> DITemplateTypeParameter;
1982
1983     pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1984
1985     pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1986
1987     pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1988                                         Scope: DIScope,
1989                                         Name: *const c_char,
1990                                         File: DIFile,
1991                                         LineNo: c_uint)
1992                                         -> DINameSpace;
1993
1994     pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1995                                             Line: c_uint,
1996                                             Column: c_uint,
1997                                             Scope: DIScope,
1998                                             InlinedAt: MetadataRef)
1999                                             -> ValueRef;
2000
2001     pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2002                                            CompositeType: DIType,
2003                                            TypeArray: DIArray);
2004     pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2005     pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2006
2007     pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2008
2009     pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2010     pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2011
2012     pub fn LLVMInitializeX86TargetInfo();
2013     pub fn LLVMInitializeX86Target();
2014     pub fn LLVMInitializeX86TargetMC();
2015     pub fn LLVMInitializeX86AsmPrinter();
2016     pub fn LLVMInitializeX86AsmParser();
2017     pub fn LLVMInitializeARMTargetInfo();
2018     pub fn LLVMInitializeARMTarget();
2019     pub fn LLVMInitializeARMTargetMC();
2020     pub fn LLVMInitializeARMAsmPrinter();
2021     pub fn LLVMInitializeARMAsmParser();
2022     pub fn LLVMInitializeAArch64TargetInfo();
2023     pub fn LLVMInitializeAArch64Target();
2024     pub fn LLVMInitializeAArch64TargetMC();
2025     pub fn LLVMInitializeAArch64AsmPrinter();
2026     pub fn LLVMInitializeAArch64AsmParser();
2027     pub fn LLVMInitializeMipsTargetInfo();
2028     pub fn LLVMInitializeMipsTarget();
2029     pub fn LLVMInitializeMipsTargetMC();
2030     pub fn LLVMInitializeMipsAsmPrinter();
2031     pub fn LLVMInitializeMipsAsmParser();
2032     pub fn LLVMInitializePowerPCTargetInfo();
2033     pub fn LLVMInitializePowerPCTarget();
2034     pub fn LLVMInitializePowerPCTargetMC();
2035     pub fn LLVMInitializePowerPCAsmPrinter();
2036     pub fn LLVMInitializePowerPCAsmParser();
2037
2038     pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2039     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2040                                        CPU: *const c_char,
2041                                        Features: *const c_char,
2042                                        Model: CodeGenModel,
2043                                        Reloc: RelocMode,
2044                                        Level: CodeGenOptLevel,
2045                                        EnableSegstk: bool,
2046                                        UseSoftFP: bool,
2047                                        PositionIndependentExecutable: bool,
2048                                        FunctionSections: bool,
2049                                        DataSections: bool) -> TargetMachineRef;
2050     pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2051     pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2052                                      PM: PassManagerRef,
2053                                      M: ModuleRef);
2054     pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2055                                          M: ModuleRef,
2056                                          DisableSimplifyLibCalls: bool);
2057     pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2058                                                OptLevel: CodeGenOptLevel,
2059                                                MergeFunctions: bool,
2060                                                SLPVectorize: bool,
2061                                                LoopVectorize: bool);
2062     pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2063                                   DisableSimplifyLibCalls: bool);
2064     pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2065     pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2066                                    PM: PassManagerRef,
2067                                    M: ModuleRef,
2068                                    Output: *const c_char,
2069                                    FileType: FileType) -> bool;
2070     pub fn LLVMRustPrintModule(PM: PassManagerRef,
2071                                M: ModuleRef,
2072                                Output: *const c_char);
2073     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2074     pub fn LLVMRustPrintPasses();
2075     pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2076     pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2077                                        AddLifetimes: bool);
2078     pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2079                                          bc: *const c_char,
2080                                          len: size_t) -> bool;
2081     pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2082                                       syms: *const *const c_char,
2083                                       len: size_t);
2084     pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2085
2086     pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2087     pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2088     pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2089     pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2090                                     size: *mut size_t) -> *const c_char;
2091     pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2092                                     size: *mut size_t) -> *const c_char;
2093     pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2094     pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2095     pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2096
2097     pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2098                                       C: DLLStorageClassTypes);
2099
2100     pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2101                                   data: *mut *const c_char) -> c_int;
2102
2103     pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2104
2105     pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2106                                            Handler: DiagnosticHandler,
2107                                            DiagnosticContext: *mut c_void);
2108
2109     pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2110                                             pass_name_out: *mut *const c_char,
2111                                             function_out: *mut ValueRef,
2112                                             debugloc_out: *mut DebugLocRef,
2113                                             message_out: *mut TwineRef);
2114     pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2115                                             cookie_out: *mut c_uint,
2116                                             message_out: *mut TwineRef,
2117                                             instruction_out: *mut ValueRef);
2118
2119     pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2120     pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2121     pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2122
2123     pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2124
2125     pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2126                                              H: InlineAsmDiagHandler,
2127                                              CX: *mut c_void);
2128
2129     pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2130
2131     pub fn LLVMRustWriteArchive(Dst: *const c_char,
2132                                 NumMembers: size_t,
2133                                 Members: *const RustArchiveMemberRef,
2134                                 WriteSymbtab: bool,
2135                                 Kind: ArchiveKind) -> c_int;
2136     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2137                                     Name: *const c_char,
2138                                     Child: ArchiveChildRef) -> RustArchiveMemberRef;
2139     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2140
2141     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2142                                                   TM: TargetMachineRef);
2143     pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2144 }
2145
2146 // LLVM requires symbols from this library, but apparently they're not printed
2147 // during llvm-config?
2148 #[cfg(windows)]
2149 #[link(name = "ole32")]
2150 extern {}
2151
2152 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2153     unsafe {
2154         LLVMSetInstructionCallConv(instr, cc as c_uint);
2155     }
2156 }
2157 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2158     unsafe {
2159         LLVMSetFunctionCallConv(fn_, cc as c_uint);
2160     }
2161 }
2162 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2163     unsafe {
2164         LLVMSetLinkage(global, link as c_uint);
2165     }
2166 }
2167
2168 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2169     unsafe {
2170         LLVMRustSetDLLStorageClass(global, class);
2171     }
2172 }
2173
2174 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2175     unsafe {
2176         LLVMSetUnnamedAddr(global, unnamed as Bool);
2177     }
2178 }
2179
2180 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2181     unsafe {
2182         LLVMSetThreadLocal(global, is_thread_local as Bool);
2183     }
2184 }
2185
2186 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2187     unsafe {
2188         LLVMConstICmp(pred as c_ushort, v1, v2)
2189     }
2190 }
2191 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2192     unsafe {
2193         LLVMConstFCmp(pred as c_ushort, v1, v2)
2194     }
2195 }
2196
2197 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2198     unsafe {
2199         LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2200                                  attr.bits() as uint64_t)
2201     }
2202 }
2203
2204 /* Memory-managed interface to target data. */
2205
2206 pub struct TargetData {
2207     pub lltd: TargetDataRef
2208 }
2209
2210 impl Drop for TargetData {
2211     fn drop(&mut self) {
2212         unsafe {
2213             LLVMDisposeTargetData(self.lltd);
2214         }
2215     }
2216 }
2217
2218 pub fn mk_target_data(string_rep: &str) -> TargetData {
2219     let string_rep = CString::new(string_rep).unwrap();
2220     TargetData {
2221         lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2222     }
2223 }
2224
2225 /* Memory-managed interface to object files. */
2226
2227 pub struct ObjectFile {
2228     pub llof: ObjectFileRef,
2229 }
2230
2231 impl ObjectFile {
2232     // This will take ownership of llmb
2233     pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2234         unsafe {
2235             let llof = LLVMCreateObjectFile(llmb);
2236             if llof as isize == 0 {
2237                 // LLVMCreateObjectFile took ownership of llmb
2238                 return None
2239             }
2240
2241             Some(ObjectFile {
2242                 llof: llof,
2243             })
2244         }
2245     }
2246 }
2247
2248 impl Drop for ObjectFile {
2249     fn drop(&mut self) {
2250         unsafe {
2251             LLVMDisposeObjectFile(self.llof);
2252         }
2253     }
2254 }
2255
2256 /* Memory-managed interface to section iterators. */
2257
2258 pub struct SectionIter {
2259     pub llsi: SectionIteratorRef
2260 }
2261
2262 impl Drop for SectionIter {
2263     fn drop(&mut self) {
2264         unsafe {
2265             LLVMDisposeSectionIterator(self.llsi);
2266         }
2267     }
2268 }
2269
2270 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2271     unsafe {
2272         SectionIter {
2273             llsi: LLVMGetSections(llof)
2274         }
2275     }
2276 }
2277
2278 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2279 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2280     unsafe {
2281         assert!(index < LLVMCountParams(llfn));
2282         LLVMGetParam(llfn, index)
2283     }
2284 }
2285
2286 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2287     unsafe {
2288         let num_params = LLVMCountParams(llfn);
2289         let mut params = Vec::with_capacity(num_params as usize);
2290         for idx in 0..num_params {
2291             params.push(LLVMGetParam(llfn, idx));
2292         }
2293
2294         params
2295     }
2296 }
2297
2298 #[allow(missing_copy_implementations)]
2299 pub enum RustString_opaque {}
2300 pub type RustStringRef = *mut RustString_opaque;
2301 type RustStringRepr = *mut RefCell<Vec<u8>>;
2302
2303 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2304 #[no_mangle]
2305 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2306                                                      ptr: *const c_char,
2307                                                      size: size_t) {
2308     let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2309
2310     let sr: RustStringRepr = mem::transmute(sr);
2311     (*sr).borrow_mut().push_all(slice);
2312 }
2313
2314 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2315     let mut buf = RefCell::new(Vec::new());
2316     f(&mut buf as RustStringRepr as RustStringRef);
2317     String::from_utf8(buf.into_inner()).ok()
2318 }
2319
2320 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2321     build_string(|s| LLVMWriteTwineToString(tr, s))
2322         .expect("got a non-UTF8 Twine from LLVM")
2323 }
2324
2325 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2326     build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2327         .expect("got a non-UTF8 DebugLoc from LLVM")
2328 }
2329
2330 // The module containing the native LLVM dependencies, generated by the build system
2331 // Note that this must come after the rustllvm extern declaration so that
2332 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2333 // Works to the above fix for #15460 to ensure LLVM dependencies that
2334 // are only used by rustllvm don't get stripped by the linker.
2335 mod llvmdeps {
2336     include! { env!("CFG_LLVM_LINKAGE_FILE") }
2337 }