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