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