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