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