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