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