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