]> git.lizzy.rs Git - rust.git/blob - src/librustc/lib/llvm.rs
rustc: Add --target-cpu flag to select a more specific processor instead of the defau...
[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 use std::c_str::ToCStr;
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         #[fast_ffi]
1557         pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1558
1559         /** Writes a module to the specified path. Returns 0 on success. */
1560         #[fast_ffi]
1561         pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1562
1563         /** Creates target data from a target layout string. */
1564         #[fast_ffi]
1565         pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1566         /// Adds the target data to the given pass manager. The pass manager
1567         /// references the target data only weakly.
1568         #[fast_ffi]
1569         pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1570         /** Number of bytes clobbered when doing a Store to *T. */
1571         #[fast_ffi]
1572         pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1573                                    -> c_ulonglong;
1574
1575         /** Number of bytes clobbered when doing a Store to *T. */
1576         #[fast_ffi]
1577         pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1578                                     -> c_ulonglong;
1579
1580         /** Distance between successive elements in an array of T.
1581         Includes ABI padding. */
1582         #[fast_ffi]
1583         pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1584
1585         /** Returns the preferred alignment of a type. */
1586         #[fast_ffi]
1587         pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1588                                             -> c_uint;
1589         /** Returns the minimum alignment of a type. */
1590         #[fast_ffi]
1591         pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1592                                       -> c_uint;
1593
1594         /// Computes the byte offset of the indexed struct element for a
1595         /// target.
1596         #[fast_ffi]
1597         pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1598                                    StructTy: TypeRef,
1599                                    Element: c_uint)
1600                                    -> c_ulonglong;
1601
1602         /**
1603          * Returns the minimum alignment of a type when part of a call frame.
1604          */
1605         #[fast_ffi]
1606         pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1607                                             -> c_uint;
1608
1609         /** Disposes target data. */
1610         #[fast_ffi]
1611         pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1612
1613         /** Creates a pass manager. */
1614         #[fast_ffi]
1615         pub fn LLVMCreatePassManager() -> PassManagerRef;
1616         /** Creates a function-by-function pass manager */
1617         #[fast_ffi]
1618         pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1619                                                       -> PassManagerRef;
1620
1621         /** Disposes a pass manager. */
1622         #[fast_ffi]
1623         pub fn LLVMDisposePassManager(PM: PassManagerRef);
1624
1625         /** Runs a pass manager on a module. */
1626         #[fast_ffi]
1627         pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1628
1629         /** Runs the function passes on the provided function. */
1630         #[fast_ffi]
1631         pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1632                                           -> Bool;
1633
1634         /** Initializes all the function passes scheduled in the manager */
1635         #[fast_ffi]
1636         pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1637
1638         /** Finalizes all the function passes scheduled in the manager */
1639         #[fast_ffi]
1640         pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1641
1642         #[fast_ffi]
1643         pub fn LLVMInitializePasses();
1644
1645         #[fast_ffi]
1646         pub fn LLVMAddPass(PM: PassManagerRef, P: PassRef);
1647
1648         #[fast_ffi]
1649         pub fn LLVMCreatePass(PassName: *c_char) -> PassRef;
1650
1651         #[fast_ffi]
1652         pub fn LLVMDestroyPass(P: PassRef);
1653
1654         /** Adds a verification pass. */
1655         #[fast_ffi]
1656         pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1657
1658         #[fast_ffi]
1659         pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1660         #[fast_ffi]
1661         pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1662         #[fast_ffi]
1663         pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1664         #[fast_ffi]
1665         pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1666         #[fast_ffi]
1667         pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1668         #[fast_ffi]
1669         pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1670         #[fast_ffi]
1671         pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1672         #[fast_ffi]
1673         pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1674         #[fast_ffi]
1675         pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1676         #[fast_ffi]
1677         pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1678         #[fast_ffi]
1679         pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1680         #[fast_ffi]
1681         pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1682         #[fast_ffi]
1683         pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1684         #[fast_ffi]
1685         pub fn LLVMAddLICMPass(PM: PassManagerRef);
1686         #[fast_ffi]
1687         pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1688         #[fast_ffi]
1689         pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1690         #[fast_ffi]
1691         pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1692         #[fast_ffi]
1693         pub fn LLVMAddGVNPass(PM: PassManagerRef);
1694         #[fast_ffi]
1695         pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1696         #[fast_ffi]
1697         pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1698         #[fast_ffi]
1699         pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1700         #[fast_ffi]
1701         pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1702         #[fast_ffi]
1703         pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1704         #[fast_ffi]
1705         pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1706         #[fast_ffi]
1707         pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1708         #[fast_ffi]
1709         pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1710         #[fast_ffi]
1711         pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1712         #[fast_ffi]
1713         pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1714         #[fast_ffi]
1715         pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1716         #[fast_ffi]
1717         pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1718         #[fast_ffi]
1719         pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1720         #[fast_ffi]
1721         pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1722         #[fast_ffi]
1723         pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1724         #[fast_ffi]
1725         pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1726         #[fast_ffi]
1727         pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1728
1729         #[fast_ffi]
1730         pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1731         #[fast_ffi]
1732         pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1733         #[fast_ffi]
1734         pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1735                                                  OptimizationLevel: c_uint);
1736         #[fast_ffi]
1737         pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1738                                                   Value: Bool);
1739         #[fast_ffi]
1740         pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1741             PMB: PassManagerBuilderRef,
1742             Value: Bool);
1743         #[fast_ffi]
1744         pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1745             PMB: PassManagerBuilderRef,
1746             Value: Bool);
1747         #[fast_ffi]
1748         pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1749             PMB: PassManagerBuilderRef,
1750             Value: Bool);
1751         #[fast_ffi]
1752         pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1753             PMB: PassManagerBuilderRef,
1754             threshold: c_uint);
1755         #[fast_ffi]
1756         pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1757             PMB: PassManagerBuilderRef,
1758             PM: PassManagerRef);
1759
1760         #[fast_ffi]
1761         pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1762             PMB: PassManagerBuilderRef,
1763             PM: PassManagerRef);
1764
1765         /** Destroys a memory buffer. */
1766         #[fast_ffi]
1767         pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1768
1769
1770         /* Stuff that's in rustllvm/ because it's not upstream yet. */
1771
1772         /** Opens an object file. */
1773         #[fast_ffi]
1774         pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1775         /** Closes an object file. */
1776         #[fast_ffi]
1777         pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1778
1779         /** Enumerates the sections in an object file. */
1780         #[fast_ffi]
1781         pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1782         /** Destroys a section iterator. */
1783         #[fast_ffi]
1784         pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1785         /** Returns true if the section iterator is at the end of the section
1786             list: */
1787         #[fast_ffi]
1788         pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1789                                           SI: SectionIteratorRef)
1790                                           -> Bool;
1791         /** Moves the section iterator to point to the next section. */
1792         #[fast_ffi]
1793         pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1794         /** Returns the current section name. */
1795         #[fast_ffi]
1796         pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1797         /** Returns the current section size. */
1798         #[fast_ffi]
1799         pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1800         /** Returns the current section contents as a string buffer. */
1801         #[fast_ffi]
1802         pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1803
1804         /** Reads the given file and returns it as a memory buffer. Use
1805             LLVMDisposeMemoryBuffer() to get rid of it. */
1806         #[fast_ffi]
1807         pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1808             -> MemoryBufferRef;
1809
1810         #[fast_ffi]
1811         pub fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1812                                        M: ModuleRef,
1813                                        Triple: *c_char,
1814                                        Cpu: *c_char,
1815                                        Feature: *c_char,
1816                                        Output: *c_char,
1817                                        // FIXME: When #2334 is fixed,
1818                                        // change c_uint to FileType
1819                                        FileType: c_uint,
1820                                        OptLevel: c_int,
1821                                        EnableSegmentedStacks: bool)
1822                                        -> bool;
1823
1824         /** Returns a string describing the last error caused by an LLVMRust*
1825             call. */
1826         #[fast_ffi]
1827         pub fn LLVMRustGetLastError() -> *c_char;
1828
1829         /** Prepare the JIT. Returns a memory manager that can load crates. */
1830         #[fast_ffi]
1831         pub fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1832
1833         /** Load a crate into the memory manager. */
1834         #[fast_ffi]
1835         pub fn LLVMRustLoadCrate(MM: *(), Filename: *c_char) -> bool;
1836
1837         /** Execute the JIT engine. */
1838         #[fast_ffi]
1839         pub fn LLVMRustBuildJIT(MM: *(),
1840                                 M: ModuleRef,
1841                                 EnableSegmentedStacks: bool)
1842                                 -> ExecutionEngineRef;
1843
1844         /** Parses the bitcode in the given memory buffer. */
1845         #[fast_ffi]
1846         pub fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
1847
1848         /** Parses LLVM asm in the given file */
1849         #[fast_ffi]
1850         pub fn LLVMRustParseAssemblyFile(Filename: *c_char, C: ContextRef)
1851                                          -> ModuleRef;
1852
1853         #[fast_ffi]
1854         pub fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1855                                           M: ModuleRef,
1856                                           Output: *c_char);
1857
1858         /** Turn on LLVM pass-timing. */
1859         #[fast_ffi]
1860         pub fn LLVMRustEnableTimePasses();
1861
1862         /// Print the pass timings since static dtors aren't picking them up.
1863         #[fast_ffi]
1864         pub fn LLVMRustPrintPassTimings();
1865
1866         #[fast_ffi]
1867         pub fn LLVMRustStartMultithreading() -> bool;
1868
1869         #[fast_ffi]
1870         pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1871
1872         #[fast_ffi]
1873         pub fn LLVMStructSetBody(StructTy: TypeRef,
1874                                  ElementTypes: *TypeRef,
1875                                  ElementCount: c_uint,
1876                                  Packed: Bool);
1877
1878         #[fast_ffi]
1879         pub fn LLVMConstNamedStruct(S: TypeRef,
1880                                     ConstantVals: *ValueRef,
1881                                     Count: c_uint)
1882                                     -> ValueRef;
1883
1884         /** Enables LLVM debug output. */
1885         #[fast_ffi]
1886         pub fn LLVMSetDebug(Enabled: c_int);
1887
1888         /** Prepares inline assembly. */
1889         #[fast_ffi]
1890         pub fn LLVMInlineAsm(Ty: TypeRef,
1891                              AsmString: *c_char,
1892                              Constraints: *c_char,
1893                              SideEffects: Bool,
1894                              AlignStack: Bool,
1895                              Dialect: c_uint)
1896                              -> ValueRef;
1897
1898
1899         #[fast_ffi]
1900         pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1901
1902         #[fast_ffi]
1903         pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1904
1905         #[fast_ffi]
1906         pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1907
1908         #[fast_ffi]
1909         pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1910                                               Lang: c_uint,
1911                                               File: *c_char,
1912                                               Dir: *c_char,
1913                                               Producer: *c_char,
1914                                               isOptimized: bool,
1915                                               Flags: *c_char,
1916                                               RuntimeVer: c_uint,
1917                                               SplitName: *c_char);
1918
1919         #[fast_ffi]
1920         pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1921                                        Filename: *c_char,
1922                                        Directory: *c_char)
1923                                        -> DIFile;
1924
1925         #[fast_ffi]
1926         pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1927                                                  File: DIFile,
1928                                                  ParameterTypes: DIArray)
1929                                                  -> DICompositeType;
1930
1931         #[fast_ffi]
1932         pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1933                                            Scope: DIDescriptor,
1934                                            Name: *c_char,
1935                                            LinkageName: *c_char,
1936                                            File: DIFile,
1937                                            LineNo: c_uint,
1938                                            Ty: DIType,
1939                                            isLocalToUnit: bool,
1940                                            isDefinition: bool,
1941                                            ScopeLine: c_uint,
1942                                            Flags: c_uint,
1943                                            isOptimized: bool,
1944                                            Fn: ValueRef,
1945                                            TParam: ValueRef,
1946                                            Decl: ValueRef)
1947                                            -> DISubprogram;
1948
1949         #[fast_ffi]
1950         pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1951                                             Name: *c_char,
1952                                             SizeInBits: c_ulonglong,
1953                                             AlignInBits: c_ulonglong,
1954                                             Encoding: c_uint)
1955                                             -> DIBasicType;
1956
1957         #[fast_ffi]
1958         pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1959                                               PointeeTy: DIType,
1960                                               SizeInBits: c_ulonglong,
1961                                               AlignInBits: c_ulonglong,
1962                                               Name: *c_char)
1963                                               -> DIDerivedType;
1964
1965         #[fast_ffi]
1966         pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1967                                              Scope: DIDescriptor,
1968                                              Name: *c_char,
1969                                              File: DIFile,
1970                                              LineNumber: c_uint,
1971                                              SizeInBits: c_ulonglong,
1972                                              AlignInBits: c_ulonglong,
1973                                              Flags: c_uint,
1974                                              DerivedFrom: DIType,
1975                                              Elements: DIArray,
1976                                              RunTimeLang: c_uint,
1977                                              VTableHolder: ValueRef)
1978                                              -> DICompositeType;
1979
1980         #[fast_ffi]
1981         pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1982                                              Scope: DIDescriptor,
1983                                              Name: *c_char,
1984                                              File: DIFile,
1985                                              LineNo: c_uint,
1986                                              SizeInBits: c_ulonglong,
1987                                              AlignInBits: c_ulonglong,
1988                                              OffsetInBits: c_ulonglong,
1989                                              Flags: c_uint,
1990                                              Ty: DIType)
1991                                              -> DIDerivedType;
1992
1993         #[fast_ffi]
1994         pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1995                                                Scope: DIDescriptor,
1996                                                File: DIFile,
1997                                                Line: c_uint,
1998                                                Col: c_uint)
1999                                                -> DILexicalBlock;
2000
2001         #[fast_ffi]
2002         pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
2003                                                 Tag: c_uint,
2004                                                 Scope: DIDescriptor,
2005                                                 Name: *c_char,
2006                                                 File: DIFile,
2007                                                 LineNo: c_uint,
2008                                                 Ty: DIType,
2009                                                 AlwaysPreserve: bool,
2010                                                 Flags: c_uint,
2011                                                 ArgNo: c_uint)
2012                                                 -> DIVariable;
2013
2014         #[fast_ffi]
2015         pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
2016                                             Size: c_ulonglong,
2017                                             AlignInBits: c_ulonglong,
2018                                             Ty: DIType,
2019                                             Subscripts: DIArray)
2020                                             -> DIType;
2021
2022         #[fast_ffi]
2023         pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
2024                                              Size: c_ulonglong,
2025                                              AlignInBits: c_ulonglong,
2026                                              Ty: DIType,
2027                                              Subscripts: DIArray)
2028                                              -> DIType;
2029
2030         #[fast_ffi]
2031         pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
2032                                                 Lo: c_longlong,
2033                                                 Count: c_longlong)
2034                                                 -> DISubrange;
2035
2036         #[fast_ffi]
2037         pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
2038                                              Ptr: *DIDescriptor,
2039                                              Count: c_uint)
2040                                              -> DIArray;
2041
2042         #[fast_ffi]
2043         pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
2044                                                Val: ValueRef,
2045                                                VarInfo: DIVariable,
2046                                                InsertAtEnd: BasicBlockRef)
2047                                                -> ValueRef;
2048
2049         #[fast_ffi]
2050         pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
2051                                                 Val: ValueRef,
2052                                                 VarInfo: DIVariable,
2053                                                 InsertBefore: ValueRef)
2054                                                 -> ValueRef;
2055
2056         #[fast_ffi]
2057         pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
2058                                              Name: *c_char,
2059                                              Val: c_ulonglong)
2060                                              -> ValueRef;
2061
2062         #[fast_ffi]
2063         pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
2064                                                   Scope: ValueRef,
2065                                                   Name: *c_char,
2066                                                   File: ValueRef,
2067                                                   LineNumber: c_uint,
2068                                                   SizeInBits: c_ulonglong,
2069                                                   AlignInBits: c_ulonglong,
2070                                                   Elements: ValueRef,
2071                                                   ClassType: ValueRef)
2072                                                   -> ValueRef;
2073
2074         #[fast_ffi]
2075         pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
2076                                             Scope: ValueRef,
2077                                             Name: *c_char,
2078                                             File: ValueRef,
2079                                             LineNumber: c_uint,
2080                                             SizeInBits: c_ulonglong,
2081                                             AlignInBits: c_ulonglong,
2082                                             Flags: c_uint,
2083                                             Elements: ValueRef,
2084                                             RunTimeLang: c_uint)
2085                                             -> ValueRef;
2086     }
2087 }
2088
2089 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
2090     unsafe {
2091         llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
2092     }
2093 }
2094 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
2095     unsafe {
2096         llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
2097     }
2098 }
2099 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
2100     unsafe {
2101         llvm::LLVMSetLinkage(Global, Link as c_uint);
2102     }
2103 }
2104
2105 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2106     unsafe {
2107         llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
2108     }
2109 }
2110 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2111     unsafe {
2112         llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
2113     }
2114 }
2115
2116 pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
2117     unsafe {
2118         let attr = attr as u64;
2119         let lower = attr & 0xffffffff;
2120         let upper = (attr >> 32) & 0xffffffff;
2121         llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2122     }
2123 }
2124
2125 // FIXME(#8199): this shouldn't require this hackery. On i686
2126 //               (FixedStackSegment as u64) will return 0 instead of 1 << 41.
2127 //               Furthermore, if we use a match of any sort then an LLVM
2128 //               assertion is generated!
2129 pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) {
2130     unsafe {
2131         let attr = 1u64 << 41;
2132         let lower = attr & 0xffffffff;
2133         let upper = (attr >> 32) & 0xffffffff;
2134         llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2135     }
2136 }
2137 /* Memory-managed object interface to type handles. */
2138
2139 pub struct TypeNames {
2140     type_names: HashMap<TypeRef, ~str>,
2141     named_types: HashMap<~str, TypeRef>
2142 }
2143
2144 impl TypeNames {
2145     pub fn new() -> TypeNames {
2146         TypeNames {
2147             type_names: HashMap::new(),
2148             named_types: HashMap::new()
2149         }
2150     }
2151
2152     pub fn associate_type(&mut self, s: &str, t: &Type) {
2153         assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
2154         assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
2155     }
2156
2157     pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
2158         match self.type_names.find(&ty.to_ref()) {
2159             Some(a) => Some(a.slice(0, a.len())),
2160             None => None
2161         }
2162     }
2163
2164     pub fn find_type(&self, s: &str) -> Option<Type> {
2165         self.named_types.find_equiv(&s).map_move(|x| Type::from_ref(*x))
2166     }
2167
2168     // We have a depth count, because we seem to make infinite types.
2169     pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
2170         match self.find_name(&ty) {
2171             option::Some(name) => return name.to_owned(),
2172             None => ()
2173         }
2174
2175         if depth == 0 {
2176             return ~"###";
2177         }
2178
2179         unsafe {
2180             let kind = ty.kind();
2181
2182             match kind {
2183                 Void => ~"Void",
2184                 Half => ~"Half",
2185                 Float => ~"Float",
2186                 Double => ~"Double",
2187                 X86_FP80 => ~"X86_FP80",
2188                 FP128 => ~"FP128",
2189                 PPC_FP128 => ~"PPC_FP128",
2190                 Label => ~"Label",
2191                 Vector => ~"Vector",
2192                 Metadata => ~"Metadata",
2193                 X86_MMX => ~"X86_MMAX",
2194                 Integer => {
2195                     fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
2196                 }
2197                 Function => {
2198                     let out_ty = ty.return_type();
2199                     let args = ty.func_params();
2200                     let args =
2201                         args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2202                     let out_ty = self.type_to_str_depth(out_ty, depth-1);
2203                     fmt!("fn(%s) -> %s", args, out_ty)
2204                 }
2205                 Struct => {
2206                     let tys = ty.field_types();
2207                     let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2208                     fmt!("{%s}", tys)
2209                 }
2210                 Array => {
2211                     let el_ty = ty.element_type();
2212                     let el_ty = self.type_to_str_depth(el_ty, depth-1);
2213                     let len = ty.array_length();
2214                     fmt!("[%s x %u]", el_ty, len)
2215                 }
2216                 Pointer => {
2217                     let el_ty = ty.element_type();
2218                     let el_ty = self.type_to_str_depth(el_ty, depth-1);
2219                     fmt!("*%s", el_ty)
2220                 }
2221                 _ => fail!("Unknown Type Kind (%u)", kind as uint)
2222             }
2223         }
2224     }
2225
2226     pub fn type_to_str(&self, ty: Type) -> ~str {
2227         self.type_to_str_depth(ty, 30)
2228     }
2229
2230     pub fn val_to_str(&self, val: ValueRef) -> ~str {
2231         unsafe {
2232             let ty = Type::from_ref(llvm::LLVMTypeOf(val));
2233             self.type_to_str(ty)
2234         }
2235     }
2236 }
2237
2238
2239 /* Memory-managed interface to target data. */
2240
2241 pub struct target_data_res {
2242     TD: TargetDataRef,
2243 }
2244
2245 impl Drop for target_data_res {
2246     fn drop(&self) {
2247         unsafe {
2248             llvm::LLVMDisposeTargetData(self.TD);
2249         }
2250     }
2251 }
2252
2253 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
2254     target_data_res {
2255         TD: TD
2256     }
2257 }
2258
2259 pub struct TargetData {
2260     lltd: TargetDataRef,
2261     dtor: @target_data_res
2262 }
2263
2264 pub fn mk_target_data(string_rep: &str) -> TargetData {
2265     let lltd = do string_rep.to_c_str().with_ref |buf| {
2266         unsafe { llvm::LLVMCreateTargetData(buf) }
2267     };
2268
2269     TargetData {
2270         lltd: lltd,
2271         dtor: @target_data_res(lltd)
2272     }
2273 }
2274
2275 /* Memory-managed interface to pass managers. */
2276
2277 pub struct pass_manager_res {
2278     PM: PassManagerRef,
2279 }
2280
2281 impl Drop for pass_manager_res {
2282     fn drop(&self) {
2283         unsafe {
2284             llvm::LLVMDisposePassManager(self.PM);
2285         }
2286     }
2287 }
2288
2289 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
2290     pass_manager_res {
2291         PM: PM
2292     }
2293 }
2294
2295 pub struct PassManager {
2296     llpm: PassManagerRef,
2297     dtor: @pass_manager_res
2298 }
2299
2300 pub fn mk_pass_manager() -> PassManager {
2301     unsafe {
2302         let llpm = llvm::LLVMCreatePassManager();
2303
2304         PassManager {
2305             llpm: llpm,
2306             dtor: @pass_manager_res(llpm)
2307         }
2308     }
2309 }
2310
2311 /* Memory-managed interface to object files. */
2312
2313 pub struct object_file_res {
2314     ObjectFile: ObjectFileRef,
2315 }
2316
2317 impl Drop for object_file_res {
2318     fn drop(&self) {
2319         unsafe {
2320             llvm::LLVMDisposeObjectFile(self.ObjectFile);
2321         }
2322     }
2323 }
2324
2325 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2326     object_file_res {
2327         ObjectFile: ObjFile
2328     }
2329 }
2330
2331 pub struct ObjectFile {
2332     llof: ObjectFileRef,
2333     dtor: @object_file_res
2334 }
2335
2336 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2337     unsafe {
2338         let llof = llvm::LLVMCreateObjectFile(llmb);
2339         if llof as int == 0 { return option::None::<ObjectFile>; }
2340
2341         option::Some(ObjectFile {
2342             llof: llof,
2343             dtor: @object_file_res(llof)
2344         })
2345     }
2346 }
2347
2348 /* Memory-managed interface to section iterators. */
2349
2350 pub struct section_iter_res {
2351     SI: SectionIteratorRef,
2352 }
2353
2354 impl Drop for section_iter_res {
2355     fn drop(&self) {
2356         unsafe {
2357             llvm::LLVMDisposeSectionIterator(self.SI);
2358         }
2359     }
2360 }
2361
2362 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
2363     section_iter_res {
2364         SI: SI
2365     }
2366 }
2367
2368 pub struct SectionIter {
2369     llsi: SectionIteratorRef,
2370     dtor: @section_iter_res
2371 }
2372
2373 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2374     unsafe {
2375         let llsi = llvm::LLVMGetSections(llof);
2376         SectionIter {
2377             llsi: llsi,
2378             dtor: @section_iter_res(llsi)
2379         }
2380     }
2381 }