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