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