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