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