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