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