]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/lib.rs
Rollup merge of #31186 - gchp:contributing, 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;
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
548 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
549 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
550
551 pub mod debuginfo {
552     pub use self::DIDescriptorFlags::*;
553     use super::{MetadataRef};
554
555     #[allow(missing_copy_implementations)]
556     pub enum DIBuilder_opaque {}
557     pub type DIBuilderRef = *mut DIBuilder_opaque;
558
559     pub type DIDescriptor = MetadataRef;
560     pub type DIScope = DIDescriptor;
561     pub type DILocation = DIDescriptor;
562     pub type DIFile = DIScope;
563     pub type DILexicalBlock = DIScope;
564     pub type DISubprogram = DIScope;
565     pub type DINameSpace = DIScope;
566     pub type DIType = DIDescriptor;
567     pub type DIBasicType = DIType;
568     pub type DIDerivedType = DIType;
569     pub type DICompositeType = DIDerivedType;
570     pub type DIVariable = DIDescriptor;
571     pub type DIGlobalVariable = DIDescriptor;
572     pub type DIArray = DIDescriptor;
573     pub type DISubrange = DIDescriptor;
574     pub type DIEnumerator = DIDescriptor;
575     pub type DITemplateTypeParameter = DIDescriptor;
576
577     #[derive(Copy, Clone)]
578     pub enum DIDescriptorFlags {
579       FlagPrivate            = 1 << 0,
580       FlagProtected          = 1 << 1,
581       FlagFwdDecl            = 1 << 2,
582       FlagAppleBlock         = 1 << 3,
583       FlagBlockByrefStruct   = 1 << 4,
584       FlagVirtual            = 1 << 5,
585       FlagArtificial         = 1 << 6,
586       FlagExplicit           = 1 << 7,
587       FlagPrototyped         = 1 << 8,
588       FlagObjcClassComplete  = 1 << 9,
589       FlagObjectPointer      = 1 << 10,
590       FlagVector             = 1 << 11,
591       FlagStaticMember       = 1 << 12,
592       FlagIndirectVariable   = 1 << 13,
593       FlagLValueReference    = 1 << 14,
594       FlagRValueReference    = 1 << 15
595     }
596 }
597
598
599 // Link to our native llvm bindings (things that we need to use the C++ api
600 // for) and because llvm is written in C++ we need to link against libstdc++
601 //
602 // You'll probably notice that there is an omission of all LLVM libraries
603 // from this location. This is because the set of LLVM libraries that we
604 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
605 // figure out the exact set of libraries. To do this, the build system
606 // generates an llvmdeps.rs file next to this one which will be
607 // automatically updated whenever LLVM is updated to include an up-to-date
608 // set of the libraries we need to link to LLVM for.
609 #[link(name = "rustllvm", kind = "static")]
610 #[linked_from = "rustllvm"] // not quite true but good enough
611 extern {
612     /* Create and destroy contexts. */
613     pub fn LLVMContextCreate() -> ContextRef;
614     pub fn LLVMContextDispose(C: ContextRef);
615     pub fn LLVMGetMDKindIDInContext(C: ContextRef,
616                                     Name: *const c_char,
617                                     SLen: c_uint)
618                                     -> c_uint;
619
620     /* Create and destroy modules. */
621     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
622                                              C: ContextRef)
623                                              -> ModuleRef;
624     pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
625     pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
626     pub fn LLVMDisposeModule(M: ModuleRef);
627
628     /// Data layout. See Module::getDataLayout.
629     pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
630     pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
631
632     /// Target triple. See Module::getTargetTriple.
633     pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
634     pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
635
636     /// See Module::dump.
637     pub fn LLVMDumpModule(M: ModuleRef);
638
639     /// See Module::setModuleInlineAsm.
640     pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
641
642     /// See llvm::LLVMTypeKind::getTypeID.
643     pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
644
645     /// See llvm::LLVMType::getContext.
646     pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
647
648     /* Operations on integer types */
649     pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
650     pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
651     pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
652     pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
653     pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
654     pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
655                                 -> TypeRef;
656
657     pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
658
659     /* Operations on real types */
660     pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
661     pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
662     pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
663     pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
664     pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
665
666     /* Operations on function types */
667     pub fn LLVMFunctionType(ReturnType: TypeRef,
668                             ParamTypes: *const TypeRef,
669                             ParamCount: c_uint,
670                             IsVarArg: Bool)
671                             -> TypeRef;
672     pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
673     pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
674     pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
675     pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
676
677     /* Operations on struct types */
678     pub fn LLVMStructTypeInContext(C: ContextRef,
679                                    ElementTypes: *const TypeRef,
680                                    ElementCount: c_uint,
681                                    Packed: Bool)
682                                    -> TypeRef;
683     pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
684     pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
685                                      Dest: *mut TypeRef);
686     pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
687
688     /* Operations on array, pointer, and vector types (sequence types) */
689     pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
690     pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
691                            -> TypeRef;
692     pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
693                           -> TypeRef;
694
695     pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
696     pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
697     pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
698     pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
699                                   -> *const c_void;
700     pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
701
702     /* Operations on other types */
703     pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
704     pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
705     pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
706
707     /* Operations on all values */
708     pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
709     pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
710     pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
711     pub fn LLVMDumpValue(Val: ValueRef);
712     pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
713     pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
714     pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
715     pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
716
717     /* Operations on Uses */
718     pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
719     pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
720     pub fn LLVMGetUser(U: UseRef) -> ValueRef;
721     pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
722
723     /* Operations on Users */
724     pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
725     pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
726     pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
727
728     /* Operations on constants of any type */
729     pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
730     /* all zeroes */
731     pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
732     pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
733                          -> ValueRef;
734     pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
735                          -> ValueRef;
736     /* only for isize/vector */
737     pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
738     pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
739     pub fn LLVMIsNull(Val: ValueRef) -> Bool;
740     pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
741     pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
742
743     /* Operations on metadata */
744     pub fn LLVMMDStringInContext(C: ContextRef,
745                                  Str: *const c_char,
746                                  SLen: c_uint)
747                                  -> ValueRef;
748     pub fn LLVMMDNodeInContext(C: ContextRef,
749                                Vals: *const ValueRef,
750                                Count: c_uint)
751                                -> ValueRef;
752     pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
753                                        Str: *const c_char,
754                                        Val: ValueRef);
755
756     /* Operations on scalar constants */
757     pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
758                         -> ValueRef;
759     pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
760                                 -> ValueRef;
761     pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
762                                        Text: *const c_char,
763                                        SLen: c_uint,
764                                        Radix: u8)
765                                        -> ValueRef;
766     pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
767     pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
768                                  -> ValueRef;
769     pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
770                                         Text: *const c_char,
771                                         SLen: c_uint)
772                                         -> ValueRef;
773     pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
774     pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
775
776
777     /* Operations on composite constants */
778     pub fn LLVMConstStringInContext(C: ContextRef,
779                                     Str: *const c_char,
780                                     Length: c_uint,
781                                     DontNullTerminate: Bool)
782                                     -> ValueRef;
783     pub fn LLVMConstStructInContext(C: ContextRef,
784                                     ConstantVals: *const ValueRef,
785                                     Count: c_uint,
786                                     Packed: Bool)
787                                     -> ValueRef;
788
789     pub fn LLVMConstArray(ElementTy: TypeRef,
790                           ConstantVals: *const ValueRef,
791                           Length: c_uint)
792                           -> ValueRef;
793     pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
794                            -> ValueRef;
795
796     /* Constant expressions */
797     pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
798     pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
799     pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
800     pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
801     pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
802     pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
803     pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
804     pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
805                         -> ValueRef;
806     pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
807                            -> ValueRef;
808     pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
809                            -> ValueRef;
810     pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
811                          -> ValueRef;
812     pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
813                         -> ValueRef;
814     pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
815                            -> ValueRef;
816     pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
817                            -> ValueRef;
818     pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
819                          -> ValueRef;
820     pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
821                         -> ValueRef;
822     pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
823                            -> ValueRef;
824     pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
825                            -> ValueRef;
826     pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
827                          -> ValueRef;
828     pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
829                          -> ValueRef;
830     pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
831                          -> ValueRef;
832     pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
833                               RHSConstant: ValueRef)
834                               -> ValueRef;
835     pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
836                          -> ValueRef;
837     pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
838                          -> ValueRef;
839     pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
840                          -> ValueRef;
841     pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
842                          -> ValueRef;
843     pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
844                         -> ValueRef;
845     pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
846                        -> ValueRef;
847     pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
848                         -> ValueRef;
849     pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
850                         -> ValueRef;
851     pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
852                          -> ValueRef;
853     pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
854                          -> ValueRef;
855     pub fn LLVMConstGEP(ConstantVal: ValueRef,
856                         ConstantIndices: *const ValueRef,
857                         NumIndices: c_uint)
858                         -> ValueRef;
859     pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
860                                 ConstantIndices: *const ValueRef,
861                                 NumIndices: c_uint)
862                                 -> ValueRef;
863     pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
864                           -> ValueRef;
865     pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
866                          -> ValueRef;
867     pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
868                          -> ValueRef;
869     pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
870                             -> ValueRef;
871     pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
872                           -> ValueRef;
873     pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
874                            -> ValueRef;
875     pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
876                            -> ValueRef;
877     pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
878                            -> ValueRef;
879     pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
880                            -> ValueRef;
881     pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
882                              -> ValueRef;
883     pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
884                              -> ValueRef;
885     pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
886                             -> ValueRef;
887     pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
888                                   -> ValueRef;
889     pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
890                                   -> ValueRef;
891     pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
892                                    -> ValueRef;
893     pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
894                                 -> ValueRef;
895     pub fn LLVMConstIntCast(ConstantVal: ValueRef,
896                             ToType: TypeRef,
897                             isSigned: Bool)
898                             -> ValueRef;
899     pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
900                            -> ValueRef;
901     pub fn LLVMConstSelect(ConstantCondition: ValueRef,
902                            ConstantIfTrue: ValueRef,
903                            ConstantIfFalse: ValueRef)
904                            -> ValueRef;
905     pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
906                                    IndexConstant: ValueRef)
907                                    -> ValueRef;
908     pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
909                                   ElementValueConstant: ValueRef,
910                                   IndexConstant: ValueRef)
911                                   -> ValueRef;
912     pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
913                                   VectorBConstant: ValueRef,
914                                   MaskConstant: ValueRef)
915                                   -> ValueRef;
916     pub fn LLVMConstExtractValue(AggConstant: ValueRef,
917                                  IdxList: *const c_uint,
918                                  NumIdx: c_uint)
919                                  -> ValueRef;
920     pub fn LLVMConstInsertValue(AggConstant: ValueRef,
921                                 ElementValueConstant: ValueRef,
922                                 IdxList: *const c_uint,
923                                 NumIdx: c_uint)
924                                 -> ValueRef;
925     pub fn LLVMConstInlineAsm(Ty: TypeRef,
926                               AsmString: *const c_char,
927                               Constraints: *const c_char,
928                               HasSideEffects: Bool,
929                               IsAlignStack: Bool)
930                               -> ValueRef;
931     pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
932
933
934
935     /* Operations on global variables, functions, and aliases (globals) */
936     pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
937     pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
938     pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
939     pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
940     pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
941     pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
942     pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
943     pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
944     pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
945     pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
946
947
948     /* Operations on global variables */
949     pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
950     pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
951                          -> ValueRef;
952     pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
953                                        Ty: TypeRef,
954                                        Name: *const c_char,
955                                        AddressSpace: c_uint)
956                                        -> ValueRef;
957     pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
958     pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
959     pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
960     pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
961     pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
962     pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
963     pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
964     pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
965     pub fn LLVMSetInitializer(GlobalVar: ValueRef,
966                               ConstantVal: ValueRef);
967     pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
968     pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
969     pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
970     pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
971     pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
972
973     /* Operations on aliases */
974     pub fn LLVMAddAlias(M: ModuleRef,
975                         Ty: TypeRef,
976                         Aliasee: ValueRef,
977                         Name: *const c_char)
978                         -> ValueRef;
979
980     /* Operations on functions */
981     pub fn LLVMAddFunction(M: ModuleRef,
982                            Name: *const c_char,
983                            FunctionTy: TypeRef)
984                            -> ValueRef;
985     pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
986     pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
987     pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
988     pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
989     pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
990     pub fn LLVMDeleteFunction(Fn: ValueRef);
991     pub fn LLVMGetOrInsertFunction(M: ModuleRef,
992                                    Name: *const c_char,
993                                    FunctionTy: TypeRef)
994                                    -> ValueRef;
995     pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
996     pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
997     pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
998     pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
999     pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
1000     pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1001     pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
1002     pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1003     pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
1004                                           Name: *const c_char,
1005                                           Value: *const c_char);
1006     pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1007     pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
1008     pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1009
1010     /* Operations on parameters */
1011     pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1012     pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1013     pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1014     pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1015     pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1016     pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1017     pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1018     pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1019     pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1020     pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1021     pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1022     pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1023
1024     /* Operations on basic blocks */
1025     pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1026     pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1027     pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1028     pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1029     pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1030     pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1031     pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1032     pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1033     pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1034     pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1035     pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1036
1037     pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1038                                          Fn: ValueRef,
1039                                          Name: *const c_char)
1040                                          -> BasicBlockRef;
1041     pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1042                                          BB: BasicBlockRef,
1043                                          Name: *const c_char)
1044                                          -> BasicBlockRef;
1045     pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1046
1047     pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1048                                    MoveAfter: BasicBlockRef);
1049
1050     pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1051                                     MoveBefore: BasicBlockRef);
1052
1053     /* Operations on instructions */
1054     pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1055     pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1056     pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1057     pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1058     pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1059     pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1060
1061     /* Operations on call sites */
1062     pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1063     pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1064     pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1065                                  index: c_uint,
1066                                  IA: c_uint);
1067     pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1068                                     index: c_uint,
1069                                     IA: c_uint);
1070     pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1071                                       index: c_uint,
1072                                       align: c_uint);
1073     pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1074                                     index: c_uint,
1075                                     Val: uint64_t);
1076     pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1077                                               index: c_uint,
1078                                               bytes: uint64_t);
1079
1080     /* Operations on call instructions (only) */
1081     pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1082     pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1083
1084     /* Operations on load/store instructions (only) */
1085     pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1086     pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1087
1088     /* Operations on phi nodes */
1089     pub fn LLVMAddIncoming(PhiNode: ValueRef,
1090                            IncomingValues: *const ValueRef,
1091                            IncomingBlocks: *const BasicBlockRef,
1092                            Count: c_uint);
1093     pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1094     pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1095                                 -> ValueRef;
1096     pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1097                                 -> BasicBlockRef;
1098
1099     /* Instruction builders */
1100     pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1101     pub fn LLVMPositionBuilder(Builder: BuilderRef,
1102                                Block: BasicBlockRef,
1103                                Instr: ValueRef);
1104     pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1105                                      Instr: ValueRef);
1106     pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1107                                     Block: BasicBlockRef);
1108     pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1109     pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1110     pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1111     pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1112                                          Instr: ValueRef,
1113                                          Name: *const c_char);
1114     pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1115
1116     /* Execution engine */
1117     pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1118     pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1119     pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1120     pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1121     pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1122     pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1123                                            -> Bool;
1124
1125     /* Metadata */
1126     pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1127     pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1128     pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1129
1130     /* Terminators */
1131     pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1132     pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1133     pub fn LLVMBuildAggregateRet(B: BuilderRef,
1134                                  RetVals: *const ValueRef,
1135                                  N: c_uint)
1136                                  -> ValueRef;
1137     pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1138     pub fn LLVMBuildCondBr(B: BuilderRef,
1139                            If: ValueRef,
1140                            Then: BasicBlockRef,
1141                            Else: BasicBlockRef)
1142                            -> ValueRef;
1143     pub fn LLVMBuildSwitch(B: BuilderRef,
1144                            V: ValueRef,
1145                            Else: BasicBlockRef,
1146                            NumCases: c_uint)
1147                            -> ValueRef;
1148     pub fn LLVMBuildIndirectBr(B: BuilderRef,
1149                                Addr: ValueRef,
1150                                NumDests: c_uint)
1151                                -> ValueRef;
1152     pub fn LLVMBuildInvoke(B: BuilderRef,
1153                            Fn: ValueRef,
1154                            Args: *const ValueRef,
1155                            NumArgs: c_uint,
1156                            Then: BasicBlockRef,
1157                            Catch: BasicBlockRef,
1158                            Name: *const c_char)
1159                            -> ValueRef;
1160     pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1161                                    Ty: TypeRef,
1162                                    PersFn: ValueRef,
1163                                    NumClauses: c_uint,
1164                                    Name: *const c_char,
1165                                    F: ValueRef)
1166                                    -> ValueRef;
1167     pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1168     pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1169
1170     /* Add a case to the switch instruction */
1171     pub fn LLVMAddCase(Switch: ValueRef,
1172                        OnVal: ValueRef,
1173                        Dest: BasicBlockRef);
1174
1175     /* Add a destination to the indirectbr instruction */
1176     pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1177
1178     /* Add a clause to the landing pad instruction */
1179     pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1180
1181     /* Set the cleanup on a landing pad instruction */
1182     pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1183
1184     /* Arithmetic */
1185     pub fn LLVMBuildAdd(B: BuilderRef,
1186                         LHS: ValueRef,
1187                         RHS: ValueRef,
1188                         Name: *const c_char)
1189                         -> ValueRef;
1190     pub fn LLVMBuildNSWAdd(B: BuilderRef,
1191                            LHS: ValueRef,
1192                            RHS: ValueRef,
1193                            Name: *const c_char)
1194                            -> ValueRef;
1195     pub fn LLVMBuildNUWAdd(B: BuilderRef,
1196                            LHS: ValueRef,
1197                            RHS: ValueRef,
1198                            Name: *const c_char)
1199                            -> ValueRef;
1200     pub fn LLVMBuildFAdd(B: BuilderRef,
1201                          LHS: ValueRef,
1202                          RHS: ValueRef,
1203                          Name: *const c_char)
1204                          -> ValueRef;
1205     pub fn LLVMBuildSub(B: BuilderRef,
1206                         LHS: ValueRef,
1207                         RHS: ValueRef,
1208                         Name: *const c_char)
1209                         -> ValueRef;
1210     pub fn LLVMBuildNSWSub(B: BuilderRef,
1211                            LHS: ValueRef,
1212                            RHS: ValueRef,
1213                            Name: *const c_char)
1214                            -> ValueRef;
1215     pub fn LLVMBuildNUWSub(B: BuilderRef,
1216                            LHS: ValueRef,
1217                            RHS: ValueRef,
1218                            Name: *const c_char)
1219                            -> ValueRef;
1220     pub fn LLVMBuildFSub(B: BuilderRef,
1221                          LHS: ValueRef,
1222                          RHS: ValueRef,
1223                          Name: *const c_char)
1224                          -> ValueRef;
1225     pub fn LLVMBuildMul(B: BuilderRef,
1226                         LHS: ValueRef,
1227                         RHS: ValueRef,
1228                         Name: *const c_char)
1229                         -> ValueRef;
1230     pub fn LLVMBuildNSWMul(B: BuilderRef,
1231                            LHS: ValueRef,
1232                            RHS: ValueRef,
1233                            Name: *const c_char)
1234                            -> ValueRef;
1235     pub fn LLVMBuildNUWMul(B: BuilderRef,
1236                            LHS: ValueRef,
1237                            RHS: ValueRef,
1238                            Name: *const c_char)
1239                            -> ValueRef;
1240     pub fn LLVMBuildFMul(B: BuilderRef,
1241                          LHS: ValueRef,
1242                          RHS: ValueRef,
1243                          Name: *const c_char)
1244                          -> ValueRef;
1245     pub fn LLVMBuildUDiv(B: BuilderRef,
1246                          LHS: ValueRef,
1247                          RHS: ValueRef,
1248                          Name: *const c_char)
1249                          -> ValueRef;
1250     pub fn LLVMBuildSDiv(B: BuilderRef,
1251                          LHS: ValueRef,
1252                          RHS: ValueRef,
1253                          Name: *const c_char)
1254                          -> ValueRef;
1255     pub fn LLVMBuildExactSDiv(B: BuilderRef,
1256                               LHS: ValueRef,
1257                               RHS: ValueRef,
1258                               Name: *const c_char)
1259                               -> ValueRef;
1260     pub fn LLVMBuildFDiv(B: BuilderRef,
1261                          LHS: ValueRef,
1262                          RHS: ValueRef,
1263                          Name: *const c_char)
1264                          -> ValueRef;
1265     pub fn LLVMBuildURem(B: BuilderRef,
1266                          LHS: ValueRef,
1267                          RHS: ValueRef,
1268                          Name: *const c_char)
1269                          -> ValueRef;
1270     pub fn LLVMBuildSRem(B: BuilderRef,
1271                          LHS: ValueRef,
1272                          RHS: ValueRef,
1273                          Name: *const c_char)
1274                          -> ValueRef;
1275     pub fn LLVMBuildFRem(B: BuilderRef,
1276                          LHS: ValueRef,
1277                          RHS: ValueRef,
1278                          Name: *const c_char)
1279                          -> ValueRef;
1280     pub fn LLVMBuildShl(B: BuilderRef,
1281                         LHS: ValueRef,
1282                         RHS: ValueRef,
1283                         Name: *const c_char)
1284                         -> ValueRef;
1285     pub fn LLVMBuildLShr(B: BuilderRef,
1286                          LHS: ValueRef,
1287                          RHS: ValueRef,
1288                          Name: *const c_char)
1289                          -> ValueRef;
1290     pub fn LLVMBuildAShr(B: BuilderRef,
1291                          LHS: ValueRef,
1292                          RHS: ValueRef,
1293                          Name: *const c_char)
1294                          -> ValueRef;
1295     pub fn LLVMBuildAnd(B: BuilderRef,
1296                         LHS: ValueRef,
1297                         RHS: ValueRef,
1298                         Name: *const c_char)
1299                         -> ValueRef;
1300     pub fn LLVMBuildOr(B: BuilderRef,
1301                        LHS: ValueRef,
1302                        RHS: ValueRef,
1303                        Name: *const c_char)
1304                            -> ValueRef;
1305     pub fn LLVMBuildXor(B: BuilderRef,
1306                         LHS: ValueRef,
1307                         RHS: ValueRef,
1308                         Name: *const c_char)
1309                         -> ValueRef;
1310     pub fn LLVMBuildBinOp(B: BuilderRef,
1311                           Op: Opcode,
1312                           LHS: ValueRef,
1313                           RHS: ValueRef,
1314                           Name: *const c_char)
1315                           -> ValueRef;
1316     pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1317                         -> ValueRef;
1318     pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1319                            -> ValueRef;
1320     pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1321                            -> ValueRef;
1322     pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1323                          -> ValueRef;
1324     pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1325                         -> ValueRef;
1326
1327     /* Memory */
1328     pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1329                            -> ValueRef;
1330     pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1331     pub fn LLVMBuildLoad(B: BuilderRef,
1332                          PointerVal: ValueRef,
1333                          Name: *const c_char)
1334                          -> ValueRef;
1335
1336     pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1337                           -> ValueRef;
1338
1339     pub fn LLVMBuildGEP(B: BuilderRef,
1340                         Pointer: ValueRef,
1341                         Indices: *const ValueRef,
1342                         NumIndices: c_uint,
1343                         Name: *const c_char)
1344                         -> ValueRef;
1345     pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1346                                 Pointer: ValueRef,
1347                                 Indices: *const ValueRef,
1348                                 NumIndices: c_uint,
1349                                 Name: *const c_char)
1350                                 -> ValueRef;
1351     pub fn LLVMBuildStructGEP(B: BuilderRef,
1352                               Pointer: ValueRef,
1353                               Idx: c_uint,
1354                               Name: *const c_char)
1355                               -> ValueRef;
1356     pub fn LLVMBuildGlobalString(B: BuilderRef,
1357                                  Str: *const c_char,
1358                                  Name: *const c_char)
1359                                  -> ValueRef;
1360     pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1361                                     Str: *const c_char,
1362                                     Name: *const c_char)
1363                                     -> ValueRef;
1364
1365     /* Casts */
1366     pub fn LLVMBuildTrunc(B: BuilderRef,
1367                           Val: ValueRef,
1368                           DestTy: TypeRef,
1369                           Name: *const c_char)
1370                           -> ValueRef;
1371     pub fn LLVMBuildZExt(B: BuilderRef,
1372                          Val: ValueRef,
1373                          DestTy: TypeRef,
1374                          Name: *const c_char)
1375                          -> ValueRef;
1376     pub fn LLVMBuildSExt(B: BuilderRef,
1377                          Val: ValueRef,
1378                          DestTy: TypeRef,
1379                          Name: *const c_char)
1380                          -> ValueRef;
1381     pub fn LLVMBuildFPToUI(B: BuilderRef,
1382                            Val: ValueRef,
1383                            DestTy: TypeRef,
1384                            Name: *const c_char)
1385                            -> ValueRef;
1386     pub fn LLVMBuildFPToSI(B: BuilderRef,
1387                            Val: ValueRef,
1388                            DestTy: TypeRef,
1389                            Name: *const c_char)
1390                            -> ValueRef;
1391     pub fn LLVMBuildUIToFP(B: BuilderRef,
1392                            Val: ValueRef,
1393                            DestTy: TypeRef,
1394                            Name: *const c_char)
1395                            -> ValueRef;
1396     pub fn LLVMBuildSIToFP(B: BuilderRef,
1397                            Val: ValueRef,
1398                            DestTy: TypeRef,
1399                            Name: *const c_char)
1400                            -> ValueRef;
1401     pub fn LLVMBuildFPTrunc(B: BuilderRef,
1402                             Val: ValueRef,
1403                             DestTy: TypeRef,
1404                             Name: *const c_char)
1405                             -> ValueRef;
1406     pub fn LLVMBuildFPExt(B: BuilderRef,
1407                           Val: ValueRef,
1408                           DestTy: TypeRef,
1409                           Name: *const c_char)
1410                           -> ValueRef;
1411     pub fn LLVMBuildPtrToInt(B: BuilderRef,
1412                              Val: ValueRef,
1413                              DestTy: TypeRef,
1414                              Name: *const c_char)
1415                              -> ValueRef;
1416     pub fn LLVMBuildIntToPtr(B: BuilderRef,
1417                              Val: ValueRef,
1418                              DestTy: TypeRef,
1419                              Name: *const c_char)
1420                              -> ValueRef;
1421     pub fn LLVMBuildBitCast(B: BuilderRef,
1422                             Val: ValueRef,
1423                             DestTy: TypeRef,
1424                             Name: *const c_char)
1425                             -> ValueRef;
1426     pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1427                                   Val: ValueRef,
1428                                   DestTy: TypeRef,
1429                                   Name: *const c_char)
1430                                   -> ValueRef;
1431     pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1432                                   Val: ValueRef,
1433                                   DestTy: TypeRef,
1434                                   Name: *const c_char)
1435                                   -> ValueRef;
1436     pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1437                                    Val: ValueRef,
1438                                    DestTy: TypeRef,
1439                                    Name: *const c_char)
1440                                    -> ValueRef;
1441     pub fn LLVMBuildCast(B: BuilderRef,
1442                          Op: Opcode,
1443                          Val: ValueRef,
1444                          DestTy: TypeRef,
1445                          Name: *const c_char) -> ValueRef;
1446     pub fn LLVMBuildPointerCast(B: BuilderRef,
1447                                 Val: ValueRef,
1448                                 DestTy: TypeRef,
1449                                 Name: *const c_char)
1450                                 -> ValueRef;
1451     pub fn LLVMBuildIntCast(B: BuilderRef,
1452                             Val: ValueRef,
1453                             DestTy: TypeRef,
1454                             Name: *const c_char)
1455                             -> ValueRef;
1456     pub fn LLVMBuildFPCast(B: BuilderRef,
1457                            Val: ValueRef,
1458                            DestTy: TypeRef,
1459                            Name: *const c_char)
1460                            -> ValueRef;
1461
1462     /* Comparisons */
1463     pub fn LLVMBuildICmp(B: BuilderRef,
1464                          Op: c_uint,
1465                          LHS: ValueRef,
1466                          RHS: ValueRef,
1467                          Name: *const c_char)
1468                          -> ValueRef;
1469     pub fn LLVMBuildFCmp(B: BuilderRef,
1470                          Op: c_uint,
1471                          LHS: ValueRef,
1472                          RHS: ValueRef,
1473                          Name: *const c_char)
1474                          -> ValueRef;
1475
1476     /* Miscellaneous instructions */
1477     pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1478                         -> ValueRef;
1479     pub fn LLVMBuildCall(B: BuilderRef,
1480                          Fn: ValueRef,
1481                          Args: *const ValueRef,
1482                          NumArgs: c_uint,
1483                          Name: *const c_char)
1484                          -> ValueRef;
1485     pub fn LLVMBuildSelect(B: BuilderRef,
1486                            If: ValueRef,
1487                            Then: ValueRef,
1488                            Else: ValueRef,
1489                            Name: *const c_char)
1490                            -> ValueRef;
1491     pub fn LLVMBuildVAArg(B: BuilderRef,
1492                           list: ValueRef,
1493                           Ty: TypeRef,
1494                           Name: *const c_char)
1495                           -> ValueRef;
1496     pub fn LLVMBuildExtractElement(B: BuilderRef,
1497                                    VecVal: ValueRef,
1498                                    Index: ValueRef,
1499                                    Name: *const c_char)
1500                                    -> ValueRef;
1501     pub fn LLVMBuildInsertElement(B: BuilderRef,
1502                                   VecVal: ValueRef,
1503                                   EltVal: ValueRef,
1504                                   Index: ValueRef,
1505                                   Name: *const c_char)
1506                                   -> ValueRef;
1507     pub fn LLVMBuildShuffleVector(B: BuilderRef,
1508                                   V1: ValueRef,
1509                                   V2: ValueRef,
1510                                   Mask: ValueRef,
1511                                   Name: *const c_char)
1512                                   -> ValueRef;
1513     pub fn LLVMBuildExtractValue(B: BuilderRef,
1514                                  AggVal: ValueRef,
1515                                  Index: c_uint,
1516                                  Name: *const c_char)
1517                                  -> ValueRef;
1518     pub fn LLVMBuildInsertValue(B: BuilderRef,
1519                                 AggVal: ValueRef,
1520                                 EltVal: ValueRef,
1521                                 Index: c_uint,
1522                                 Name: *const c_char)
1523                                 -> ValueRef;
1524
1525     pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1526                            -> ValueRef;
1527     pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1528                               -> ValueRef;
1529     pub fn LLVMBuildPtrDiff(B: BuilderRef,
1530                             LHS: ValueRef,
1531                             RHS: ValueRef,
1532                             Name: *const c_char)
1533                             -> ValueRef;
1534
1535     /* Atomic Operations */
1536     pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1537                                PointerVal: ValueRef,
1538                                Name: *const c_char,
1539                                Order: AtomicOrdering,
1540                                Alignment: c_uint)
1541                                -> ValueRef;
1542
1543     pub fn LLVMBuildAtomicStore(B: BuilderRef,
1544                                 Val: ValueRef,
1545                                 Ptr: ValueRef,
1546                                 Order: AtomicOrdering,
1547                                 Alignment: c_uint)
1548                                 -> ValueRef;
1549
1550     pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1551                                   LHS: ValueRef,
1552                                   CMP: ValueRef,
1553                                   RHS: ValueRef,
1554                                   Order: AtomicOrdering,
1555                                   FailureOrder: AtomicOrdering)
1556                                   -> ValueRef;
1557     pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1558                               Op: AtomicBinOp,
1559                               LHS: ValueRef,
1560                               RHS: ValueRef,
1561                               Order: AtomicOrdering,
1562                               SingleThreaded: Bool)
1563                               -> ValueRef;
1564
1565     pub fn LLVMBuildAtomicFence(B: BuilderRef,
1566                                 Order: AtomicOrdering,
1567                                 Scope: SynchronizationScope);
1568
1569
1570     /* Selected entries from the downcasts. */
1571     pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1572     pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1573
1574     /// Writes a module to the specified path. Returns 0 on success.
1575     pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1576
1577     /// Creates target data from a target layout string.
1578     pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1579     /// Adds the target data to the given pass manager. The pass manager
1580     /// references the target data only weakly.
1581     pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1582     /// Number of bytes clobbered when doing a Store to *T.
1583     pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1584                                -> c_ulonglong;
1585
1586     /// Number of bytes clobbered when doing a Store to *T.
1587     pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1588                                 -> c_ulonglong;
1589
1590     /// Distance between successive elements in an array of T. Includes ABI padding.
1591     pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1592
1593     /// Returns the preferred alignment of a type.
1594     pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1595                                         -> c_uint;
1596     /// Returns the minimum alignment of a type.
1597     pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1598                                   -> c_uint;
1599
1600     /// Computes the byte offset of the indexed struct element for a
1601     /// target.
1602     pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1603                                StructTy: TypeRef,
1604                                Element: c_uint)
1605                                -> c_ulonglong;
1606
1607     /// Returns the minimum alignment of a type when part of a call frame.
1608     pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1609                                         -> c_uint;
1610
1611     /// Disposes target data.
1612     pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1613
1614     /// Creates a pass manager.
1615     pub fn LLVMCreatePassManager() -> PassManagerRef;
1616
1617     /// Creates a function-by-function pass manager
1618     pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1619                                                   -> PassManagerRef;
1620
1621     /// Disposes a pass manager.
1622     pub fn LLVMDisposePassManager(PM: PassManagerRef);
1623
1624     /// Runs a pass manager on a module.
1625     pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1626
1627     /// Runs the function passes on the provided function.
1628     pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1629                                       -> Bool;
1630
1631     /// Initializes all the function passes scheduled in the manager
1632     pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1633
1634     /// Finalizes all the function passes scheduled in the manager
1635     pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1636
1637     pub fn LLVMInitializePasses();
1638
1639     /// Adds a verification pass.
1640     pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1641
1642     pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1643     pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1644     pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1645     pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1646     pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1647     pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1648     pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1649     pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1650     pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1651     pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1652     pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1653     pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1654     pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1655     pub fn LLVMAddLICMPass(PM: PassManagerRef);
1656     pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1657     pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1658     pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1659     pub fn LLVMAddGVNPass(PM: PassManagerRef);
1660     pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1661     pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1662     pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1663     pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1664     pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1665     pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1666     pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1667     pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1668     pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1669     pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1670     pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1671     pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1672     pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1673     pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1674     pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1675     pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1676     pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1677
1678     pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1679     pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1680     pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1681                                              OptimizationLevel: c_uint);
1682     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1683                                               Value: Bool);
1684     pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1685         PMB: PassManagerBuilderRef,
1686         Value: Bool);
1687     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1688         PMB: PassManagerBuilderRef,
1689         Value: Bool);
1690     pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1691         PMB: PassManagerBuilderRef,
1692         Value: Bool);
1693     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1694         PMB: PassManagerBuilderRef,
1695         threshold: c_uint);
1696     pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1697         PMB: PassManagerBuilderRef,
1698         PM: PassManagerRef);
1699
1700     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1701         PMB: PassManagerBuilderRef,
1702         PM: PassManagerRef);
1703     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1704         PMB: PassManagerBuilderRef,
1705         PM: PassManagerRef,
1706         Internalize: Bool,
1707         RunInliner: Bool);
1708
1709     /// Destroys a memory buffer.
1710     pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1711
1712
1713     /* Stuff that's in rustllvm/ because it's not upstream yet. */
1714
1715     /// Opens an object file.
1716     pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1717     /// Closes an object file.
1718     pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1719
1720     /// Enumerates the sections in an object file.
1721     pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1722     /// Destroys a section iterator.
1723     pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1724     /// Returns true if the section iterator is at the end of the section
1725     /// list:
1726     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1727                                       SI: SectionIteratorRef)
1728                                       -> Bool;
1729     /// Moves the section iterator to point to the next section.
1730     pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1731     /// Returns the current section size.
1732     pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1733     /// Returns the current section contents as a string buffer.
1734     pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1735
1736     /// Reads the given file and returns it as a memory buffer. Use
1737     /// LLVMDisposeMemoryBuffer() to get rid of it.
1738     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1739                                                         -> MemoryBufferRef;
1740     /// Borrows the contents of the memory buffer (doesn't copy it)
1741     pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1742                                                  InputDataLength: size_t,
1743                                                  BufferName: *const c_char,
1744                                                  RequiresNull: Bool)
1745                                                  -> MemoryBufferRef;
1746     pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1747                                                      InputDataLength: size_t,
1748                                                      BufferName: *const c_char)
1749                                                      -> MemoryBufferRef;
1750
1751     pub fn LLVMIsMultithreaded() -> Bool;
1752     pub fn LLVMStartMultithreaded() -> Bool;
1753
1754     /// Returns a string describing the last error caused by an LLVMRust* call.
1755     pub fn LLVMRustGetLastError() -> *const c_char;
1756
1757     /// Print the pass timings since static dtors aren't picking them up.
1758     pub fn LLVMRustPrintPassTimings();
1759
1760     pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1761
1762     pub fn LLVMStructSetBody(StructTy: TypeRef,
1763                              ElementTypes: *const TypeRef,
1764                              ElementCount: c_uint,
1765                              Packed: Bool);
1766
1767     pub fn LLVMConstNamedStruct(S: TypeRef,
1768                                 ConstantVals: *const ValueRef,
1769                                 Count: c_uint)
1770                                 -> ValueRef;
1771
1772     /// Enables LLVM debug output.
1773     pub fn LLVMSetDebug(Enabled: c_int);
1774
1775     /// Prepares inline assembly.
1776     pub fn LLVMInlineAsm(Ty: TypeRef,
1777                          AsmString: *const c_char,
1778                          Constraints: *const c_char,
1779                          SideEffects: Bool,
1780                          AlignStack: Bool,
1781                          Dialect: c_uint)
1782                          -> ValueRef;
1783
1784     pub fn LLVMRustDebugMetadataVersion() -> u32;
1785     pub fn LLVMVersionMajor() -> u32;
1786     pub fn LLVMVersionMinor() -> u32;
1787
1788     pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1789                                  name: *const c_char,
1790                                  value: u32);
1791
1792     pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1793
1794     pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1795
1796     pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1797
1798     pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1799                                           Lang: c_uint,
1800                                           File: *const c_char,
1801                                           Dir: *const c_char,
1802                                           Producer: *const c_char,
1803                                           isOptimized: bool,
1804                                           Flags: *const c_char,
1805                                           RuntimeVer: c_uint,
1806                                           SplitName: *const c_char)
1807                                           -> DIDescriptor;
1808
1809     pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1810                                    Filename: *const c_char,
1811                                    Directory: *const c_char)
1812                                    -> DIFile;
1813
1814     pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1815                                              File: DIFile,
1816                                              ParameterTypes: DIArray)
1817                                              -> DICompositeType;
1818
1819     pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1820                                        Scope: DIDescriptor,
1821                                        Name: *const c_char,
1822                                        LinkageName: *const c_char,
1823                                        File: DIFile,
1824                                        LineNo: c_uint,
1825                                        Ty: DIType,
1826                                        isLocalToUnit: bool,
1827                                        isDefinition: bool,
1828                                        ScopeLine: c_uint,
1829                                        Flags: c_uint,
1830                                        isOptimized: bool,
1831                                        Fn: ValueRef,
1832                                        TParam: DIArray,
1833                                        Decl: DIDescriptor)
1834                                        -> DISubprogram;
1835
1836     pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1837                                         Name: *const c_char,
1838                                         SizeInBits: c_ulonglong,
1839                                         AlignInBits: c_ulonglong,
1840                                         Encoding: c_uint)
1841                                         -> DIBasicType;
1842
1843     pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1844                                           PointeeTy: DIType,
1845                                           SizeInBits: c_ulonglong,
1846                                           AlignInBits: c_ulonglong,
1847                                           Name: *const c_char)
1848                                           -> DIDerivedType;
1849
1850     pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1851                                          Scope: DIDescriptor,
1852                                          Name: *const c_char,
1853                                          File: DIFile,
1854                                          LineNumber: c_uint,
1855                                          SizeInBits: c_ulonglong,
1856                                          AlignInBits: c_ulonglong,
1857                                          Flags: c_uint,
1858                                          DerivedFrom: DIType,
1859                                          Elements: DIArray,
1860                                          RunTimeLang: c_uint,
1861                                          VTableHolder: DIType,
1862                                          UniqueId: *const c_char)
1863                                          -> DICompositeType;
1864
1865     pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1866                                          Scope: DIDescriptor,
1867                                          Name: *const c_char,
1868                                          File: DIFile,
1869                                          LineNo: c_uint,
1870                                          SizeInBits: c_ulonglong,
1871                                          AlignInBits: c_ulonglong,
1872                                          OffsetInBits: c_ulonglong,
1873                                          Flags: c_uint,
1874                                          Ty: DIType)
1875                                          -> DIDerivedType;
1876
1877     pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1878                                            Scope: DIScope,
1879                                            File: DIFile,
1880                                            Line: c_uint,
1881                                            Col: c_uint)
1882                                            -> DILexicalBlock;
1883
1884     pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1885                                              Context: DIScope,
1886                                              Name: *const c_char,
1887                                              LinkageName: *const c_char,
1888                                              File: DIFile,
1889                                              LineNo: c_uint,
1890                                              Ty: DIType,
1891                                              isLocalToUnit: bool,
1892                                              Val: ValueRef,
1893                                              Decl: DIDescriptor)
1894                                              -> DIGlobalVariable;
1895
1896     pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1897                                             Tag: c_uint,
1898                                             Scope: DIDescriptor,
1899                                             Name: *const c_char,
1900                                             File: DIFile,
1901                                             LineNo: c_uint,
1902                                             Ty: DIType,
1903                                             AlwaysPreserve: bool,
1904                                             Flags: c_uint,
1905                                             AddrOps: *const i64,
1906                                             AddrOpsCount: c_uint,
1907                                             ArgNo: c_uint)
1908                                             -> DIVariable;
1909
1910     pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1911                                         Size: c_ulonglong,
1912                                         AlignInBits: c_ulonglong,
1913                                         Ty: DIType,
1914                                         Subscripts: DIArray)
1915                                         -> DIType;
1916
1917     pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1918                                          Size: c_ulonglong,
1919                                          AlignInBits: c_ulonglong,
1920                                          Ty: DIType,
1921                                          Subscripts: DIArray)
1922                                          -> DIType;
1923
1924     pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1925                                             Lo: c_longlong,
1926                                             Count: c_longlong)
1927                                             -> DISubrange;
1928
1929     pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1930                                          Ptr: *const DIDescriptor,
1931                                          Count: c_uint)
1932                                          -> DIArray;
1933
1934     pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1935                                            Val: ValueRef,
1936                                            VarInfo: DIVariable,
1937                                            AddrOps: *const i64,
1938                                            AddrOpsCount: c_uint,
1939                                            DL: ValueRef,
1940                                            InsertAtEnd: BasicBlockRef)
1941                                            -> ValueRef;
1942
1943     pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1944                                             Val: ValueRef,
1945                                             VarInfo: DIVariable,
1946                                             AddrOps: *const i64,
1947                                             AddrOpsCount: c_uint,
1948                                             DL: ValueRef,
1949                                             InsertBefore: ValueRef)
1950                                             -> ValueRef;
1951
1952     pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1953                                          Name: *const c_char,
1954                                          Val: c_ulonglong)
1955                                          -> DIEnumerator;
1956
1957     pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1958                                               Scope: DIScope,
1959                                               Name: *const c_char,
1960                                               File: DIFile,
1961                                               LineNumber: c_uint,
1962                                               SizeInBits: c_ulonglong,
1963                                               AlignInBits: c_ulonglong,
1964                                               Elements: DIArray,
1965                                               ClassType: DIType)
1966                                               -> DIType;
1967
1968     pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1969                                         Scope: DIScope,
1970                                         Name: *const c_char,
1971                                         File: DIFile,
1972                                         LineNumber: c_uint,
1973                                         SizeInBits: c_ulonglong,
1974                                         AlignInBits: c_ulonglong,
1975                                         Flags: c_uint,
1976                                         Elements: DIArray,
1977                                         RunTimeLang: c_uint,
1978                                         UniqueId: *const c_char)
1979                                         -> DIType;
1980
1981     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1982
1983     pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1984                                                     Scope: DIScope,
1985                                                     Name: *const c_char,
1986                                                     Ty: DIType,
1987                                                     File: DIFile,
1988                                                     LineNo: c_uint,
1989                                                     ColumnNo: c_uint)
1990                                                     -> DITemplateTypeParameter;
1991
1992     pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1993
1994     pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1995
1996     pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1997                                         Scope: DIScope,
1998                                         Name: *const c_char,
1999                                         File: DIFile,
2000                                         LineNo: c_uint)
2001                                         -> DINameSpace;
2002
2003     pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
2004                                             Line: c_uint,
2005                                             Column: c_uint,
2006                                             Scope: DIScope,
2007                                             InlinedAt: MetadataRef)
2008                                             -> ValueRef;
2009
2010     pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2011                                            CompositeType: DIType,
2012                                            TypeArray: DIArray);
2013     pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2014     pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2015
2016     pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2017
2018     pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2019     pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2020
2021     pub fn LLVMRustPassKind(Pass: PassRef) -> SupportedPassKind;
2022     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
2023     pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
2024
2025     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2026                                        CPU: *const c_char,
2027                                        Features: *const c_char,
2028                                        Model: CodeGenModel,
2029                                        Reloc: RelocMode,
2030                                        Level: CodeGenOptLevel,
2031                                        UseSoftFP: bool,
2032                                        PositionIndependentExecutable: bool,
2033                                        FunctionSections: bool,
2034                                        DataSections: bool) -> TargetMachineRef;
2035     pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2036     pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2037                                      PM: PassManagerRef,
2038                                      M: ModuleRef);
2039     pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2040                                          M: ModuleRef,
2041                                          DisableSimplifyLibCalls: bool);
2042     pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2043                                                OptLevel: CodeGenOptLevel,
2044                                                MergeFunctions: bool,
2045                                                SLPVectorize: bool,
2046                                                LoopVectorize: bool);
2047     pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2048                                   DisableSimplifyLibCalls: bool);
2049     pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2050     pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2051                                    PM: PassManagerRef,
2052                                    M: ModuleRef,
2053                                    Output: *const c_char,
2054                                    FileType: FileType) -> bool;
2055     pub fn LLVMRustPrintModule(PM: PassManagerRef,
2056                                M: ModuleRef,
2057                                Output: *const c_char);
2058     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2059     pub fn LLVMRustPrintPasses();
2060     pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2061     pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2062                                        AddLifetimes: bool);
2063     pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2064                                          bc: *const c_char,
2065                                          len: size_t) -> bool;
2066     pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2067                                       syms: *const *const c_char,
2068                                       len: size_t);
2069     pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2070
2071     pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2072     pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2073     pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2074     pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2075                                     size: *mut size_t) -> *const c_char;
2076     pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2077                                     size: *mut size_t) -> *const c_char;
2078     pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2079     pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2080     pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2081
2082     pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2083                                       C: DLLStorageClassTypes);
2084
2085     pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2086                                   data: *mut *const c_char) -> c_int;
2087
2088     pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2089
2090     pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2091                                            Handler: DiagnosticHandler,
2092                                            DiagnosticContext: *mut c_void);
2093
2094     pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2095                                             pass_name_out: *mut *const c_char,
2096                                             function_out: *mut ValueRef,
2097                                             debugloc_out: *mut DebugLocRef,
2098                                             message_out: *mut TwineRef);
2099     pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2100                                             cookie_out: *mut c_uint,
2101                                             message_out: *mut TwineRef,
2102                                             instruction_out: *mut ValueRef);
2103
2104     pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2105     pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2106     pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2107
2108     pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2109
2110     pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2111                                              H: InlineAsmDiagHandler,
2112                                              CX: *mut c_void);
2113
2114     pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2115
2116     pub fn LLVMRustWriteArchive(Dst: *const c_char,
2117                                 NumMembers: size_t,
2118                                 Members: *const RustArchiveMemberRef,
2119                                 WriteSymbtab: bool,
2120                                 Kind: ArchiveKind) -> c_int;
2121     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2122                                     Name: *const c_char,
2123                                     Child: ArchiveChildRef) -> RustArchiveMemberRef;
2124     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2125
2126     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2127                                                   TM: TargetMachineRef);
2128     pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2129 }
2130
2131 #[cfg(have_component_x86)]
2132 extern {
2133     pub fn LLVMInitializeX86TargetInfo();
2134     pub fn LLVMInitializeX86Target();
2135     pub fn LLVMInitializeX86TargetMC();
2136     pub fn LLVMInitializeX86AsmPrinter();
2137     pub fn LLVMInitializeX86AsmParser();
2138 }
2139 #[cfg(have_component_arm)]
2140 extern {
2141     pub fn LLVMInitializeARMTargetInfo();
2142     pub fn LLVMInitializeARMTarget();
2143     pub fn LLVMInitializeARMTargetMC();
2144     pub fn LLVMInitializeARMAsmPrinter();
2145     pub fn LLVMInitializeARMAsmParser();
2146 }
2147 #[cfg(have_component_aarch64)]
2148 extern {
2149     pub fn LLVMInitializeAArch64TargetInfo();
2150     pub fn LLVMInitializeAArch64Target();
2151     pub fn LLVMInitializeAArch64TargetMC();
2152     pub fn LLVMInitializeAArch64AsmPrinter();
2153     pub fn LLVMInitializeAArch64AsmParser();
2154 }
2155 #[cfg(have_component_mips)]
2156 extern {
2157     pub fn LLVMInitializeMipsTargetInfo();
2158     pub fn LLVMInitializeMipsTarget();
2159     pub fn LLVMInitializeMipsTargetMC();
2160     pub fn LLVMInitializeMipsAsmPrinter();
2161     pub fn LLVMInitializeMipsAsmParser();
2162 }
2163 #[cfg(have_component_powerpc)]
2164 extern {
2165     pub fn LLVMInitializePowerPCTargetInfo();
2166     pub fn LLVMInitializePowerPCTarget();
2167     pub fn LLVMInitializePowerPCTargetMC();
2168     pub fn LLVMInitializePowerPCAsmPrinter();
2169     pub fn LLVMInitializePowerPCAsmParser();
2170 }
2171 #[cfg(have_component_pnacl)]
2172 extern {
2173     pub fn LLVMInitializePNaClTargetInfo();
2174     pub fn LLVMInitializePNaClTarget();
2175     pub fn LLVMInitializePNaClTargetMC();
2176 }
2177
2178 // LLVM requires symbols from this library, but apparently they're not printed
2179 // during llvm-config?
2180 #[cfg(windows)]
2181 #[link(name = "ole32")]
2182 extern {}
2183
2184 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2185     unsafe {
2186         LLVMSetInstructionCallConv(instr, cc as c_uint);
2187     }
2188 }
2189 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2190     unsafe {
2191         LLVMSetFunctionCallConv(fn_, cc as c_uint);
2192     }
2193 }
2194 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2195     unsafe {
2196         LLVMSetLinkage(global, link as c_uint);
2197     }
2198 }
2199
2200 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2201     unsafe {
2202         LLVMRustSetDLLStorageClass(global, class);
2203     }
2204 }
2205
2206 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2207     unsafe {
2208         LLVMSetUnnamedAddr(global, unnamed as Bool);
2209     }
2210 }
2211
2212 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2213     unsafe {
2214         LLVMSetThreadLocal(global, is_thread_local as Bool);
2215     }
2216 }
2217
2218 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2219     unsafe {
2220         LLVMConstICmp(pred as c_ushort, v1, v2)
2221     }
2222 }
2223 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2224     unsafe {
2225         LLVMConstFCmp(pred as c_ushort, v1, v2)
2226     }
2227 }
2228
2229 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2230     unsafe {
2231         LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2232                                  attr.bits() as uint64_t)
2233     }
2234 }
2235
2236 /* Memory-managed interface to target data. */
2237
2238 pub struct TargetData {
2239     pub lltd: TargetDataRef
2240 }
2241
2242 impl Drop for TargetData {
2243     fn drop(&mut self) {
2244         unsafe {
2245             LLVMDisposeTargetData(self.lltd);
2246         }
2247     }
2248 }
2249
2250 pub fn mk_target_data(string_rep: &str) -> TargetData {
2251     let string_rep = CString::new(string_rep).unwrap();
2252     TargetData {
2253         lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2254     }
2255 }
2256
2257 /* Memory-managed interface to object files. */
2258
2259 pub struct ObjectFile {
2260     pub llof: ObjectFileRef,
2261 }
2262
2263 impl ObjectFile {
2264     // This will take ownership of llmb
2265     pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2266         unsafe {
2267             let llof = LLVMCreateObjectFile(llmb);
2268             if llof as isize == 0 {
2269                 // LLVMCreateObjectFile took ownership of llmb
2270                 return None
2271             }
2272
2273             Some(ObjectFile {
2274                 llof: llof,
2275             })
2276         }
2277     }
2278 }
2279
2280 impl Drop for ObjectFile {
2281     fn drop(&mut self) {
2282         unsafe {
2283             LLVMDisposeObjectFile(self.llof);
2284         }
2285     }
2286 }
2287
2288 /* Memory-managed interface to section iterators. */
2289
2290 pub struct SectionIter {
2291     pub llsi: SectionIteratorRef
2292 }
2293
2294 impl Drop for SectionIter {
2295     fn drop(&mut self) {
2296         unsafe {
2297             LLVMDisposeSectionIterator(self.llsi);
2298         }
2299     }
2300 }
2301
2302 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2303     unsafe {
2304         SectionIter {
2305             llsi: LLVMGetSections(llof)
2306         }
2307     }
2308 }
2309
2310 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2311 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2312     unsafe {
2313         assert!(index < LLVMCountParams(llfn));
2314         LLVMGetParam(llfn, index)
2315     }
2316 }
2317
2318 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2319     unsafe {
2320         let num_params = LLVMCountParams(llfn);
2321         let mut params = Vec::with_capacity(num_params as usize);
2322         for idx in 0..num_params {
2323             params.push(LLVMGetParam(llfn, idx));
2324         }
2325
2326         params
2327     }
2328 }
2329
2330 #[allow(missing_copy_implementations)]
2331 pub enum RustString_opaque {}
2332 pub type RustStringRef = *mut RustString_opaque;
2333 type RustStringRepr = *mut RefCell<Vec<u8>>;
2334
2335 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2336 #[no_mangle]
2337 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2338                                                      ptr: *const c_char,
2339                                                      size: size_t) {
2340     let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2341
2342     let sr = sr as RustStringRepr;
2343     (*sr).borrow_mut().extend_from_slice(slice);
2344 }
2345
2346 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2347     let mut buf = RefCell::new(Vec::new());
2348     f(&mut buf as RustStringRepr as RustStringRef);
2349     String::from_utf8(buf.into_inner()).ok()
2350 }
2351
2352 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2353     build_string(|s| LLVMWriteTwineToString(tr, s))
2354         .expect("got a non-UTF8 Twine from LLVM")
2355 }
2356
2357 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2358     build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2359         .expect("got a non-UTF8 DebugLoc from LLVM")
2360 }
2361
2362 pub fn initialize_available_targets() {
2363     macro_rules! init_target(
2364         ($cfg:ident $arch:ident) => { {
2365             #[cfg($cfg)]
2366             fn init() {
2367                 unsafe {
2368                     let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2369                     f();
2370                     let f = concat_idents!(LLVMInitialize, $arch, Target);
2371                     f();
2372                     let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2373                     f();
2374                     let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2375                     f();
2376                     let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2377                     f();
2378                 }
2379             }
2380             #[cfg(not($cfg))]
2381             fn init() { }
2382             init();
2383         } }
2384     );
2385
2386     init_target!(have_component_powerpc PowerPC);
2387     init_target!(have_component_mips Mips);
2388     init_target!(have_component_aarch64 AArch64);
2389     init_target!(have_component_arm ARM);
2390     init_target!(have_component_x86 X86);
2391
2392     // PNaCl doesn't provide some of the optional target components, so we
2393     // manually initialize it here.
2394     #[cfg(have_component_pnacl)]
2395     fn init_pnacl() {
2396         unsafe {
2397             LLVMInitializePNaClTargetInfo();
2398             LLVMInitializePNaClTarget();
2399             LLVMInitializePNaClTargetMC();
2400         }
2401     }
2402     #[cfg(not(have_component_pnacl))]
2403     fn init_pnacl() { }
2404     init_pnacl();
2405 }
2406
2407 // The module containing the native LLVM dependencies, generated by the build system
2408 // Note that this must come after the rustllvm extern declaration so that
2409 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2410 // Works to the above fix for #15460 to ensure LLVM dependencies that
2411 // are only used by rustllvm don't get stripped by the linker.
2412 mod llvmdeps {
2413     include! { env!("CFG_LLVM_LINKAGE_FILE") }
2414 }