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