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