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