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