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