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