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