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