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