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