]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/ffi.rs
Make trans const eval error on overflow and NaN, matching HIR const eval.
[rust.git] / src / librustc_llvm / ffi.rs
1 // Copyright 2012-2015 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 // FIXME: Rename 'DIGlobalVariable' to 'DIGlobalVariableExpression'
12 // once support for LLVM 3.9 is dropped.
13 //
14 // This method was changed in this LLVM patch:
15 // https://reviews.llvm.org/D26769
16
17 use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
18                 DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
19                 DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
20                 DINameSpace, DIFlags};
21
22 use libc::{c_uint, c_int, size_t, c_char};
23 use libc::{c_longlong, c_ulonglong, c_void};
24
25 use RustStringRef;
26
27 pub type Opcode = u32;
28 pub type Bool = c_uint;
29
30 pub const True: Bool = 1 as Bool;
31 pub const False: Bool = 0 as Bool;
32
33 #[derive(Copy, Clone, PartialEq)]
34 #[repr(C)]
35 pub enum LLVMRustResult {
36     Success,
37     Failure,
38 }
39 // Consts for the LLVM CallConv type, pre-cast to usize.
40
41 /// LLVM CallingConv::ID. Should we wrap this?
42 #[derive(Copy, Clone, PartialEq, Debug)]
43 #[repr(C)]
44 pub enum CallConv {
45     CCallConv = 0,
46     FastCallConv = 8,
47     ColdCallConv = 9,
48     X86StdcallCallConv = 64,
49     X86FastcallCallConv = 65,
50     ArmAapcsCallConv = 67,
51     Msp430Intr = 69,
52     X86_ThisCall = 70,
53     PtxKernel = 71,
54     X86_64_SysV = 78,
55     X86_64_Win64 = 79,
56     X86_VectorCall = 80,
57     X86_Intr = 83,
58 }
59
60 /// LLVMRustLinkage
61 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
62 #[repr(C)]
63 pub enum Linkage {
64     ExternalLinkage = 0,
65     AvailableExternallyLinkage = 1,
66     LinkOnceAnyLinkage = 2,
67     LinkOnceODRLinkage = 3,
68     WeakAnyLinkage = 4,
69     WeakODRLinkage = 5,
70     AppendingLinkage = 6,
71     InternalLinkage = 7,
72     PrivateLinkage = 8,
73     ExternalWeakLinkage = 9,
74     CommonLinkage = 10,
75 }
76
77 // LLVMRustVisibility
78 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
79 #[repr(C)]
80 pub enum Visibility {
81     Default = 0,
82     Hidden = 1,
83     Protected = 2,
84 }
85
86 /// LLVMDiagnosticSeverity
87 #[derive(Copy, Clone, Debug)]
88 #[repr(C)]
89 pub enum DiagnosticSeverity {
90     Error = 0,
91     Warning = 1,
92     Remark = 2,
93     Note = 3,
94 }
95
96 /// LLVMDLLStorageClass
97 #[derive(Copy, Clone)]
98 #[repr(C)]
99 pub enum DLLStorageClass {
100     Default = 0,
101     DllImport = 1, // Function to be imported from DLL.
102     DllExport = 2, // Function to be accessible from DLL.
103 }
104
105 /// Matches LLVMRustAttribute in rustllvm.h
106 /// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
107 /// though it is not ABI compatible (since it's a C++ enum)
108 #[repr(C)]
109 #[derive(Copy, Clone, Debug)]
110 pub enum Attribute {
111     AlwaysInline    = 0,
112     ByVal           = 1,
113     Cold            = 2,
114     InlineHint      = 3,
115     MinSize         = 4,
116     Naked           = 5,
117     NoAlias         = 6,
118     NoCapture       = 7,
119     NoInline        = 8,
120     NonNull         = 9,
121     NoRedZone       = 10,
122     NoReturn        = 11,
123     NoUnwind        = 12,
124     OptimizeForSize = 13,
125     ReadOnly        = 14,
126     SExt            = 15,
127     StructRet       = 16,
128     UWTable         = 17,
129     ZExt            = 18,
130     InReg           = 19,
131     SanitizeThread  = 20,
132     SanitizeAddress = 21,
133     SanitizeMemory  = 22,
134 }
135
136 /// LLVMIntPredicate
137 #[derive(Copy, Clone)]
138 #[repr(C)]
139 pub enum IntPredicate {
140     IntEQ = 32,
141     IntNE = 33,
142     IntUGT = 34,
143     IntUGE = 35,
144     IntULT = 36,
145     IntULE = 37,
146     IntSGT = 38,
147     IntSGE = 39,
148     IntSLT = 40,
149     IntSLE = 41,
150 }
151
152 /// LLVMRealPredicate
153 #[derive(Copy, Clone)]
154 #[repr(C)]
155 pub enum RealPredicate {
156     RealPredicateFalse = 0,
157     RealOEQ = 1,
158     RealOGT = 2,
159     RealOGE = 3,
160     RealOLT = 4,
161     RealOLE = 5,
162     RealONE = 6,
163     RealORD = 7,
164     RealUNO = 8,
165     RealUEQ = 9,
166     RealUGT = 10,
167     RealUGE = 11,
168     RealULT = 12,
169     RealULE = 13,
170     RealUNE = 14,
171     RealPredicateTrue = 15,
172 }
173
174 /// LLVMTypeKind
175 #[derive(Copy, Clone, PartialEq, Debug)]
176 #[repr(C)]
177 pub enum TypeKind {
178     Void = 0,
179     Half = 1,
180     Float = 2,
181     Double = 3,
182     X86_FP80 = 4,
183     FP128 = 5,
184     PPC_FP128 = 6,
185     Label = 7,
186     Integer = 8,
187     Function = 9,
188     Struct = 10,
189     Array = 11,
190     Pointer = 12,
191     Vector = 13,
192     Metadata = 14,
193     X86_MMX = 15,
194     Token = 16,
195 }
196
197 /// LLVMAtomicRmwBinOp
198 #[derive(Copy, Clone)]
199 #[repr(C)]
200 pub enum AtomicRmwBinOp {
201     AtomicXchg = 0,
202     AtomicAdd = 1,
203     AtomicSub = 2,
204     AtomicAnd = 3,
205     AtomicNand = 4,
206     AtomicOr = 5,
207     AtomicXor = 6,
208     AtomicMax = 7,
209     AtomicMin = 8,
210     AtomicUMax = 9,
211     AtomicUMin = 10,
212 }
213
214 /// LLVMAtomicOrdering
215 #[derive(Copy, Clone)]
216 #[repr(C)]
217 pub enum AtomicOrdering {
218     NotAtomic = 0,
219     Unordered = 1,
220     Monotonic = 2,
221     // Consume = 3,  // Not specified yet.
222     Acquire = 4,
223     Release = 5,
224     AcquireRelease = 6,
225     SequentiallyConsistent = 7,
226 }
227
228 /// LLVMRustSynchronizationScope
229 #[derive(Copy, Clone)]
230 #[repr(C)]
231 pub enum SynchronizationScope {
232     Other,
233     SingleThread,
234     CrossThread,
235 }
236
237 /// LLVMRustFileType
238 #[derive(Copy, Clone)]
239 #[repr(C)]
240 pub enum FileType {
241     Other,
242     AssemblyFile,
243     ObjectFile,
244 }
245
246 /// LLVMMetadataType
247 #[derive(Copy, Clone)]
248 #[repr(C)]
249 pub enum MetadataType {
250     MD_dbg = 0,
251     MD_tbaa = 1,
252     MD_prof = 2,
253     MD_fpmath = 3,
254     MD_range = 4,
255     MD_tbaa_struct = 5,
256     MD_invariant_load = 6,
257     MD_alias_scope = 7,
258     MD_noalias = 8,
259     MD_nontemporal = 9,
260     MD_mem_parallel_loop_access = 10,
261     MD_nonnull = 11,
262 }
263
264 /// LLVMRustAsmDialect
265 #[derive(Copy, Clone)]
266 #[repr(C)]
267 pub enum AsmDialect {
268     Other,
269     Att,
270     Intel,
271 }
272
273 /// LLVMRustCodeGenOptLevel
274 #[derive(Copy, Clone, PartialEq)]
275 #[repr(C)]
276 pub enum CodeGenOptLevel {
277     Other,
278     None,
279     Less,
280     Default,
281     Aggressive,
282 }
283
284 /// LLVMRelocMode
285 #[derive(Copy, Clone, PartialEq)]
286 #[repr(C)]
287 pub enum RelocMode {
288     Default,
289     Static,
290     PIC,
291     DynamicNoPic,
292     ROPI,
293     RWPI,
294     ROPI_RWPI,
295 }
296
297 /// LLVMRustCodeModel
298 #[derive(Copy, Clone)]
299 #[repr(C)]
300 pub enum CodeModel {
301     Other,
302     Default,
303     JITDefault,
304     Small,
305     Kernel,
306     Medium,
307     Large,
308 }
309
310 /// LLVMRustDiagnosticKind
311 #[derive(Copy, Clone)]
312 #[repr(C)]
313 pub enum DiagnosticKind {
314     Other,
315     InlineAsm,
316     StackSize,
317     DebugMetadataVersion,
318     SampleProfile,
319     OptimizationRemark,
320     OptimizationRemarkMissed,
321     OptimizationRemarkAnalysis,
322     OptimizationRemarkAnalysisFPCommute,
323     OptimizationRemarkAnalysisAliasing,
324     OptimizationRemarkOther,
325     OptimizationFailure,
326 }
327
328 /// LLVMRustArchiveKind
329 #[derive(Copy, Clone)]
330 #[repr(C)]
331 pub enum ArchiveKind {
332     Other,
333     K_GNU,
334     K_MIPS64,
335     K_BSD,
336     K_COFF,
337 }
338
339 /// LLVMRustPassKind
340 #[derive(Copy, Clone, PartialEq, Debug)]
341 #[repr(C)]
342 pub enum PassKind {
343     Other,
344     Function,
345     Module,
346 }
347
348 /// LLVMRustThinLTOData
349 pub enum ThinLTOData {}
350
351 /// LLVMRustThinLTOBuffer
352 pub enum ThinLTOBuffer {}
353
354 /// LLVMRustThinLTOModule
355 #[repr(C)]
356 pub struct ThinLTOModule {
357     pub identifier: *const c_char,
358     pub data: *const u8,
359     pub len: usize,
360 }
361
362 /// LLVMThreadLocalMode
363 #[derive(Copy, Clone)]
364 #[repr(C)]
365 pub enum ThreadLocalMode {
366   NotThreadLocal,
367   GeneralDynamic,
368   LocalDynamic,
369   InitialExec,
370   LocalExec
371 }
372
373 // Opaque pointer types
374 #[allow(missing_copy_implementations)]
375 pub enum Module_opaque {}
376 pub type ModuleRef = *mut Module_opaque;
377 #[allow(missing_copy_implementations)]
378 pub enum Context_opaque {}
379 pub type ContextRef = *mut Context_opaque;
380 #[allow(missing_copy_implementations)]
381 pub enum Type_opaque {}
382 pub type TypeRef = *mut Type_opaque;
383 #[allow(missing_copy_implementations)]
384 pub enum Value_opaque {}
385 pub type ValueRef = *mut Value_opaque;
386 #[allow(missing_copy_implementations)]
387 pub enum Metadata_opaque {}
388 pub type MetadataRef = *mut Metadata_opaque;
389 #[allow(missing_copy_implementations)]
390 pub enum BasicBlock_opaque {}
391 pub type BasicBlockRef = *mut BasicBlock_opaque;
392 #[allow(missing_copy_implementations)]
393 pub enum Builder_opaque {}
394 pub type BuilderRef = *mut Builder_opaque;
395 #[allow(missing_copy_implementations)]
396 pub enum ExecutionEngine_opaque {}
397 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
398 #[allow(missing_copy_implementations)]
399 pub enum MemoryBuffer_opaque {}
400 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
401 #[allow(missing_copy_implementations)]
402 pub enum PassManager_opaque {}
403 pub type PassManagerRef = *mut PassManager_opaque;
404 #[allow(missing_copy_implementations)]
405 pub enum PassManagerBuilder_opaque {}
406 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
407 #[allow(missing_copy_implementations)]
408 pub enum Use_opaque {}
409 pub type UseRef = *mut Use_opaque;
410 #[allow(missing_copy_implementations)]
411 pub enum TargetData_opaque {}
412 pub type TargetDataRef = *mut TargetData_opaque;
413 #[allow(missing_copy_implementations)]
414 pub enum ObjectFile_opaque {}
415 pub type ObjectFileRef = *mut ObjectFile_opaque;
416 #[allow(missing_copy_implementations)]
417 pub enum SectionIterator_opaque {}
418 pub type SectionIteratorRef = *mut SectionIterator_opaque;
419 #[allow(missing_copy_implementations)]
420 pub enum Pass_opaque {}
421 pub type PassRef = *mut Pass_opaque;
422 #[allow(missing_copy_implementations)]
423 pub enum TargetMachine_opaque {}
424 pub type TargetMachineRef = *mut TargetMachine_opaque;
425 pub enum Archive_opaque {}
426 pub type ArchiveRef = *mut Archive_opaque;
427 pub enum ArchiveIterator_opaque {}
428 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
429 pub enum ArchiveChild_opaque {}
430 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
431 #[allow(missing_copy_implementations)]
432 pub enum Twine_opaque {}
433 pub type TwineRef = *mut Twine_opaque;
434 #[allow(missing_copy_implementations)]
435 pub enum DiagnosticInfo_opaque {}
436 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
437 #[allow(missing_copy_implementations)]
438 pub enum DebugLoc_opaque {}
439 pub type DebugLocRef = *mut DebugLoc_opaque;
440 #[allow(missing_copy_implementations)]
441 pub enum SMDiagnostic_opaque {}
442 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
443 #[allow(missing_copy_implementations)]
444 pub enum RustArchiveMember_opaque {}
445 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
446 #[allow(missing_copy_implementations)]
447 pub enum OperandBundleDef_opaque {}
448 pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
449
450 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
451 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
452
453
454 pub mod debuginfo {
455     use super::MetadataRef;
456
457     #[allow(missing_copy_implementations)]
458     pub enum DIBuilder_opaque {}
459     pub type DIBuilderRef = *mut DIBuilder_opaque;
460
461     pub type DIDescriptor = MetadataRef;
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 DINameSpace = DIScope;
468     pub type DIType = DIDescriptor;
469     pub type DIBasicType = DIType;
470     pub type DIDerivedType = DIType;
471     pub type DICompositeType = DIDerivedType;
472     pub type DIVariable = DIDescriptor;
473     pub type DIGlobalVariable = DIDescriptor;
474     pub type DIArray = DIDescriptor;
475     pub type DISubrange = DIDescriptor;
476     pub type DIEnumerator = DIDescriptor;
477     pub type DITemplateTypeParameter = DIDescriptor;
478
479     // These values **must** match with LLVMRustDIFlags!!
480     bitflags! {
481         #[repr(C)]
482         #[derive(Default)]
483         pub struct DIFlags: ::libc::uint32_t {
484             const FlagZero                = 0;
485             const FlagPrivate             = 1;
486             const FlagProtected           = 2;
487             const FlagPublic              = 3;
488             const FlagFwdDecl             = (1 << 2);
489             const FlagAppleBlock          = (1 << 3);
490             const FlagBlockByrefStruct    = (1 << 4);
491             const FlagVirtual             = (1 << 5);
492             const FlagArtificial          = (1 << 6);
493             const FlagExplicit            = (1 << 7);
494             const FlagPrototyped          = (1 << 8);
495             const FlagObjcClassComplete   = (1 << 9);
496             const FlagObjectPointer       = (1 << 10);
497             const FlagVector              = (1 << 11);
498             const FlagStaticMember        = (1 << 12);
499             const FlagLValueReference     = (1 << 13);
500             const FlagRValueReference     = (1 << 14);
501             const FlagMainSubprogram      = (1 << 21);
502         }
503     }
504 }
505
506 pub enum ModuleBuffer {}
507
508 // Link to our native llvm bindings (things that we need to use the C++ api
509 // for) and because llvm is written in C++ we need to link against libstdc++
510 //
511 // You'll probably notice that there is an omission of all LLVM libraries
512 // from this location. This is because the set of LLVM libraries that we
513 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
514 // figure out the exact set of libraries. To do this, the build system
515 // generates an llvmdeps.rs file next to this one which will be
516 // automatically updated whenever LLVM is updated to include an up-to-date
517 // set of the libraries we need to link to LLVM for.
518 #[link(name = "rustllvm", kind = "static")] // not quite true but good enough
519 extern "C" {
520     // Create and destroy contexts.
521     pub fn LLVMContextCreate() -> ContextRef;
522     pub fn LLVMContextDispose(C: ContextRef);
523     pub fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *const c_char, SLen: c_uint) -> c_uint;
524
525     // Create and destroy modules.
526     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: ContextRef) -> ModuleRef;
527     pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
528     pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
529     pub fn LLVMDisposeModule(M: ModuleRef);
530
531     /// Data layout. See Module::getDataLayout.
532     pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
533     pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
534
535     /// See Module::dump.
536     pub fn LLVMDumpModule(M: ModuleRef);
537
538     /// See Module::setModuleInlineAsm.
539     pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
540     pub fn LLVMRustAppendModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
541
542     /// See llvm::LLVMTypeKind::getTypeID.
543     pub fn LLVMRustGetTypeKind(Ty: TypeRef) -> TypeKind;
544
545     /// See llvm::Value::getContext
546     pub fn LLVMRustGetValueContext(V: ValueRef) -> ContextRef;
547
548     // Operations on integer types
549     pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
550     pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
551     pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
552     pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
553     pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
554     pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint) -> TypeRef;
555
556     pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
557
558     // Operations on real types
559     pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
560     pub fn LLVMDoubleTypeInContext(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 LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
569     pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
570     pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
571
572     // Operations on struct types
573     pub fn LLVMStructTypeInContext(C: ContextRef,
574                                    ElementTypes: *const TypeRef,
575                                    ElementCount: c_uint,
576                                    Packed: Bool)
577                                    -> TypeRef;
578     pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
579     pub fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *mut TypeRef);
580     pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
581
582     // Operations on array, pointer, and vector types (sequence types)
583     pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
584     pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint) -> TypeRef;
585     pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint) -> TypeRef;
586
587     pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
588     pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
589     pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
590
591     // Operations on other types
592     pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
593     pub fn LLVMRustMetadataTypeInContext(C: ContextRef) -> TypeRef;
594
595     // Operations on all values
596     pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
597     pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
598     pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
599     pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
600     pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
601
602     // Operations on Uses
603     pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
604     pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
605     pub fn LLVMGetUser(U: UseRef) -> ValueRef;
606
607     // Operations on Users
608     pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
609
610     // Operations on constants of any type
611     pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
612     pub fn LLVMConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef;
613     pub fn LLVMConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef;
614     // only for isize/vector
615     pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
616     pub fn LLVMIsNull(Val: ValueRef) -> Bool;
617     pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
618
619     // Operations on metadata
620     pub fn LLVMMDStringInContext(C: ContextRef, Str: *const c_char, SLen: c_uint) -> ValueRef;
621     pub fn LLVMMDNodeInContext(C: ContextRef, Vals: *const ValueRef, Count: c_uint) -> ValueRef;
622     pub fn LLVMAddNamedMetadataOperand(M: ModuleRef, Name: *const c_char, Val: ValueRef);
623
624     // Operations on scalar constants
625     pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) -> ValueRef;
626     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: TypeRef, Wn: c_uint, Ws: *const u64) -> ValueRef;
627     pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
628     pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
629     pub fn LLVMRustConstInt128Get(ConstantVal: ValueRef, SExt: bool,
630                                   high: *mut u64, low: *mut u64) -> bool;
631
632
633     // Operations on composite constants
634     pub fn LLVMConstStringInContext(C: ContextRef,
635                                     Str: *const c_char,
636                                     Length: c_uint,
637                                     DontNullTerminate: Bool)
638                                     -> ValueRef;
639     pub fn LLVMConstStructInContext(C: ContextRef,
640                                     ConstantVals: *const ValueRef,
641                                     Count: c_uint,
642                                     Packed: Bool)
643                                     -> ValueRef;
644
645     pub fn LLVMConstArray(ElementTy: TypeRef,
646                           ConstantVals: *const ValueRef,
647                           Length: c_uint)
648                           -> ValueRef;
649     pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint) -> ValueRef;
650
651     // Constant expressions
652     pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
653     pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
654     pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
655     pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
656     pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
657     pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
658     pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
659     pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
660     pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
661     pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
662     pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
663     pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
664     pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
665     pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
666     pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
667     pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
668     pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
669     pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
670     pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
671     pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
672     pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
673     pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
674     pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
675     pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
676     pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
677     pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
678     pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
679     pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
680     pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
681     pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
682     pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
683     pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
684     pub fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef, isSigned: Bool) -> ValueRef;
685     pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
686     pub fn LLVMConstExtractValue(AggConstant: ValueRef,
687                                  IdxList: *const c_uint,
688                                  NumIdx: c_uint)
689                                  -> ValueRef;
690     pub fn LLVMConstInlineAsm(Ty: TypeRef,
691                               AsmString: *const c_char,
692                               Constraints: *const c_char,
693                               HasSideEffects: Bool,
694                               IsAlignStack: Bool)
695                               -> ValueRef;
696
697
698     // Operations on global variables, functions, and aliases (globals)
699     pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
700     pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
701     pub fn LLVMRustGetLinkage(Global: ValueRef) -> Linkage;
702     pub fn LLVMRustSetLinkage(Global: ValueRef, RustLinkage: Linkage);
703     pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
704     pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
705     pub fn LLVMRustGetVisibility(Global: ValueRef) -> Visibility;
706     pub fn LLVMRustSetVisibility(Global: ValueRef, Viz: Visibility);
707     pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
708     pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
709     pub fn LLVMSetDLLStorageClass(V: ValueRef, C: DLLStorageClass);
710
711
712     // Operations on global variables
713     pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
714     pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char) -> ValueRef;
715     pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
716     pub fn LLVMRustGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
717     pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
718     pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
719     pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
720     pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
721     pub fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef);
722     pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
723     pub fn LLVMSetThreadLocalMode(GlobalVar: ValueRef, Mode: ThreadLocalMode);
724     pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
725     pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
726     pub fn LLVMRustGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
727     pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
728
729     // Operations on functions
730     pub fn LLVMAddFunction(M: ModuleRef, Name: *const c_char, FunctionTy: TypeRef) -> ValueRef;
731     pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
732     pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
733     pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
734     pub fn LLVMRustGetOrInsertFunction(M: ModuleRef,
735                                        Name: *const c_char,
736                                        FunctionTy: TypeRef)
737                                        -> ValueRef;
738     pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
739     pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: u64);
740     pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: Attribute);
741     pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef,
742                                               index: c_uint,
743                                               Name: *const c_char,
744                                               Value: *const c_char);
745     pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: Attribute);
746
747     // Operations on parameters
748     pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
749     pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
750
751     // Operations on basic blocks
752     pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
753     pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
754     pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
755                                          Fn: ValueRef,
756                                          Name: *const c_char)
757                                          -> BasicBlockRef;
758     pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
759
760     // Operations on instructions
761     pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
762     pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
763     pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
764     pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
765
766     // Operations on call sites
767     pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
768     pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: Attribute);
769     pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef, index: c_uint, bytes: u64);
770
771     // Operations on load/store instructions (only)
772     pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
773
774     // Operations on phi nodes
775     pub fn LLVMAddIncoming(PhiNode: ValueRef,
776                            IncomingValues: *const ValueRef,
777                            IncomingBlocks: *const BasicBlockRef,
778                            Count: c_uint);
779
780     // Instruction builders
781     pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
782     pub fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef, Instr: ValueRef);
783     pub fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef);
784     pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef);
785     pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
786     pub fn LLVMDisposeBuilder(Builder: BuilderRef);
787
788     // Metadata
789     pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
790     pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
791     pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
792
793     // Terminators
794     pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
795     pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
796     pub fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *const ValueRef, N: c_uint) -> ValueRef;
797     pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
798     pub fn LLVMBuildCondBr(B: BuilderRef,
799                            If: ValueRef,
800                            Then: BasicBlockRef,
801                            Else: BasicBlockRef)
802                            -> ValueRef;
803     pub fn LLVMBuildSwitch(B: BuilderRef,
804                            V: ValueRef,
805                            Else: BasicBlockRef,
806                            NumCases: c_uint)
807                            -> ValueRef;
808     pub fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef, NumDests: c_uint) -> ValueRef;
809     pub fn LLVMRustBuildInvoke(B: BuilderRef,
810                                Fn: ValueRef,
811                                Args: *const ValueRef,
812                                NumArgs: c_uint,
813                                Then: BasicBlockRef,
814                                Catch: BasicBlockRef,
815                                Bundle: OperandBundleDefRef,
816                                Name: *const c_char)
817                                -> ValueRef;
818     pub fn LLVMRustBuildLandingPad(B: BuilderRef,
819                                    Ty: TypeRef,
820                                    PersFn: ValueRef,
821                                    NumClauses: c_uint,
822                                    Name: *const c_char,
823                                    F: ValueRef)
824                                    -> ValueRef;
825     pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
826     pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
827
828     pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
829                                    ParentPad: ValueRef,
830                                    ArgCnt: c_uint,
831                                    Args: *const ValueRef,
832                                    Name: *const c_char)
833                                    -> ValueRef;
834     pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
835                                    CleanupPad: ValueRef,
836                                    UnwindBB: BasicBlockRef)
837                                    -> ValueRef;
838     pub fn LLVMRustBuildCatchPad(B: BuilderRef,
839                                  ParentPad: ValueRef,
840                                  ArgCnt: c_uint,
841                                  Args: *const ValueRef,
842                                  Name: *const c_char)
843                                  -> ValueRef;
844     pub fn LLVMRustBuildCatchRet(B: BuilderRef, Pad: ValueRef, BB: BasicBlockRef) -> ValueRef;
845     pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
846                                     ParentPad: ValueRef,
847                                     BB: BasicBlockRef,
848                                     NumHandlers: c_uint,
849                                     Name: *const c_char)
850                                     -> ValueRef;
851     pub fn LLVMRustAddHandler(CatchSwitch: ValueRef, Handler: BasicBlockRef);
852     pub fn LLVMSetPersonalityFn(Func: ValueRef, Pers: ValueRef);
853
854     // Add a case to the switch instruction
855     pub fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
856
857     // Add a clause to the landing pad instruction
858     pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
859
860     // Set the cleanup on a landing pad instruction
861     pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
862
863     // Arithmetic
864     pub fn LLVMBuildAdd(B: BuilderRef,
865                         LHS: ValueRef,
866                         RHS: ValueRef,
867                         Name: *const c_char)
868                         -> ValueRef;
869     pub fn LLVMBuildNSWAdd(B: BuilderRef,
870                            LHS: ValueRef,
871                            RHS: ValueRef,
872                            Name: *const c_char)
873                            -> ValueRef;
874     pub fn LLVMBuildNUWAdd(B: BuilderRef,
875                            LHS: ValueRef,
876                            RHS: ValueRef,
877                            Name: *const c_char)
878                            -> ValueRef;
879     pub fn LLVMBuildFAdd(B: BuilderRef,
880                          LHS: ValueRef,
881                          RHS: ValueRef,
882                          Name: *const c_char)
883                          -> ValueRef;
884     pub fn LLVMBuildSub(B: BuilderRef,
885                         LHS: ValueRef,
886                         RHS: ValueRef,
887                         Name: *const c_char)
888                         -> ValueRef;
889     pub fn LLVMBuildNSWSub(B: BuilderRef,
890                            LHS: ValueRef,
891                            RHS: ValueRef,
892                            Name: *const c_char)
893                            -> ValueRef;
894     pub fn LLVMBuildNUWSub(B: BuilderRef,
895                            LHS: ValueRef,
896                            RHS: ValueRef,
897                            Name: *const c_char)
898                            -> ValueRef;
899     pub fn LLVMBuildFSub(B: BuilderRef,
900                          LHS: ValueRef,
901                          RHS: ValueRef,
902                          Name: *const c_char)
903                          -> ValueRef;
904     pub fn LLVMBuildMul(B: BuilderRef,
905                         LHS: ValueRef,
906                         RHS: ValueRef,
907                         Name: *const c_char)
908                         -> ValueRef;
909     pub fn LLVMBuildNSWMul(B: BuilderRef,
910                            LHS: ValueRef,
911                            RHS: ValueRef,
912                            Name: *const c_char)
913                            -> ValueRef;
914     pub fn LLVMBuildNUWMul(B: BuilderRef,
915                            LHS: ValueRef,
916                            RHS: ValueRef,
917                            Name: *const c_char)
918                            -> ValueRef;
919     pub fn LLVMBuildFMul(B: BuilderRef,
920                          LHS: ValueRef,
921                          RHS: ValueRef,
922                          Name: *const c_char)
923                          -> ValueRef;
924     pub fn LLVMBuildUDiv(B: BuilderRef,
925                          LHS: ValueRef,
926                          RHS: ValueRef,
927                          Name: *const c_char)
928                          -> ValueRef;
929     pub fn LLVMBuildSDiv(B: BuilderRef,
930                          LHS: ValueRef,
931                          RHS: ValueRef,
932                          Name: *const c_char)
933                          -> ValueRef;
934     pub fn LLVMBuildExactSDiv(B: BuilderRef,
935                               LHS: ValueRef,
936                               RHS: ValueRef,
937                               Name: *const c_char)
938                               -> ValueRef;
939     pub fn LLVMBuildFDiv(B: BuilderRef,
940                          LHS: ValueRef,
941                          RHS: ValueRef,
942                          Name: *const c_char)
943                          -> ValueRef;
944     pub fn LLVMBuildURem(B: BuilderRef,
945                          LHS: ValueRef,
946                          RHS: ValueRef,
947                          Name: *const c_char)
948                          -> ValueRef;
949     pub fn LLVMBuildSRem(B: BuilderRef,
950                          LHS: ValueRef,
951                          RHS: ValueRef,
952                          Name: *const c_char)
953                          -> ValueRef;
954     pub fn LLVMBuildFRem(B: BuilderRef,
955                          LHS: ValueRef,
956                          RHS: ValueRef,
957                          Name: *const c_char)
958                          -> ValueRef;
959     pub fn LLVMBuildShl(B: BuilderRef,
960                         LHS: ValueRef,
961                         RHS: ValueRef,
962                         Name: *const c_char)
963                         -> ValueRef;
964     pub fn LLVMBuildLShr(B: BuilderRef,
965                          LHS: ValueRef,
966                          RHS: ValueRef,
967                          Name: *const c_char)
968                          -> ValueRef;
969     pub fn LLVMBuildAShr(B: BuilderRef,
970                          LHS: ValueRef,
971                          RHS: ValueRef,
972                          Name: *const c_char)
973                          -> ValueRef;
974     pub fn LLVMBuildAnd(B: BuilderRef,
975                         LHS: ValueRef,
976                         RHS: ValueRef,
977                         Name: *const c_char)
978                         -> ValueRef;
979     pub fn LLVMBuildOr(B: BuilderRef,
980                        LHS: ValueRef,
981                        RHS: ValueRef,
982                        Name: *const c_char)
983                        -> ValueRef;
984     pub fn LLVMBuildXor(B: BuilderRef,
985                         LHS: ValueRef,
986                         RHS: ValueRef,
987                         Name: *const c_char)
988                         -> ValueRef;
989     pub fn LLVMBuildBinOp(B: BuilderRef,
990                           Op: Opcode,
991                           LHS: ValueRef,
992                           RHS: ValueRef,
993                           Name: *const c_char)
994                           -> ValueRef;
995     pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef;
996     pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef;
997     pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef;
998     pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef;
999     pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef;
1000     pub fn LLVMRustSetHasUnsafeAlgebra(Instr: ValueRef);
1001
1002     // Memory
1003     pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char) -> ValueRef;
1004     pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1005     pub fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *const c_char) -> ValueRef;
1006
1007     pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) -> ValueRef;
1008
1009     pub fn LLVMBuildGEP(B: BuilderRef,
1010                         Pointer: ValueRef,
1011                         Indices: *const ValueRef,
1012                         NumIndices: c_uint,
1013                         Name: *const c_char)
1014                         -> ValueRef;
1015     pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1016                                 Pointer: ValueRef,
1017                                 Indices: *const ValueRef,
1018                                 NumIndices: c_uint,
1019                                 Name: *const c_char)
1020                                 -> ValueRef;
1021     pub fn LLVMBuildStructGEP(B: BuilderRef,
1022                               Pointer: ValueRef,
1023                               Idx: c_uint,
1024                               Name: *const c_char)
1025                               -> ValueRef;
1026     pub fn LLVMBuildGlobalString(B: BuilderRef,
1027                                  Str: *const c_char,
1028                                  Name: *const c_char)
1029                                  -> ValueRef;
1030     pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1031                                     Str: *const c_char,
1032                                     Name: *const c_char)
1033                                     -> ValueRef;
1034
1035     // Casts
1036     pub fn LLVMBuildTrunc(B: BuilderRef,
1037                           Val: ValueRef,
1038                           DestTy: TypeRef,
1039                           Name: *const c_char)
1040                           -> ValueRef;
1041     pub fn LLVMBuildZExt(B: BuilderRef,
1042                          Val: ValueRef,
1043                          DestTy: TypeRef,
1044                          Name: *const c_char)
1045                          -> ValueRef;
1046     pub fn LLVMBuildSExt(B: BuilderRef,
1047                          Val: ValueRef,
1048                          DestTy: TypeRef,
1049                          Name: *const c_char)
1050                          -> ValueRef;
1051     pub fn LLVMBuildFPToUI(B: BuilderRef,
1052                            Val: ValueRef,
1053                            DestTy: TypeRef,
1054                            Name: *const c_char)
1055                            -> ValueRef;
1056     pub fn LLVMBuildFPToSI(B: BuilderRef,
1057                            Val: ValueRef,
1058                            DestTy: TypeRef,
1059                            Name: *const c_char)
1060                            -> ValueRef;
1061     pub fn LLVMBuildUIToFP(B: BuilderRef,
1062                            Val: ValueRef,
1063                            DestTy: TypeRef,
1064                            Name: *const c_char)
1065                            -> ValueRef;
1066     pub fn LLVMBuildSIToFP(B: BuilderRef,
1067                            Val: ValueRef,
1068                            DestTy: TypeRef,
1069                            Name: *const c_char)
1070                            -> ValueRef;
1071     pub fn LLVMBuildFPTrunc(B: BuilderRef,
1072                             Val: ValueRef,
1073                             DestTy: TypeRef,
1074                             Name: *const c_char)
1075                             -> ValueRef;
1076     pub fn LLVMBuildFPExt(B: BuilderRef,
1077                           Val: ValueRef,
1078                           DestTy: TypeRef,
1079                           Name: *const c_char)
1080                           -> ValueRef;
1081     pub fn LLVMBuildPtrToInt(B: BuilderRef,
1082                              Val: ValueRef,
1083                              DestTy: TypeRef,
1084                              Name: *const c_char)
1085                              -> ValueRef;
1086     pub fn LLVMBuildIntToPtr(B: BuilderRef,
1087                              Val: ValueRef,
1088                              DestTy: TypeRef,
1089                              Name: *const c_char)
1090                              -> ValueRef;
1091     pub fn LLVMBuildBitCast(B: BuilderRef,
1092                             Val: ValueRef,
1093                             DestTy: TypeRef,
1094                             Name: *const c_char)
1095                             -> ValueRef;
1096     pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1097                                   Val: ValueRef,
1098                                   DestTy: TypeRef,
1099                                   Name: *const c_char)
1100                                   -> ValueRef;
1101     pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1102                                   Val: ValueRef,
1103                                   DestTy: TypeRef,
1104                                   Name: *const c_char)
1105                                   -> ValueRef;
1106     pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1107                                    Val: ValueRef,
1108                                    DestTy: TypeRef,
1109                                    Name: *const c_char)
1110                                    -> ValueRef;
1111     pub fn LLVMBuildCast(B: BuilderRef,
1112                          Op: Opcode,
1113                          Val: ValueRef,
1114                          DestTy: TypeRef,
1115                          Name: *const c_char)
1116                          -> ValueRef;
1117     pub fn LLVMBuildPointerCast(B: BuilderRef,
1118                                 Val: ValueRef,
1119                                 DestTy: TypeRef,
1120                                 Name: *const c_char)
1121                                 -> ValueRef;
1122     pub fn LLVMRustBuildIntCast(B: BuilderRef,
1123                                 Val: ValueRef,
1124                                 DestTy: TypeRef,
1125                                 IsSized: bool)
1126                                 -> ValueRef;
1127     pub fn LLVMBuildFPCast(B: BuilderRef,
1128                            Val: ValueRef,
1129                            DestTy: TypeRef,
1130                            Name: *const c_char)
1131                            -> ValueRef;
1132
1133     // Comparisons
1134     pub fn LLVMBuildICmp(B: BuilderRef,
1135                          Op: c_uint,
1136                          LHS: ValueRef,
1137                          RHS: ValueRef,
1138                          Name: *const c_char)
1139                          -> ValueRef;
1140     pub fn LLVMBuildFCmp(B: BuilderRef,
1141                          Op: c_uint,
1142                          LHS: ValueRef,
1143                          RHS: ValueRef,
1144                          Name: *const c_char)
1145                          -> ValueRef;
1146
1147     // Miscellaneous instructions
1148     pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char) -> ValueRef;
1149     pub fn LLVMRustBuildCall(B: BuilderRef,
1150                              Fn: ValueRef,
1151                              Args: *const ValueRef,
1152                              NumArgs: c_uint,
1153                              Bundle: OperandBundleDefRef,
1154                              Name: *const c_char)
1155                              -> ValueRef;
1156     pub fn LLVMBuildSelect(B: BuilderRef,
1157                            If: ValueRef,
1158                            Then: ValueRef,
1159                            Else: ValueRef,
1160                            Name: *const c_char)
1161                            -> ValueRef;
1162     pub fn LLVMBuildVAArg(B: BuilderRef,
1163                           list: ValueRef,
1164                           Ty: TypeRef,
1165                           Name: *const c_char)
1166                           -> ValueRef;
1167     pub fn LLVMBuildExtractElement(B: BuilderRef,
1168                                    VecVal: ValueRef,
1169                                    Index: ValueRef,
1170                                    Name: *const c_char)
1171                                    -> ValueRef;
1172     pub fn LLVMBuildInsertElement(B: BuilderRef,
1173                                   VecVal: ValueRef,
1174                                   EltVal: ValueRef,
1175                                   Index: ValueRef,
1176                                   Name: *const c_char)
1177                                   -> ValueRef;
1178     pub fn LLVMBuildShuffleVector(B: BuilderRef,
1179                                   V1: ValueRef,
1180                                   V2: ValueRef,
1181                                   Mask: ValueRef,
1182                                   Name: *const c_char)
1183                                   -> ValueRef;
1184     pub fn LLVMBuildExtractValue(B: BuilderRef,
1185                                  AggVal: ValueRef,
1186                                  Index: c_uint,
1187                                  Name: *const c_char)
1188                                  -> ValueRef;
1189     pub fn LLVMBuildInsertValue(B: BuilderRef,
1190                                 AggVal: ValueRef,
1191                                 EltVal: ValueRef,
1192                                 Index: c_uint,
1193                                 Name: *const c_char)
1194                                 -> ValueRef;
1195
1196     pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
1197     pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
1198     pub fn LLVMBuildPtrDiff(B: BuilderRef,
1199                             LHS: ValueRef,
1200                             RHS: ValueRef,
1201                             Name: *const c_char)
1202                             -> ValueRef;
1203
1204     // Atomic Operations
1205     pub fn LLVMRustBuildAtomicLoad(B: BuilderRef,
1206                                    PointerVal: ValueRef,
1207                                    Name: *const c_char,
1208                                    Order: AtomicOrdering,
1209                                    Alignment: c_uint)
1210                                    -> ValueRef;
1211
1212     pub fn LLVMRustBuildAtomicStore(B: BuilderRef,
1213                                     Val: ValueRef,
1214                                     Ptr: ValueRef,
1215                                     Order: AtomicOrdering,
1216                                     Alignment: c_uint)
1217                                     -> ValueRef;
1218
1219     pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef,
1220                                       LHS: ValueRef,
1221                                       CMP: ValueRef,
1222                                       RHS: ValueRef,
1223                                       Order: AtomicOrdering,
1224                                       FailureOrder: AtomicOrdering,
1225                                       Weak: Bool)
1226                                       -> ValueRef;
1227
1228     pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1229                               Op: AtomicRmwBinOp,
1230                               LHS: ValueRef,
1231                               RHS: ValueRef,
1232                               Order: AtomicOrdering,
1233                               SingleThreaded: Bool)
1234                               -> ValueRef;
1235
1236     pub fn LLVMRustBuildAtomicFence(B: BuilderRef,
1237                                     Order: AtomicOrdering,
1238                                     Scope: SynchronizationScope);
1239
1240
1241     // Selected entries from the downcasts.
1242     pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1243     pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1244
1245     /// Writes a module to the specified path. Returns 0 on success.
1246     pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1247
1248     /// Creates target data from a target layout string.
1249     pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1250     /// Number of bytes clobbered when doing a Store to *T.
1251     pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1252
1253     /// Distance between successive elements in an array of T. Includes ABI padding.
1254     pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1255
1256     /// Returns the preferred alignment of a type.
1257     pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1258     /// Returns the minimum alignment of a type.
1259     pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1260
1261     /// Computes the byte offset of the indexed struct element for a
1262     /// target.
1263     pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1264                                StructTy: TypeRef,
1265                                Element: c_uint)
1266                                -> c_ulonglong;
1267
1268     /// Disposes target data.
1269     pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1270
1271     /// Creates a pass manager.
1272     pub fn LLVMCreatePassManager() -> PassManagerRef;
1273
1274     /// Creates a function-by-function pass manager
1275     pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef) -> PassManagerRef;
1276
1277     /// Disposes a pass manager.
1278     pub fn LLVMDisposePassManager(PM: PassManagerRef);
1279
1280     /// Runs a pass manager on a module.
1281     pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1282
1283     pub fn LLVMInitializePasses();
1284
1285     pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1286     pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1287     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, Value: Bool);
1288     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef, Value: Bool);
1289     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: PassManagerBuilderRef,
1290                                                          threshold: c_uint);
1291     pub fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: PassManagerBuilderRef,
1292                                                            PM: PassManagerRef);
1293
1294     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: PassManagerBuilderRef,
1295                                                              PM: PassManagerRef);
1296     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(PMB: PassManagerBuilderRef,
1297                                                         PM: PassManagerRef,
1298                                                         Internalize: Bool,
1299                                                         RunInliner: Bool);
1300     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1301         PMB: PassManagerBuilderRef,
1302         PM: PassManagerRef) -> bool;
1303
1304     // Stuff that's in rustllvm/ because it's not upstream yet.
1305
1306     /// Opens an object file.
1307     pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1308     /// Closes an object file.
1309     pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1310
1311     /// Enumerates the sections in an object file.
1312     pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1313     /// Destroys a section iterator.
1314     pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1315     /// Returns true if the section iterator is at the end of the section
1316     /// list:
1317     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef, SI: SectionIteratorRef) -> Bool;
1318     /// Moves the section iterator to point to the next section.
1319     pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1320     /// Returns the current section size.
1321     pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1322     /// Returns the current section contents as a string buffer.
1323     pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1324
1325     /// Reads the given file and returns it as a memory buffer. Use
1326     /// LLVMDisposeMemoryBuffer() to get rid of it.
1327     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char) -> MemoryBufferRef;
1328
1329     pub fn LLVMStartMultithreaded() -> Bool;
1330
1331     /// Returns a string describing the last error caused by an LLVMRust* call.
1332     pub fn LLVMRustGetLastError() -> *const c_char;
1333
1334     /// Print the pass timings since static dtors aren't picking them up.
1335     pub fn LLVMRustPrintPassTimings();
1336
1337     pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1338
1339     pub fn LLVMStructSetBody(StructTy: TypeRef,
1340                              ElementTypes: *const TypeRef,
1341                              ElementCount: c_uint,
1342                              Packed: Bool);
1343
1344     pub fn LLVMConstNamedStruct(S: TypeRef,
1345                                 ConstantVals: *const ValueRef,
1346                                 Count: c_uint)
1347                                 -> ValueRef;
1348
1349     /// Enables LLVM debug output.
1350     pub fn LLVMRustSetDebug(Enabled: c_int);
1351
1352     /// Prepares inline assembly.
1353     pub fn LLVMRustInlineAsm(Ty: TypeRef,
1354                              AsmString: *const c_char,
1355                              Constraints: *const c_char,
1356                              SideEffects: Bool,
1357                              AlignStack: Bool,
1358                              Dialect: AsmDialect)
1359                              -> ValueRef;
1360
1361     pub fn LLVMRustDebugMetadataVersion() -> u32;
1362     pub fn LLVMRustVersionMajor() -> u32;
1363     pub fn LLVMRustVersionMinor() -> u32;
1364
1365     pub fn LLVMRustAddModuleFlag(M: ModuleRef, name: *const c_char, value: u32);
1366
1367     pub fn LLVMRustMetadataAsValue(C: ContextRef, MD: MetadataRef) -> ValueRef;
1368
1369     pub fn LLVMRustDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1370
1371     pub fn LLVMRustDIBuilderDispose(Builder: DIBuilderRef);
1372
1373     pub fn LLVMRustDIBuilderFinalize(Builder: DIBuilderRef);
1374
1375     pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1376                                               Lang: c_uint,
1377                                               File: DIFile,
1378                                               Producer: *const c_char,
1379                                               isOptimized: bool,
1380                                               Flags: *const c_char,
1381                                               RuntimeVer: c_uint,
1382                                               SplitName: *const c_char)
1383                                               -> DIDescriptor;
1384
1385     pub fn LLVMRustDIBuilderCreateFile(Builder: DIBuilderRef,
1386                                        Filename: *const c_char,
1387                                        Directory: *const c_char)
1388                                        -> DIFile;
1389
1390     pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1391                                                  File: DIFile,
1392                                                  ParameterTypes: DIArray)
1393                                                  -> DICompositeType;
1394
1395     pub fn LLVMRustDIBuilderCreateFunction(Builder: DIBuilderRef,
1396                                            Scope: DIDescriptor,
1397                                            Name: *const c_char,
1398                                            LinkageName: *const c_char,
1399                                            File: DIFile,
1400                                            LineNo: c_uint,
1401                                            Ty: DIType,
1402                                            isLocalToUnit: bool,
1403                                            isDefinition: bool,
1404                                            ScopeLine: c_uint,
1405                                            Flags: DIFlags,
1406                                            isOptimized: bool,
1407                                            Fn: ValueRef,
1408                                            TParam: DIArray,
1409                                            Decl: DIDescriptor)
1410                                            -> DISubprogram;
1411
1412     pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef,
1413                                             Name: *const c_char,
1414                                             SizeInBits: u64,
1415                                             AlignInBits: u32,
1416                                             Encoding: c_uint)
1417                                             -> DIBasicType;
1418
1419     pub fn LLVMRustDIBuilderCreatePointerType(Builder: DIBuilderRef,
1420                                               PointeeTy: DIType,
1421                                               SizeInBits: u64,
1422                                               AlignInBits: u32,
1423                                               Name: *const c_char)
1424                                               -> DIDerivedType;
1425
1426     pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef,
1427                                              Scope: DIDescriptor,
1428                                              Name: *const c_char,
1429                                              File: DIFile,
1430                                              LineNumber: c_uint,
1431                                              SizeInBits: u64,
1432                                              AlignInBits: u32,
1433                                              Flags: DIFlags,
1434                                              DerivedFrom: DIType,
1435                                              Elements: DIArray,
1436                                              RunTimeLang: c_uint,
1437                                              VTableHolder: DIType,
1438                                              UniqueId: *const c_char)
1439                                              -> DICompositeType;
1440
1441     pub fn LLVMRustDIBuilderCreateMemberType(Builder: DIBuilderRef,
1442                                              Scope: DIDescriptor,
1443                                              Name: *const c_char,
1444                                              File: DIFile,
1445                                              LineNo: c_uint,
1446                                              SizeInBits: u64,
1447                                              AlignInBits: u32,
1448                                              OffsetInBits: u64,
1449                                              Flags: DIFlags,
1450                                              Ty: DIType)
1451                                              -> DIDerivedType;
1452
1453     pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1454                                                Scope: DIScope,
1455                                                File: DIFile,
1456                                                Line: c_uint,
1457                                                Col: c_uint)
1458                                                -> DILexicalBlock;
1459
1460     pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: DIBuilderRef,
1461                                                    Scope: DIScope,
1462                                                    File: DIFile)
1463                                                    -> DILexicalBlock;
1464
1465     pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1466                                                  Context: DIScope,
1467                                                  Name: *const c_char,
1468                                                  LinkageName: *const c_char,
1469                                                  File: DIFile,
1470                                                  LineNo: c_uint,
1471                                                  Ty: DIType,
1472                                                  isLocalToUnit: bool,
1473                                                  Val: ValueRef,
1474                                                  Decl: DIDescriptor,
1475                                                  AlignInBits: u32)
1476                                                  -> DIGlobalVariable;
1477
1478     pub fn LLVMRustDIBuilderCreateVariable(Builder: DIBuilderRef,
1479                                            Tag: c_uint,
1480                                            Scope: DIDescriptor,
1481                                            Name: *const c_char,
1482                                            File: DIFile,
1483                                            LineNo: c_uint,
1484                                            Ty: DIType,
1485                                            AlwaysPreserve: bool,
1486                                            Flags: DIFlags,
1487                                            ArgNo: c_uint,
1488                                            AlignInBits: u32)
1489                                            -> DIVariable;
1490
1491     pub fn LLVMRustDIBuilderCreateArrayType(Builder: DIBuilderRef,
1492                                             Size: u64,
1493                                             AlignInBits: u32,
1494                                             Ty: DIType,
1495                                             Subscripts: DIArray)
1496                                             -> DIType;
1497
1498     pub fn LLVMRustDIBuilderCreateVectorType(Builder: DIBuilderRef,
1499                                              Size: u64,
1500                                              AlignInBits: u32,
1501                                              Ty: DIType,
1502                                              Subscripts: DIArray)
1503                                              -> DIType;
1504
1505     pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1506                                                 Lo: i64,
1507                                                 Count: i64)
1508                                                 -> DISubrange;
1509
1510     pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1511                                              Ptr: *const DIDescriptor,
1512                                              Count: c_uint)
1513                                              -> DIArray;
1514
1515     pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1516                                                Val: ValueRef,
1517                                                VarInfo: DIVariable,
1518                                                AddrOps: *const i64,
1519                                                AddrOpsCount: c_uint,
1520                                                DL: ValueRef,
1521                                                InsertAtEnd: BasicBlockRef)
1522                                                -> ValueRef;
1523
1524     pub fn LLVMRustDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1525                                              Name: *const c_char,
1526                                              Val: u64)
1527                                              -> DIEnumerator;
1528
1529     pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1530                                                   Scope: DIScope,
1531                                                   Name: *const c_char,
1532                                                   File: DIFile,
1533                                                   LineNumber: c_uint,
1534                                                   SizeInBits: u64,
1535                                                   AlignInBits: u32,
1536                                                   Elements: DIArray,
1537                                                   ClassType: DIType)
1538                                                   -> DIType;
1539
1540     pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef,
1541                                             Scope: DIScope,
1542                                             Name: *const c_char,
1543                                             File: DIFile,
1544                                             LineNumber: c_uint,
1545                                             SizeInBits: u64,
1546                                             AlignInBits: u32,
1547                                             Flags: DIFlags,
1548                                             Elements: DIArray,
1549                                             RunTimeLang: c_uint,
1550                                             UniqueId: *const c_char)
1551                                             -> DIType;
1552
1553     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1554
1555     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1556                                                         Scope: DIScope,
1557                                                         Name: *const c_char,
1558                                                         Ty: DIType,
1559                                                         File: DIFile,
1560                                                         LineNo: c_uint,
1561                                                         ColumnNo: c_uint)
1562                                                         -> DITemplateTypeParameter;
1563
1564
1565     pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1566                                             Scope: DIScope,
1567                                             Name: *const c_char,
1568                                             File: DIFile,
1569                                             LineNo: c_uint)
1570                                             -> DINameSpace;
1571     pub fn LLVMRustDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
1572                                                CompositeType: DIType,
1573                                                TypeArray: DIArray);
1574
1575
1576     pub fn LLVMRustDIBuilderCreateDebugLocation(Context: ContextRef,
1577                                                 Line: c_uint,
1578                                                 Column: c_uint,
1579                                                 Scope: DIScope,
1580                                                 InlinedAt: MetadataRef)
1581                                                 -> ValueRef;
1582     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
1583     pub fn LLVMRustDIBuilderCreateOpPlus() -> i64;
1584
1585     pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef);
1586     pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef);
1587
1588     pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
1589
1590     pub fn LLVMRustPassKind(Pass: PassRef) -> PassKind;
1591     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
1592     pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
1593
1594     pub fn LLVMRustHasFeature(T: TargetMachineRef, s: *const c_char) -> bool;
1595
1596     pub fn LLVMRustPrintTargetCPUs(T: TargetMachineRef);
1597     pub fn LLVMRustPrintTargetFeatures(T: TargetMachineRef);
1598
1599     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
1600                                        CPU: *const c_char,
1601                                        Features: *const c_char,
1602                                        Model: CodeModel,
1603                                        Reloc: RelocMode,
1604                                        Level: CodeGenOptLevel,
1605                                        UseSoftFP: bool,
1606                                        PositionIndependentExecutable: bool,
1607                                        FunctionSections: bool,
1608                                        DataSections: bool)
1609                                        -> TargetMachineRef;
1610     pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1611     pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef, PM: PassManagerRef, M: ModuleRef);
1612     pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1613                                          M: ModuleRef,
1614                                          DisableSimplifyLibCalls: bool);
1615     pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
1616                                                OptLevel: CodeGenOptLevel,
1617                                                MergeFunctions: bool,
1618                                                SLPVectorize: bool,
1619                                                LoopVectorize: bool);
1620     pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef,
1621                                   M: ModuleRef,
1622                                   DisableSimplifyLibCalls: bool);
1623     pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1624     pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1625                                    PM: PassManagerRef,
1626                                    M: ModuleRef,
1627                                    Output: *const c_char,
1628                                    FileType: FileType)
1629                                    -> LLVMRustResult;
1630     pub fn LLVMRustPrintModule(PM: PassManagerRef,
1631                                M: ModuleRef,
1632                                Output: *const c_char,
1633                                Demangle: extern fn(*const c_char,
1634                                                    size_t,
1635                                                    *mut c_char,
1636                                                    size_t) -> size_t);
1637     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1638     pub fn LLVMRustPrintPasses();
1639     pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
1640     pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef, AddLifetimes: bool);
1641     pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef, bc: *const c_char, len: size_t) -> bool;
1642     pub fn LLVMRustLinkInParsedExternalBitcode(M: ModuleRef, M: ModuleRef) -> bool;
1643     pub fn LLVMRustRunRestrictionPass(M: ModuleRef, syms: *const *const c_char, len: size_t);
1644     pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
1645
1646     pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
1647     pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
1648     pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
1649     pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char;
1650     pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char;
1651     pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
1652     pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
1653     pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
1654
1655     pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: *mut *const c_char) -> size_t;
1656
1657     pub fn LLVMRustWriteTwineToString(T: TwineRef, s: RustStringRef);
1658
1659     pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
1660                                            Handler: DiagnosticHandler,
1661                                            DiagnosticContext: *mut c_void);
1662
1663     pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
1664                                                 pass_name_out: RustStringRef,
1665                                                 function_out: *mut ValueRef,
1666                                                 loc_line_out: *mut c_uint,
1667                                                 loc_column_out: *mut c_uint,
1668                                                 loc_filename_out: RustStringRef,
1669                                                 message_out: RustStringRef);
1670     pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
1671                                              cookie_out: *mut c_uint,
1672                                              message_out: *mut TwineRef,
1673                                              instruction_out: *mut ValueRef);
1674
1675     pub fn LLVMRustWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
1676     pub fn LLVMRustGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
1677
1678     pub fn LLVMRustWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
1679
1680     pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: ContextRef,
1681                                                  H: InlineAsmDiagHandler,
1682                                                  CX: *mut c_void);
1683
1684     pub fn LLVMRustWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
1685
1686     pub fn LLVMRustWriteArchive(Dst: *const c_char,
1687                                 NumMembers: size_t,
1688                                 Members: *const RustArchiveMemberRef,
1689                                 WriteSymbtab: bool,
1690                                 Kind: ArchiveKind)
1691                                 -> LLVMRustResult;
1692     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
1693                                     Name: *const c_char,
1694                                     Child: ArchiveChildRef)
1695                                     -> RustArchiveMemberRef;
1696     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
1697
1698     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef, TM: TargetMachineRef);
1699     pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
1700
1701     pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
1702                                          Inputs: *const ValueRef,
1703                                          NumInputs: c_uint)
1704                                          -> OperandBundleDefRef;
1705     pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
1706
1707     pub fn LLVMRustPositionBuilderAtStart(B: BuilderRef, BB: BasicBlockRef);
1708
1709     pub fn LLVMRustSetComdat(M: ModuleRef, V: ValueRef, Name: *const c_char);
1710     pub fn LLVMRustUnsetComdat(V: ValueRef);
1711     pub fn LLVMRustSetModulePIELevel(M: ModuleRef);
1712     pub fn LLVMRustModuleBufferCreate(M: ModuleRef) -> *mut ModuleBuffer;
1713     pub fn LLVMRustModuleBufferPtr(p: *const ModuleBuffer) -> *const u8;
1714     pub fn LLVMRustModuleBufferLen(p: *const ModuleBuffer) -> usize;
1715     pub fn LLVMRustModuleBufferFree(p: *mut ModuleBuffer);
1716     pub fn LLVMRustModuleCost(M: ModuleRef) -> u64;
1717
1718     pub fn LLVMRustThinLTOAvailable() -> bool;
1719     pub fn LLVMRustWriteThinBitcodeToFile(PMR: PassManagerRef,
1720                                           M: ModuleRef,
1721                                           BC: *const c_char) -> bool;
1722     pub fn LLVMRustThinLTOBufferCreate(M: ModuleRef) -> *mut ThinLTOBuffer;
1723     pub fn LLVMRustThinLTOBufferFree(M: *mut ThinLTOBuffer);
1724     pub fn LLVMRustThinLTOBufferPtr(M: *const ThinLTOBuffer) -> *const c_char;
1725     pub fn LLVMRustThinLTOBufferLen(M: *const ThinLTOBuffer) -> size_t;
1726     pub fn LLVMRustCreateThinLTOData(
1727         Modules: *const ThinLTOModule,
1728         NumModules: c_uint,
1729         PreservedSymbols: *const *const c_char,
1730         PreservedSymbolsLen: c_uint,
1731     ) -> *mut ThinLTOData;
1732     pub fn LLVMRustPrepareThinLTORename(
1733         Data: *const ThinLTOData,
1734         Module: ModuleRef,
1735     ) -> bool;
1736     pub fn LLVMRustPrepareThinLTOResolveWeak(
1737         Data: *const ThinLTOData,
1738         Module: ModuleRef,
1739     ) -> bool;
1740     pub fn LLVMRustPrepareThinLTOInternalize(
1741         Data: *const ThinLTOData,
1742         Module: ModuleRef,
1743     ) -> bool;
1744     pub fn LLVMRustPrepareThinLTOImport(
1745         Data: *const ThinLTOData,
1746         Module: ModuleRef,
1747     ) -> bool;
1748     pub fn LLVMRustFreeThinLTOData(Data: *mut ThinLTOData);
1749     pub fn LLVMRustParseBitcodeForThinLTO(
1750         Context: ContextRef,
1751         Data: *const u8,
1752         len: usize,
1753         Identifier: *const c_char,
1754     ) -> ModuleRef;
1755     pub fn LLVMGetModuleIdentifier(M: ModuleRef, size: *mut usize) -> *const c_char;
1756 }