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