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