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