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