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