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