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